From 2bdc47d5c7968cfcf17a541c750320db39e08eb7 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Tue, 4 Jun 2024 11:16:29 -0500 Subject: [PATCH 1/3] retry fetch logs --- types/types.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/types/types.go b/types/types.go index f9df9ffd..b0ddd011 100644 --- a/types/types.go +++ b/types/types.go @@ -6,7 +6,9 @@ package types import ( "context" "errors" + "fmt" "math/big" + "time" "github.com/ava-labs/subnet-evm/core/types" "github.com/ava-labs/subnet-evm/ethclient" @@ -18,6 +20,8 @@ import ( var WarpPrecompileLogFilter = warp.WarpABI.Events["SendWarpMessage"].ID var ErrInvalidLog = errors.New("invalid warp message log") +const filterLogsRetries = 5 + // WarpBlockInfo describes the block height and logs needed to process Warp messages. // WarpBlockInfo instances are populated by the subscriber, and forwared to the // listener to process @@ -43,14 +47,22 @@ func NewWarpBlockInfo(header *types.Header, ethClient ethclient.Client) (*WarpBl ) // Check if the block contains warp logs, and fetch them from the client if it does if header.Bloom.Test(WarpPrecompileLogFilter[:]) { - logs, err = ethClient.FilterLogs(context.Background(), interfaces.FilterQuery{ - Topics: [][]common.Hash{{WarpPrecompileLogFilter}}, - Addresses: []common.Address{warp.ContractAddress}, - FromBlock: big.NewInt(int64(header.Number.Uint64())), - ToBlock: big.NewInt(int64(header.Number.Uint64())), - }) - if err != nil { - return nil, err + // The node serving the filter logs request may be behind the node serving the block header request, + // so we retry a few times to ensure we get the logs + for i := 0; i < filterLogsRetries; i++ { + logs, err = ethClient.FilterLogs(context.Background(), interfaces.FilterQuery{ + Topics: [][]common.Hash{{WarpPrecompileLogFilter}}, + Addresses: []common.Address{warp.ContractAddress}, + FromBlock: big.NewInt(int64(header.Number.Uint64())), + ToBlock: big.NewInt(int64(header.Number.Uint64())), + }) + if err == nil { + break + } + if i == filterLogsRetries-1 { + return nil, fmt.Errorf("failed to fetch warp logs for block %d after %d retries: %w", header.Number.Uint64(), filterLogsRetries, err) + } + time.Sleep(1 * time.Second) } } return &WarpBlockInfo{ From 45afd570a221e7d6b7eaad8f8df06063cafb43f4 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Tue, 4 Jun 2024 15:56:36 -0500 Subject: [PATCH 2/3] fetch logs helper --- types/types.go | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/types/types.go b/types/types.go index b0ddd011..fab58804 100644 --- a/types/types.go +++ b/types/types.go @@ -7,7 +7,6 @@ import ( "context" "errors" "fmt" - "math/big" "time" "github.com/ava-labs/subnet-evm/core/types" @@ -20,7 +19,10 @@ import ( var WarpPrecompileLogFilter = warp.WarpABI.Events["SendWarpMessage"].ID var ErrInvalidLog = errors.New("invalid warp message log") -const filterLogsRetries = 5 +const ( + filterLogsRetries = 5 + retryInterval = 1 * time.Second +) // WarpBlockInfo describes the block height and logs needed to process Warp messages. // WarpBlockInfo instances are populated by the subscriber, and forwared to the @@ -47,22 +49,9 @@ func NewWarpBlockInfo(header *types.Header, ethClient ethclient.Client) (*WarpBl ) // Check if the block contains warp logs, and fetch them from the client if it does if header.Bloom.Test(WarpPrecompileLogFilter[:]) { - // The node serving the filter logs request may be behind the node serving the block header request, - // so we retry a few times to ensure we get the logs - for i := 0; i < filterLogsRetries; i++ { - logs, err = ethClient.FilterLogs(context.Background(), interfaces.FilterQuery{ - Topics: [][]common.Hash{{WarpPrecompileLogFilter}}, - Addresses: []common.Address{warp.ContractAddress}, - FromBlock: big.NewInt(int64(header.Number.Uint64())), - ToBlock: big.NewInt(int64(header.Number.Uint64())), - }) - if err == nil { - break - } - if i == filterLogsRetries-1 { - return nil, fmt.Errorf("failed to fetch warp logs for block %d after %d retries: %w", header.Number.Uint64(), filterLogsRetries, err) - } - time.Sleep(1 * time.Second) + logs, err = fetchWarpLogsWithRetries(ethClient, header, filterLogsRetries, retryInterval) + if err != nil { + return nil, err } } return &WarpBlockInfo{ @@ -86,3 +75,28 @@ func NewWarpLogInfo(log types.Log) (*WarpLogInfo, error) { UnsignedMsgBytes: log.Data, }, nil } + +// The node serving the filter logs request may be behind the node serving the block header request, +// so we retry a few times to ensure we get the logs +func fetchWarpLogsWithRetries(ethClient ethclient.Client, header *types.Header, numRetries int, retryInterval time.Duration) ([]types.Log, error) { + var ( + logs []types.Log + err error + ) + + for i := 0; i < numRetries; i++ { + logs, err = ethClient.FilterLogs(context.Background(), interfaces.FilterQuery{ + Topics: [][]common.Hash{{WarpPrecompileLogFilter}}, + Addresses: []common.Address{warp.ContractAddress}, + FromBlock: header.Number, + ToBlock: header.Number, + }) + if err == nil { + return logs, nil + } + if i != numRetries-1 { + time.Sleep(retryInterval) + } + } + return nil, fmt.Errorf("failed to fetch warp logs for block %d after %d retries: %w", header.Number.Uint64(), filterLogsRetries, err) +} From 71d01c91f3f56edc809534befe096ef7bf277329 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Wed, 5 Jun 2024 10:33:38 -0500 Subject: [PATCH 3/3] do not mark rc's as latest --- .goreleaser.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 180c78ef..8863ead1 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -53,6 +53,8 @@ docker_manifests: image_templates: - 'avaplatform/awm-relayer:{{ .Tag }}-amd64' - 'avaplatform/awm-relayer:{{ .Tag }}-arm64' + # If tag is an rc, do not push the latest tag + skip_push: auto release: # Repo in which the release will be created. # Default is extracted from the origin remote URL or empty if its private hosted.