Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node/EVM: Add more cases to canRetryGetBlockTime #4010

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 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,17 @@ 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 */
_, exists := blockNotFoundErrors[err.Error()]
return exists
}

// 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!")))
}
Loading