Skip to content

Commit 55693cf

Browse files
committed
chore: Fix format and lint errors
1 parent 89caf32 commit 55693cf

12 files changed

Lines changed: 108 additions & 104 deletions

File tree

node/cmd/guardiand/admintemplate.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,20 +1175,20 @@ func runCoreBridgeSetMessageFeeTemplate(cmd *cobra.Command, args []string) {
11751175
}
11761176

11771177
func runDelegatedGuardiansConfigTemplate(cmd *cobra.Command, args []string) {
1178-
if *delegatedGuardiansConfigId == "" {
1179-
log.Fatal("--config-id must be specified")
1180-
}
1181-
if *delegatedGuardiansConfigJson == "" {
1182-
log.Fatal("--config must be specified")
1183-
}
1178+
if *delegatedGuardiansConfigId == "" {
1179+
log.Fatal("--config-id must be specified")
1180+
}
1181+
if *delegatedGuardiansConfigJson == "" {
1182+
log.Fatal("--config must be specified")
1183+
}
11841184

1185-
// Parse config ID from string to uint32
1186-
configID, err := strconv.ParseUint(*delegatedGuardiansConfigId, 10, 32)
1187-
if err != nil {
1188-
log.Fatal("invalid config-id: ", err)
1189-
}
1185+
// Parse config ID from string to uint32
1186+
configID, err := strconv.ParseUint(*delegatedGuardiansConfigId, 10, 32)
1187+
if err != nil {
1188+
log.Fatal("invalid config-id: ", err)
1189+
}
11901190

1191-
seq, nonce := randSeqNonce()
1191+
seq, nonce := randSeqNonce()
11921192

11931193
m := &nodev1.InjectGovernanceVAARequest{
11941194
CurrentSetIndex: uint32(*templateGuardianIndex), // #nosec G115 -- Number of guardians will never overflow here

node/cmd/guardiand/adminverify.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ func runGovernanceVAAVerify(cmd *cobra.Command, args []string) {
4242
}
4343

4444
digest := v.SigningDigest().Bytes()
45-
if err != nil {
46-
panic(err)
47-
}
4845

4946
b, err := v.Marshal()
5047
if err != nil {

node/pkg/adminrpc/adminserver_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"context"
77
"testing"
88
"time"
9-
"fmt"
9+
1010
wh_common "github.com/certusone/wormhole/node/pkg/common"
1111
"github.com/certusone/wormhole/node/pkg/db"
1212
"github.com/certusone/wormhole/node/pkg/governor"
@@ -469,9 +469,6 @@ func TestDelegatedGuardiansConfigToVaa(t *testing.T) {
469469
require.NotNil(t, v)
470470

471471
verifyGovernanceVAA(t, v, sequence, nonce)
472-
473-
fmt.Println(v.Payload)
474-
475472
assert.NotEmpty(t, v.Payload)
476473
}
477474

@@ -505,4 +502,3 @@ func TestDelegatedGuardiansConfigToVaa_InvalidChainID(t *testing.T) {
505502
require.Error(t, err)
506503
assert.Contains(t, err.Error(), "invalid chain ID")
507504
}
508-

node/pkg/node/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const (
6161
// TODO(delegated-guardian-sets): The buffer size is arbitrarily set and should be verified
6262
// delegateObservationInboundBufferSize configures the size of delegateObsvC.
6363
delegateObservationInboundBufferSize = 1000
64-
64+
6565
// delegateObservationOutboundBufferSize configures the size of delegateObsvSendC.
6666
delegateObservationOutboundBufferSize = 1000
6767
)

node/pkg/p2p/p2p.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ var signedDelegateObservationPrefix = []byte("signed_delegate_observation|")
9292
// heartbeatMaxTimeDifference specifies the maximum time difference between the local clock and the timestamp in incoming heartbeat messages. Heartbeats that are this old or this much into the future will be dropped. This value should encompass clock skew and network delay.
9393
var heartbeatMaxTimeDifference = time.Minute * 15
9494
var observationRequestMaxTimeDifference = time.Minute * 15
95+
9596
// TODO(delegated-guardian-sets): Remove if no freshness check required
9697
var delegateObservationMaxTimeDifference = time.Minute * 15
9798

@@ -691,7 +692,7 @@ func Run(params *RunParams) func(ctx context.Context) error {
691692
} else {
692693
logger.Info("published signed observation request", zap.Any("signed_observation_request", sReq))
693694
}
694-
case msg:= <-params.delegateObsvSendC:
695+
case msg := <-params.delegateObsvSendC:
695696
logger.Debug("p2p: received delegate observation from channel",
696697
zap.Uint32("emitter_chain", msg.EmitterChain),
697698
zap.Uint64("sequence", msg.Sequence),
@@ -923,8 +924,8 @@ func Run(params *RunParams) func(ctx context.Context) error {
923924
gs := params.gst.Get()
924925
if gs == nil {
925926
if logger.Level().Enabled(zapcore.DebugLevel) {
926-
logger.Debug("dropping SignedDelegateObservation - no guardian set",
927-
zap.Any("value", d),
927+
logger.Debug("dropping SignedDelegateObservation - no guardian set",
928+
zap.Any("value", d),
928929
zap.String("from", envelope.GetFrom().String()),
929930
)
930931
}
@@ -1241,7 +1242,7 @@ func processSignedDelegateObservation(d *gossipv1.SignedDelegateObservation, gs
12411242
}
12421243

12431244
digest := signedDelegateObservationDigest(d.DelegateObservation)
1244-
1245+
12451246
pubKey, err := ethcrypto.Ecrecover(digest.Bytes(), d.Signature)
12461247
if err != nil {
12471248
return nil, errors.New("failed to recover public key")

node/pkg/p2p/run_params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type (
5151
gossipAttestationSendC chan []byte
5252
gossipVaaSendC chan []byte
5353
obsvReqSendC <-chan *gossipv1.ObservationRequest
54-
delegateObsvSendC <-chan *gossipv1.DelegateObservation
54+
delegateObsvSendC <-chan *gossipv1.DelegateObservation
5555
acct *accountant.Accountant
5656
gov *governor.ChainGovernor
5757
components *Components

node/pkg/p2p/watermark_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ type G struct {
2929
batchObsvC chan *node_common.MsgWithTimeStamp[gossipv1.SignedObservationBatch]
3030
obsvReqC chan *gossipv1.ObservationRequest
3131
obsvReqSendC chan *gossipv1.ObservationRequest
32-
delegateObsvRecvC chan *gossipv1.DelegateObservation
33-
delegateObsvSendC chan *gossipv1.DelegateObservation
32+
delegateObsvRecvC chan *gossipv1.DelegateObservation
33+
delegateObsvSendC chan *gossipv1.DelegateObservation
3434
controlSendC chan []byte
3535
attestationSendC chan []byte
3636
vaaSendC chan []byte

node/pkg/processor/observation.go

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func signaturesToVaaFormat(signatures map[common.Address][]byte, gsKeys []common
7676

7777
// handleDelegateMessagePublication converts the MessagePublication into a DelegateObservation and sends it to the delegateObsvSendC channel.
7878
// This should only be called by a delegated guardian for the chain.
79-
func (p* Processor) handleDelegateMessagePublication(k *node_common.MessagePublication) error {
79+
func (p *Processor) handleDelegateMessagePublication(k *node_common.MessagePublication) error {
8080
p.logger.Info("handleDelegateMessagePublication: CALLED - converting message to delegate observation",
8181
zap.String("msgID", k.MessageIDString()),
8282
zap.Uint32("emitter_chain", uint32(k.EmitterChain)),
@@ -466,62 +466,66 @@ func (p *Processor) handleInboundSignedVAAWithQuorum(m *gossipv1.SignedVAAWithQu
466466
}
467467

468468
// handleDelegateObservation processes a delegate observation
469-
func (p *Processor) handleDelegateObservation(ctx context.Context, m *gossipv1.DelegateObservation) {
470-
if p.logger.Core().Enabled(zapcore.DebugLevel) {
471-
p.logger.Debug("received delegate observation",
469+
func (p *Processor) handleDelegateObservation(ctx context.Context, m *gossipv1.DelegateObservation) error {
470+
if p.logger.Core().Enabled(zapcore.DebugLevel) {
471+
p.logger.Debug("received delegate observation",
472472
// TODO(delegated-guardian-sets): Add additional relevant fields if necessary
473-
zap.Uint32("emitter_chain", m.EmitterChain),
474-
zap.Uint64("sequence", m.Sequence),
475-
zap.String("txhash", hex.EncodeToString(m.TxHash)),
476-
zap.String("txhash_b58", base58.Encode(m.TxHash)),
473+
zap.Uint32("emitter_chain", m.EmitterChain),
474+
zap.Uint64("sequence", m.Sequence),
475+
zap.String("txhash", hex.EncodeToString(m.TxHash)),
476+
zap.String("txhash_b58", base58.Encode(m.TxHash)),
477477
zap.String("guardian_addr", hex.EncodeToString(m.GuardianAddr)),
478-
)
479-
}
478+
)
479+
}
480+
481+
c, err := vaa.ChainIDFromNumber(m.EmitterChain)
482+
if err != nil {
483+
p.logger.Warn("invalid delegate observation emitter chain", zap.Error(err))
484+
return nil
485+
}
480486

481-
c := vaa.ChainID(m.EmitterChain)
482-
483487
cfg := p.dgc.GetChainConfig(c)
484488
if cfg == nil {
485489
p.logger.Debug("ignoring delegate observation for chain without delegate chain config",
486490
zap.Stringer("emitter_chain", c),
487491
zap.Uint64("sequence", m.Sequence),
488492
)
489-
return
493+
return nil
490494
}
491495

492-
_, ok := cfg.KeyIndex(p.ourAddr)
496+
_, ok := cfg.KeyIndex(p.ourAddr)
493497
if ok {
494-
p.logger.Debug("ignoring delegate observation since we are a delegated guardian for this chain",
498+
p.logger.Debug("ignoring delegate observation since we are a delegated guardian for this chain",
495499
zap.Stringer("emitter_chain", c),
496-
zap.Uint64("sequence", m.Sequence),
500+
zap.Uint64("sequence", m.Sequence),
497501
)
498-
return
502+
return nil
499503
}
500504

501505
addr := common.BytesToAddress(m.GuardianAddr)
502506
_, ok = cfg.KeyIndex(addr)
503507
if !ok {
504-
p.logger.Debug("ignoring delegate observation from non-delegated guardian for this chain",
508+
p.logger.Debug("ignoring delegate observation from non-delegated guardian for this chain",
505509
zap.Stringer("emitter_chain", c),
506-
zap.Uint64("sequence", m.Sequence),
510+
zap.Uint64("sequence", m.Sequence),
507511
zap.String("guardian", addr.Hex()),
508512
)
509-
return
513+
return nil
510514
}
511515

512-
p.handleCanonicalDelegateObservation(ctx, cfg, m)
516+
return p.handleCanonicalDelegateObservation(ctx, cfg, m)
513517
}
514518

515519
// handleCanonicalDelegateObservation processes a delegate observation as a canonical guardian
516520
// This function assumes cfg corresponds to m.EmitterChain
517521
// TODO(delegated-guardian-sets): Should ^ be explicitly asserted?
518-
func (p *Processor) handleCanonicalDelegateObservation(ctx context.Context, cfg *DelegateGuardianChainConfig, m *gossipv1.DelegateObservation) {
522+
func (p *Processor) handleCanonicalDelegateObservation(ctx context.Context, cfg *DelegateGuardianChainConfig, m *gossipv1.DelegateObservation) error {
519523
mp, err := delegateObservationToMessagePublication(m)
520-
if err != nil {
521-
p.logger.Warn("failed to convert delegate observation to message publication", zap.Error(err))
522-
return
523-
}
524-
524+
if err != nil {
525+
p.logger.Warn("failed to convert delegate observation to message publication", zap.Error(err))
526+
return nil
527+
}
528+
525529
hash := mp.CreateDigest()
526530

527531
// Get / create our state entry.
@@ -539,15 +543,16 @@ func (p *Processor) handleCanonicalDelegateObservation(ctx context.Context, cfg
539543
s.observations[addr] = m
540544

541545
if !s.submitted {
542-
p.checkForDelegateQuorum(ctx, mp, s, cfg)
546+
return p.checkForDelegateQuorum(ctx, mp, s, cfg)
543547
}
548+
return nil
544549
}
545550

546-
// checkForDelegateQuorum checks for quorum after a delegate observation has been added to the state. If quorum is met, it runs the converted
551+
// checkForDelegateQuorum checks for quorum after a delegate observation has been added to the state. If quorum is met, it runs the converted
547552
// MessagePublication through the normal message pipeline.
548553
// This function assumes mp corresponds to s
549554
// TODO(delegated-guardian-sets): Should ^ be explicitly asserted?
550-
func (p *Processor) checkForDelegateQuorum(ctx context.Context, mp *node_common.MessagePublication, s *delegateState, dgs *DelegateGuardianChainConfig) {
555+
func (p *Processor) checkForDelegateQuorum(ctx context.Context, mp *node_common.MessagePublication, s *delegateState, dgs *DelegateGuardianChainConfig) error {
551556
// TODO(delegated-guardian-sets): Handle case for when delegate guardian set changes
552557
// Check if we have more delegate observations than required for quorum.
553558
if len(s.observations) < dgs.Quorum() {
@@ -556,14 +561,14 @@ func (p *Processor) checkForDelegateQuorum(ctx context.Context, mp *node_common.
556561
if p.logger.Level().Enabled(zapcore.DebugLevel) {
557562
p.logger.Debug("quorum not yet met",
558563
zap.Stringer("emitter_chain", c),
559-
zap.Uint64("sequence", mp.Sequence),
564+
zap.Uint64("sequence", mp.Sequence),
560565
)
561566
}
562-
return
567+
return nil
563568
}
564569

565570
s.submitted = true
566-
p.handleMessagePublication(ctx, mp)
571+
return p.handleMessagePublication(ctx, mp)
567572
}
568573

569574
// delegateObservationToMessagePublication converts a DelegateObservation into a MessagePublication that can be passed through the normal processor pipeline.
@@ -577,31 +582,35 @@ func delegateObservationToMessagePublication(d *gossipv1.DelegateObservation) (*
577582
return nil, fmt.Errorf("delegate observation tx_hash too short: got %d; want at least %d", txIDLen, node_common.TxIDLenMin)
578583
}
579584

580-
addr, err := vaa.BytesToAddress(d.EmitterAddress)
581-
if err != nil {
582-
return nil, fmt.Errorf("invalid delegate observation emitter address: %w", err)
585+
if d.ConsistencyLevel > math.MaxUint8 {
586+
return nil, fmt.Errorf("invalid delegate observation consistency : %d", d.ConsistencyLevel)
583587
}
584588

585589
c, err := vaa.ChainIDFromNumber(d.EmitterChain)
586590
if err != nil {
587591
return nil, fmt.Errorf("invalid delegate observation emitter chain: %w", err)
588592
}
589593

590-
mp := &node_common.MessagePublication{
591-
TxID: d.TxHash,
592-
Timestamp: time.Unix(int64(d.Timestamp), 0), // Timestamp is uint32 representing seconds since UNIX epoch so is safe to convert.
593-
Nonce: d.Nonce,
594-
Sequence: d.Sequence,
595-
ConsistencyLevel: uint8(d.ConsistencyLevel),
596-
EmitterChain: c,
597-
EmitterAddress: addr,
598-
Payload: d.Payload,
599-
IsReobservation: false,
600-
Unreliable: false,
601-
// verificationState intentionally left at the default (NotVerified).
602-
}
603-
604-
return mp, nil
594+
addr, err := vaa.BytesToAddress(d.EmitterAddress)
595+
if err != nil {
596+
return nil, fmt.Errorf("invalid delegate observation emitter address: %w", err)
597+
}
598+
599+
mp := &node_common.MessagePublication{
600+
TxID: d.TxHash,
601+
Timestamp: time.Unix(int64(d.Timestamp), 0), // Timestamp is uint32 representing seconds since UNIX epoch so is safe to convert.
602+
Nonce: d.Nonce,
603+
Sequence: d.Sequence,
604+
ConsistencyLevel: uint8(d.ConsistencyLevel),
605+
EmitterChain: c,
606+
EmitterAddress: addr,
607+
Payload: d.Payload,
608+
IsReobservation: false,
609+
Unreliable: false,
610+
// verificationState intentionally left at the default (NotVerified).
611+
}
612+
613+
return mp, nil
605614
}
606615

607616
// messagePublicationToDelegateObservation converts a MessagePublication into a DelegateObservation to be sent by a delegated guardian.

node/pkg/processor/processor.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ type (
8787
signatures observationMap
8888
}
8989

90-
9190
// delegateState represents the local view of a given delegate observation
9291
delegateState struct {
9392
// First time this digest was seen.
@@ -104,7 +103,7 @@ type (
104103

105104
// delegateAggregationState represents the node's aggregation of delegate guardian signatures.
106105
delegateAggregationState struct {
107-
observations delegateObservationMap
106+
observations delegateObservationMap
108107
}
109108
)
110109

@@ -277,7 +276,7 @@ func NewProcessor(
277276
gossipAttestationSendC: gossipAttestationSendC,
278277
gossipVaaSendC: gossipVaaSendC,
279278
batchObsvC: batchObsvC,
280-
delegateObsvC: delegateObsvC,
279+
delegateObsvC: delegateObsvC,
281280
obsvReqSendC: obsvReqSendC,
282281
delegateObsvSendC: delegateObsvSendC,
283282
signedInC: signedInC,
@@ -299,7 +298,7 @@ func NewProcessor(
299298
batchObsvPubC: make(chan *gossipv1.Observation, batchObsvPubChanSize),
300299
updatedVAAs: make(map[string]*updateVaaEntry),
301300
networkID: networkID,
302-
dgc: NewDelegateGuardianConfig(),
301+
dgc: NewDelegateGuardianConfig(),
303302
}
304303
}
305304

@@ -414,7 +413,9 @@ func (p *Processor) Run(ctx context.Context) error {
414413
case m := <-p.signedInC:
415414
p.handleInboundSignedVAAWithQuorum(m)
416415
case m := <-p.delegateObsvC:
417-
p.handleDelegateObservation(ctx, m)
416+
if err := p.handleDelegateObservation(ctx, m); err != nil {
417+
return err
418+
}
418419
case <-cleanup.C:
419420
p.handleCleanup(ctx)
420421
case <-pollTimer.C:

node/pkg/watchers/evm/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import (
1313
)
1414

1515
type WatcherConfig struct {
16-
NetworkID watchers.NetworkID // human readable name
17-
ChainID vaa.ChainID // ChainID
18-
Rpc string // RPC URL
19-
Contract string // hex representation of the contract address
20-
GuardianSetUpdateChain bool // if `true`, we will retrieve the GuardianSet from this chain and watch this chain for GuardianSet updates
21-
DelegatedGuardiansContract string // hex representation of the delegated guardians contract address
22-
DelegatedGuardiansUpdateChain bool // if `true`, we will retrieve the DelegatedGuardians config from this chain
23-
CcqBackfillCache bool
24-
TxVerifierEnabled bool
25-
DgConfigC chan<- *processor.DelegateGuardianConfig // Delegated guardian config channel, set by GuardianOptionWatchers
16+
NetworkID watchers.NetworkID // human readable name
17+
ChainID vaa.ChainID // ChainID
18+
Rpc string // RPC URL
19+
Contract string // hex representation of the contract address
20+
GuardianSetUpdateChain bool // if `true`, we will retrieve the GuardianSet from this chain and watch this chain for GuardianSet updates
21+
DelegatedGuardiansContract string // hex representation of the delegated guardians contract address
22+
DelegatedGuardiansUpdateChain bool // if `true`, we will retrieve the DelegatedGuardians config from this chain
23+
CcqBackfillCache bool
24+
TxVerifierEnabled bool
25+
DgConfigC chan<- *processor.DelegateGuardianConfig // Delegated guardian config channel, set by GuardianOptionWatchers
2626
}
2727

2828
func (wc *WatcherConfig) GetNetworkID() watchers.NetworkID {

0 commit comments

Comments
 (0)