Skip to content

Commit

Permalink
Node/EVM: Add more cases to canRetryGetBlockTime
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley committed Jul 5, 2024
1 parent 2eb5cca commit fc2d182
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions node/pkg/watchers/evm/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/prometheus/client_golang/prometheus"

ethereum "github.com/ethereum/go-ethereum"
eth_common "github.com/ethereum/go-ethereum/common"
eth_hexutil "github.com/ethereum/go-ethereum/common/hexutil"
"go.uber.org/zap"
Expand Down Expand Up @@ -895,9 +894,19 @@ func (w *Watcher) postMessage(logger *zap.Logger, ev *ethabi.AbiLogMessagePublis
w.pendingMu.Unlock()
}

// blockNotFoundErrors is used by `canRetryGetBlockTime`. It is a map of the error returns from `getBlockTime` that can trigger a retry.
var blockNotFoundErrors = map[string]struct{}{
"not found": {},
"Unknown block": {},
"cannot query unfinalized data": {}, // Seen on Avalanche
}

// canRetryGetBlockTime returns true if the error returned by getBlockTime warrants doing a retry.
func canRetryGetBlockTime(err error) bool {
return err == ethereum.NotFound /* go-ethereum */ || err.Error() == "cannot query unfinalized data" /* avalanche */
if _, exists := blockNotFoundErrors[err.Error()]; exists {
return true
}
return false
}

// waitForBlockTime is a go routine that repeatedly attempts to read the block time for a single log event. It is used when the initial attempt to read
Expand Down
10 changes: 10 additions & 0 deletions node/pkg/watchers/evm/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package evm

import (
"encoding/json"
"errors"
"testing"

"github.com/certusone/wormhole/node/pkg/watchers/evm/connectors/ethabi"
ethereum "github.com/ethereum/go-ethereum"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/wormhole-foundation/wormhole/sdk/vaa"
Expand Down Expand Up @@ -40,3 +42,11 @@ func TestMsgIdFromLogEvent(t *testing.T) {
msgId := msgIdFromLogEvent(vaa.ChainIDSepolia, &ev)
assert.Equal(t, "10002/00000000000000000000000045c140dd2526e4bfd1c2a5bb0aa6aa1db00b1744/3685", msgId)
}

func Test_canRetryGetBlockTime(t *testing.T) {
assert.True(t, canRetryGetBlockTime(ethereum.NotFound))
assert.True(t, canRetryGetBlockTime(errors.New("not found")))
assert.True(t, canRetryGetBlockTime(errors.New("Unknown block")))
assert.True(t, canRetryGetBlockTime(errors.New("cannot query unfinalized data")))
assert.False(t, canRetryGetBlockTime(errors.New("Hello, World!")))
}

0 comments on commit fc2d182

Please sign in to comment.