From 19bf9399f91eefe65683e8a7225be4edfa8d06f4 Mon Sep 17 00:00:00 2001 From: Cameron Schultz Date: Thu, 31 Aug 2023 15:53:37 -0400 Subject: [PATCH 01/10] check if message already delivered --- messages/teleporter/message.go | 18 +++++++ messages/teleporter/message_manager.go | 72 +++++++++++++++++++++++++- vms/destination_client.go | 10 +++- vms/evm/destination_client.go | 64 ++++++++--------------- 4 files changed, 118 insertions(+), 46 deletions(-) diff --git a/messages/teleporter/message.go b/messages/teleporter/message.go index 0d467bef..fded23c5 100644 --- a/messages/teleporter/message.go +++ b/messages/teleporter/message.go @@ -9,6 +9,7 @@ import ( "github.com/ava-labs/subnet-evm/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ava-labs/avalanchego/ids" ) // TeleporterMessage contains the Teleporter message, including @@ -34,6 +35,13 @@ type ReceiveCrossChainMessageInput struct { RelayerRewardAddress common.Address `json:"relayerRewardAddress"` } +// MessageReceivedInput is the input to the MessageReceived +// in the contract deployed on the receiving chain +type MessageReceivedInput struct { + OriginChainID ids.ID `json:"relayerRewardAddress"` + MessageID *big.Int `json:"messageID"` +} + // unpack Teleporter message bytes according to EVM ABI encoding rules func unpackTeleporterMessage(messageBytes []byte) (*TeleporterMessage, error) { args := abi.Arguments{ @@ -60,3 +68,13 @@ func unpackTeleporterMessage(messageBytes []byte) (*TeleporterMessage, error) { func packReceiverMessage(inputStruct ReceiveCrossChainMessageInput) ([]byte, error) { return EVMTeleporterContractABI.Pack("receiveCrossChainMessage", inputStruct.RelayerRewardAddress) } + +func packMessageReceivedMessage(inputStruct MessageReceivedInput) ([]byte, error) { + return EVMTeleporterContractABI.Pack("messageReceived", inputStruct.OriginChainID, inputStruct.MessageID) +} + +func unpackMessageReceivedResult(result []byte) (bool, error) { + var success bool + err := EVMTeleporterContractABI.UnpackIntoInterface(&success, "messageReceived", result) + return success, err +} \ No newline at end of file diff --git a/messages/teleporter/message_manager.go b/messages/teleporter/message_manager.go index e7cca282..96557015 100644 --- a/messages/teleporter/message_manager.go +++ b/messages/teleporter/message_manager.go @@ -4,7 +4,9 @@ package teleporter import ( + "context" "encoding/json" + "errors" "fmt" "github.com/ava-labs/avalanchego/cache" @@ -14,6 +16,8 @@ import ( "github.com/ava-labs/awm-relayer/config" "github.com/ava-labs/awm-relayer/vms" "github.com/ava-labs/awm-relayer/vms/vmtypes" + "github.com/ava-labs/subnet-evm/ethclient" + "github.com/ava-labs/subnet-evm/interfaces" "github.com/ethereum/go-ethereum/common" "go.uber.org/zap" ) @@ -70,6 +74,24 @@ func NewMessageManager( }, nil } +func isDestination(messageDestinationID ids.ID, allowedDestinationID ids.ID) bool { + return messageDestinationID == allowedDestinationID +} + +func isAllowedRelayer(allowedRelayers []common.Address, eoa common.Address) bool { + // If no allowed relayer addresses were set, then anyone can relay it. + if len(allowedRelayers) == 0 { + return true + } + + for _, addr := range allowedRelayers { + if addr == eoa { + return true + } + } + return false +} + // ShouldSendMessage returns true if the message should be sent to the destination chain func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageInfo, destinationChainID ids.ID) (bool, error) { // Unpack the teleporter message and add it to the cache @@ -87,13 +109,59 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI if !ok { return false, fmt.Errorf("relayer not configured to deliver to destination. destinationChainID=%s", destinationChainID.String()) } - if !destinationClient.Allowed(destinationChainID, teleporterMessage.AllowedRelayerAddresses) { + senderAddress := destinationClient.SenderAddress() + if !isAllowedRelayer(teleporterMessage.AllowedRelayerAddresses, senderAddress) { + m.logger.Info("Relayer EOA not allowed to deliver this message.") + return false, nil + } + if !isDestination(destinationChainID, destinationClient.DestinationChainID()) { m.logger.Info( - "Relayer not allowed to deliver to chain.", + "Destination chain ID for message not supported by relayer.", zap.String("destinationChainID", destinationChainID.String()), ) return false, nil } + + // Check if the message has already been delivered to the destination chain + client, ok := destinationClient.Client().(ethclient.Client) + if !ok { + m.logger.Info("Destination client is not an Ethereum client.") + return false, errors.New("destination client is not an Ethereum client") + } + + data, err := packMessageReceivedMessage(MessageReceivedInput{ + OriginChainID: warpMessageInfo.WarpUnsignedMessage.SourceChainID, + MessageID: teleporterMessage.MessageID, + }) + if err != nil { + m.logger.Info("Failed packing messageReceived call data.") + return false, err + } + protocolAddress := common.BytesToAddress(m.protocolAddress[:]) + callMessage := interfaces.CallMsg{ + To: &protocolAddress, + From: senderAddress, + Data: data, + } + result, err := client.CallContract(context.Background(), callMessage, nil) + if err != nil { + m.logger.Info("Failed calling messageReceived method on destination chain.") + return false, err + } + // check the contract call result + received, err := unpackMessageReceivedResult(result) + if err != nil { + return false, err + } + if received { + m.logger.Info( + "Message already deliverd to destination.", + zap.String("destinationChainID", destinationChainID.String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), + ) + return false, nil + } + // Cache the message so it can be reused in SendMessage m.teleporterMessageCache.Put(warpMessageInfo.WarpUnsignedMessage.ID(), teleporterMessage) return true, nil diff --git a/vms/destination_client.go b/vms/destination_client.go index cec3b06b..44752d0f 100644 --- a/vms/destination_client.go +++ b/vms/destination_client.go @@ -22,8 +22,14 @@ type DestinationClient interface { // TODO: Make generic for any VM. SendTx(signedMessage *warp.Message, toAddress string, gasLimit uint64, callData []byte) error - // Allowed checks if the relayer is allowed to relay the message according to the VM rules and the message metadata - Allowed(chainID ids.ID, allowedRelayers []common.Address) bool + // Client returns the underlying client for the destination chain + Client() interface{} + + // SenderAddress returns the address of the relayer on the destination chain + SenderAddress() common.Address + + // DestinationChainID returns the ID of the destination chain + DestinationChainID() ids.ID } func NewDestinationClient(logger logging.Logger, subnetInfo config.DestinationSubnet) (DestinationClient, error) { diff --git a/vms/evm/destination_client.go b/vms/evm/destination_client.go index 57ade4ce..b904e54d 100644 --- a/vms/evm/destination_client.go +++ b/vms/evm/destination_client.go @@ -95,18 +95,18 @@ func NewDestinationClient(logger logging.Logger, subnetInfo config.DestinationSu }, nil } -func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message, +func (c *destinationClient) SendTx(signedMessage *avalancheWarp.Message, toAddress string, gasLimit uint64, callData []byte) error { // Synchronize teleporter message requests to the same destination chain so that message ordering is preserved - tdc.lock.Lock() - defer tdc.lock.Unlock() + c.lock.Lock() + defer c.lock.Unlock() // We need the global 32-byte representation of the destination chain ID, as well as the destination's configured chainID // Without the destination's configured chainID, transaction signature verification will fail - destinationChainIDBigInt, err := tdc.client.ChainID(context.Background()) + destinationChainIDBigInt, err := c.client.ChainID(context.Background()) if err != nil { - tdc.logger.Error( + c.logger.Error( "Failed to get chain ID from destination chain endpoint", zap.Error(err), ) @@ -114,9 +114,9 @@ func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message, } // Get the current base fee estimation, which is based on the previous blocks gas usage. - baseFee, err := tdc.client.EstimateBaseFee(context.Background()) + baseFee, err := c.client.EstimateBaseFee(context.Background()) if err != nil { - tdc.logger.Error( + c.logger.Error( "Failed to get base fee", zap.Error(err), ) @@ -125,9 +125,9 @@ func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message, // Get the suggested gas tip cap of the network // TODO: Add a configurable ceiling to this value - gasTipCap, err := tdc.client.SuggestGasTipCap(context.Background()) + gasTipCap, err := c.client.SuggestGasTipCap(context.Background()) if err != nil { - tdc.logger.Error( + c.logger.Error( "Failed to get gas tip cap", zap.Error(err), ) @@ -146,7 +146,7 @@ func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message, // Construct the actual transaction to broadcast on the destination chain tx := types.NewTx(&types.DynamicFeeTx{ ChainID: destinationChainIDBigInt, - Nonce: tdc.currentNonce, + Nonce: c.currentNonce, To: &to, Gas: gasLimit, GasFeeCap: gasFeeCap, @@ -163,17 +163,17 @@ func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message, // Sign and send the transaction on the destination chain signer := types.LatestSignerForChainID(destinationChainIDBigInt) - signedTx, err := types.SignTx(tx, signer, tdc.pk) + signedTx, err := types.SignTx(tx, signer, c.pk) if err != nil { - tdc.logger.Error( + c.logger.Error( "Failed to sign transaction", zap.Error(err), ) return err } - if err := tdc.client.SendTransaction(context.Background(), signedTx); err != nil { - tdc.logger.Error( + if err := c.client.SendTransaction(context.Background(), signedTx); err != nil { + c.logger.Error( "Failed to send transaction", zap.Error(err), ) @@ -182,8 +182,8 @@ func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message, // Increment the nonce to use on the destination chain now that we've sent // a transaction using the current value. - tdc.currentNonce++ - tdc.logger.Info( + c.currentNonce++ + c.logger.Info( "Sent transaction", zap.String("txID", signedTx.Hash().String()), ) @@ -191,34 +191,14 @@ func (tdc *destinationClient) SendTx(signedMessage *avalancheWarp.Message, return nil } -func (tdc *destinationClient) isDestination(chainID ids.ID) bool { - if chainID != tdc.destinationChainID { - tdc.logger.Info( - "Destination chain ID for message not supported by relayer.", - zap.String("chainID", chainID.String()), - ) - return false - } - return true +func (c *destinationClient) Client() interface{} { + return c.client } -func (tdc *destinationClient) isAllowedRelayer(allowedRelayers []common.Address) bool { - // If no allowed relayer addresses were set, then anyone can relay it. - if len(allowedRelayers) == 0 { - return true - } - - for _, addr := range allowedRelayers { - if addr == tdc.eoa { - return true - } - } - - tdc.logger.Info("Relayer EOA not allowed to deliver this message.") - return false +func (c *destinationClient) SenderAddress() common.Address { + return c.eoa } -func (tdc *destinationClient) Allowed(chainID ids.ID, allowedRelayers []common.Address) bool { - return tdc.isDestination(chainID) && - tdc.isAllowedRelayer(allowedRelayers) +func (c *destinationClient) DestinationChainID() ids.ID { + return c.destinationChainID } From b9f9f68163b090fb647095e5b9f0380e1c7b44eb Mon Sep 17 00:00:00 2001 From: Cameron Schultz Date: Fri, 1 Sep 2023 11:39:58 -0400 Subject: [PATCH 02/10] clarify ShouldSendMessage handling --- messages/message_manager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/messages/message_manager.go b/messages/message_manager.go index 3a7601e6..46d608ab 100644 --- a/messages/message_manager.go +++ b/messages/message_manager.go @@ -20,6 +20,7 @@ import ( // for each message protocol, and performs the sending to the destination chain. type MessageManager interface { // ShouldSendMessage returns true if the message should be sent to the destination chain + // If an error is returned, the boolean should be ignored by the caller. ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageInfo, destinationChainID ids.ID) (bool, error) // SendMessage sends the signed message to the destination chain. The payload parsed according to // the VM rules is also passed in, since MessageManager does not assume any particular VM From aaad98cbe84ef3c25762698446b06f5d44fb9be2 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Tue, 5 Sep 2023 15:46:35 +0000 Subject: [PATCH 03/10] formatting --- messages/teleporter/message.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/messages/teleporter/message.go b/messages/teleporter/message.go index fded23c5..7f754c2b 100644 --- a/messages/teleporter/message.go +++ b/messages/teleporter/message.go @@ -7,9 +7,9 @@ import ( "fmt" "math/big" + "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/subnet-evm/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ava-labs/avalanchego/ids" ) // TeleporterMessage contains the Teleporter message, including @@ -38,8 +38,8 @@ type ReceiveCrossChainMessageInput struct { // MessageReceivedInput is the input to the MessageReceived // in the contract deployed on the receiving chain type MessageReceivedInput struct { - OriginChainID ids.ID `json:"relayerRewardAddress"` - MessageID *big.Int `json:"messageID"` + OriginChainID ids.ID `json:"relayerRewardAddress"` + MessageID *big.Int `json:"messageID"` } // unpack Teleporter message bytes according to EVM ABI encoding rules @@ -77,4 +77,4 @@ func unpackMessageReceivedResult(result []byte) (bool, error) { var success bool err := EVMTeleporterContractABI.UnpackIntoInterface(&success, "messageReceived", result) return success, err -} \ No newline at end of file +} From 6505639246742e0eff4bd56efd171e886385d663 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Thu, 7 Sep 2023 21:56:15 +0000 Subject: [PATCH 04/10] cleanup message manager --- messages/teleporter/message_manager.go | 67 +++++++++++++++++++------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/messages/teleporter/message_manager.go b/messages/teleporter/message_manager.go index 96557015..de8f5f89 100644 --- a/messages/teleporter/message_manager.go +++ b/messages/teleporter/message_manager.go @@ -111,21 +111,57 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI } senderAddress := destinationClient.SenderAddress() if !isAllowedRelayer(teleporterMessage.AllowedRelayerAddresses, senderAddress) { - m.logger.Info("Relayer EOA not allowed to deliver this message.") + m.logger.Info( + "Relayer EOA not allowed to deliver this message.", + zap.String("destinationChainID", destinationChainID.String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), + ) return false, nil } - if !isDestination(destinationChainID, destinationClient.DestinationChainID()) { + + delivered, err := m.messageDelivered( + destinationClient, + warpMessageInfo, + teleporterMessage, + senderAddress, + destinationChainID, + ) + if err != nil { + m.logger.Error( + "Failed to check if message has been delivered to destination chain.", + zap.String("destinationChainID", destinationChainID.String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), + zap.Error(err), + ) + return false, err + } + if delivered { m.logger.Info( - "Destination chain ID for message not supported by relayer.", + "Message already delivered to destination.", zap.String("destinationChainID", destinationChainID.String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), ) return false, nil } + // Cache the message so it can be reused in SendMessage + m.teleporterMessageCache.Put(warpMessageInfo.WarpUnsignedMessage.ID(), teleporterMessage) + return true, nil +} + +// Helper to check if a message has been delivered to the destination chain +// Returns true if the message has been delivered, false if not +// On error, the boolean result should be ignored +func (m *messageManager) messageDelivered( + destinationClient vms.DestinationClient, + warpMessageInfo *vmtypes.WarpMessageInfo, + teleporterMessage *TeleporterMessage, + senderAddress common.Address, + destinationChainID ids.ID) (bool, error) { // Check if the message has already been delivered to the destination chain client, ok := destinationClient.Client().(ethclient.Client) if !ok { - m.logger.Info("Destination client is not an Ethereum client.") + m.logger.Error("Destination client is not an Ethereum client.") return false, errors.New("destination client is not an Ethereum client") } @@ -134,7 +170,7 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI MessageID: teleporterMessage.MessageID, }) if err != nil { - m.logger.Info("Failed packing messageReceived call data.") + m.logger.Error("Failed packing messageReceived call data.") return false, err } protocolAddress := common.BytesToAddress(m.protocolAddress[:]) @@ -145,26 +181,21 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI } result, err := client.CallContract(context.Background(), callMessage, nil) if err != nil { - m.logger.Info("Failed calling messageReceived method on destination chain.") + m.logger.Error( + "Failed calling messageReceived method on destination chain.", + zap.String("destinationChainID", destinationChainID.String()), + ) return false, err } // check the contract call result - received, err := unpackMessageReceivedResult(result) + delivered, err := unpackMessageReceivedResult(result) if err != nil { return false, err } - if received { - m.logger.Info( - "Message already deliverd to destination.", - zap.String("destinationChainID", destinationChainID.String()), - zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), - ) - return false, nil + if delivered { + return true, nil } - - // Cache the message so it can be reused in SendMessage - m.teleporterMessageCache.Put(warpMessageInfo.WarpUnsignedMessage.ID(), teleporterMessage) - return true, nil + return false, nil } // SendMessage extracts the gasLimit and packs the call data to call the receiveCrossChainMessage method of the Teleporter contract, From 08cdef5f4697885d7c7cd2f920342e5fb62f1624 Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Fri, 8 Sep 2023 14:26:31 +0000 Subject: [PATCH 05/10] clarify comment --- messages/teleporter/message.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/messages/teleporter/message.go b/messages/teleporter/message.go index 7f754c2b..7729b394 100644 --- a/messages/teleporter/message.go +++ b/messages/teleporter/message.go @@ -29,14 +29,14 @@ type TeleporterMessageReceipt struct { RelayerRewardAddress common.Address `json:"relayerRewardAddress"` } -// ReceiveCrossChainMessageInput is the input to the ReceiveCrossChainMessage -// in the contract deployed on the receiving chain +// ReceiveCrossChainMessageInput is the input to receiveCrossChainMessage call +// in the contract deployed on the destination chain type ReceiveCrossChainMessageInput struct { RelayerRewardAddress common.Address `json:"relayerRewardAddress"` } -// MessageReceivedInput is the input to the MessageReceived -// in the contract deployed on the receiving chain +// MessageReceivedInput is the input to messageReceived call +// in the contract deployed on the destination chain type MessageReceivedInput struct { OriginChainID ids.ID `json:"relayerRewardAddress"` MessageID *big.Int `json:"messageID"` From 3526d032a39836e88b4ad549b6dbb415e5970dfa Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Fri, 8 Sep 2023 14:26:42 +0000 Subject: [PATCH 06/10] remove unused helper --- messages/teleporter/message_manager.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/messages/teleporter/message_manager.go b/messages/teleporter/message_manager.go index de8f5f89..c2d80f40 100644 --- a/messages/teleporter/message_manager.go +++ b/messages/teleporter/message_manager.go @@ -74,10 +74,6 @@ func NewMessageManager( }, nil } -func isDestination(messageDestinationID ids.ID, allowedDestinationID ids.ID) bool { - return messageDestinationID == allowedDestinationID -} - func isAllowedRelayer(allowedRelayers []common.Address, eoa common.Address) bool { // If no allowed relayer addresses were set, then anyone can relay it. if len(allowedRelayers) == 0 { From 03267da9e1ff06f6cf964d7f66be24f33c58c3ce Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Fri, 8 Sep 2023 14:31:21 +0000 Subject: [PATCH 07/10] improve logging --- messages/teleporter/message_manager.go | 32 +++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/messages/teleporter/message_manager.go b/messages/teleporter/message_manager.go index c2d80f40..772d5faa 100644 --- a/messages/teleporter/message_manager.go +++ b/messages/teleporter/message_manager.go @@ -110,6 +110,7 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI m.logger.Info( "Relayer EOA not allowed to deliver this message.", zap.String("destinationChainID", destinationChainID.String()), + zap.String("warpMessageID", warpMessageInfo.WarpUnsignedMessage.ID().String()), zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), ) return false, nil @@ -126,6 +127,7 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI m.logger.Error( "Failed to check if message has been delivered to destination chain.", zap.String("destinationChainID", destinationChainID.String()), + zap.String("warpMessageID", warpMessageInfo.WarpUnsignedMessage.ID().String()), zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), zap.Error(err), ) @@ -157,7 +159,10 @@ func (m *messageManager) messageDelivered( // Check if the message has already been delivered to the destination chain client, ok := destinationClient.Client().(ethclient.Client) if !ok { - m.logger.Error("Destination client is not an Ethereum client.") + m.logger.Error( + "Destination client is not an Ethereum client.", + zap.String("destinationChainID", destinationChainID.String()), + ) return false, errors.New("destination client is not an Ethereum client") } @@ -166,7 +171,11 @@ func (m *messageManager) messageDelivered( MessageID: teleporterMessage.MessageID, }) if err != nil { - m.logger.Error("Failed packing messageReceived call data.") + m.logger.Error( + "Failed packing messageReceived call data.", + zap.String("destinationChainID", destinationChainID.String()), + zap.Error(err), + ) return false, err } protocolAddress := common.BytesToAddress(m.protocolAddress[:]) @@ -180,12 +189,18 @@ func (m *messageManager) messageDelivered( m.logger.Error( "Failed calling messageReceived method on destination chain.", zap.String("destinationChainID", destinationChainID.String()), + zap.Error(err), ) return false, err } // check the contract call result delivered, err := unpackMessageReceivedResult(result) if err != nil { + m.logger.Error( + "Failed unpacking messageReceived result.", + zap.String("destinationChainID", destinationChainID.String()), + zap.Error(err), + ) return false, err } if delivered { @@ -205,6 +220,7 @@ func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayloa if !ok { m.logger.Debug( "Teleporter message to send not in cache. Extracting from signed warp message.", + zap.String("destinationChainID", destinationChainID.String()), zap.String("warpMessageID", signedMessage.ID().String()), ) var err error @@ -212,6 +228,7 @@ func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayloa if err != nil { m.logger.Error( "Failed unpacking teleporter message.", + zap.String("destinationChainID", destinationChainID.String()), zap.String("warpMessageID", signedMessage.ID().String()), ) return err @@ -221,13 +238,16 @@ func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayloa m.logger.Info( "Sending message to destination chain", zap.String("destinationChainID", destinationChainID.String()), + zap.String("warpMessageID", signedMessage.ID().String()), zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), ) numSigners, err := signedMessage.Signature.NumSigners() if err != nil { m.logger.Error( "Failed to get number of signers", + zap.String("destinationChainID", destinationChainID.String()), zap.String("warpMessageID", signedMessage.ID().String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), ) return err } @@ -235,7 +255,9 @@ func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayloa if err != nil { m.logger.Error( "Gas limit required overflowed uint64 max. not relaying message", + zap.String("destinationChainID", destinationChainID.String()), zap.String("warpMessageID", signedMessage.ID().String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), ) return err } @@ -246,7 +268,9 @@ func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayloa if err != nil { m.logger.Error( "Failed packing receiveCrossChainMessage call data", + zap.String("destinationChainID", destinationChainID.String()), zap.String("warpMessageID", signedMessage.ID().String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), ) return err } @@ -260,8 +284,9 @@ func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayloa if err != nil { m.logger.Error( "Failed to send tx.", - zap.String("warpMessageID", signedMessage.ID().String()), zap.String("destinationChainID", destinationChainID.String()), + zap.String("warpMessageID", signedMessage.ID().String()), + zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), zap.Error(err), ) return err @@ -269,6 +294,7 @@ func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayloa m.logger.Info( "Sent message to destination chain", zap.String("destinationChainID", destinationChainID.String()), + zap.String("warpMessageID", signedMessage.ID().String()), zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), ) return nil From 63e65f8ec4b9b709c37d93b8bafbd8a29c02dbab Mon Sep 17 00:00:00 2001 From: cam-schultz Date: Fri, 8 Sep 2023 14:32:52 +0000 Subject: [PATCH 08/10] cleanup var decl --- messages/teleporter/message_manager.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/messages/teleporter/message_manager.go b/messages/teleporter/message_manager.go index 772d5faa..92fbc2df 100644 --- a/messages/teleporter/message_manager.go +++ b/messages/teleporter/message_manager.go @@ -212,11 +212,7 @@ func (m *messageManager) messageDelivered( // SendMessage extracts the gasLimit and packs the call data to call the receiveCrossChainMessage method of the Teleporter contract, // and dispatches transaction construction and broadcast to the destination client func (m *messageManager) SendMessage(signedMessage *warp.Message, parsedVmPayload []byte, destinationChainID ids.ID) error { - var ( - teleporterMessage *TeleporterMessage - ok bool - ) - teleporterMessage, ok = m.teleporterMessageCache.Get(signedMessage.ID()) + teleporterMessage, ok := m.teleporterMessageCache.Get(signedMessage.ID()) if !ok { m.logger.Debug( "Teleporter message to send not in cache. Extracting from signed warp message.", From 707915336dc372da46ee1484381e6bba562478e5 Mon Sep 17 00:00:00 2001 From: Cameron Schultz Date: Wed, 13 Sep 2023 11:47:25 -0500 Subject: [PATCH 09/10] lint --- messages/teleporter/message.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/messages/teleporter/message.go b/messages/teleporter/message.go index fded23c5..7f754c2b 100644 --- a/messages/teleporter/message.go +++ b/messages/teleporter/message.go @@ -7,9 +7,9 @@ import ( "fmt" "math/big" + "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/subnet-evm/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/ava-labs/avalanchego/ids" ) // TeleporterMessage contains the Teleporter message, including @@ -38,8 +38,8 @@ type ReceiveCrossChainMessageInput struct { // MessageReceivedInput is the input to the MessageReceived // in the contract deployed on the receiving chain type MessageReceivedInput struct { - OriginChainID ids.ID `json:"relayerRewardAddress"` - MessageID *big.Int `json:"messageID"` + OriginChainID ids.ID `json:"relayerRewardAddress"` + MessageID *big.Int `json:"messageID"` } // unpack Teleporter message bytes according to EVM ABI encoding rules @@ -77,4 +77,4 @@ func unpackMessageReceivedResult(result []byte) (bool, error) { var success bool err := EVMTeleporterContractABI.UnpackIntoInterface(&success, "messageReceived", result) return success, err -} \ No newline at end of file +} From 0a1a368ff2f4d13b878817963d8cac5d5e786980 Mon Sep 17 00:00:00 2001 From: Cameron Schultz Date: Thu, 14 Sep 2023 15:11:20 -0500 Subject: [PATCH 10/10] cleanup unnecessary param+return logic --- messages/teleporter/message_manager.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/messages/teleporter/message_manager.go b/messages/teleporter/message_manager.go index 92fbc2df..aa6c152e 100644 --- a/messages/teleporter/message_manager.go +++ b/messages/teleporter/message_manager.go @@ -120,7 +120,6 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI destinationClient, warpMessageInfo, teleporterMessage, - senderAddress, destinationChainID, ) if err != nil { @@ -154,7 +153,6 @@ func (m *messageManager) messageDelivered( destinationClient vms.DestinationClient, warpMessageInfo *vmtypes.WarpMessageInfo, teleporterMessage *TeleporterMessage, - senderAddress common.Address, destinationChainID ids.ID) (bool, error) { // Check if the message has already been delivered to the destination chain client, ok := destinationClient.Client().(ethclient.Client) @@ -181,7 +179,6 @@ func (m *messageManager) messageDelivered( protocolAddress := common.BytesToAddress(m.protocolAddress[:]) callMessage := interfaces.CallMsg{ To: &protocolAddress, - From: senderAddress, Data: data, } result, err := client.CallContract(context.Background(), callMessage, nil) @@ -203,10 +200,8 @@ func (m *messageManager) messageDelivered( ) return false, err } - if delivered { - return true, nil - } - return false, nil + + return delivered, nil } // SendMessage extracts the gasLimit and packs the call data to call the receiveCrossChainMessage method of the Teleporter contract,