From fb9eb4169e2bb09bf8e3617fc47beb87104dfe55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Mlinari=C4=87?= <35880252+nmlinaric@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:12:34 +0100 Subject: [PATCH 1/7] chore: update codeowners (#237) --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1b0d452a..0bc70b60 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,5 @@ # CODEOWNERS: https://help.github.com/articles/about-codeowners/ # Primary repo maintainers -* @P1sar @waymobetta @mpetrun5 @tcar121293 @MakMuftic @nmlinaric @vezenovm @freddyli7 +* @mpetrun5 @tcar121293 @MakMuftic @nmlinaric @freddyli7 tss/* @timoth-y From 30ec0a902fcf26f42e1bce79883129035fa51c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Petruni=C4=87?= Date: Thu, 30 Nov 2023 13:09:52 +0100 Subject: [PATCH 2/7] chore: add version on startup (#240) --- Dockerfile | 2 +- app/app.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c0b6944a..e9bddcb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ ADD . /src WORKDIR /src RUN cd /src && echo $(ls -1 /src) RUN go mod download -RUN go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore" -o /bridge . +RUN go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=ignore -X github.com/ChainSafe/sygma-relayer/app.Version=$(sed -n '0,/## \[\([0-9.]*\)\]/s/.*\[\([0-9.]*\)\].*/\1/p' CHANGELOG.md)" -o /bridge . # final stage FROM debian:stable-slim diff --git a/app/app.go b/app/app.go index bf65b503..07fc68c3 100644 --- a/app/app.go +++ b/app/app.go @@ -57,6 +57,8 @@ import ( "github.com/spf13/viper" ) +var Version string + func Run() error { var err error @@ -276,7 +278,7 @@ func Run() error { syscall.SIGQUIT) relayerName := viper.GetString("name") - log.Info().Msgf("Started relayer: %s with PID: %s", relayerName, host.ID().Pretty()) + log.Info().Msgf("Started relayer: %s with PID: %s. Version: v%s", relayerName, host.ID().Pretty(), Version) _, err = keyshareStore.GetKeyshare() if err != nil { From 89798f34a9c3f69250fc4acb52eb3bd0f9e351de Mon Sep 17 00:00:00 2001 From: mace Date: Thu, 30 Nov 2023 13:19:59 +0100 Subject: [PATCH 3/7] chore(main): release 1.10.2 (#238) --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28da2749..efa73c7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.10.2](https://github.com/sygmaprotocol/sygma-relayer/compare/v1.10.1...v1.10.2) (2023-11-30) + + +### Miscellaneous + +* add version on startup ([#240](https://github.com/sygmaprotocol/sygma-relayer/issues/240)) ([e86c9d9](https://github.com/sygmaprotocol/sygma-relayer/commit/e86c9d9b31cc24bce542f99bab1d774863dab608)) +* update codeowners ([#237](https://github.com/sygmaprotocol/sygma-relayer/issues/237)) ([a6be32a](https://github.com/sygmaprotocol/sygma-relayer/commit/a6be32a19dbfe2b856840fd1995fde2dcfb14f91)) + ## [1.10.1](https://github.com/sygmaprotocol/sygma-relayer/compare/v1.10.0...v1.10.1) (2023-10-19) From 5fc1eb399488a3b87c029205e7ad8a4bef1c6cb2 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Thu, 4 Jan 2024 16:09:23 +0100 Subject: [PATCH 4/7] Message handling generalization --- app/app.go | 30 +- chains/evm/executor/message-handler.go | 134 +++++++- chains/evm/executor/message-handler_test.go | 349 ++++++++++++++++++-- chains/evm/listener/deposit-handler.go | 4 + chains/proposal.go | 26 ++ go.mod | 1 + go.sum | 38 +++ 7 files changed, 521 insertions(+), 61 deletions(-) diff --git a/app/app.go b/app/app.go index 07fc68c3..8352a0f5 100644 --- a/app/app.go +++ b/app/app.go @@ -19,7 +19,6 @@ import ( "github.com/ChainSafe/chainbridge-core/chains/evm/calls/evmgaspricer" "github.com/ChainSafe/chainbridge-core/chains/evm/calls/evmtransaction" "github.com/ChainSafe/chainbridge-core/chains/evm/calls/transactor/monitored" - coreExecutor "github.com/ChainSafe/chainbridge-core/chains/evm/executor" coreListener "github.com/ChainSafe/chainbridge-core/chains/evm/listener" "github.com/ChainSafe/chainbridge-core/crypto/secp256k1" "github.com/ChainSafe/chainbridge-core/flags" @@ -55,6 +54,8 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" "github.com/rs/zerolog/log" "github.com/spf13/viper" + + coreMessage "github.com/sygmaprotocol/sygma-core/relayer/message" ) var Version string @@ -157,7 +158,6 @@ func Run() error { { config, err := evm.NewEVMConfig(chainConfig) panicOnError(err) - kp, err := secp256k1.NewKeypairFromString(config.GeneralChainConfig.Key) panicOnError(err) @@ -176,30 +176,10 @@ func Run() error { bridgeContract := bridge.NewBridgeContract(client, bridgeAddress, t) depositHandler := coreListener.NewETHDepositHandler(bridgeContract) - mh := coreExecutor.NewEVMMessageHandler(bridgeContract) + mh := coreMessage.NewMessageHandler() for _, handler := range config.Handlers { - switch handler.Type { - case "erc20": - { - depositHandler.RegisterDepositHandler(handler.Address, listener.Erc20DepositHandler) - mh.RegisterMessageHandler(handler.Address, coreExecutor.ERC20MessageHandler) - } - case "permissionedGeneric": - { - depositHandler.RegisterDepositHandler(handler.Address, coreListener.GenericDepositHandler) - mh.RegisterMessageHandler(handler.Address, coreExecutor.GenericMessageHandler) - } - case "permissionlessGeneric": - { - depositHandler.RegisterDepositHandler(handler.Address, listener.PermissionlessGenericDepositHandler) - mh.RegisterMessageHandler(handler.Address, executor.PermissionlessGenericMessageHandler) - } - case "erc721": - { - depositHandler.RegisterDepositHandler(handler.Address, coreListener.Erc721DepositHandler) - mh.RegisterMessageHandler(handler.Address, coreExecutor.ERC721MessageHandler) - } - } + depositHandler.RegisterDepositHandler(handler.Address, listener.TransferDepositHandler) + mh.RegisterMessageHandler("transfer", &executor.TransferMessageHandler{}) } depositListener := coreEvents.NewListener(client) tssListener := events.NewListener(client) diff --git a/chains/evm/executor/message-handler.go b/chains/evm/executor/message-handler.go index fff76d0f..3cab2b75 100644 --- a/chains/evm/executor/message-handler.go +++ b/chains/evm/executor/message-handler.go @@ -10,28 +10,77 @@ import ( "github.com/ethereum/go-ethereum/common" - "github.com/ChainSafe/chainbridge-core/chains/evm/executor/proposal" - "github.com/ChainSafe/chainbridge-core/relayer/message" + "github.com/sygmaprotocol/sygma-core/relayer/message" + "github.com/sygmaprotocol/sygma-core/relayer/proposal" + + "github.com/ChainSafe/sygma-relayer/chains" +) + +const ( + TransferProposalType proposal.ProposalType = "Transfer" + ERC20 message.MessageType = "erc20" + ERC721 message.MessageType = "erc721" + PermissionedGeneric message.MessageType = "permissionedGeneric" + PermissionlessGeneric message.MessageType = "permissionlessGeneric" ) -func PermissionlessGenericMessageHandler(msg *message.Message, handlerAddr, bridgeAddress common.Address) (*proposal.Proposal, error) { - executeFunctionSignature, ok := msg.Payload[0].([]byte) +type TransferMessageData struct { + DepositNonce uint64 + ResourceId [32]byte + Payload []interface{} + Metadata map[string]interface{} +} + +type TransferMessage struct { + Source uint8 + Destination uint8 + Data TransferMessageData + Type message.MessageType +} + +type TransferMessageHandler struct{} + +func (h *TransferMessageHandler) HandleMessage(msg *message.Message) (*proposal.Proposal, error) { + + transferMessage := &TransferMessage{ + Source: msg.Source, + Destination: msg.Destination, + Data: msg.Data.(TransferMessageData), + Type: msg.Type, + } + + switch msg.Type { + case ERC20: + return ERC20MessageHandler(transferMessage) + case ERC721: + return ERC721MessageHandler(transferMessage) + case PermissionedGeneric: + return GenericMessageHandler(transferMessage) + case PermissionlessGeneric: + return PermissionlessGenericMessageHandler(transferMessage) + } + return nil, errors.New("wrong message type passed while handling message") +} + +func PermissionlessGenericMessageHandler(msg *TransferMessage) (*proposal.Proposal, error) { + + executeFunctionSignature, ok := msg.Data.Payload[0].([]byte) if !ok { return nil, errors.New("wrong function signature format") } - executeContractAddress, ok := msg.Payload[1].([]byte) + executeContractAddress, ok := msg.Data.Payload[1].([]byte) if !ok { return nil, errors.New("wrong contract address format") } - maxFee, ok := msg.Payload[2].([]byte) + maxFee, ok := msg.Data.Payload[2].([]byte) if !ok { return nil, errors.New("wrong max fee format") } - depositor, ok := msg.Payload[3].([]byte) + depositor, ok := msg.Data.Payload[3].([]byte) if !ok { return nil, errors.New("wrong depositor data format") } - executionData, ok := msg.Payload[4].([]byte) + executionData, ok := msg.Data.Payload[4].([]byte) if !ok { return nil, errors.New("wrong execution data format") } @@ -49,6 +98,73 @@ func PermissionlessGenericMessageHandler(msg *message.Message, handlerAddr, brid data.Write(depositor) data.Write(executionData) + return chains.NewTransferProposal(msg.Source, msg.Destination, msg.Data.DepositNonce, + msg.Data.ResourceId, msg.Data.Metadata, data.Bytes(), TransferProposalType), nil +} - return proposal.NewProposal(msg.Source, msg.Destination, msg.DepositNonce, msg.ResourceId, data.Bytes(), handlerAddr, bridgeAddress, msg.Metadata), nil +func ERC20MessageHandler(msg *TransferMessage) (*proposal.Proposal, error) { + if len(msg.Data.Payload) != 2 { + return nil, errors.New("malformed payload. Len of payload should be 2") + } + amount, ok := msg.Data.Payload[0].([]byte) + if !ok { + return nil, errors.New("wrong payload amount format") + } + recipient, ok := msg.Data.Payload[1].([]byte) + if !ok { + return nil, errors.New("wrong payload recipient format") + } + var data []byte + data = append(data, common.LeftPadBytes(amount, 32)...) // amount (uint256) + recipientLen := big.NewInt(int64(len(recipient))).Bytes() + data = append(data, common.LeftPadBytes(recipientLen, 32)...) // length of recipient (uint256) + data = append(data, recipient...) // recipient ([]byte) + + return chains.NewTransferProposal(msg.Source, msg.Destination, msg.Data.DepositNonce, + msg.Data.ResourceId, msg.Data.Metadata, data, TransferProposalType), nil +} + +func ERC721MessageHandler(msg *TransferMessage) (*proposal.Proposal, error) { + + if len(msg.Data.Payload) != 3 { + return nil, errors.New("malformed payload. Len of payload should be 3") + } + tokenID, ok := msg.Data.Payload[0].([]byte) + if !ok { + return nil, errors.New("wrong payload tokenID format") + } + recipient, ok := msg.Data.Payload[1].([]byte) + if !ok { + return nil, errors.New("wrong payload recipient format") + } + metadata, ok := msg.Data.Payload[2].([]byte) + if !ok { + return nil, errors.New("wrong payload metadata format") + } + data := bytes.Buffer{} + data.Write(common.LeftPadBytes(tokenID, 32)) + recipientLen := big.NewInt(int64(len(recipient))).Bytes() + data.Write(common.LeftPadBytes(recipientLen, 32)) + data.Write(recipient) + metadataLen := big.NewInt(int64(len(metadata))).Bytes() + data.Write(common.LeftPadBytes(metadataLen, 32)) + data.Write(metadata) + return chains.NewTransferProposal(msg.Source, msg.Destination, msg.Data.DepositNonce, + msg.Data.ResourceId, msg.Data.Metadata, data.Bytes(), TransferProposalType), nil +} + +func GenericMessageHandler(msg *TransferMessage) (*proposal.Proposal, error) { + if len(msg.Data.Payload) != 1 { + return nil, errors.New("malformed payload. Len of payload should be 1") + } + metadata, ok := msg.Data.Payload[0].([]byte) + if !ok { + return nil, errors.New("wrong payload metadata format") + } + data := bytes.Buffer{} + metadataLen := big.NewInt(int64(len(metadata))).Bytes() + data.Write(common.LeftPadBytes(metadataLen, 32)) // length of metadata (uint256) + data.Write(metadata) + return chains.NewTransferProposal(msg.Source, msg.Destination, msg.Data.DepositNonce, + msg.Data.ResourceId, msg.Data.Metadata, data.Bytes(), TransferProposalType), nil } diff --git a/chains/evm/executor/message-handler_test.go b/chains/evm/executor/message-handler_test.go index 846e00e5..b10e21c4 100644 --- a/chains/evm/executor/message-handler_test.go +++ b/chains/evm/executor/message-handler_test.go @@ -5,20 +5,320 @@ package executor_test import ( "encoding/hex" + "errors" "math/big" "testing" "github.com/ChainSafe/chainbridge-core/chains/evm/calls/events" - "github.com/ChainSafe/chainbridge-core/chains/evm/executor/proposal" - "github.com/ChainSafe/chainbridge-core/relayer/message" + "github.com/ChainSafe/sygma-relayer/chains" "github.com/ChainSafe/sygma-relayer/chains/evm/calls/contracts/bridge" "github.com/ChainSafe/sygma-relayer/chains/evm/executor" - "github.com/ChainSafe/sygma-relayer/chains/evm/listener" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/suite" ) +var errIncorrectERC20PayloadLen = errors.New("malformed payload. Len of payload should be 2") +var errIncorrectERC721PayloadLen = errors.New("malformed payload. Len of payload should be 3") +var errIncorrectGenericPayloadLen = errors.New("malformed payload. Len of payload should be 1") + +var errIncorrectAmount = errors.New("wrong payload amount format") +var errIncorrectRecipient = errors.New("wrong payload recipient format") +var errIncorrectTokenID = errors.New("wrong payload tokenID format") +var errIncorrectMetadata = errors.New("wrong payload metadata format") + +// ERC20 +type Erc20HandlerTestSuite struct { + suite.Suite +} + +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) TestErc20HandleMessage() { + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{2}, // amount + []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}, // recipientAddress + }, + }, + } + + prop, err := executor.ERC20MessageHandler(message) + + s.Nil(err) + s.NotNil(prop) +} + +func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectDataLen() { + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{2}, // amount + }, + }, + } + + prop, err := executor.ERC20MessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectERC20PayloadLen.Error()) +} + +func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectAmount() { + + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + "incorrectAmount", // amount + []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}, // recipientAddress + }, + }, + } + + prop, err := executor.ERC20MessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectAmount.Error()) +} + +func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectRecipient() { + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{2}, // amount + "incorrectRecipient", // recipientAddress + }, + }, + } + + prop, err := executor.ERC20MessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectRecipient.Error()) +} + +// ERC721 +type Erc721HandlerTestSuite struct { + suite.Suite +} + +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) TestErc721MessageHandlerEmptyMetadata() { + + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{2}, // tokenID + []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}, // recipientAddress + []byte{}, // metadata + }, + }, + } + + prop, err := executor.ERC721MessageHandler(message) + + s.Nil(err) + s.NotNil(prop) +} + +func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectDataLen() { + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{2}, // tokenID + }, + }, + } + + prop, err := executor.ERC721MessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectERC721PayloadLen.Error()) +} + +func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectAmount() { + + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + "incorrectAmount", // tokenID + []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}, // recipientAddress + []byte{}, // metadata + }, + }, + } + + prop, err := executor.ERC721MessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectTokenID.Error()) +} + +func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectRecipient() { + + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{2}, // amount + "incorrectRecipient", + []byte{}, // metadata + }, + }, + } + + prop, err := executor.ERC721MessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectRecipient.Error()) +} + +func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectMetadata() { + + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{2}, // amount + []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}, // recipientAddress + "incorrectMetadata", // metadata + }, + }, + } + + prop, err := executor.ERC721MessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectMetadata.Error()) +} + +// GENERIC +type GenericHandlerTestSuite struct { + suite.Suite +} + +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) TestGenericHandleEvent() { + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + []byte{}, // metadata + }, + }, + } + + prop, err := executor.GenericMessageHandler(message) + + s.Nil(err) + s.NotNil(prop) +} + +func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectDataLen() { + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{}, + }, + } + + prop, err := executor.GenericMessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectGenericPayloadLen.Error()) +} + +func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectMetadata() { + message := &executor.TransferMessage{ + Source: 1, + Destination: 0, + Data: executor.TransferMessageData{ + DepositNonce: 1, + ResourceId: [32]byte{0}, + Payload: []interface{}{ + "incorrectMetadata", // metadata + }, + }, + } + prop, err := executor.GenericMessageHandler(message) + + s.Nil(prop) + s.NotNil(err) + s.EqualError(err, errIncorrectMetadata.Error()) +} + +// Permissionless type PermissionlessGenericHandlerTestSuite struct { suite.Suite } @@ -51,39 +351,34 @@ func (s *PermissionlessGenericHandlerTestSuite) Test_HandleMessage() { HandlerResponse: []byte{}, } sourceID := uint8(1) - message := &message.Message{ - Source: sourceID, - Destination: depositLog.DestinationDomainID, - DepositNonce: depositLog.DepositNonce, - ResourceId: depositLog.ResourceID, - Type: listener.PermissionlessGenericTransfer, - Payload: []interface{}{ - functionSig, - contractAddress.Bytes(), - common.LeftPadBytes(maxFee.Bytes(), 32), - depositor.Bytes(), - hash, - }, - } - handlerAddr := common.HexToAddress("0x4CEEf6139f00F9F4535Ad19640Ff7A0137708485") - bridgeAddr := common.HexToAddress("0xf1e58fb17704c2da8479a533f9fad4ad0993ca6b") + message := &executor.TransferMessage{ + Source: sourceID, + Destination: depositLog.DestinationDomainID, + Data: executor.TransferMessageData{ + DepositNonce: depositLog.DepositNonce, + ResourceId: depositLog.ResourceID, + Payload: []interface{}{ + functionSig, + contractAddress.Bytes(), + common.LeftPadBytes(maxFee.Bytes(), 32), + depositor.Bytes(), + hash, + }, + }} prop, err := executor.PermissionlessGenericMessageHandler( message, - handlerAddr, - bridgeAddr, ) expectedData, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000030d4000001402091eeff969b33a5ce8a729dae325879bf76f90145c1f5961696bad2e73f73417f07ef55c62a2dc5b307868617368") - expected := proposal.NewProposal( + expected := chains.NewTransferProposal( message.Source, message.Destination, - message.DepositNonce, - message.ResourceId, + message.Data.DepositNonce, + message.Data.ResourceId, + message.Data.Metadata, expectedData, - handlerAddr, - bridgeAddr, - message.Metadata, + executor.TransferProposalType, ) s.Nil(err) s.Equal(expected, prop) diff --git a/chains/evm/listener/deposit-handler.go b/chains/evm/listener/deposit-handler.go index 1bd05a9b..442a8376 100644 --- a/chains/evm/listener/deposit-handler.go +++ b/chains/evm/listener/deposit-handler.go @@ -15,6 +15,10 @@ const ( PermissionlessGenericTransfer message.TransferType = "PermissionlessGenericTransfer" ) +func TransferDepositHandler(sourceID, destId uint8, nonce uint64, resourceID types.ResourceID, calldata, handlerResponse []byte) (*message.Message, error) { + return nil, nil +} + // GenericDepositHandler converts data pulled from generic deposit event logs into message func PermissionlessGenericDepositHandler(sourceID, destId uint8, nonce uint64, resourceID types.ResourceID, calldata, handlerResponse []byte) (*message.Message, error) { if len(calldata) < 76 { diff --git a/chains/proposal.go b/chains/proposal.go index 251bc560..3b16973e 100644 --- a/chains/proposal.go +++ b/chains/proposal.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/signer/core/apitypes" + "github.com/sygmaprotocol/sygma-core/relayer/proposal" ) func NewProposal(source, destination uint8, depositNonce uint64, resourceId types.ResourceID, data []byte, metadata message.Metadata) *Proposal { @@ -25,6 +26,31 @@ func NewProposal(source, destination uint8, depositNonce uint64, resourceId type } } +type TransferProposalData struct { + DepositNonce uint64 + ResourceId [32]byte + Metadata map[string]interface{} + Data []byte +} + +func NewTransferProposal(source, destination uint8, depositNonce uint64, + resourceId [32]byte, metadata map[string]interface{}, data []byte, propType proposal.ProposalType) *proposal.Proposal { + + transferProposal := TransferProposalData{ + DepositNonce: depositNonce, + ResourceId: resourceId, + Metadata: metadata, + Data: data, + } + + return &proposal.Proposal{ + Source: source, + Destination: destination, + Data: transferProposal, + Type: propType, + } +} + type Proposal struct { OriginDomainID uint8 // Source domainID where message was initiated DepositNonce uint64 // Nonce for the deposit diff --git a/go.mod b/go.mod index d89cd1cd..298d8036 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,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-20240104134009-a7865e7a9ad6 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 7c792c40..07ffa42e 100644 --- a/go.sum +++ b/go.sum @@ -102,7 +102,9 @@ 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= @@ -114,6 +116,7 @@ github.com/centrifuge/go-substrate-rpc-client v2.0.0+incompatible/go.mod h1:GBML github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0 h1:GEvub7kU5YFAcn5A2uOo4AZSM1/cWZCOvfu7E3gQmK8= github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0/go.mod h1:szA5wf9suAIcNg/1S3rGeFITHqrnqH5TC6b+O0SEQ94= github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= +github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -180,10 +183,13 @@ 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/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M= 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= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/elastic/gosigar v0.12.0/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/4= github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs= @@ -203,6 +209,7 @@ github.com/ethereum/go-ethereum v1.13.4/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUt github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= +github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= @@ -215,6 +222,7 @@ github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmV github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= +github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= @@ -236,6 +244,7 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= @@ -310,6 +319,7 @@ github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+u github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64= +github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gopacket v1.1.17/go.mod h1:UdDNZ1OO62aGYVnPhxT1U6aI7ukYtA/kB8vaU0diBUM= github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8= github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= @@ -359,6 +369,7 @@ github.com/hashicorp/consul/api v1.10.1/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/ github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpxn4uE= +github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= @@ -372,6 +383,7 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= @@ -380,6 +392,7 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= +github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -393,6 +406,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/influxdata/influxdb-client-go/v2 v2.4.0/go.mod h1:vLNHdxTJkIf2mSLvGrpj8TCcISApPoXkaxP8g9uRlW8= +github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/ipfs/go-cid v0.3.2 h1:OGgOd+JCFM+y1DjWPmVH+2/4POtpDzwcr7VgnB7mZXc= github.com/ipfs/go-cid v0.3.2/go.mod h1:gQ8pKqT/sUxGY+tIwy1RPpAojYu7jAyCp5Tz1svoupw= github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ6cOk= @@ -408,6 +423,8 @@ 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/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= 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= @@ -443,8 +460,11 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 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/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= 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= @@ -529,6 +549,7 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh github.com/mitchellh/mapstructure v1.4.2 h1:6h7AQ0yhTcIsmFmnAwQls75jp2Gzs4iB8W7pjMO+rqo= github.com/mitchellh/mapstructure v1.4.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= +github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= @@ -566,12 +587,15 @@ github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2 github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/naoina/go-stringutil v0.1.0/go.mod h1:XJ2SJL9jCtBh+P9q5btrd/Ylo8XwT/h1USek5+NqSA0= +github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= +github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= @@ -603,6 +627,7 @@ github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2D github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y= github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/pierrec/xxHash v0.1.5 h1:n/jBpwTHiER4xYvK3/CdPVnLDPchj8eTJFFLUb4QHBo= github.com/pierrec/xxHash v0.1.5/go.mod h1:w2waW5Zoa/Wc4Yqe0wgrIYAGKqRMf7czn2HNKXmuL+I= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -643,9 +668,11 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRrjvIXnJho= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= @@ -734,6 +761,16 @@ 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-20231023115554-62219e098d0d h1:S2129X3uNculIdDae6J88ekiPWfzpcYhnVAeEuNRLQg= +github.com/sygmaprotocol/sygma-core v0.0.0-20231023115554-62219e098d0d/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104100450-afa68196ac4b h1:czluw0nos2T3Y/P56320RI1SqgMvIj/wsEy1uWi4lm4= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104100450-afa68196ac4b/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104105922-862b0234ddf3 h1:SBDVA3/x+XK0w6l+kaVHmO3V5Cuk6DbEbJEyk9WsyQE= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104105922-862b0234ddf3/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104110947-6683673f732f h1:9IXiXq1yYzKlTZrzYpN/HyeaApHdQgKHs05L2lhQjj4= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104110947-6683673f732f/go.mod h1:b4RZCyYr20Mp4WAAj4TkC6gU2KZ0ZWcpSGmKc6n8NKc= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104134009-a7865e7a9ad6 h1:J/Xa/kBbXTjg0wZRPrUvolLoe2MnTtldG8Srt0In5HI= +github.com/sygmaprotocol/sygma-core v0.0.0-20240104134009-a7865e7a9ad6/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= @@ -792,6 +829,7 @@ go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= 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/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= From 84b7f028b514e8b4eb2d5a625144414e6a5a713d Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 5 Jan 2024 11:52:38 +0100 Subject: [PATCH 5/7] Refactored executor.go --- chains/evm/executor/executor.go | 49 ++++++++++++++++----------------- chains/proposal.go | 7 +++++ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/chains/evm/executor/executor.go b/chains/evm/executor/executor.go index 64aad00c..028eb8d2 100644 --- a/chains/evm/executor/executor.go +++ b/chains/evm/executor/executor.go @@ -17,19 +17,19 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/rs/zerolog/log" - "github.com/ChainSafe/chainbridge-core/chains/evm/calls/transactor" - "github.com/ChainSafe/chainbridge-core/chains/evm/executor/proposal" - "github.com/ChainSafe/chainbridge-core/relayer/message" "github.com/ChainSafe/sygma-relayer/chains" "github.com/ChainSafe/sygma-relayer/comm" "github.com/ChainSafe/sygma-relayer/tss" "github.com/ChainSafe/sygma-relayer/tss/signing" + "github.com/sygmaprotocol/sygma-core/chains/evm/transactor" + "github.com/sygmaprotocol/sygma-core/relayer/message" + "github.com/sygmaprotocol/sygma-core/relayer/proposal" ) const TRANSFER_GAS_COST = 200000 type Batch struct { - proposals []*chains.Proposal + proposals []*proposal.Proposal gasLimit uint64 } @@ -38,14 +38,10 @@ var ( signingTimeout = 30 * time.Minute ) -type MessageHandler interface { - HandleMessage(m *message.Message) (*proposal.Proposal, error) -} - type BridgeContract interface { - IsProposalExecuted(p *chains.Proposal) (bool, error) - ExecuteProposals(proposals []*chains.Proposal, signature []byte, opts transactor.TransactOptions) (*ethCommon.Hash, error) - ProposalsHash(proposals []*chains.Proposal) ([]byte, error) + IsProposalExecuted(p *proposal.Proposal) (bool, error) + ExecuteProposals(proposals []*proposal.Proposal, signature []byte, opts transactor.TransactOptions) (*ethCommon.Hash, error) + ProposalsHash(proposals []*proposal.Proposal) ([]byte, error) } type Executor struct { @@ -54,7 +50,7 @@ type Executor struct { comm comm.Communication fetcher signing.SaveDataFetcher bridge BridgeContract - mh MessageHandler + mh *message.MessageHandler exitLock *sync.RWMutex transactionMaxGas uint64 } @@ -63,7 +59,7 @@ func NewExecutor( host host.Host, comm comm.Communication, coordinator *tss.Coordinator, - mh MessageHandler, + mh *message.MessageHandler, bridgeContract BridgeContract, fetcher signing.SaveDataFetcher, exitLock *sync.RWMutex, @@ -82,11 +78,11 @@ func NewExecutor( } // Execute starts a signing process and executes proposals when signature is generated -func (e *Executor) Execute(msgs []*message.Message) error { +func (e *Executor) Execute(proposals []*proposal.Proposal) error { e.exitLock.RLock() defer e.exitLock.RUnlock() - batches, err := e.proposalBatches(msgs) + batches, err := e.proposalBatches(proposals) if err != nil { return err } @@ -182,21 +178,22 @@ func (e *Executor) watchExecution(ctx context.Context, cancelExecution context.C } } -func (e *Executor) proposalBatches(msgs []*message.Message) ([]*Batch, error) { +func (e *Executor) proposalBatches(proposals []*proposal.Proposal) ([]*Batch, error) { batches := make([]*Batch, 1) currentBatch := &Batch{ - proposals: make([]*chains.Proposal, 0), + proposals: make([]*proposal.Proposal, 0), gasLimit: 0, } batches[0] = currentBatch - for _, m := range msgs { - prop, err := e.mh.HandleMessage(m) - if err != nil { - return nil, err + for _, prop := range proposals { + prop := &chains.TransferProposal{ + Source: prop.Source, + Destination: prop.Destination, + Data: prop.Data.(chains.TransferProposalData), + Type: prop.Type, } - - evmProposal := chains.NewProposal(prop.Source, prop.Destination, prop.DepositNonce, prop.ResourceId, prop.Data, prop.Metadata) + evmProposal := chains.NewTransferProposal(prop.Source, prop.Destination, prop.Data.DepositNonce, prop.Data.ResourceId, prop.Data.Metadata, prop.Data.Data, TransferProposalType) isExecuted, err := e.bridge.IsProposalExecuted(evmProposal) if err != nil { return nil, err @@ -207,7 +204,7 @@ func (e *Executor) proposalBatches(msgs []*message.Message) ([]*Batch, error) { } var propGasLimit uint64 - l, ok := evmProposal.Metadata.Data["gasLimit"] + l, ok := evmProposal.Data.(TransferMessageData).Metadata["gasLimit"] if ok { propGasLimit = l.(uint64) } else { @@ -216,7 +213,7 @@ func (e *Executor) proposalBatches(msgs []*message.Message) ([]*Batch, error) { currentBatch.gasLimit += propGasLimit if currentBatch.gasLimit >= e.transactionMaxGas { currentBatch = &Batch{ - proposals: make([]*chains.Proposal, 0), + proposals: make([]*proposal.Proposal, 0), gasLimit: 0, } batches = append(batches, currentBatch) @@ -245,7 +242,7 @@ func (e *Executor) executeBatch(batch *Batch, signatureData *common.SignatureDat return hash, err } -func (e *Executor) areProposalsExecuted(proposals []*chains.Proposal, sessionID string) bool { +func (e *Executor) areProposalsExecuted(proposals []*proposal.Proposal, sessionID string) bool { for _, prop := range proposals { isExecuted, err := e.bridge.IsProposalExecuted(prop) if err != nil || !isExecuted { diff --git a/chains/proposal.go b/chains/proposal.go index 3b16973e..1e95ce40 100644 --- a/chains/proposal.go +++ b/chains/proposal.go @@ -26,6 +26,13 @@ func NewProposal(source, destination uint8, depositNonce uint64, resourceId type } } +type TransferProposal struct { + Source uint8 + Destination uint8 + Data TransferProposalData + Type proposal.ProposalType +} + type TransferProposalData struct { DepositNonce uint64 ResourceId [32]byte From f41f870fd2b7a9f2fe856299d4f323c7c83046fd Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 5 Jan 2024 14:25:41 +0100 Subject: [PATCH 6/7] Modified tests --- app/app.go | 2 +- chains/evm/executor/executor.go | 4 - chains/evm/executor/message-handler_test.go | 92 ++++++++++++++------- example/app/app.go | 2 +- 4 files changed, 62 insertions(+), 38 deletions(-) diff --git a/app/app.go b/app/app.go index 8352a0f5..c471f234 100644 --- a/app/app.go +++ b/app/app.go @@ -190,7 +190,7 @@ func Run() error { eventHandlers = append(eventHandlers, listener.NewRefreshEventHandler(l, topologyProvider, topologyStore, tssListener, coordinator, host, communication, connectionGate, keyshareStore, bridgeAddress)) eventHandlers = append(eventHandlers, listener.NewRetryEventHandler(l, tssListener, depositHandler, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations)) evmListener := coreListener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval) - executor := executor.NewExecutor(host, communication, coordinator, mh, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64()) + executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64()) chain := evm.NewEVMChain( client, evmListener, executor, blockstore, *config.GeneralChainConfig.Id, config.StartBlock, diff --git a/chains/evm/executor/executor.go b/chains/evm/executor/executor.go index 028eb8d2..7a57aede 100644 --- a/chains/evm/executor/executor.go +++ b/chains/evm/executor/executor.go @@ -22,7 +22,6 @@ import ( "github.com/ChainSafe/sygma-relayer/tss" "github.com/ChainSafe/sygma-relayer/tss/signing" "github.com/sygmaprotocol/sygma-core/chains/evm/transactor" - "github.com/sygmaprotocol/sygma-core/relayer/message" "github.com/sygmaprotocol/sygma-core/relayer/proposal" ) @@ -50,7 +49,6 @@ type Executor struct { comm comm.Communication fetcher signing.SaveDataFetcher bridge BridgeContract - mh *message.MessageHandler exitLock *sync.RWMutex transactionMaxGas uint64 } @@ -59,7 +57,6 @@ func NewExecutor( host host.Host, comm comm.Communication, coordinator *tss.Coordinator, - mh *message.MessageHandler, bridgeContract BridgeContract, fetcher signing.SaveDataFetcher, exitLock *sync.RWMutex, @@ -69,7 +66,6 @@ func NewExecutor( host: host, comm: comm, coordinator: coordinator, - mh: mh, bridge: bridgeContract, fetcher: fetcher, exitLock: exitLock, diff --git a/chains/evm/executor/message-handler_test.go b/chains/evm/executor/message-handler_test.go index b10e21c4..be016bec 100644 --- a/chains/evm/executor/message-handler_test.go +++ b/chains/evm/executor/message-handler_test.go @@ -11,6 +11,8 @@ import ( "github.com/ChainSafe/chainbridge-core/chains/evm/calls/events" + "github.com/sygmaprotocol/sygma-core/relayer/message" + "github.com/ChainSafe/sygma-relayer/chains" "github.com/ChainSafe/sygma-relayer/chains/evm/calls/contracts/bridge" "github.com/ChainSafe/sygma-relayer/chains/evm/executor" @@ -42,7 +44,8 @@ func (s *Erc20HandlerTestSuite) SetupTest() {} func (s *Erc20HandlerTestSuite) TearDownTest() {} func (s *Erc20HandlerTestSuite) TestErc20HandleMessage() { - message := &executor.TransferMessage{ + + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -53,16 +56,18 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleMessage() { []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}, // recipientAddress }, }, + Type: executor.ERC20, } - prop, err := executor.ERC20MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(err) s.NotNil(prop) } func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectDataLen() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -72,9 +77,11 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectDataLen() { []byte{2}, // amount }, }, + Type: executor.ERC20, } - prop, err := executor.ERC20MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -83,7 +90,7 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectDataLen() { func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectAmount() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -94,9 +101,11 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectAmount() { []byte{241, 229, 143, 177, 119, 4, 194, 218, 132, 121, 165, 51, 249, 250, 212, 173, 9, 147, 202, 107}, // recipientAddress }, }, + Type: executor.ERC20, } - prop, err := executor.ERC20MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -104,7 +113,7 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectAmount() { } func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectRecipient() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -115,9 +124,11 @@ func (s *Erc20HandlerTestSuite) TestErc20HandleMessageIncorrectRecipient() { "incorrectRecipient", // recipientAddress }, }, + Type: executor.ERC20, } - prop, err := executor.ERC20MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -140,7 +151,7 @@ func (s *Erc721HandlerTestSuite) TearDownTest() {} func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerEmptyMetadata() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -152,16 +163,18 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerEmptyMetadata() { []byte{}, // metadata }, }, + Type: executor.ERC721, } - prop, err := executor.ERC721MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(err) s.NotNil(prop) } func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectDataLen() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -171,9 +184,11 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectDataLen() { []byte{2}, // tokenID }, }, + Type: executor.ERC721, } - prop, err := executor.ERC721MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -182,7 +197,7 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectDataLen() { func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectAmount() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -194,9 +209,11 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectAmount() { []byte{}, // metadata }, }, + Type: executor.ERC721, } - prop, err := executor.ERC721MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -205,7 +222,7 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectAmount() { func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectRecipient() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -217,9 +234,11 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectRecipient() { []byte{}, // metadata }, }, + Type: executor.ERC721, } - prop, err := executor.ERC721MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -228,7 +247,7 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectRecipient() { func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectMetadata() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -240,9 +259,11 @@ func (s *Erc721HandlerTestSuite) TestErc721MessageHandlerIncorrectMetadata() { "incorrectMetadata", // metadata }, }, + Type: executor.ERC721, } - prop, err := executor.ERC721MessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -263,7 +284,7 @@ func (s *GenericHandlerTestSuite) TearDownSuite() {} func (s *GenericHandlerTestSuite) SetupTest() {} func (s *GenericHandlerTestSuite) TearDownTest() {} func (s *GenericHandlerTestSuite) TestGenericHandleEvent() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -273,16 +294,18 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEvent() { []byte{}, // metadata }, }, + Type: executor.PermissionedGeneric, } - prop, err := executor.GenericMessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(err) s.NotNil(prop) } func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectDataLen() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -290,9 +313,11 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectDataLen() { ResourceId: [32]byte{0}, Payload: []interface{}{}, }, + Type: executor.PermissionedGeneric, } - prop, err := executor.GenericMessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -300,7 +325,7 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectDataLen() { } func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectMetadata() { - message := &executor.TransferMessage{ + message := &message.Message{ Source: 1, Destination: 0, Data: executor.TransferMessageData{ @@ -310,8 +335,10 @@ func (s *GenericHandlerTestSuite) TestGenericHandleEventIncorrectMetadata() { "incorrectMetadata", // metadata }, }, + Type: executor.PermissionedGeneric, } - prop, err := executor.GenericMessageHandler(message) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) s.Nil(prop) s.NotNil(err) @@ -351,7 +378,7 @@ func (s *PermissionlessGenericHandlerTestSuite) Test_HandleMessage() { HandlerResponse: []byte{}, } sourceID := uint8(1) - message := &executor.TransferMessage{ + message := &message.Message{ Source: sourceID, Destination: depositLog.DestinationDomainID, Data: executor.TransferMessageData{ @@ -364,19 +391,20 @@ func (s *PermissionlessGenericHandlerTestSuite) Test_HandleMessage() { depositor.Bytes(), hash, }, - }} + }, + Type: executor.PermissionlessGeneric, + } - prop, err := executor.PermissionlessGenericMessageHandler( - message, - ) + mh := executor.TransferMessageHandler{} + prop, err := mh.HandleMessage(message) expectedData, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000030d4000001402091eeff969b33a5ce8a729dae325879bf76f90145c1f5961696bad2e73f73417f07ef55c62a2dc5b307868617368") expected := chains.NewTransferProposal( message.Source, message.Destination, - message.Data.DepositNonce, - message.Data.ResourceId, - message.Data.Metadata, + message.Data.(executor.TransferMessageData).DepositNonce, + message.Data.(executor.TransferMessageData).ResourceId, + message.Data.(executor.TransferMessageData).Metadata, expectedData, executor.TransferProposalType, ) diff --git a/example/app/app.go b/example/app/app.go index f61316f1..5504a461 100644 --- a/example/app/app.go +++ b/example/app/app.go @@ -183,7 +183,7 @@ func Run() error { eventHandlers = append(eventHandlers, listener.NewRefreshEventHandler(l, nil, nil, tssListener, coordinator, host, communication, connectionGate, keyshareStore, bridgeAddress)) eventHandlers = append(eventHandlers, listener.NewRetryEventHandler(l, tssListener, depositHandler, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations)) evmListener := coreListener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval) - executor := executor.NewExecutor(host, communication, coordinator, mh, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64()) + executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64()) chain := evm.NewEVMChain( client, evmListener, executor, blockstore, *config.GeneralChainConfig.Id, config.StartBlock, From 83c1da41d65a1034422c6bc6f27bf093954360e3 Mon Sep 17 00:00:00 2001 From: mj52951 Date: Fri, 5 Jan 2024 14:58:44 +0100 Subject: [PATCH 7/7] Made proposed changes --- app/app.go | 2 +- chains/evm/executor/executor.go | 15 ++++----------- chains/evm/listener/deposit-handler.go | 4 ---- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/app/app.go b/app/app.go index c471f234..7eeb47be 100644 --- a/app/app.go +++ b/app/app.go @@ -178,7 +178,7 @@ func Run() error { depositHandler := coreListener.NewETHDepositHandler(bridgeContract) mh := coreMessage.NewMessageHandler() for _, handler := range config.Handlers { - depositHandler.RegisterDepositHandler(handler.Address, listener.TransferDepositHandler) + depositHandler.RegisterDepositHandler(handler.Address, listener.PermissionlessGenericDepositHandler) mh.RegisterMessageHandler("transfer", &executor.TransferMessageHandler{}) } depositListener := coreEvents.NewListener(client) diff --git a/chains/evm/executor/executor.go b/chains/evm/executor/executor.go index 7a57aede..0afd22b7 100644 --- a/chains/evm/executor/executor.go +++ b/chains/evm/executor/executor.go @@ -17,7 +17,6 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/rs/zerolog/log" - "github.com/ChainSafe/sygma-relayer/chains" "github.com/ChainSafe/sygma-relayer/comm" "github.com/ChainSafe/sygma-relayer/tss" "github.com/ChainSafe/sygma-relayer/tss/signing" @@ -183,14 +182,8 @@ func (e *Executor) proposalBatches(proposals []*proposal.Proposal) ([]*Batch, er batches[0] = currentBatch for _, prop := range proposals { - prop := &chains.TransferProposal{ - Source: prop.Source, - Destination: prop.Destination, - Data: prop.Data.(chains.TransferProposalData), - Type: prop.Type, - } - evmProposal := chains.NewTransferProposal(prop.Source, prop.Destination, prop.Data.DepositNonce, prop.Data.ResourceId, prop.Data.Metadata, prop.Data.Data, TransferProposalType) - isExecuted, err := e.bridge.IsProposalExecuted(evmProposal) + + isExecuted, err := e.bridge.IsProposalExecuted(prop) if err != nil { return nil, err } @@ -200,7 +193,7 @@ func (e *Executor) proposalBatches(proposals []*proposal.Proposal) ([]*Batch, er } var propGasLimit uint64 - l, ok := evmProposal.Data.(TransferMessageData).Metadata["gasLimit"] + l, ok := prop.Data.(TransferMessageData).Metadata["gasLimit"] if ok { propGasLimit = l.(uint64) } else { @@ -215,7 +208,7 @@ func (e *Executor) proposalBatches(proposals []*proposal.Proposal) ([]*Batch, er batches = append(batches, currentBatch) } - currentBatch.proposals = append(currentBatch.proposals, evmProposal) + currentBatch.proposals = append(currentBatch.proposals, prop) } return batches, nil diff --git a/chains/evm/listener/deposit-handler.go b/chains/evm/listener/deposit-handler.go index 442a8376..1bd05a9b 100644 --- a/chains/evm/listener/deposit-handler.go +++ b/chains/evm/listener/deposit-handler.go @@ -15,10 +15,6 @@ const ( PermissionlessGenericTransfer message.TransferType = "PermissionlessGenericTransfer" ) -func TransferDepositHandler(sourceID, destId uint8, nonce uint64, resourceID types.ResourceID, calldata, handlerResponse []byte) (*message.Message, error) { - return nil, nil -} - // GenericDepositHandler converts data pulled from generic deposit event logs into message func PermissionlessGenericDepositHandler(sourceID, destId uint8, nonce uint64, resourceID types.ResourceID, calldata, handlerResponse []byte) (*message.Message, error) { if len(calldata) < 76 {