Skip to content

Commit

Permalink
Guardian eth nil event check (wormhole-foundation#1300)
Browse files Browse the repository at this point in the history
* Guardian eth nil event check

* Check for number being nil in watcher
  • Loading branch information
bruce-riley authored Jun 23, 2022
1 parent fe198be commit cdc6edd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
8 changes: 8 additions & 0 deletions node/pkg/celo/celoimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ func (e *CeloImpl) SubscribeForBlocks(ctx context.Context, sink chan<- *common.N
case <-ctx.Done():
return
case ev := <-headSink:
if ev == nil {
e.logger.Error("new header event is nil", zap.String("eth_network", e.NetworkName))
continue
}
if ev.Number == nil {
e.logger.Error("new header block number is nil", zap.String("eth_network", e.NetworkName))
continue
}
sink <- &common.NewBlock{
Number: ev.Number,
Hash: ethCommon.BytesToHash(ev.Hash().Bytes()),
Expand Down
13 changes: 12 additions & 1 deletion node/pkg/ethereum/ethimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ import (

type EthImpl struct {
NetworkName string
logger *zap.Logger
client *ethClient.Client
filterer *ethAbi.AbiFilterer
caller *ethAbi.AbiCaller
}

func (e *EthImpl) SetLogger(_l *zap.Logger) {}
func (e *EthImpl) SetLogger(l *zap.Logger) {
e.logger = l
}

func (e *EthImpl) DialContext(ctx context.Context, rawurl string) (err error) {
e.client, err = ethClient.DialContext(ctx, rawurl)
Expand Down Expand Up @@ -115,6 +118,14 @@ func (e *EthImpl) SubscribeForBlocks(ctx context.Context, sink chan<- *common.Ne
case <-ctx.Done():
return
case ev := <-headSink:
if ev == nil {
e.logger.Error("new header event is nil", zap.String("eth_network", e.NetworkName))
continue
}
if ev.Number == nil {
e.logger.Error("new header block number is nil", zap.String("eth_network", e.NetworkName))
continue
}
sink <- &common.NewBlock{
Number: ev.Number,
Hash: ev.Hash(),
Expand Down
5 changes: 0 additions & 5 deletions node/pkg/ethereum/getlogsimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ func (f *GetLogsQuery) DialContext(ctx context.Context, rawurl string) (err erro
timeout, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()
f.client, err = ethClient.DialContext(timeout, rawurl)

if err != nil {
return err
}

return err
}

Expand Down
5 changes: 5 additions & 0 deletions node/pkg/ethereum/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,15 @@ func (e *Watcher) Run(ctx context.Context) error {
p2p.DefaultRegistry.AddErrorCount(e.chainID, 1)
return
case ev := <-headSink:
// These two pointers should have been checked before the event was placed on the channel, but just being safe.
if ev == nil {
logger.Error("new header event is nil", zap.String("eth_network", e.networkName))
continue
}
if ev.Number == nil {
logger.Error("new header block number is nil", zap.String("eth_network", e.networkName))
continue
}

start := time.Now()
currentHash := ev.Hash
Expand Down

0 comments on commit cdc6edd

Please sign in to comment.