From a89330dc04ca11badc1d4bb28494f26e2cd385ec Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 1 Aug 2024 15:21:53 -0400 Subject: [PATCH 01/22] Update teleporter --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6fc2fe79..3af4fe63 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/ava-labs/avalanchego v1.11.10-0.20240718133512-d9ddf0a774e1 github.com/ava-labs/coreth v0.13.6-rc.1.0.20240718130554-0110293d1f4b github.com/ava-labs/subnet-evm v0.6.8-status-removal.0.20240718155830-1d577b6a5e0b - github.com/ava-labs/teleporter v1.0.3 + github.com/ava-labs/teleporter v1.0.4 github.com/aws/aws-sdk-go-v2 v1.30.3 github.com/aws/aws-sdk-go-v2/config v1.27.9 github.com/aws/aws-sdk-go-v2/service/kms v1.35.3 diff --git a/go.sum b/go.sum index 9669380c..9ed63e3b 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/ava-labs/coreth v0.13.6-rc.1.0.20240718130554-0110293d1f4b h1:XUc8KVA github.com/ava-labs/coreth v0.13.6-rc.1.0.20240718130554-0110293d1f4b/go.mod h1:EXQ/+Uk64XTBdMvgmapzy56dZ8xEkbVSgNMpSLkTKos= github.com/ava-labs/subnet-evm v0.6.8-status-removal.0.20240718155830-1d577b6a5e0b h1:qGNyH3O3VanpbgFW6DbxCAV/qF6QUDs2Ckul6wuEhmg= github.com/ava-labs/subnet-evm v0.6.8-status-removal.0.20240718155830-1d577b6a5e0b/go.mod h1:Dw/PykU2GR/FPl3Psoi9Pp6HL1qEl8Jm3QcBsBKobBQ= -github.com/ava-labs/teleporter v1.0.3 h1:5Kwso1yk5dtuIg7356MF+cJFRFge8nvun/JK0MDAUAM= -github.com/ava-labs/teleporter v1.0.3/go.mod h1:h8wp8x7531OLeyQUzC2M20S6AVXSuj598Hmo8QSUVOM= +github.com/ava-labs/teleporter v1.0.4 h1:+OAS3YyPc/LijR29qu3EqU6xAnQnjOgf4EtDlCMcDsc= +github.com/ava-labs/teleporter v1.0.4/go.mod h1:bUiOSIGjFktkYg01XDjeaZdgLEx0ZpUDfJXI6Z0rHY8= github.com/aws/aws-sdk-go-v2 v1.30.3 h1:jUeBtG0Ih+ZIFH0F4UkmL9w3cSpaMv9tYYDbzILP8dY= github.com/aws/aws-sdk-go-v2 v1.30.3/go.mod h1:nIQjQVp5sfpQcTc9mPSr1B0PaWK5ByX9MOoDadSN4lc= github.com/aws/aws-sdk-go-v2/config v1.27.9 h1:gRx/NwpNEFSk+yQlgmk1bmxxvQ5TyJ76CWXs9XScTqg= From afdbfddcbf137e9a2b06229da8ccb7be7db99b5a Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 1 Aug 2024 15:34:28 -0400 Subject: [PATCH 02/22] Update teleporter --- tests/contracts/lib/teleporter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contracts/lib/teleporter b/tests/contracts/lib/teleporter index 8b7d7245..bd88a999 160000 --- a/tests/contracts/lib/teleporter +++ b/tests/contracts/lib/teleporter @@ -1 +1 @@ -Subproject commit 8b7d7245d6998f14a0655b86670c998ba5e5f964 +Subproject commit bd88a999e3b2b5131837180601c7c798acbac7e2 From 57558743a0e880b460313c76816f54d4b1d7512e Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 1 Aug 2024 15:50:23 -0400 Subject: [PATCH 03/22] Update teleporter --- messages/teleporter/message_handler.go | 5 +++-- messages/teleporter/message_handler_test.go | 2 +- scripts/build.sh | 2 -- tests/utils/utils.go | 3 ++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/messages/teleporter/message_handler.go b/messages/teleporter/message_handler.go index dd7d8b58..f072556a 100644 --- a/messages/teleporter/message_handler.go +++ b/messages/teleporter/message_handler.go @@ -388,7 +388,8 @@ func (f *factory) parseTeleporterMessage( ) return nil, err } - teleporterMessage, err := teleportermessenger.UnpackTeleporterMessage(addressedPayload.Payload) + var teleporterMessage teleportermessenger.TeleporterMessage + err = teleporterMessage.Unpack(addressedPayload.Payload) if err != nil { f.logger.Error( "Failed unpacking teleporter message.", @@ -397,7 +398,7 @@ func (f *factory) parseTeleporterMessage( return nil, err } - return teleporterMessage, nil + return &teleporterMessage, nil } // getTeleporterMessenger returns the Teleporter messenger instance for the destination chain. diff --git a/messages/teleporter/message_handler_test.go b/messages/teleporter/message_handler_test.go index 677735be..aa0b0c86 100644 --- a/messages/teleporter/message_handler_test.go +++ b/messages/teleporter/message_handler_test.go @@ -70,7 +70,7 @@ func init() { } func TestShouldSendMessage(t *testing.T) { - validMessageBytes, err := teleportermessenger.PackTeleporterMessage(validTeleporterMessage) + validMessageBytes, err := validTeleporterMessage.Pack() require.NoError(t, err) validAddressedCall, err := warpPayload.NewAddressedCall( diff --git a/scripts/build.sh b/scripts/build.sh index d4661991..c09c205b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -39,8 +39,6 @@ if version_lt "$(go_version)" "$go_version_minimum"; then exit 1 fi -scripts/protobuf_codegen.sh - if [[ $# -eq 1 ]]; then binary_path=$1 elif [[ $# -eq 0 ]]; then diff --git a/tests/utils/utils.go b/tests/utils/utils.go index 99bbd41d..92f25246 100644 --- a/tests/utils/utils.go +++ b/tests/utils/utils.go @@ -385,7 +385,8 @@ func RelayBasicMessage( // Check that the teleporter message is correct // We don't validate the entire message, since the message receipts // are populated by the Teleporter contract - receivedTeleporterMessage, err := teleportermessenger.UnpackTeleporterMessage(addressedPayload.Payload) + var receivedTeleporterMessage teleportermessenger.TeleporterMessage + err = receivedTeleporterMessage.Unpack(addressedPayload.Payload) Expect(err).Should(BeNil()) receivedMessageID, err := teleporterUtils.CalculateMessageID( From 719034ab241bf0f0dd4dab7b208a7758d715c40f Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Tue, 6 Aug 2024 11:52:01 -0400 Subject: [PATCH 04/22] Update readme --- README.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c10e44a2..d33ad498 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,6 @@ awm-relayer --help Display awm-relayer usag ### Building -Before building, be sure to install Go, which is required even if you're just building the Docker image. You'll also need to install [buf](github.com/bufbuild/buf/). - Build the relayer by running the script: ```bash @@ -410,3 +408,19 @@ The E2E tests use the `TeleporterMessenger` contract deployment transaction spec ```bash go generate ./... ``` + +### Generate Protobuf Files + +[buf](github.com/bufbuild/buf/) is used to generate protobuf definitions for communication with the decider module. If you change any of the protobuf definitions you will have to regenerate the `.go` files. To generate these files, run the following command at the root of the project: + +```bash +./scripts/protobuf_codegen.sh +``` + +### Generate Abi Bindings + +[subnet-evm](github.com/ava-labs/subnet-evm/cmd/abigen/) is used to generate abi binding `.go` files for solidity contracts. If you change any of the smart contracts, you will have to update the abi bindings. To generate these files, run the following command at the root of the project: + +```bash +./scripts/abi_bindings.sh +``` From 6f0a6cb4308767a1bb73b59f33c574ee7d5bd558 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 8 Aug 2024 12:38:21 -0400 Subject: [PATCH 05/22] Update README.md Co-authored-by: cam-schultz <78878559+cam-schultz@users.noreply.github.com> Signed-off-by: Geoff Stuart --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d33ad498..425c1805 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ go generate ./... ### Generate Protobuf Files -[buf](github.com/bufbuild/buf/) is used to generate protobuf definitions for communication with the decider module. If you change any of the protobuf definitions you will have to regenerate the `.go` files. To generate these files, run the following command at the root of the project: +[buf](github.com/bufbuild/buf/) is used to generate protobuf definitions for communication with the [Decider service](https://github.com/ava-labs/awm-relayer/blob/main/proto/decider/decider.proto). If you change any of the protobuf definitions you will have to regenerate the `.go` files. To generate these files, run the following command at the root of the project: ```bash ./scripts/protobuf_codegen.sh From c486c836c8000830315cebdf3224c9ac2524b3ef Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Mon, 12 Aug 2024 16:14:49 -0500 Subject: [PATCH 06/22] commit tip if catch up disabled --- main/main.go | 32 ++++++++++++++++++-------------- relayer/listener.go | 23 ++++++----------------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/main/main.go b/main/main.go index 7dc5ac2d..aa0df76d 100644 --- a/main/main.go +++ b/main/main.go @@ -268,7 +268,6 @@ func main() { *sourceBlockchain, sourceClients[sourceBlockchain.GetBlockchainID()], relayerHealth[sourceBlockchain.GetBlockchainID()], - cfg.ProcessMissedBlocks, minHeights[sourceBlockchain.GetBlockchainID()], messageCoordinator, ) @@ -431,20 +430,25 @@ func createApplicationRelayersForSourceChain( // The Listener begins processing messages starting from the minimum height across all the ApplicationRelayers minHeight := uint64(0) for _, relayerID := range database.GetSourceBlockchainRelayerIDs(&sourceBlockchain) { - height, err := database.CalculateStartingBlockHeight( - logger, - db, - relayerID, - sourceBlockchain.ProcessHistoricalBlocksFromHeight, - currentHeight, - ) - if err != nil { - logger.Error( - "Failed to calculate starting block height", - zap.String("relayerID", relayerID.ID.String()), - zap.Error(err), + // Calculate the starting block height for the relayer only if we're processing historical blocks + height := currentHeight + if cfg.ProcessMissedBlocks { + var err error + height, err = database.CalculateStartingBlockHeight( + logger, + db, + relayerID, + sourceBlockchain.ProcessHistoricalBlocksFromHeight, + currentHeight, ) - return nil, 0, err + if err != nil { + logger.Error( + "Failed to calculate starting block height", + zap.String("relayerID", relayerID.ID.String()), + zap.Error(err), + ) + return nil, 0, err + } } if minHeight == 0 || height < minHeight { minHeight = height diff --git a/relayer/listener.go b/relayer/listener.go index bef9fa22..0a7998b1 100644 --- a/relayer/listener.go +++ b/relayer/listener.go @@ -47,8 +47,7 @@ func RunListener( sourceBlockchain config.SourceBlockchain, ethRPCClient ethclient.Client, relayerHealth *atomic.Bool, - processMissedBlocks bool, - minHeight uint64, + startingHeight uint64, messageCoordinator *MessageCoordinator, ) error { // Create the Listener @@ -58,8 +57,7 @@ func RunListener( sourceBlockchain, ethRPCClient, relayerHealth, - processMissedBlocks, - minHeight, + startingHeight, messageCoordinator, ) if err != nil { @@ -82,7 +80,6 @@ func newListener( sourceBlockchain config.SourceBlockchain, ethRPCClient ethclient.Client, relayerHealth *atomic.Bool, - processMissedBlocks bool, startingHeight uint64, messageCoordinator *MessageCoordinator, ) (*Listener, error) { @@ -149,18 +146,10 @@ func newListener( return nil, err } - if processMissedBlocks { - // Process historical blocks in a separate goroutine so that the main processing loop can - // start processing new blocks as soon as possible. Otherwise, it's possible for - // ProcessFromHeight to overload the message queue and cause a deadlock. - go sub.ProcessFromHeight(big.NewInt(0).SetUint64(startingHeight), lstnr.catchUpResultChan) - } else { - lstnr.logger.Info( - "processed-missed-blocks set to false, starting processing from chain head", - zap.String("blockchainID", lstnr.sourceBlockchain.GetBlockchainID().String()), - ) - lstnr.catchUpResultChan <- true - } + // Process historical blocks in a separate goroutine so that the main processing loop can + // start processing new blocks as soon as possible. Otherwise, it's possible for + // ProcessFromHeight to overload the message queue and cause a deadlock. + go sub.ProcessFromHeight(big.NewInt(0).SetUint64(startingHeight), lstnr.catchUpResultChan) return &lstnr, nil } From 4338a5e4da13622012432c6b9bc92595e7bae02f Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Mon, 12 Aug 2024 16:57:54 -0500 Subject: [PATCH 07/22] issue additional tx --- tests/relay_message_api.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/relay_message_api.go b/tests/relay_message_api.go index b737e4c7..b5c8e727 100644 --- a/tests/relay_message_api.go +++ b/tests/relay_message_api.go @@ -52,6 +52,15 @@ func RelayMessageAPI(network interfaces.LocalNetwork) { ) warpMessage := getWarpMessageFromLog(ctx, receipt, subnetAInfo) + // Send an additional tx to make sure the relayer doesn't process the previous one on startup + testUtils.SendBasicTeleporterMessage( + ctx, + subnetAInfo, + subnetBInfo, + fundedKey, + fundedAddress, + ) + // Set up relayer config relayerConfig := testUtils.CreateDefaultRelayerConfig( []interfaces.SubnetTestInfo{subnetAInfo, subnetBInfo}, From 7607acf019d9f34c5b0702c7b7d5970f7c43fcdf Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Mon, 12 Aug 2024 17:08:39 -0500 Subject: [PATCH 08/22] if catch up disabled, start from next block --- main/main.go | 3 ++- tests/relay_message_api.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/main/main.go b/main/main.go index aa0df76d..4593463c 100644 --- a/main/main.go +++ b/main/main.go @@ -431,7 +431,8 @@ func createApplicationRelayersForSourceChain( minHeight := uint64(0) for _, relayerID := range database.GetSourceBlockchainRelayerIDs(&sourceBlockchain) { // Calculate the starting block height for the relayer only if we're processing historical blocks - height := currentHeight + // Otherwies, the first block we process is the next block after the current height + height := currentHeight + 1 if cfg.ProcessMissedBlocks { var err error height, err = database.CalculateStartingBlockHeight( diff --git a/tests/relay_message_api.go b/tests/relay_message_api.go index b5c8e727..d2123043 100644 --- a/tests/relay_message_api.go +++ b/tests/relay_message_api.go @@ -52,14 +52,14 @@ func RelayMessageAPI(network interfaces.LocalNetwork) { ) warpMessage := getWarpMessageFromLog(ctx, receipt, subnetAInfo) - // Send an additional tx to make sure the relayer doesn't process the previous one on startup - testUtils.SendBasicTeleporterMessage( - ctx, - subnetAInfo, - subnetBInfo, - fundedKey, - fundedAddress, - ) + // // Send an additional tx to make sure the relayer doesn't process the previous one on startup + // testUtils.SendBasicTeleporterMessage( + // ctx, + // subnetAInfo, + // subnetBInfo, + // fundedKey, + // fundedAddress, + // ) // Set up relayer config relayerConfig := testUtils.CreateDefaultRelayerConfig( From 2e60c0d7b9e0403c9f92a284f6ecc66625148f06 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Tue, 13 Aug 2024 09:06:28 -0500 Subject: [PATCH 09/22] remove commented code --- tests/relay_message_api.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/relay_message_api.go b/tests/relay_message_api.go index d2123043..b737e4c7 100644 --- a/tests/relay_message_api.go +++ b/tests/relay_message_api.go @@ -52,15 +52,6 @@ func RelayMessageAPI(network interfaces.LocalNetwork) { ) warpMessage := getWarpMessageFromLog(ctx, receipt, subnetAInfo) - // // Send an additional tx to make sure the relayer doesn't process the previous one on startup - // testUtils.SendBasicTeleporterMessage( - // ctx, - // subnetAInfo, - // subnetBInfo, - // fundedKey, - // fundedAddress, - // ) - // Set up relayer config relayerConfig := testUtils.CreateDefaultRelayerConfig( []interfaces.SubnetTestInfo{subnetAInfo, subnetBInfo}, From c6e8f8722d5cf8e180192773ca9ecea89f54e01f Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Tue, 13 Aug 2024 09:17:42 -0500 Subject: [PATCH 10/22] clean up control flow --- main/main.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main/main.go b/main/main.go index 4593463c..25e8aa60 100644 --- a/main/main.go +++ b/main/main.go @@ -431,8 +431,8 @@ func createApplicationRelayersForSourceChain( minHeight := uint64(0) for _, relayerID := range database.GetSourceBlockchainRelayerIDs(&sourceBlockchain) { // Calculate the starting block height for the relayer only if we're processing historical blocks - // Otherwies, the first block we process is the next block after the current height - height := currentHeight + 1 + // Otherwise, the first block we process is the next block after the current height + var height uint64 if cfg.ProcessMissedBlocks { var err error height, err = database.CalculateStartingBlockHeight( @@ -450,7 +450,15 @@ func createApplicationRelayersForSourceChain( ) return nil, 0, err } + } else { + logger.Info( + "processed-missed-blocks set to false, starting processing from chain head", + zap.String("blockchainID", sourceBlockchain.GetBlockchainID().String()), + ) + height = currentHeight + 1 } + + // Update the min height if minHeight == 0 || height < minHeight { minHeight = height } From ec0107d5cf804df31eb66791db7b974b729b5882 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Wed, 14 Aug 2024 09:38:36 -0500 Subject: [PATCH 11/22] emit log once per source --- main/main.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/main/main.go b/main/main.go index 25e8aa60..09e1f743 100644 --- a/main/main.go +++ b/main/main.go @@ -426,13 +426,20 @@ func createApplicationRelayersForSourceChain( ) applicationRelayers := make(map[common.Hash]*relayer.ApplicationRelayer) - // Each ApplicationRelayer determines its starting height based on the database state. + // Each ApplicationRelayer determines its starting height based on the configuration and database state. // The Listener begins processing messages starting from the minimum height across all the ApplicationRelayers - minHeight := uint64(0) + // If catch up is disabled, the first block the ApplicationRelayer processes is the next block after the current height + var height, minHeight uint64 + if !cfg.ProcessMissedBlocks { + logger.Info( + "processed-missed-blocks set to false, starting processing from chain head", + zap.String("blockchainID", sourceBlockchain.GetBlockchainID().String()), + ) + height = currentHeight + 1 + minHeight = height + } for _, relayerID := range database.GetSourceBlockchainRelayerIDs(&sourceBlockchain) { - // Calculate the starting block height for the relayer only if we're processing historical blocks - // Otherwise, the first block we process is the next block after the current height - var height uint64 + // Calculate the catcp-up starting block height, and update the min height if necessary if cfg.ProcessMissedBlocks { var err error height, err = database.CalculateStartingBlockHeight( @@ -450,17 +457,11 @@ func createApplicationRelayersForSourceChain( ) return nil, 0, err } - } else { - logger.Info( - "processed-missed-blocks set to false, starting processing from chain head", - zap.String("blockchainID", sourceBlockchain.GetBlockchainID().String()), - ) - height = currentHeight + 1 - } - // Update the min height - if minHeight == 0 || height < minHeight { - minHeight = height + // Update the min height. This is the height that the listener will start processing from + if minHeight == 0 || height < minHeight { + minHeight = height + } } checkpointManager := checkpoint.NewCheckpointManager( From 7bd60a3bf7b3e62c2ac20f3d9a2d8e744727bd8b Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Wed, 14 Aug 2024 09:42:21 -0500 Subject: [PATCH 12/22] generalize log namespace --- peers/app_request_network.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peers/app_request_network.go b/peers/app_request_network.go index 651d0adb..9f5cc878 100644 --- a/peers/app_request_network.go +++ b/peers/app_request_network.go @@ -50,7 +50,7 @@ func NewNetwork( cfg Config, ) (*AppRequestNetwork, error) { logger := logging.NewLogger( - "awm-relayer-p2p", + "p2p-network", logging.NewWrappedCore( logLevel, os.Stdout, From 8cad4042c20ffa953f4b7b2ee099b5eeece0f0a0 Mon Sep 17 00:00:00 2001 From: cam-schultz <78878559+cam-schultz@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:06:04 -0500 Subject: [PATCH 13/22] Update main/main.go Co-authored-by: Ian Suvak Signed-off-by: cam-schultz <78878559+cam-schultz@users.noreply.github.com> --- main/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/main.go b/main/main.go index 09e1f743..6900ccc3 100644 --- a/main/main.go +++ b/main/main.go @@ -439,7 +439,7 @@ func createApplicationRelayersForSourceChain( minHeight = height } for _, relayerID := range database.GetSourceBlockchainRelayerIDs(&sourceBlockchain) { - // Calculate the catcp-up starting block height, and update the min height if necessary + // Calculate the catch-up starting block height, and update the min height if necessary if cfg.ProcessMissedBlocks { var err error height, err = database.CalculateStartingBlockHeight( From d636c087484f90d70427949369f078232015dda5 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 14 Aug 2024 15:27:05 -0400 Subject: [PATCH 14/22] Update go --- CONTRIBUTING.md | 2 +- database/json_file_storage_test.go | 6 ++---- go.mod | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a0b4b4ac..64889bb3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## Setup -To start developing on AWM Relayer, you'll need Golang v1.21.13. +To start developing on AWM Relayer, you'll need Golang v1.22.6. ## Issues diff --git a/database/json_file_storage_test.go b/database/json_file_storage_test.go index 9361a730..6f7a1303 100644 --- a/database/json_file_storage_test.go +++ b/database/json_file_storage_test.go @@ -50,10 +50,9 @@ func TestConcurrentWriteReadSingleChain(t *testing.T) { wg := sync.WaitGroup{} for i := 0; i < 10; i++ { wg.Add(1) - idx := i go func() { defer wg.Done() - testWrite(jsonStorage, relayerIDs[0], uint64(idx)) + testWrite(jsonStorage, relayerIDs[0], uint64(i)) }() } wg.Wait() @@ -94,10 +93,9 @@ func TestConcurrentWriteReadMultipleChains(t *testing.T) { wg := sync.WaitGroup{} for i := 0; i < 3; i++ { wg.Add(1) - index := i go func() { defer wg.Done() - testWrite(jsonStorage, relayerIDs[index], uint64(index)) + testWrite(jsonStorage, relayerIDs[i], uint64(i)) }() } wg.Wait() diff --git a/go.mod b/go.mod index e88ce79b..c82e40c1 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ava-labs/awm-relayer -go 1.21.13 +go 1.22.6 require ( github.com/ava-labs/avalanchego v1.11.10 From 590966c0a530b97484d0b76ba3a9db6953a13e93 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 14 Aug 2024 15:48:34 -0400 Subject: [PATCH 15/22] Update linter --- scripts/versions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/versions.sh b/scripts/versions.sh index 4c00db33..85951548 100755 --- a/scripts/versions.sh +++ b/scripts/versions.sh @@ -25,4 +25,4 @@ GINKGO_VERSION=${GINKGO_VERSION:-$(getDepVersion github.com/onsi/ginkgo/v2)} SUBNET_EVM_VERSION=${SUBNET_EVM_VERSION:-update-avago-teleporter} # Set golangci-lint version -GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.55'} +GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION:-'v1.60'} From 427b5ef04a7d70afef6ec6dfd9739aba3a2c843e Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Wed, 14 Aug 2024 16:29:17 -0500 Subject: [PATCH 16/22] add explicit gas check --- messages/teleporter/message_handler.go | 18 +++++++++++++++ messages/teleporter/message_handler_test.go | 25 +++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/messages/teleporter/message_handler.go b/messages/teleporter/message_handler.go index dd7d8b58..0be4f664 100644 --- a/messages/teleporter/message_handler.go +++ b/messages/teleporter/message_handler.go @@ -29,6 +29,10 @@ import ( "google.golang.org/grpc" ) +// The maximum gas limit that can be specified for a Teleporter message +// Based on the C-Chain 15_000_000 gas limit per block, with other Warp message gas overhead conservatively estimated. +const maxTeleporterGasLimit = 12_000_000 + type factory struct { messageConfig Config protocolAddress common.Address @@ -159,6 +163,19 @@ func (m *messageHandler) ShouldSendMessage(destinationClient vms.DestinationClie return false, fmt.Errorf("failed to calculate Teleporter message ID: %w", err) } + // Check if the specified gas limit is below the maximum threshold + if m.teleporterMessage.RequiredGasLimit.Uint64() > maxTeleporterGasLimit { + m.logger.Info( + "Gas limit exceeds maximum threshold", + zap.String("destinationBlockchainID", destinationBlockchainID.String()), + zap.String("teleporterMessageID", teleporterMessageID.String()), + zap.Uint64("requiredGasLimit", m.teleporterMessage.RequiredGasLimit.Uint64()), + zap.Uint64("maxGasLimit", maxTeleporterGasLimit), + ) + return false, nil + } + + // Check if the relayer is allowed to deliver this message senderAddress := destinationClient.SenderAddress() if !isAllowedRelayer(m.teleporterMessage.AllowedRelayerAddresses, senderAddress) { m.logger.Info( @@ -191,6 +208,7 @@ func (m *messageHandler) ShouldSendMessage(destinationClient vms.DestinationClie ) return false, nil } + // Dispatch to the external decider service. If the service is unavailable or returns // an error, then use the decision that has already been made, i.e. return true decision, err := m.getShouldSendMessageFromDecider() diff --git a/messages/teleporter/message_handler_test.go b/messages/teleporter/message_handler_test.go index 677735be..65322000 100644 --- a/messages/teleporter/message_handler_test.go +++ b/messages/teleporter/message_handler_test.go @@ -116,6 +116,25 @@ func TestShouldSendMessage(t *testing.T) { ) require.NoError(t, err) + gasLimitExceededTeleporterMessage := validTeleporterMessage + gasLimitExceededTeleporterMessage.RequiredGasLimit = big.NewInt(maxTeleporterGasLimit + 1) + gasLimitExceededTeleporterMessageBytes, err := + teleportermessenger.PackTeleporterMessage(gasLimitExceededTeleporterMessage) + require.NoError(t, err) + + gasLimitExceededAddressedCall, err := warpPayload.NewAddressedCall( + messageProtocolAddress.Bytes(), + gasLimitExceededTeleporterMessageBytes, + ) + require.NoError(t, err) + + gasLimitExceededWarpUnsignedMessage, err := warp.NewUnsignedMessage( + 0, + sourceBlockchainID, + gasLimitExceededAddressedCall.Bytes(), + ) + require.NoError(t, err) + testCases := []struct { name string destinationBlockchainID ids.ID @@ -177,6 +196,12 @@ func TestShouldSendMessage(t *testing.T) { }, expectedResult: false, }, + { + name: "gas limit exceeded", + destinationBlockchainID: destinationBlockchainID, + warpUnsignedMessage: gasLimitExceededWarpUnsignedMessage, + expectedResult: false, + }, } for _, test := range testCases { t.Run(test.name, func(t *testing.T) { From d3ad37cdc64d4ac22ba4ade65b5b65deb6e854a9 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Wed, 14 Aug 2024 16:59:20 -0500 Subject: [PATCH 17/22] reduce number of messages to pass gas limit check --- tests/batch_relay.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/batch_relay.go b/tests/batch_relay.go index aebde3bb..e4290fa1 100644 --- a/tests/batch_relay.go +++ b/tests/batch_relay.go @@ -83,7 +83,7 @@ func BatchRelay(network interfaces.LocalNetwork) { Expect(err).Should(BeNil()) defer sub.Unsubscribe() - numMessages := 50 + numMessages := 40 sentMessages := set.NewSet[string](numMessages) for i := 0; i < numMessages; i++ { sentMessages.Add(strconv.Itoa(i)) From ba1609a0e724e4c3fd472d06845b2fd02663762a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:25:59 +0000 Subject: [PATCH 18/22] Bump github.com/prometheus/client_golang from 1.19.1 to 1.20.0 Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.19.1 to 1.20.0. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.19.1...v1.20.0) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 11 ++++++----- go.sum | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index e88ce79b..1e11e8a5 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/onsi/ginkgo/v2 v2.20.0 github.com/onsi/gomega v1.34.1 github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.19.1 + github.com/prometheus/client_golang v1.20.0 github.com/redis/go-redis/v9 v9.6.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.16.0 @@ -72,7 +72,7 @@ require ( github.com/huin/goupnp v1.3.0 // indirect github.com/jackpal/gateway v1.0.6 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect - github.com/klauspost/compress v1.15.15 // indirect + github.com/klauspost/compress v1.17.9 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -81,6 +81,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/pointerstructure v1.2.0 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect @@ -131,9 +132,9 @@ require ( github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/pires/go-proxyproto v0.6.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.5.0 // indirect - github.com/prometheus/common v0.48.0 // indirect - github.com/prometheus/procfs v0.12.0 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.55.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect github.com/rs/cors v1.7.0 // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/status-im/keycard-go v0.2.0 // indirect diff --git a/go.sum b/go.sum index c899bca6..917dbb80 100644 --- a/go.sum +++ b/go.sum @@ -412,8 +412,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= -github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -470,6 +470,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= @@ -514,15 +516,15 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= -github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_golang v1.20.0 h1:jBzTZ7B099Rg24tny+qngoynol8LtVYlA2bqx3vEloI= +github.com/prometheus/client_golang v1.20.0/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= -github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= -github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= -github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= -github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= -github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc= +github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4= github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= From 41e7872dd91d44148416090ae04d1cd74096fb28 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 15 Aug 2024 09:58:18 -0400 Subject: [PATCH 19/22] Update loop --- relayer/application_relayer.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/relayer/application_relayer.go b/relayer/application_relayer.go index 2ae439c3..aa2ec06b 100644 --- a/relayer/application_relayer.go +++ b/relayer/application_relayer.go @@ -148,11 +148,8 @@ func (r *ApplicationRelayer) ProcessHeight( ) { var eg errgroup.Group for _, handler := range handlers { - // Copy the loop variable to a local variable to avoid the loop variable being captured by the - // goroutine. Once we upgrade to Go 1.22, we can use the loop variable directly in the goroutine. - h := handler eg.Go(func() error { - _, err := r.ProcessMessage(h) + _, err := r.ProcessMessage(handler) return err }) } From 762effd86fc299d4afb7a51b2be8ffbb00ac651d Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 15 Aug 2024 12:01:34 -0400 Subject: [PATCH 20/22] Add to readme --- README.md | 2 ++ scripts/build_relayer.sh | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d4038ba3..7591febc 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ See the [Building](#building) section for instructions on how to build the relay ## Requirements +[buf](github.com/bufbuild/buf/) is required to rebuild protobuf definitions if changes are made to any `.proto` files. See [Generate Protobuf Files](#generate-protobuf-files) for more information. + ### System Requirements - Ubuntu 22.04 or later diff --git a/scripts/build_relayer.sh b/scripts/build_relayer.sh index 8069a874..c1afa7c9 100755 --- a/scripts/build_relayer.sh +++ b/scripts/build_relayer.sh @@ -39,8 +39,6 @@ if version_lt "$(go_version)" "$go_version_minimum"; then exit 1 fi -scripts/protobuf_codegen.sh - if [[ $# -eq 1 ]]; then binary_path=$1 elif [[ $# -eq 0 ]]; then From 42603538cfb30895c79683d1804509fdd955ec0e Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 15 Aug 2024 12:03:06 -0400 Subject: [PATCH 21/22] fix build section --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7591febc..54575b9c 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,8 @@ awm-relayer --help Display awm-relayer usag ### Building +Before building, be sure to install Go, which is required even if you're just building the Docker image. + Build the relayer by running the script: ```bash From e478a55605001e7f94d40d7a1aa931685e124653 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Thu, 15 Aug 2024 12:06:15 -0400 Subject: [PATCH 22/22] fix test --- messages/teleporter/message_handler_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/messages/teleporter/message_handler_test.go b/messages/teleporter/message_handler_test.go index e96c1cab..abb78afa 100644 --- a/messages/teleporter/message_handler_test.go +++ b/messages/teleporter/message_handler_test.go @@ -118,8 +118,7 @@ func TestShouldSendMessage(t *testing.T) { gasLimitExceededTeleporterMessage := validTeleporterMessage gasLimitExceededTeleporterMessage.RequiredGasLimit = big.NewInt(maxTeleporterGasLimit + 1) - gasLimitExceededTeleporterMessageBytes, err := - teleportermessenger.PackTeleporterMessage(gasLimitExceededTeleporterMessage) + gasLimitExceededTeleporterMessageBytes, err := gasLimitExceededTeleporterMessage.Pack() require.NoError(t, err) gasLimitExceededAddressedCall, err := warpPayload.NewAddressedCall(