Skip to content

Commit

Permalink
Reformat files with golines
Browse files Browse the repository at this point in the history
  • Loading branch information
schmir committed Oct 5, 2023
1 parent 4868f55 commit 6d69a8c
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 34 deletions.
8 changes: 6 additions & 2 deletions rolling-shutter/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,10 @@ func (app *ShutterApp) handlePolyEvalMsg(msg *shmsg.PolyEval, sender common.Addr
}
}

func (app *ShutterApp) handlePolyCommitmentMsg(msg *shmsg.PolyCommitment, sender common.Address) abcitypes.ResponseDeliverTx {
func (app *ShutterApp) handlePolyCommitmentMsg(
msg *shmsg.PolyCommitment,
sender common.Address,
) abcitypes.ResponseDeliverTx {
appMsg, err := ParsePolyCommitmentMsg(msg, sender)
if err != nil {
msg := fmt.Sprintf("Error: Failed to parse PolyCommitment message: %+v", err)
Expand Down Expand Up @@ -717,7 +720,8 @@ func (app *ShutterApp) EndBlock(req abcitypes.RequestEndBlock) abcitypes.Respons
}.MakeABCIEvent())
}
}
if config.Started && !config.ValidatorsUpdated && app.countCheckedInKeypers(config.Keypers) >= numRequiredTransitionValidators(config) {
if config.Started && !config.ValidatorsUpdated &&
app.countCheckedInKeypers(config.Keypers) >= numRequiredTransitionValidators(config) {
config.ValidatorsUpdated = true
}
}
Expand Down
6 changes: 5 additions & 1 deletion rolling-shutter/app/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ func (dkg *DKGInstance) RegisterPolyEvalMsg(msg PolyEval) error {
}
_, ok := dkg.PolyEvalsSeen[SenderReceiverPair{sender, receiver}]
if ok {
return errors.Errorf("polynomial evaluation from keyper %s for receiver %s already present", sender.Hex(), receiver.Hex())
return errors.Errorf(
"polynomial evaluation from keyper %s for receiver %s already present",
sender.Hex(),
receiver.Hex(),
)
}
}

Expand Down
12 changes: 10 additions & 2 deletions rolling-shutter/app/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func validateAddress(address []byte) (common.Address, error) {
// ParsePolyEvalMsg converts a shmsg.PolyEvalMsg to an app.PolyEvalMsg.
func ParsePolyEvalMsg(msg *shmsg.PolyEval, sender common.Address) (*PolyEval, error) {
if len(msg.Receivers) != len(msg.EncryptedEvals) {
return nil, errors.Errorf("number of receivers %d does not match number of evals %d", len(msg.Receivers), len(msg.EncryptedEvals))
return nil, errors.Errorf(
"number of receivers %d does not match number of evals %d",
len(msg.Receivers),
len(msg.EncryptedEvals),
)
}

receivers := []common.Address{}
Expand Down Expand Up @@ -95,7 +99,11 @@ func ParseAccusationMsg(msg *shmsg.Accusation, sender common.Address) (*Accusati
// ParseApologyMsg converts a shmsg.ApologyMsg to an app.ApologyMsg.
func ParseApologyMsg(msg *shmsg.Apology, sender common.Address) (*Apology, error) {
if len(msg.Accusers) != len(msg.PolyEvals) {
return nil, errors.Errorf("number of accusers %d and apology evals %d not equal", len(msg.Accusers), len(msg.PolyEvals))
return nil, errors.Errorf(
"number of accusers %d and apology evals %d not equal",
len(msg.Accusers),
len(msg.PolyEvals),
)
}

accusers := []common.Address{}
Expand Down
5 changes: 4 additions & 1 deletion rolling-shutter/cmd/chain/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ func initFilesWithConfig(tendermintConfig *cfg.Config, config *Config, appState
if err != nil {
return errors.Wrapf(err, "Could not write to %s", validatorPubKeyPath)
}
log.Info().Str("path", validatorPubKeyPath).Str("validatorPublicKey", validatorPublicKeyHex).Msg("Saved private validator publickey")
log.Info().
Str("path", validatorPubKeyPath).
Str("validatorPublicKey", validatorPublicKeyHex).
Msg("Saved private validator publickey")

// genesis file
genFile := tendermintConfig.GenesisFile()
Expand Down
8 changes: 7 additions & 1 deletion rolling-shutter/collator/batcher/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ func TestConfirmTransactionsIntegration(t *testing.T) {
assert.NilError(t, err)
assert.Equal(t, 5, len(txs), "should have exactly one tx: %+v", txs)
for nonce := 0; nonce < 5; nonce++ {
assert.Equal(t, cltrdb.TxstatusCommitted, txs[nonce].Status, "expected tx to have status committed: %+v", txs[nonce])
assert.Equal(
t,
cltrdb.TxstatusCommitted,
txs[nonce].Status,
"expected tx to have status committed: %+v",
txs[nonce],
)
}
}

Expand Down
6 changes: 5 additions & 1 deletion rolling-shutter/keyper/epochkghandler/eonpublickey.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ func (*EonPublicKeyHandler) MessagePrototypes() []p2pmsg.Message {
func (handler *EonPublicKeyHandler) ValidateMessage(_ context.Context, msg p2pmsg.Message) (bool, error) {
key := msg.(*p2pmsg.EonPublicKey)
if key.GetInstanceID() != handler.config.GetInstanceID() {
return false, errors.Errorf("instance ID mismatch (want=%d, have=%d)", handler.config.GetInstanceID(), key.GetInstanceID())
return false, errors.Errorf(
"instance ID mismatch (want=%d, have=%d)",
handler.config.GetInstanceID(),
key.GetInstanceID(),
)
}
return true, nil
}
Expand Down
6 changes: 5 additions & 1 deletion rolling-shutter/keyper/epochkghandler/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func (*DecryptionKeyHandler) MessagePrototypes() []p2pmsg.Message {
func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2pmsg.Message) (bool, error) {
key := msg.(*p2pmsg.DecryptionKey)
if key.GetInstanceID() != handler.config.GetInstanceID() {
return false, errors.Errorf("instance ID mismatch (want=%d, have=%d)", handler.config.GetInstanceID(), key.GetInstanceID())
return false, errors.Errorf(
"instance ID mismatch (want=%d, have=%d)",
handler.config.GetInstanceID(),
key.GetInstanceID(),
)
}
if _, err := epochid.BytesToEpochID(key.EpochID); err != nil {
return false, errors.Wrapf(err, "invalid epoch id")
Expand Down
11 changes: 9 additions & 2 deletions rolling-shutter/keyper/epochkghandler/keyshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ func (*DecryptionKeyShareHandler) MessagePrototypes() []p2pmsg.Message {
func (handler *DecryptionKeyShareHandler) ValidateMessage(ctx context.Context, msg p2pmsg.Message) (bool, error) {
keyShare := msg.(*p2pmsg.DecryptionKeyShares)
if keyShare.GetInstanceID() != handler.config.GetInstanceID() {
return false, errors.Errorf("instance ID mismatch (want=%d, have=%d)", handler.config.GetInstanceID(), keyShare.GetInstanceID())
return false, errors.Errorf(
"instance ID mismatch (want=%d, have=%d)",
handler.config.GetInstanceID(),
keyShare.GetInstanceID(),
)
}
if keyShare.Eon > math.MaxInt64 {
return false, errors.Errorf("eon %d overflows int64", keyShare.Eon)
Expand Down Expand Up @@ -78,7 +82,10 @@ func (handler *DecryptionKeyShareHandler) ValidateMessage(ctx context.Context, m
return true, nil
}

func (handler *DecryptionKeyShareHandler) HandleMessage(ctx context.Context, m p2pmsg.Message) ([]p2pmsg.Message, error) {
func (handler *DecryptionKeyShareHandler) HandleMessage(
ctx context.Context,
m p2pmsg.Message,
) ([]p2pmsg.Message, error) {
metricsEpochKGDecryptionKeySharesReceived.Inc()
msg := m.(*p2pmsg.DecryptionKeyShares)
// Insert the share into the db. We assume that it's valid as it already passed the libp2p
Expand Down
23 changes: 19 additions & 4 deletions rolling-shutter/keyper/epochkghandler/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func (*DecryptionTriggerHandler) MessagePrototypes() []p2pmsg.Message {
func (handler *DecryptionTriggerHandler) ValidateMessage(ctx context.Context, msg p2pmsg.Message) (bool, error) {
trigger := msg.(*p2pmsg.DecryptionTrigger)
if trigger.GetInstanceID() != handler.config.GetInstanceID() {
return false, errors.Errorf("instance ID mismatch (want=%d, have=%d)", handler.config.GetInstanceID(), trigger.GetInstanceID())
return false, errors.Errorf(
"instance ID mismatch (want=%d, have=%d)",
handler.config.GetInstanceID(),
trigger.GetInstanceID(),
)
}
if _, err := epochid.BytesToEpochID(trigger.EpochID); err != nil {
return false, errors.Wrapf(err, "invalid epoch id")
Expand All @@ -53,20 +57,31 @@ func (handler *DecryptionTriggerHandler) ValidateMessage(ctx context.Context, ms

collator, err := shdb.DecodeAddress(chainCollator.Collator)
if err != nil {
return false, errors.Wrapf(err, "error while converting collator from string to address: %s", chainCollator.Collator)
return false, errors.Wrapf(
err,
"error while converting collator from string to address: %s",
chainCollator.Collator,
)
}

signatureValid, err := p2pmsg.VerifySignature(trigger, collator)
if err != nil {
return false, errors.Wrapf(err, "error while verifying decryption trigger signature for epoch: %x", trigger.EpochID)
return false, errors.Wrapf(
err,
"error while verifying decryption trigger signature for epoch: %x",
trigger.EpochID,
)
}
if !signatureValid {
return false, errors.Errorf("decryption trigger signature invalid for epoch: %x", trigger.EpochID)
}
return signatureValid, nil
}

func (handler *DecryptionTriggerHandler) HandleMessage(ctx context.Context, m p2pmsg.Message) ([]p2pmsg.Message, error) {
func (handler *DecryptionTriggerHandler) HandleMessage(
ctx context.Context,
m p2pmsg.Message,
) ([]p2pmsg.Message, error) {
msg, ok := m.(*p2pmsg.DecryptionTrigger)
if !ok {
return nil, errors.New("Message type assertion mismatch")
Expand Down
3 changes: 2 additions & 1 deletion rolling-shutter/keyper/keyper.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ func (kpr *keyper) handleOnChainKeyperSetChanges(
}
// We *MUST* check if the l1BlockNumber is smaller than the activationBlockNumber since both are uint64 and therefore subtraction can never result in negative numbers.
// This means that if we missed the activationBlockNumber we will never submit the config.
if l1BlockNumber < activationBlockNumber && activationBlockNumber-l1BlockNumber > kpr.config.Shuttermint.DKGStartBlockDelta {
if l1BlockNumber < activationBlockNumber &&
activationBlockNumber-l1BlockNumber > kpr.config.Shuttermint.DKGStartBlockDelta {
log.Info().Interface("keyper-set", keyperSet).
Uint64("l1-block-number", l1BlockNumber).
Uint64("dkg-start-delta", kpr.config.Shuttermint.DKGStartBlockDelta).
Expand Down
15 changes: 13 additions & 2 deletions rolling-shutter/medley/eventsyncer/eventsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ type EventSyncer struct {
// New creates a new event syncer. It will look for events starting at a certain block number and
// log index. The types of events to filter for are specified as a set of EventTypes. The finality
// offset is the number of blocks we trail behind the current block to be safe from reorgs.
func New(client *ethclient.Client, finalityOffset uint64, events []*EventType, fromBlock uint64, fromLogIndex uint64) *EventSyncer {
func New(
client *ethclient.Client,
finalityOffset uint64,
events []*EventType,
fromBlock uint64,
fromLogIndex uint64,
) *EventSyncer {
return &EventSyncer{
Client: client,
FinalityOffset: finalityOffset,
Expand Down Expand Up @@ -219,7 +225,12 @@ func (s *EventSyncer) syncAllInRange(ctx context.Context, fromBlock uint64, toBl
}

// syncSingleInRange returns the events matching the given type in the given block range.
func (s *EventSyncer) syncSingleInRange(ctx context.Context, event *EventType, fromBlock uint64, toBlock uint64) ([]logChannelItem, error) {
func (s *EventSyncer) syncSingleInRange(
ctx context.Context,
event *EventType,
fromBlock uint64,
toBlock uint64,
) ([]logChannelItem, error) {
topic := event.ABI.Events[event.Name].ID
query := ethereum.FilterQuery{
BlockHash: nil,
Expand Down
8 changes: 7 additions & 1 deletion rolling-shutter/medley/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import (
// Adapted from https://ethereum.stackexchange.com/a/80766

// GetRevertReason returns the reason for a failed transaction.
func GetRevertReason(ctx context.Context, b ethereum.ContractCaller, from common.Address, tx *types.Transaction, blockNum *big.Int) error {
func GetRevertReason(
ctx context.Context,
b ethereum.ContractCaller,
from common.Address,
tx *types.Transaction,
blockNum *big.Int,
) error {
msg := ethereum.CallMsg{
From: from,
To: tx.To(),
Expand Down
15 changes: 12 additions & 3 deletions rolling-shutter/medley/testkeygen/keygenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func (tkg *TestKeyGenerator) EonKeysForEpoch(epochID epochid.EpochID) *EonKeys {
return res
}

func (tkg *TestKeyGenerator) EonPublicKeyShare(epochID epochid.EpochID, keyperIndex uint64) *shcrypto.EonPublicKeyShare {
func (tkg *TestKeyGenerator) EonPublicKeyShare(
epochID epochid.EpochID,
keyperIndex uint64,
) *shcrypto.EonPublicKeyShare {
tkg.t.Helper()
return tkg.EonKeysForEpoch(epochID).keyperShares[keyperIndex].eonPublicKeyShare
}
Expand All @@ -69,12 +72,18 @@ func (tkg *TestKeyGenerator) EonPublicKey(epochID epochid.EpochID) *shcrypto.Eon
return tkg.EonKeysForEpoch(epochID).publicKey
}

func (tkg *TestKeyGenerator) EonSecretKeyShare(epochID epochid.EpochID, keyperIndex uint64) *shcrypto.EonSecretKeyShare {
func (tkg *TestKeyGenerator) EonSecretKeyShare(
epochID epochid.EpochID,
keyperIndex uint64,
) *shcrypto.EonSecretKeyShare {
tkg.t.Helper()
return tkg.EonKeysForEpoch(epochID).keyperShares[keyperIndex].eonSecretKeyShare
}

func (tkg *TestKeyGenerator) EpochSecretKeyShare(epochID epochid.EpochID, keyperIndex uint64) *shcrypto.EpochSecretKeyShare {
func (tkg *TestKeyGenerator) EpochSecretKeyShare(
epochID epochid.EpochID,
keyperIndex uint64,
) *shcrypto.EpochSecretKeyShare {
tkg.t.Helper()
return tkg.EonKeysForEpoch(epochID).keyperShares[keyperIndex].ComputeEpochSecretKeyShare(epochID)
}
Expand Down
14 changes: 12 additions & 2 deletions rolling-shutter/medley/txbatch/txbatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ func (txbatch *TXBatch) WaitMined(ctx context.Context) ([]*types.Receipt, error)
}
res = append(res, receipt)
if receipt.Status != 1 {
err = medley.GetRevertReason(ctx, txbatch.Ethclient, crypto.PubkeyToAddress(txbatch.key.PublicKey), tx, receipt.BlockNumber)
err = medley.GetRevertReason(
ctx,
txbatch.Ethclient,
crypto.PubkeyToAddress(txbatch.key.PublicKey),
tx,
receipt.BlockNumber,
)
fmt.Print("\n")
log.Info().Err(err).Str("hash", tx.Hash().Hex()).Int("index", i).
Msg("transaction reverted")
Expand All @@ -71,7 +77,11 @@ func (txbatch *TXBatch) WaitMined(ctx context.Context) ([]*types.Receipt, error)
}

// InitTransactOpts initializes the transact options struct.
func InitTransactOpts(ctx context.Context, client *ethclient.Client, key *ecdsa.PrivateKey) (*bind.TransactOpts, error) {
func InitTransactOpts(
ctx context.Context,
client *ethclient.Client,
key *ecdsa.PrivateKey,
) (*bind.TransactOpts, error) {
chainID, err := client.ChainID(ctx)
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion rolling-shutter/mocksequencer/rpc/service_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func (s *AdminService) Name() string {
func (s *AdminService) AddCollator(address string, l1BlockNumber uint64) (int, error) {
var err error
defer func() {
log.Info().Err(err).Str("address", address).Uint64("l1-blocknumber", l1BlockNumber).Msg("admin method AddCollator called")
log.Info().
Err(err).
Str("address", address).
Uint64("l1-blocknumber", l1BlockNumber).
Msg("admin method AddCollator called")
}()

collator, err := encoding.StringToAddress(address)
Expand Down
11 changes: 9 additions & 2 deletions rolling-shutter/mocksequencer/rpc/service_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ func (s *EthService) Name() string {
return "eth"
}

func (s *EthService) GetTransactionCount(address common.Address, blockNrOrHash ethrpc.BlockNumberOrHash) (*hexutil.Uint64, error) {
func (s *EthService) GetTransactionCount(
address common.Address,
blockNrOrHash ethrpc.BlockNumberOrHash,
) (*hexutil.Uint64, error) {
s.processor.Mux.RLock()
defer s.processor.Mux.RUnlock()
block, err := s.processor.GetBlock(blockNrOrHash)
Expand Down Expand Up @@ -86,7 +89,11 @@ func (s *EthService) ChainId() *hexutil.Big {
return (*hexutil.Big)(s.processor.ChainID())
}

func (s *EthService) GetBlockByNumber(_ context.Context, blockNumber ethrpc.BlockNumber, _ bool) (map[string]interface{}, error) {
func (s *EthService) GetBlockByNumber(
_ context.Context,
blockNumber ethrpc.BlockNumber,
_ bool,
) (map[string]interface{}, error) {
var result map[string]interface{}
s.processor.Mux.RLock()
defer s.processor.Mux.RUnlock()
Expand Down
13 changes: 11 additions & 2 deletions rolling-shutter/mocksequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ func (b *BlockData) GetNonce(a common.Address) uint64 {
return nonce
}

func CreateNextBlockData(baseFee *big.Int, gasLimit uint64, feeBeneficiary common.Address, previous *BlockData) *BlockData {
func CreateNextBlockData(
baseFee *big.Int,
gasLimit uint64,
feeBeneficiary common.Address,
previous *BlockData,
) *BlockData {
gasPool := core.GasPool(gasLimit)
bd := &BlockData{
mux: sync.Mutex{},
Expand Down Expand Up @@ -404,7 +409,11 @@ func (proc *Sequencer) ProcessEncryptedTx(
}

shutterTxStr, _ := tx.MarshalJSON()
log.Ctx(ctx).Info().Str("signer", sender.Hex()).RawJSON("transaction", shutterTxStr).Msg("received shutter transaction")
log.Ctx(ctx).
Info().
Str("signer", sender.Hex()).
RawJSON("transaction", shutterTxStr).
Msg("received shutter transaction")

if tx.L1BlockNumber() != batchL1BlockNumber {
return errors.New("l1-block-number mismatch")
Expand Down
5 changes: 4 additions & 1 deletion rolling-shutter/p2p/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func UnmarshalPubsubMessage(msg *pubsub.Message) (p2pmsg.Message, *p2pmsg.TraceC

err = unmshl.Validate()
if err != nil {
return nil, traceContext, errors.Wrap(err, fmt.Sprintf("verification failed <%s>", reflect.TypeOf(unmshl).String()))
return nil, traceContext, errors.Wrap(
err,
fmt.Sprintf("verification failed <%s>", reflect.TypeOf(unmshl).String()),
)
}
return unmshl, traceContext, nil
}
6 changes: 5 additions & 1 deletion rolling-shutter/p2pmsg/messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import (
"github.com/shutter-network/rolling-shutter/rolling-shutter/trace"
)

func marshalUnmarshalMessage[M Message](t *testing.T, message M, traceContext *TraceContext) (M, *TraceContext) { //nolint:thelper
func marshalUnmarshalMessage[M Message]( //nolint:thelper
t *testing.T,
message M,
traceContext *TraceContext,
) (M, *TraceContext) {
var (
err error
ok bool
Expand Down
Loading

0 comments on commit 6d69a8c

Please sign in to comment.