diff --git a/chains/evm/executor/executor.go b/chains/evm/executor/executor.go index 4fb4d054..92a84434 100644 --- a/chains/evm/executor/executor.go +++ b/chains/evm/executor/executor.go @@ -83,7 +83,7 @@ func (e *Executor) Execute(proposals []*proposal.Proposal) error { } p := pool.New().WithErrors() - for _, batch := range batches { + for i, batch := range batches { if len(batch.proposals) == 0 { continue } @@ -95,12 +95,14 @@ func (e *Executor) Execute(proposals []*proposal.Proposal) error { return err } - sessionID := e.sessionID(propHash) + sessionID := fmt.Sprintf("%s-%d", batch.proposals[0].MessageID, i) + log.Info().Str("messageID", batch.proposals[0].MessageID).Msgf("Starting session with ID: %s", sessionID) + msg := big.NewInt(0) msg.SetBytes(propHash) signing, err := signing.NewSigning( msg, - e.sessionID(propHash), + sessionID, e.host, e.comm, e.fetcher) @@ -150,7 +152,7 @@ func (e *Executor) watchExecution(ctx context.Context, cancelExecution context.C return err } - log.Info().Str("SessionID", sessionID).Msgf("Sent proposals execution with hash: %s", hash) + log.Info().Str("messageID", sessionID).Msgf("Sent proposals execution with hash: %s", hash) } case <-ticker.C: { @@ -158,7 +160,7 @@ func (e *Executor) watchExecution(ctx context.Context, cancelExecution context.C continue } - log.Info().Str("SessionID", sessionID).Msgf("Successfully executed proposals") + log.Info().Str("messageID", sessionID).Msgf("Successfully executed proposals") return nil } case <-timeout.C: @@ -194,7 +196,7 @@ func (e *Executor) proposalBatches(proposals []*proposal.Proposal) ([]*Batch, er return nil, err } if isExecuted { - log.Info().Msgf("Proposal %p already executed", transferProposal) + log.Info().Str("messageID", transferProposal.MessageID).Msgf("Proposal %p already executed", transferProposal) continue } @@ -247,7 +249,3 @@ func (e *Executor) areProposalsExecuted(proposals []*transfer.TransferProposal) return true } - -func (e *Executor) sessionID(hash []byte) string { - return fmt.Sprintf("signing-%s", ethCommon.Bytes2Hex(hash)) -} diff --git a/chains/evm/executor/message-handler.go b/chains/evm/executor/message-handler.go index 83072e27..8597eca6 100644 --- a/chains/evm/executor/message-handler.go +++ b/chains/evm/executor/message-handler.go @@ -21,12 +21,12 @@ import ( type TransferMessageHandler struct{} func (h *TransferMessageHandler) HandleMessage(msg *message.Message) (*proposal.Proposal, error) { - transferMessage := &transfer.TransferMessage{ Source: msg.Source, Destination: msg.Destination, Data: msg.Data.(transfer.TransferMessageData), Type: msg.Type, + ID: msg.ID, } switch transferMessage.Data.Type { @@ -45,7 +45,6 @@ func (h *TransferMessageHandler) HandleMessage(msg *message.Message) (*proposal. } func PermissionlessGenericMessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, error) { - executeFunctionSignature, ok := msg.Data.Payload[0].([]byte) if !ok { return nil, errors.New("wrong function signature format") @@ -85,7 +84,7 @@ func PermissionlessGenericMessageHandler(msg *transfer.TransferMessage) (*propos ResourceId: msg.Data.ResourceId, Metadata: msg.Data.Metadata, Data: data.Bytes(), - }, transfer.TransferProposalType), nil + }, msg.ID, transfer.TransferProposalType), nil } func ERC20MessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, error) { @@ -111,11 +110,10 @@ func ERC20MessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, err ResourceId: msg.Data.ResourceId, Metadata: msg.Data.Metadata, Data: data, - }, transfer.TransferProposalType), nil + }, msg.ID, transfer.TransferProposalType), nil } func ERC721MessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, error) { - if len(msg.Data.Payload) != 3 { return nil, errors.New("malformed payload. Len of payload should be 3") } @@ -144,11 +142,10 @@ func ERC721MessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, er ResourceId: msg.Data.ResourceId, Metadata: msg.Data.Metadata, Data: data.Bytes(), - }, transfer.TransferProposalType), nil + }, msg.ID, transfer.TransferProposalType), nil } func ERC1155MessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, error) { - if len(msg.Data.Payload) != 4 { return nil, errors.New("malformed payload. Len of payload should be 4") } @@ -187,7 +184,7 @@ func ERC1155MessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, e ResourceId: msg.Data.ResourceId, Metadata: msg.Data.Metadata, Data: data, - }, transfer.TransferProposalType), nil + }, msg.ID, transfer.TransferProposalType), nil } func GenericMessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, error) { @@ -207,5 +204,5 @@ func GenericMessageHandler(msg *transfer.TransferMessage) (*proposal.Proposal, e ResourceId: msg.Data.ResourceId, Metadata: msg.Data.Metadata, Data: data.Bytes(), - }, transfer.TransferProposalType), nil + }, msg.ID, transfer.TransferProposalType), nil } diff --git a/chains/evm/executor/message-handler_test.go b/chains/evm/executor/message-handler_test.go index df704f54..d7d1673d 100644 --- a/chains/evm/executor/message-handler_test.go +++ b/chains/evm/executor/message-handler_test.go @@ -409,6 +409,7 @@ func (s *PermissionlessGenericHandlerTestSuite) Test_HandleMessage() { Type: transfer.PermissionlessGenericTransfer, }, Type: transfer.TransferMessageType, + ID: "messageID", } mh := executor.TransferMessageHandler{} @@ -424,6 +425,7 @@ func (s *PermissionlessGenericHandlerTestSuite) Test_HandleMessage() { Metadata: message.Data.(transfer.TransferMessageData).Metadata, Data: expectedData, }, + "messageID", transfer.TransferProposalType, ) s.Nil(err) diff --git a/chains/evm/listener/depositHandlers/deposit-handler.go b/chains/evm/listener/depositHandlers/deposit-handler.go index 09c051f4..fea8a5ec 100644 --- a/chains/evm/listener/depositHandlers/deposit-handler.go +++ b/chains/evm/listener/depositHandlers/deposit-handler.go @@ -31,7 +31,14 @@ func NewETHDepositHandler(handlerMatcher HandlerMatcher) *ETHDepositHandler { } } -func (e *ETHDepositHandler) HandleDeposit(sourceID, destID uint8, depositNonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) { +func (e *ETHDepositHandler) HandleDeposit( + sourceID, + destID uint8, + depositNonce uint64, + resourceID [32]byte, + calldata, + handlerResponse []byte, + messageID string) (*message.Message, error) { handlerAddr, err := e.handlerMatcher.GetHandlerAddressForResourceID(resourceID) if err != nil { return nil, err @@ -42,7 +49,7 @@ func (e *ETHDepositHandler) HandleDeposit(sourceID, destID uint8, depositNonce u return nil, err } - return depositHandler.HandleDeposit(sourceID, destID, depositNonce, resourceID, calldata, handlerResponse) + return depositHandler.HandleDeposit(sourceID, destID, depositNonce, resourceID, calldata, handlerResponse, messageID) } // matchAddressWithHandlerFunc matches a handler address with an associated handler function diff --git a/chains/evm/listener/depositHandlers/erc1155.go b/chains/evm/listener/depositHandlers/erc1155.go index 95250718..12c20f0d 100644 --- a/chains/evm/listener/depositHandlers/erc1155.go +++ b/chains/evm/listener/depositHandlers/erc1155.go @@ -8,6 +8,44 @@ import ( type Erc1155DepositHandler struct{} +func (dh *Erc1155DepositHandler) HandleDeposit( + sourceID, + destID uint8, + nonce uint64, + resourceID [32]byte, + calldata, handlerResponse []byte, + messageID string) (*message.Message, error) { + erc1155Type, err := GetErc1155Type() + if err != nil { + return nil, err + } + + decodedCallData, err := erc1155Type.UnpackValues(calldata) + if err != nil { + return nil, err + } + + payload := []interface{}{ + decodedCallData[0], + decodedCallData[1], + decodedCallData[2], + decodedCallData[3], + } + + return message.NewMessage( + sourceID, + destID, + transfer.TransferMessageData{ + DepositNonce: nonce, + ResourceId: resourceID, + Metadata: nil, + Payload: payload, + Type: transfer.SemiFungibleTransfer, + }, + messageID, + transfer.TransferMessageType), nil +} + func GetErc1155Type() (abi.Arguments, error) { tokenIDsType, err := abi.NewType("uint256[]", "", nil) if err != nil { @@ -37,31 +75,3 @@ func GetErc1155Type() (abi.Arguments, error) { abi.Argument{Name: "transferData", Type: transferDataType, Indexed: false}, }, nil } - -func (dh *Erc1155DepositHandler) HandleDeposit(sourceID, destId uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) { - - erc1155Type, err := GetErc1155Type() - if err != nil { - return nil, err - } - - decodedCallData, err := erc1155Type.UnpackValues(calldata) - if err != nil { - return nil, err - } - - payload := []interface{}{ - decodedCallData[0], - decodedCallData[1], - decodedCallData[2], - decodedCallData[3], - } - - return message.NewMessage(sourceID, destId, transfer.TransferMessageData{ - DepositNonce: nonce, - ResourceId: resourceID, - Metadata: nil, - Payload: payload, - Type: transfer.SemiFungibleTransfer, - }, transfer.TransferMessageType), nil -} diff --git a/chains/evm/listener/depositHandlers/erc1155_test.go b/chains/evm/listener/depositHandlers/erc1155_test.go index c3483b51..c33033be 100644 --- a/chains/evm/listener/depositHandlers/erc1155_test.go +++ b/chains/evm/listener/depositHandlers/erc1155_test.go @@ -52,9 +52,17 @@ func (s *Erc1155HandlerTestSuite) Test_Erc1155HandleEvent() { Type: transfer.SemiFungibleTransfer, }, Type: transfer.TransferMessageType, + ID: "messageID", } erc1155DepositHandler := depositHandlers.Erc1155DepositHandler{} - message, err := erc1155DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse) + message, err := erc1155DepositHandler.HandleDeposit( + sourceID, + depositLog.DestinationDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.Data, + depositLog.HandlerResponse, + "messageID") s.Nil(err) s.NotNil(message) @@ -75,7 +83,14 @@ func (s *Erc1155HandlerTestSuite) Test_Erc1155HandleEvent_ErrInvalidCallData() { sourceID := uint8(1) erc1155DepositHandler := depositHandlers.Erc1155DepositHandler{} - message, err := erc1155DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse) + message, err := erc1155DepositHandler.HandleDeposit( + sourceID, + depositLog.DestinationDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.Data, + depositLog.HandlerResponse, + "messageID") s.Nil(message) s.NotNil(err) diff --git a/chains/evm/listener/depositHandlers/erc20.go b/chains/evm/listener/depositHandlers/erc20.go index cb23c729..9b29d36f 100644 --- a/chains/evm/listener/depositHandlers/erc20.go +++ b/chains/evm/listener/depositHandlers/erc20.go @@ -12,7 +12,14 @@ type Erc20DepositHandler struct{} // Erc20DepositHandler converts data pulled from event logs into message // handlerResponse can be an empty slice -func (dh *Erc20DepositHandler) HandleDeposit(sourceID, destId uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) { +func (dh *Erc20DepositHandler) HandleDeposit( + sourceID, + destID uint8, + nonce uint64, + resourceID [32]byte, + calldata, + handlerResponse []byte, + messageID string) (*message.Message, error) { if len(calldata) < 84 { err := errors.New("invalid calldata length: less than 84 bytes") return nil, err @@ -33,11 +40,16 @@ func (dh *Erc20DepositHandler) HandleDeposit(sourceID, destId uint8, nonce uint6 amount, recipientAddress, } - return message.NewMessage(sourceID, destId, transfer.TransferMessageData{ - DepositNonce: nonce, - ResourceId: resourceID, - Metadata: nil, - Payload: payload, - Type: transfer.FungibleTransfer, - }, transfer.TransferMessageType), nil + return message.NewMessage( + sourceID, + destID, + transfer.TransferMessageData{ + DepositNonce: nonce, + ResourceId: resourceID, + Metadata: nil, + Payload: payload, + Type: transfer.FungibleTransfer, + }, + messageID, + transfer.TransferMessageType), nil } diff --git a/chains/evm/listener/depositHandlers/erc20_test.go b/chains/evm/listener/depositHandlers/erc20_test.go index 38e9c58e..cfa5f71c 100644 --- a/chains/evm/listener/depositHandlers/erc20_test.go +++ b/chains/evm/listener/depositHandlers/erc20_test.go @@ -26,11 +26,6 @@ func TestRunErc20HandlerTestSuite(t *testing.T) { suite.Run(t, new(Erc20HandlerTestSuite)) } -func (s *Erc20HandlerTestSuite) SetupSuite() {} -func (s *Erc20HandlerTestSuite) TearDownSuite() {} -func (s *Erc20HandlerTestSuite) SetupTest() {} -func (s *Erc20HandlerTestSuite) TearDownTest() {} - func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() { // 0xf1e58fb17704c2da8479a533f9fad4ad0993ca6b recipientByteSlice := []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107} @@ -62,9 +57,17 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() { Type: transfer.FungibleTransfer, }, Type: transfer.TransferMessageType, + ID: "messageID", } erc20DepositHandler := depositHandlers.Erc20DepositHandler{} - message, err := erc20DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse) + message, err := erc20DepositHandler.HandleDeposit( + sourceID, + depositLog.DestinationDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.Data, + depositLog.HandlerResponse, + "messageID") s.Nil(err) s.NotNil(message) @@ -90,7 +93,15 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEventIncorrectDataLen() { sourceID := uint8(1) erc20DepositHandler := depositHandlers.Erc20DepositHandler{} - message, err := erc20DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse) + message, err := erc20DepositHandler.HandleDeposit( + sourceID, + depositLog.DestinationDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.Data, + depositLog.HandlerResponse, + "messageID", + ) s.Nil(message) s.EqualError(err, errIncorrectDataLen.Error()) diff --git a/chains/evm/listener/depositHandlers/erc721.go b/chains/evm/listener/depositHandlers/erc721.go index ef4ba4a6..37d8a610 100644 --- a/chains/evm/listener/depositHandlers/erc721.go +++ b/chains/evm/listener/depositHandlers/erc721.go @@ -12,7 +12,13 @@ import ( type Erc721DepositHandler struct{} // Erc721DepositHandler converts data pulled from ERC721 deposit event logs into message -func (dh *Erc721DepositHandler) HandleDeposit(sourceID, destId uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) { +func (dh *Erc721DepositHandler) HandleDeposit( + sourceID, + destID uint8, + nonce uint64, + resourceID [32]byte, + calldata, handlerResponse []byte, + messageID string) (*message.Message, error) { if len(calldata) < 64 { err := errors.New("invalid calldata length: less than 84 bytes") return nil, err @@ -47,11 +53,16 @@ func (dh *Erc721DepositHandler) HandleDeposit(sourceID, destId uint8, nonce uint metadata, } - return message.NewMessage(sourceID, destId, transfer.TransferMessageData{ - DepositNonce: nonce, - ResourceId: resourceID, - Metadata: meta, - Payload: payload, - Type: transfer.NonFungibleTransfer, - }, transfer.TransferMessageType), nil + return message.NewMessage( + sourceID, + destID, + transfer.TransferMessageData{ + DepositNonce: nonce, + ResourceId: resourceID, + Metadata: meta, + Payload: payload, + Type: transfer.NonFungibleTransfer, + }, + messageID, + transfer.TransferMessageType), nil } diff --git a/chains/evm/listener/depositHandlers/erc721_test.go b/chains/evm/listener/depositHandlers/erc721_test.go index e6a8d009..48ace4e4 100644 --- a/chains/evm/listener/depositHandlers/erc721_test.go +++ b/chains/evm/listener/depositHandlers/erc721_test.go @@ -22,11 +22,6 @@ func TestRunErc721HandlerTestSuite(t *testing.T) { suite.Run(t, new(Erc721HandlerTestSuite)) } -func (s *Erc721HandlerTestSuite) SetupSuite() {} -func (s *Erc721HandlerTestSuite) TearDownSuite() {} -func (s *Erc721HandlerTestSuite) SetupTest() {} -func (s *Erc721HandlerTestSuite) TearDownTest() {} - func (s *Erc721HandlerTestSuite) TestErc721DepositHandlerEmptyMetadata() { recipient := common.HexToAddress("0xf1e58fb17704c2da8479a533f9fad4ad0993ca6b") @@ -59,10 +54,18 @@ func (s *Erc721HandlerTestSuite) TestErc721DepositHandlerEmptyMetadata() { }, Type: transfer.TransferMessageType, + ID: "messageID", } erc721DepositHandler := depositHandlers.Erc721DepositHandler{} - m, err := erc721DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse) + m, err := erc721DepositHandler.HandleDeposit( + sourceID, + depositLog.DestinationDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.Data, + depositLog.HandlerResponse, + "messageID") s.Nil(err) s.NotNil(m) @@ -88,7 +91,14 @@ func (s *Erc721HandlerTestSuite) TestErc721DepositHandlerIncorrectDataLen() { sourceID := uint8(1) erc721DepositHandler := depositHandlers.Erc721DepositHandler{} - m, err := erc721DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse) + m, err := erc721DepositHandler.HandleDeposit( + sourceID, + depositLog.DestinationDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.Data, + depositLog.HandlerResponse, + "messageID") s.Nil(m) s.EqualError(err, "invalid calldata length: less than 84 bytes") } @@ -126,10 +136,18 @@ func (s *Erc721HandlerTestSuite) TestErc721DepositHandler() { }, Type: transfer.TransferMessageType, + ID: "messageID", } erc721DepositHandler := depositHandlers.Erc721DepositHandler{} - m, err := erc721DepositHandler.HandleDeposit(sourceID, depositLog.DestinationDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse) + m, err := erc721DepositHandler.HandleDeposit( + sourceID, + depositLog.DestinationDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.Data, + depositLog.HandlerResponse, + "messageID") s.Nil(err) s.NotNil(m) s.Equal(expected, m) diff --git a/chains/evm/listener/depositHandlers/generic.go b/chains/evm/listener/depositHandlers/generic.go index ef3d60ca..0c07f01f 100644 --- a/chains/evm/listener/depositHandlers/generic.go +++ b/chains/evm/listener/depositHandlers/generic.go @@ -11,7 +11,13 @@ import ( type GenericDepositHandler struct{} // GenericDepositHandler converts data pulled from generic deposit event logs into message -func (dh *GenericDepositHandler) HandleDeposit(sourceID, destId uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) { +func (dh *GenericDepositHandler) HandleDeposit( + sourceID, + destID uint8, + nonce uint64, + resourceID [32]byte, + calldata, handlerResponse []byte, + messageID string) (*message.Message, error) { if len(calldata) < 32 { err := errors.New("invalid calldata length: less than 32 bytes") return nil, err @@ -25,11 +31,16 @@ func (dh *GenericDepositHandler) HandleDeposit(sourceID, destId uint8, nonce uin } // generic handler has specific payload length and doesn't support arbitrary metadata - return message.NewMessage(sourceID, destId, transfer.TransferMessageData{ - DepositNonce: nonce, - ResourceId: resourceID, - Metadata: nil, - Payload: payload, - Type: transfer.PermissionedGenericTransfer, - }, transfer.TransferMessageType), nil + return message.NewMessage( + sourceID, + destID, + transfer.TransferMessageData{ + DepositNonce: nonce, + ResourceId: resourceID, + Metadata: nil, + Payload: payload, + Type: transfer.PermissionedGenericTransfer, + }, + messageID, + transfer.TransferMessageType), nil } diff --git a/chains/evm/listener/depositHandlers/generic_test.go b/chains/evm/listener/depositHandlers/generic_test.go index 174613a0..c7cb7707 100644 --- a/chains/evm/listener/depositHandlers/generic_test.go +++ b/chains/evm/listener/depositHandlers/generic_test.go @@ -23,11 +23,6 @@ func TestRunGenericHandlerTestSuite(t *testing.T) { suite.Run(t, new(GenericHandlerTestSuite)) } -func (s *GenericHandlerTestSuite) SetupSuite() {} -func (s *GenericHandlerTestSuite) TearDownSuite() {} -func (s *GenericHandlerTestSuite) SetupTest() {} -func (s *GenericHandlerTestSuite) TearDownTest() {} - func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectDataLen() { metadata := []byte("0xdeadbeef") @@ -54,7 +49,7 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectDataLen() { depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse, - ) + "messageID") s.Nil(message) s.EqualError(err, "invalid calldata length: less than 32 bytes") @@ -87,6 +82,7 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEventEmptyMetadata() { }, Type: transfer.TransferMessageType, + ID: "messageID", } genericDepositHandler := depositHandlers.GenericDepositHandler{} @@ -97,7 +93,7 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEventEmptyMetadata() { depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse, - ) + "messageID") s.Nil(err) s.NotNil(message) @@ -131,6 +127,7 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEvent() { }, Type: transfer.TransferMessageType, + ID: "messageID", } genericDepositHandler := depositHandlers.GenericDepositHandler{} @@ -141,7 +138,7 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEvent() { depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse, - ) + "messageID") s.Nil(err) s.NotNil(message) diff --git a/chains/evm/listener/depositHandlers/permissionless.go b/chains/evm/listener/depositHandlers/permissionless.go index 13cae244..89a4feb2 100644 --- a/chains/evm/listener/depositHandlers/permissionless.go +++ b/chains/evm/listener/depositHandlers/permissionless.go @@ -11,7 +11,12 @@ import ( type PermissionlessGenericDepositHandler struct{} // GenericDepositHandler converts data pulled from generic deposit event logs into message -func (dh *PermissionlessGenericDepositHandler) HandleDeposit(sourceID, destId uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) { +func (dh *PermissionlessGenericDepositHandler) HandleDeposit( + sourceID, destID uint8, + nonce uint64, + resourceID [32]byte, + calldata, handlerResponse []byte, + messageID string) (*message.Message, error) { if len(calldata) < 76 { err := errors.New("invalid calldata length: less than 76 bytes") return nil, err @@ -44,11 +49,16 @@ func (dh *PermissionlessGenericDepositHandler) HandleDeposit(sourceID, destId ui metadata["gasLimit"] = uint64(big.NewInt(0).SetBytes(maxFee).Int64()) - return message.NewMessage(sourceID, destId, transfer.TransferMessageData{ - DepositNonce: nonce, - ResourceId: resourceID, - Metadata: metadata, - Payload: payload, - Type: transfer.PermissionlessGenericTransfer, - }, transfer.TransferMessageType), nil + return message.NewMessage( + sourceID, + destID, + transfer.TransferMessageData{ + DepositNonce: nonce, + ResourceId: resourceID, + Metadata: metadata, + Payload: payload, + Type: transfer.PermissionlessGenericTransfer, + }, + messageID, + transfer.TransferMessageType), nil } diff --git a/chains/evm/listener/depositHandlers/permissionless_test.go b/chains/evm/listener/depositHandlers/permissionless_test.go index a47e0e10..98e1601a 100644 --- a/chains/evm/listener/depositHandlers/permissionless_test.go +++ b/chains/evm/listener/depositHandlers/permissionless_test.go @@ -73,6 +73,7 @@ func (s *PermissionlessGenericHandlerTestSuite) TestHandleEvent() { Type: transfer.PermissionlessGenericTransfer, }, Type: transfer.TransferMessageType, + ID: "messageID", } permissionlessGenericHandler := depositHandlers.PermissionlessGenericDepositHandler{} @@ -84,6 +85,7 @@ func (s *PermissionlessGenericHandlerTestSuite) TestHandleEvent() { depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse, + "messageID", ) s.Nil(err) @@ -115,7 +117,7 @@ func (s *PermissionlessGenericHandlerTestSuite) Test_HandleEvent_IncorrectDataLe depositLog.ResourceID, depositLog.Data, depositLog.HandlerResponse, - ) + "messageID") s.NotNil(err) } diff --git a/chains/evm/listener/eventHandlers/event-handler.go b/chains/evm/listener/eventHandlers/event-handler.go index 8b8c2e17..fd312e27 100644 --- a/chains/evm/listener/eventHandlers/event-handler.go +++ b/chains/evm/listener/eventHandlers/event-handler.go @@ -94,16 +94,17 @@ func (eh *RetryEventHandler) HandleEvents( } for _, d := range deposits { + messageID := fmt.Sprintf("%d-%d-%d-%d", eh.domainID, d.DestinationDomainID, startBlock, endBlock) msg, err := eh.depositHandler.HandleDeposit( eh.domainID, d.DestinationDomainID, d.DepositNonce, - d.ResourceID, d.Data, d.HandlerResponse, + d.ResourceID, d.Data, d.HandlerResponse, messageID, ) if err != nil { - eh.log.Error().Err(err).Msgf("Failed handling deposit %+v", d) + eh.log.Err(err).Str("messageID", msg.ID).Msgf("Failed handling deposit %+v", d) continue } - eh.log.Info().Msgf( + eh.log.Info().Str("messageID", msg.ID).Msgf( "Resolved retry message %+v in block range: %s-%s", msg, startBlock.String(), endBlock.String(), ) retriesByDomain[msg.Destination] = append(retriesByDomain[msg.Destination], msg) @@ -278,7 +279,7 @@ func (eh *RefreshEventHandler) sessionID(block *big.Int) string { } type DepositHandler interface { - HandleDeposit(sourceID, destID uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) + HandleDeposit(sourceID, destID uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte, messageID string) (*message.Message, error) } type DepositEventHandler struct { @@ -314,13 +315,14 @@ func (eh *DepositEventHandler) HandleEvents(startBlock *big.Int, endBlock *big.I } }() - m, err := eh.depositHandler.HandleDeposit(eh.domainID, d.DestinationDomainID, d.DepositNonce, d.ResourceID, d.Data, d.HandlerResponse) + messageID := fmt.Sprintf("%d-%d-%d-%d", eh.domainID, d.DestinationDomainID, startBlock, endBlock) + m, err := eh.depositHandler.HandleDeposit(eh.domainID, d.DestinationDomainID, d.DepositNonce, d.ResourceID, d.Data, d.HandlerResponse, messageID) if err != nil { log.Error().Err(err).Str("start block", startBlock.String()).Str("end block", endBlock.String()).Uint8("domainID", eh.domainID).Msgf("%v", err) return } - log.Debug().Msgf("Resolved message %+v in block range: %s-%s", m, startBlock.String(), endBlock.String()) + log.Debug().Str("messageID", m.ID).Msgf("Resolved message %+v in block range: %s-%s", m, startBlock.String(), endBlock.String()) domainDeposits[m.Destination] = append(domainDeposits[m.Destination], m) }(d) } diff --git a/chains/evm/listener/eventHandlers/event-handler_test.go b/chains/evm/listener/eventHandlers/event-handler_test.go index 067fdcba..3c241994 100644 --- a/chains/evm/listener/eventHandlers/event-handler_test.go +++ b/chains/evm/listener/eventHandlers/event-handler_test.go @@ -60,6 +60,7 @@ func (s *RetryEventHandlerTestSuite) Test_FetchDepositFails_ExecutionContinues() HandlerResponse: []byte{}, Data: []byte{}, } + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 5) s.mockEventListener.EXPECT().FetchRetryEvents( gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), ).Return([]events.RetryEvent{{TxHash: "event1"}, {TxHash: "event2"}}, nil) @@ -72,6 +73,7 @@ func (s *RetryEventHandlerTestSuite) Test_FetchDepositFails_ExecutionContinues() d.ResourceID, d.Data, d.HandlerResponse, + msgID, ).Return(&message.Message{ Data: transfer.TransferMessageData{ DepositNonce: 2, @@ -102,6 +104,7 @@ func (s *RetryEventHandlerTestSuite) Test_HandleDepositFails_ExecutionContinues( HandlerResponse: []byte{}, Data: []byte{}, } + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 5) s.mockEventListener.EXPECT().FetchRetryEvents( gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), ).Return([]events.RetryEvent{{TxHash: "event1"}, {TxHash: "event2"}}, nil) @@ -114,6 +117,7 @@ func (s *RetryEventHandlerTestSuite) Test_HandleDepositFails_ExecutionContinues( d1.ResourceID, d1.Data, d1.HandlerResponse, + msgID, ).Return(&message.Message{Data: transfer.TransferMessageData{ DepositNonce: 1, }}, fmt.Errorf("error")) @@ -124,6 +128,7 @@ func (s *RetryEventHandlerTestSuite) Test_HandleDepositFails_ExecutionContinues( d2.ResourceID, d2.Data, d2.HandlerResponse, + msgID, ).Return(&message.Message{Data: transfer.TransferMessageData{ DepositNonce: 2, }}, nil) @@ -132,9 +137,7 @@ func (s *RetryEventHandlerTestSuite) Test_HandleDepositFails_ExecutionContinues( msgs := <-s.msgChan s.Nil(err) - s.Equal(msgs, []*message.Message{{Data: transfer.TransferMessageData{ - DepositNonce: 2, - }}}) + s.Equal(msgs, []*message.Message{{Data: transfer.TransferMessageData{DepositNonce: 2}}}) } func (s *RetryEventHandlerTestSuite) Test_HandlingRetryPanics_ExecutionContinue() { @@ -157,6 +160,7 @@ func (s *RetryEventHandlerTestSuite) Test_HandlingRetryPanics_ExecutionContinue( ).Return([]events.RetryEvent{{TxHash: "event1"}, {TxHash: "event2"}}, nil) s.mockEventListener.EXPECT().FetchRetryDepositEvents(events.RetryEvent{TxHash: "event1"}, gomock.Any(), big.NewInt(5)).Return([]events.Deposit{d1}, nil) s.mockEventListener.EXPECT().FetchRetryDepositEvents(events.RetryEvent{TxHash: "event2"}, gomock.Any(), big.NewInt(5)).Return([]events.Deposit{d2}, nil) + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 5) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1.DestinationDomainID, @@ -164,7 +168,8 @@ func (s *RetryEventHandlerTestSuite) Test_HandlingRetryPanics_ExecutionContinue( d1.ResourceID, d1.Data, d1.HandlerResponse, - ).Do(func(sourceID, destID, nonce, resourceID, calldata, handlerResponse interface{}) { + msgID, + ).Do(func(sourceID, destID, nonce, resourceID, calldata, handlerResponse, msgID interface{}) { panic("error") }) s.mockDepositHandler.EXPECT().HandleDeposit( @@ -174,6 +179,7 @@ func (s *RetryEventHandlerTestSuite) Test_HandlingRetryPanics_ExecutionContinue( d2.ResourceID, d2.Data, d2.HandlerResponse, + msgID, ).Return(&message.Message{Data: transfer.TransferMessageData{ DepositNonce: 2, }}, nil) @@ -206,6 +212,7 @@ func (s *RetryEventHandlerTestSuite) Test_MultipleDeposits() { gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), ).Return([]events.RetryEvent{{TxHash: "event1"}}, nil) s.mockEventListener.EXPECT().FetchRetryDepositEvents(events.RetryEvent{TxHash: "event1"}, gomock.Any(), big.NewInt(5)).Return([]events.Deposit{d1, d2}, nil) + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 5) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1.DestinationDomainID, @@ -213,6 +220,7 @@ func (s *RetryEventHandlerTestSuite) Test_MultipleDeposits() { d1.ResourceID, d1.Data, d1.HandlerResponse, + msgID, ).Return(&message.Message{Data: transfer.TransferMessageData{ DepositNonce: 1, }}, nil) @@ -223,6 +231,7 @@ func (s *RetryEventHandlerTestSuite) Test_MultipleDeposits() { d2.ResourceID, d2.Data, d2.HandlerResponse, + msgID, ).Return(&message.Message{Data: transfer.TransferMessageData{ DepositNonce: 2, }}, nil) @@ -286,6 +295,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { } deposits := []*events.Deposit{d1, d2} s.mockEventListener.EXPECT().FetchDeposits(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(deposits, nil) + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 5) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1.DestinationDomainID, @@ -293,6 +303,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { d1.ResourceID, d1.Data, d1.HandlerResponse, + msgID, ).Return(&message.Message{}, fmt.Errorf("error")) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, @@ -301,6 +312,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { d2.ResourceID, d2.Data, d2.HandlerResponse, + msgID, ).Return( &message.Message{ Data: transfer.TransferMessageData{ @@ -334,6 +346,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositPanis_ExecutionContinues() { } deposits := []*events.Deposit{d1, d2} s.mockEventListener.EXPECT().FetchDeposits(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(deposits, nil) + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 5) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1.DestinationDomainID, @@ -341,7 +354,8 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositPanis_ExecutionContinues() { d1.ResourceID, d1.Data, d1.HandlerResponse, - ).Do(func(sourceID, destID, nonce, resourceID, calldata, handlerResponse interface{}) { + msgID, + ).Do(func(sourceID, destID, nonce, resourceID, calldata, handlerResponse, msgID interface{}) { panic("error") }) s.mockDepositHandler.EXPECT().HandleDeposit( @@ -351,6 +365,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositPanis_ExecutionContinues() { d2.ResourceID, d2.Data, d2.HandlerResponse, + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 2}}, nil, @@ -380,6 +395,7 @@ func (s *DepositHandlerTestSuite) Test_SuccessfulHandleDeposit() { } deposits := []*events.Deposit{d1, d2} s.mockEventListener.EXPECT().FetchDeposits(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(deposits, nil) + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 5) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1.DestinationDomainID, @@ -387,6 +403,7 @@ func (s *DepositHandlerTestSuite) Test_SuccessfulHandleDeposit() { d1.ResourceID, d1.Data, d1.HandlerResponse, + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 1}}, nil, @@ -398,6 +415,7 @@ func (s *DepositHandlerTestSuite) Test_SuccessfulHandleDeposit() { d2.ResourceID, d2.Data, d2.HandlerResponse, + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 2}}, nil, diff --git a/chains/evm/listener/eventHandlers/mock/listener.go b/chains/evm/listener/eventHandlers/mock/listener.go index 4180094e..e8cc6558 100644 --- a/chains/evm/listener/eventHandlers/mock/listener.go +++ b/chains/evm/listener/eventHandlers/mock/listener.go @@ -138,16 +138,16 @@ func (m *MockDepositHandler) EXPECT() *MockDepositHandlerMockRecorder { } // HandleDeposit mocks base method. -func (m *MockDepositHandler) HandleDeposit(sourceID, destID uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte) (*message.Message, error) { +func (m *MockDepositHandler) HandleDeposit(sourceID, destID uint8, nonce uint64, resourceID [32]byte, calldata, handlerResponse []byte, messageID string) (*message.Message, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HandleDeposit", sourceID, destID, nonce, resourceID, calldata, handlerResponse) + ret := m.ctrl.Call(m, "HandleDeposit", sourceID, destID, nonce, resourceID, calldata, handlerResponse, messageID) ret0, _ := ret[0].(*message.Message) ret1, _ := ret[1].(error) return ret0, ret1 } // HandleDeposit indicates an expected call of HandleDeposit. -func (mr *MockDepositHandlerMockRecorder) HandleDeposit(sourceID, destID, nonce, resourceID, calldata, handlerResponse interface{}) *gomock.Call { +func (mr *MockDepositHandlerMockRecorder) HandleDeposit(sourceID, destID, nonce, resourceID, calldata, handlerResponse, messageID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleDeposit", reflect.TypeOf((*MockDepositHandler)(nil).HandleDeposit), sourceID, destID, nonce, resourceID, calldata, handlerResponse) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleDeposit", reflect.TypeOf((*MockDepositHandler)(nil).HandleDeposit), sourceID, destID, nonce, resourceID, calldata, handlerResponse, messageID) } diff --git a/chains/substrate/executor/executor.go b/chains/substrate/executor/executor.go index 6fd0a420..15452dc0 100644 --- a/chains/substrate/executor/executor.go +++ b/chains/substrate/executor/executor.go @@ -76,14 +76,13 @@ func (e *Executor) Execute(proposals []*proposal.Proposal) error { defer e.exitLock.RUnlock() transferProposals := make([]*transfer.TransferProposal, 0) - for _, prop := range proposals { - transferProposal := &transfer.TransferProposal{ Source: prop.Source, Destination: prop.Destination, Data: prop.Data.(transfer.TransferProposalData), Type: prop.Type, + MessageID: prop.MessageID, } transferProposals = append(transferProposals, transferProposal) @@ -106,12 +105,12 @@ func (e *Executor) Execute(proposals []*proposal.Proposal) error { return err } - sessionID := e.sessionID(propHash) + sessionID := transferProposals[0].MessageID msg := big.NewInt(0) msg.SetBytes(propHash) signing, err := signing.NewSigning( msg, - e.sessionID(propHash), + sessionID, e.host, e.comm, e.fetcher) @@ -169,7 +168,7 @@ func (e *Executor) watchExecution(ctx context.Context, cancelExecution context.C continue } - log.Info().Str("SessionID", sessionID).Msgf("Successfully executed proposals") + log.Info().Str("messageID", sessionID).Msgf("Successfully executed proposals") return nil } case <-timeout.C: @@ -209,7 +208,3 @@ func (e *Executor) areProposalsExecuted(proposals []*transfer.TransferProposal) return true } - -func (e *Executor) sessionID(hash []byte) string { - return fmt.Sprintf("signing-%s", ethCommon.Bytes2Hex(hash)) -} diff --git a/chains/substrate/executor/message-handler.go b/chains/substrate/executor/message-handler.go index 3f711269..82b4ea21 100644 --- a/chains/substrate/executor/message-handler.go +++ b/chains/substrate/executor/message-handler.go @@ -21,6 +21,7 @@ func (mh *SubstrateMessageHandler) HandleMessage(m *message.Message) (*proposal. Destination: m.Destination, Data: m.Data.(transfer.TransferMessageData), Type: m.Type, + ID: m.ID, } switch transferMessage.Data.Type { case transfer.FungibleTransfer: @@ -30,7 +31,6 @@ func (mh *SubstrateMessageHandler) HandleMessage(m *message.Message) (*proposal. } func fungibleTransferMessageHandler(m *transfer.TransferMessage) (*proposal.Proposal, error) { - if len(m.Data.Payload) != 2 { return nil, errors.New("malformed payload. Len of payload should be 2") } @@ -53,5 +53,5 @@ func fungibleTransferMessageHandler(m *transfer.TransferMessage) (*proposal.Prop ResourceId: m.Data.ResourceId, Metadata: m.Data.Metadata, Data: data, - }, transfer.TransferProposalType), nil + }, m.ID, transfer.TransferProposalType), nil } diff --git a/chains/substrate/listener/deposit-handler.go b/chains/substrate/listener/deposit-handler.go index 81b8ea3e..dd7bbae4 100644 --- a/chains/substrate/listener/deposit-handler.go +++ b/chains/substrate/listener/deposit-handler.go @@ -13,7 +13,7 @@ import ( ) type DepositHandlers map[transfer.TransferType]DepositHandlerFunc -type DepositHandlerFunc func(sourceID uint8, destId types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte) (*message.Message, error) +type DepositHandlerFunc func(sourceID uint8, destId types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte, messageID string) (*message.Message, error) type SubstrateDepositHandler struct { depositHandlers DepositHandlers @@ -31,7 +31,14 @@ func NewSubstrateDepositHandler() *SubstrateDepositHandler { } } -func (e *SubstrateDepositHandler) HandleDeposit(sourceID uint8, destID types.U8, depositNonce types.U64, resourceID types.Bytes32, calldata []byte, transferType types.U8) (*message.Message, error) { +func (e *SubstrateDepositHandler) HandleDeposit( + sourceID uint8, + destID types.U8, + depositNonce types.U64, + resourceID types.Bytes32, + calldata []byte, + transferType types.U8, + messageID string) (*message.Message, error) { var depositType transfer.TransferType if transferType == FungibleTransfer { depositType = transfer.FungibleTransfer @@ -44,7 +51,7 @@ func (e *SubstrateDepositHandler) HandleDeposit(sourceID uint8, destID types.U8, return nil, err } - return depositHandler(sourceID, destID, depositNonce, resourceID, calldata) + return depositHandler(sourceID, destID, depositNonce, resourceID, calldata, messageID) } // matchAddressWithHandlerFunc matches a transfer type with an associated handler function @@ -68,7 +75,13 @@ func (e *SubstrateDepositHandler) RegisterDepositHandler(transferType transfer.T // FungibleTransferHandler converts data pulled from event logs into message // handlerResponse can be an empty slice -func FungibleTransferHandler(sourceID uint8, destId types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte) (*message.Message, error) { +func FungibleTransferHandler( + sourceID uint8, + destID types.U8, + nonce types.U64, + resourceID types.Bytes32, + calldata []byte, + messageID string) (*message.Message, error) { if len(calldata) < 84 { err := errors.New("invalid calldata length: less than 84 bytes") return nil, err @@ -89,10 +102,15 @@ func FungibleTransferHandler(sourceID uint8, destId types.U8, nonce types.U64, r recipientAddress, } - return message.NewMessage(sourceID, uint8(destId), transfer.TransferMessageData{ - DepositNonce: uint64(nonce), - ResourceId: resourceID, - Payload: payload, - Type: transfer.FungibleTransfer, - }, transfer.TransferMessageType), nil + return message.NewMessage( + sourceID, + uint8(destID), + transfer.TransferMessageData{ + DepositNonce: uint64(nonce), + ResourceId: resourceID, + Payload: payload, + Type: transfer.FungibleTransfer, + }, + messageID, + transfer.TransferMessageType), nil } diff --git a/chains/substrate/listener/deposit-handler_test.go b/chains/substrate/listener/deposit-handler_test.go index 8934a328..b9785650 100644 --- a/chains/substrate/listener/deposit-handler_test.go +++ b/chains/substrate/listener/deposit-handler_test.go @@ -69,9 +69,16 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEvent() { Type: transfer.FungibleTransfer, }, Type: transfer.TransferMessageType, + ID: "messageID", } - message, err := listener.FungibleTransferHandler(sourceID, depositLog.DestDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.CallData) + message, err := listener.FungibleTransferHandler( + sourceID, + depositLog.DestDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.CallData, + "messageID") s.Nil(err) s.NotNil(message) @@ -92,7 +99,13 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleEventIncorrectdeposit_dataLen() { sourceID := uint8(1) - message, err := listener.FungibleTransferHandler(sourceID, depositLog.DestDomainID, depositLog.DepositNonce, depositLog.ResourceID, depositLog.CallData) + message, err := listener.FungibleTransferHandler( + sourceID, + depositLog.DestDomainID, + depositLog.DepositNonce, + depositLog.ResourceID, + depositLog.CallData, + "messageID") s.Nil(message) s.EqualError(err, errIncorrectDataLen.Error()) } @@ -120,12 +133,12 @@ func (s *Erc20HandlerTestSuite) TestSuccesfullyRegisterFungibleTransferHandler() depositHandler := listener.NewSubstrateDepositHandler() // Register FungibleTransferHandler function depositHandler.RegisterDepositHandler(transfer.FungibleTransfer, listener.FungibleTransferHandler) - message1, err1 := depositHandler.HandleDeposit(1, d1.DestDomainID, d1.DepositNonce, d1.ResourceID, d1.CallData, d1.TransferType) + message1, err1 := depositHandler.HandleDeposit(1, d1.DestDomainID, d1.DepositNonce, d1.ResourceID, d1.CallData, d1.TransferType, "messageID") s.Nil(err1) s.NotNil(message1) // Use unregistered transfer type - message2, err2 := depositHandler.HandleDeposit(1, d1.DestDomainID, d1.DepositNonce, d1.ResourceID, d1.CallData, 1) + message2, err2 := depositHandler.HandleDeposit(1, d1.DestDomainID, d1.DepositNonce, d1.ResourceID, d1.CallData, 1, "messageID") s.Nil(message2) s.NotNil(err2) s.EqualError(err2, errNoCorrespondingDepositHandler.Error()) diff --git a/chains/substrate/listener/event-handlers.go b/chains/substrate/listener/event-handlers.go index 104d6968..9eb1eb56 100644 --- a/chains/substrate/listener/event-handlers.go +++ b/chains/substrate/listener/event-handlers.go @@ -4,6 +4,7 @@ package listener import ( + "fmt" "math/big" "github.com/ChainSafe/sygma-relayer/chains/substrate/events" @@ -34,7 +35,6 @@ func NewSystemUpdateEventHandler(conn Connection) *SystemUpdateEventHandler { } func (eh *SystemUpdateEventHandler) HandleEvents(startBlock *big.Int, endBlock *big.Int) error { - evts, err := eh.conn.FetchEvents(startBlock, endBlock) if err != nil { log.Error().Err(err).Msg("Error fetching events") @@ -56,7 +56,7 @@ func (eh *SystemUpdateEventHandler) HandleEvents(startBlock *big.Int, endBlock * } type DepositHandler interface { - HandleDeposit(sourceID uint8, destID types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte, transferType types.U8) (*message.Message, error) + HandleDeposit(sourceID uint8, destID types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte, transferType types.U8, messageID string) (*message.Message, error) } type FungibleTransferEventHandler struct { @@ -100,14 +100,14 @@ func (eh *FungibleTransferEventHandler) HandleEvents(startBlock *big.Int, endBlo return } - m, err := eh.depositHandler.HandleDeposit(eh.domainID, d.DestDomainID, d.DepositNonce, d.ResourceID, d.CallData, d.TransferType) + messageID := fmt.Sprintf("%d-%d-%d-%d", eh.domainID, d.DestDomainID, startBlock, endBlock) + m, err := eh.depositHandler.HandleDeposit(eh.domainID, d.DestDomainID, d.DepositNonce, d.ResourceID, d.CallData, d.TransferType, messageID) if err != nil { log.Error().Err(err).Msgf("%v", err) return } - eh.log.Info().Msgf("Resolved deposit message %+v", d) - + eh.log.Info().Str("messageID", messageID).Msgf("Resolved deposit message %+v", d) domainDeposits[m.Destination] = append(domainDeposits[m.Destination], m) }(*evt) } @@ -191,12 +191,14 @@ func (rh *RetryEventHandler) HandleEvents(startBlock *big.Int, endBlock *big.Int if err != nil { return err } - m, err := rh.depositHandler.HandleDeposit(rh.domainID, d.DestDomainID, d.DepositNonce, d.ResourceID, d.CallData, d.TransferType) + + messageID := fmt.Sprintf("%d-%d-%d-%d", rh.domainID, d.DestDomainID, startBlock, endBlock) + m, err := rh.depositHandler.HandleDeposit(rh.domainID, d.DestDomainID, d.DepositNonce, d.ResourceID, d.CallData, d.TransferType, messageID) if err != nil { return err } - rh.log.Info().Msgf("Resolved retry message %+v", d) + rh.log.Info().Str("messageID", messageID).Msgf("Resolved retry message %+v", d) domainDeposits[m.Destination] = append(domainDeposits[m.Destination], m) } diff --git a/chains/substrate/listener/event-handlers_test.go b/chains/substrate/listener/event-handlers_test.go index 1861dbb6..2e11a7ee 100644 --- a/chains/substrate/listener/event-handlers_test.go +++ b/chains/substrate/listener/event-handlers_test.go @@ -112,6 +112,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { "deposit_data": []byte{}, "handler_response": [1]byte{0}, } + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 1) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1["dest_domain_id"], @@ -119,8 +120,8 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { d1["resource_id"], d1["deposit_data"], d1["sygma_traits_TransferType"], + msgID, ).Return(&message.Message{}, fmt.Errorf("error")) - s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d2["dest_domain_id"], @@ -128,6 +129,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { d2["resource_id"], d2["deposit_data"], d2["sygma_traits_TransferType"], + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 2}}, nil, @@ -183,6 +185,7 @@ func (s *DepositHandlerTestSuite) Test_SuccessfulHandleDeposit() { "handler_response": [1]byte{0}, "deposit_data": []byte{}, } + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 1) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1["dest_domain_id"], @@ -190,6 +193,7 @@ func (s *DepositHandlerTestSuite) Test_SuccessfulHandleDeposit() { d1["resource_id"], d1["deposit_data"], d1["sygma_traits_TransferType"], + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 1}}, nil, @@ -201,6 +205,7 @@ func (s *DepositHandlerTestSuite) Test_SuccessfulHandleDeposit() { d2["resource_id"], d2["deposit_data"], d2["sygma_traits_TransferType"], + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 2}}, nil, @@ -256,6 +261,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositPanics_ExecutionContinues() "handler_response": [1]byte{0}, "deposit_data": []byte{}, } + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 1) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1["dest_domain_id"], @@ -263,7 +269,8 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositPanics_ExecutionContinues() d1["resource_id"], d1["deposit_data"], d1["sygma_traits_TransferType"], - ).Do(func(sourceID, destID, nonce, resourceID, calldata, depositType interface{}) { + msgID, + ).Do(func(sourceID, destID, nonce, resourceID, calldata, depositType, msgID interface{}) { panic("error") }) s.mockDepositHandler.EXPECT().HandleDeposit( @@ -273,6 +280,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositPanics_ExecutionContinues() d2["resource_id"], d2["deposit_data"], d2["sygma_traits_TransferType"], + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 2}}, nil, @@ -505,6 +513,7 @@ func (s *RetryHandlerTestSuite) Test_ValidEvents() { }, }, } + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 1) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1["dest_domain_id"], @@ -512,6 +521,7 @@ func (s *RetryHandlerTestSuite) Test_ValidEvents() { d1["resource_id"], d1["deposit_data"], d1["sygma_traits_TransferType"], + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 1}}, nil, @@ -523,6 +533,7 @@ func (s *RetryHandlerTestSuite) Test_ValidEvents() { d2["resource_id"], d2["deposit_data"], d2["sygma_traits_TransferType"], + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 2}}, nil, @@ -603,6 +614,7 @@ func (s *RetryHandlerTestSuite) Test_EventPanics() { }, } + msgID := fmt.Sprintf("%d-%d-%d-%d", 1, 2, 0, 1) s.mockDepositHandler.EXPECT().HandleDeposit( s.domainID, d1["dest_domain_id"], @@ -610,7 +622,8 @@ func (s *RetryHandlerTestSuite) Test_EventPanics() { d1["resource_id"], d1["deposit_data"], d1["sygma_traits_TransferType"], - ).Do(func(sourceID, destID, nonce, resourceID, calldata, depositType interface{}) { + msgID, + ).Do(func(sourceID, destID, nonce, resourceID, calldata, depositType, msgID interface{}) { panic("error") }) s.mockDepositHandler.EXPECT().HandleDeposit( @@ -620,6 +633,7 @@ func (s *RetryHandlerTestSuite) Test_EventPanics() { d2["resource_id"], d2["deposit_data"], d2["sygma_traits_TransferType"], + msgID, ).Return( &message.Message{Data: transfer.TransferMessageData{DepositNonce: 2}}, nil, diff --git a/chains/substrate/listener/mock/handlers.go b/chains/substrate/listener/mock/handlers.go index 60e3400e..ffaa8429 100644 --- a/chains/substrate/listener/mock/handlers.go +++ b/chains/substrate/listener/mock/handlers.go @@ -150,16 +150,16 @@ func (m *MockDepositHandler) EXPECT() *MockDepositHandlerMockRecorder { } // HandleDeposit mocks base method. -func (m *MockDepositHandler) HandleDeposit(sourceID uint8, destID types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte, transferType types.U8) (*message.Message, error) { +func (m *MockDepositHandler) HandleDeposit(sourceID uint8, destID types.U8, nonce types.U64, resourceID types.Bytes32, calldata []byte, transferType types.U8, messageID string) (*message.Message, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "HandleDeposit", sourceID, destID, nonce, resourceID, calldata, transferType) + ret := m.ctrl.Call(m, "HandleDeposit", sourceID, destID, nonce, resourceID, calldata, transferType, messageID) ret0, _ := ret[0].(*message.Message) ret1, _ := ret[1].(error) return ret0, ret1 } // HandleDeposit indicates an expected call of HandleDeposit. -func (mr *MockDepositHandlerMockRecorder) HandleDeposit(sourceID, destID, nonce, resourceID, calldata, transferType interface{}) *gomock.Call { +func (mr *MockDepositHandlerMockRecorder) HandleDeposit(sourceID, destID, nonce, resourceID, calldata, transferType, messageID interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleDeposit", reflect.TypeOf((*MockDepositHandler)(nil).HandleDeposit), sourceID, destID, nonce, resourceID, calldata, transferType) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HandleDeposit", reflect.TypeOf((*MockDepositHandler)(nil).HandleDeposit), sourceID, destID, nonce, resourceID, calldata, transferType, messageID) } diff --git a/go.mod b/go.mod index 2985c7b1..b7cdf50a 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/spf13/cobra v1.5.0 github.com/spf13/viper v1.9.0 github.com/stretchr/testify v1.8.4 - github.com/sygmaprotocol/sygma-core v0.0.0-20240404092135-d56ed6c6424c + github.com/sygmaprotocol/sygma-core v0.0.0-20240411120252-bf0131a81565 go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/metric v1.16.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 diff --git a/go.sum b/go.sum index edffdc82..988828ec 100644 --- a/go.sum +++ b/go.sum @@ -100,9 +100,7 @@ github.com/btcsuite/btcutil v1.0.3-0.20211129182920-9c4bbabe7acd h1:vAwk2PCYxzUU github.com/btcsuite/btcutil v1.0.3-0.20211129182920-9c4bbabe7acd/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= -github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= -github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= @@ -178,7 +176,6 @@ github.com/decred/dcrd/dcrec/edwards/v2 v2.0.2 h1:bX7rtGTMBDJxujZ29GNqtn7YCAdINj github.com/decred/dcrd/dcrec/edwards/v2 v2.0.2/go.mod h1:d0H8xGMWbiIQP7gN3v2rByWUcuZPm9YsgmnfoxgbINc= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc= -github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -407,7 +404,6 @@ github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABo github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPwbGVtZVWC34vc5WLsDk= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= @@ -444,7 +440,6 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= -github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6cdF0Y8= github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38yPW7c= @@ -734,10 +729,10 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= -github.com/sygmaprotocol/sygma-core v0.0.0-20240214134652-eb3fbea40cd9 h1:ba8YgA5+s2LaHKYS0HwQxqjuDYH6J79vJ4EfVHoKUG8= -github.com/sygmaprotocol/sygma-core v0.0.0-20240214134652-eb3fbea40cd9/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= -github.com/sygmaprotocol/sygma-core v0.0.0-20240404092135-d56ed6c6424c h1:OGICEMPePKpAuDeixZUlvRmhMEifFCHyQr55VxKMXAQ= -github.com/sygmaprotocol/sygma-core v0.0.0-20240404092135-d56ed6c6424c/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/sygmaprotocol/sygma-core v0.0.0-20240410132338-3378ddf94d94 h1:X54V8UoBM3BzQWX52ZaqPxIHDMHf+aKy3tTTrCzPh2k= +github.com/sygmaprotocol/sygma-core v0.0.0-20240410132338-3378ddf94d94/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/sygmaprotocol/sygma-core v0.0.0-20240411120252-bf0131a81565 h1:oEd8KmRDSyGvQGg/A0cd4JbWNiVP8GGjK672JWQ0QAk= +github.com/sygmaprotocol/sygma-core v0.0.0-20240411120252-bf0131a81565/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= @@ -797,6 +792,7 @@ go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= +go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= diff --git a/relayer/transfer/transfer.go b/relayer/transfer/transfer.go index 6c848d87..84ae88ce 100644 --- a/relayer/transfer/transfer.go +++ b/relayer/transfer/transfer.go @@ -33,6 +33,7 @@ type TransferMessage struct { Destination uint8 Data TransferMessageData Type message.MessageType + ID string } type TransferProposalData struct { @@ -47,4 +48,5 @@ type TransferProposal struct { Destination uint8 Data TransferProposalData Type proposal.ProposalType + MessageID string }