From b64644f7cfd8d7d7aad068d78c1828c4489d3b0b Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Thu, 3 Oct 2024 16:50:42 +0200 Subject: [PATCH 1/2] Assign message id to all messages --- chains/evm/executor/executor.go | 4 ++-- chains/evm/listener/handlers/deposit.go | 6 +++--- chains/evm/listener/handlers/hashi.go | 3 ++- chains/evm/listener/handlers/stateRoot.go | 5 +++-- chains/evm/message/hashi.go | 3 ++- chains/evm/message/stateRoot.go | 5 +++-- chains/evm/message/transfer.go | 3 ++- 7 files changed, 17 insertions(+), 12 deletions(-) diff --git a/chains/evm/executor/executor.go b/chains/evm/executor/executor.go index ce3f323..f4ab47a 100644 --- a/chains/evm/executor/executor.go +++ b/chains/evm/executor/executor.go @@ -87,7 +87,7 @@ func (e *EVMExecutor) storeMessage(props []*proposal.Proposal) error { return err } - log.Info().Uint8("domainID", e.domainID).Msgf("Sent hashi message execution with hash: %s", hash) + log.Info().Str("messageID", props[0].MessageID).Uint8("domainID", e.domainID).Msgf("Sent hashi message execution with hash: %s", hash) return nil } @@ -112,7 +112,7 @@ func (e *EVMExecutor) transfer(props []*proposal.Proposal) error { continue } - log.Info().Uint8("domainID", e.domainID).Msgf("Sent proposals execution with hash: %s", hash) + log.Info().Str("messageID", props[0].MessageID).Uint8("domainID", e.domainID).Msgf("Sent proposals execution with hash: %s", hash) } return nil } diff --git a/chains/evm/listener/handlers/deposit.go b/chains/evm/listener/handlers/deposit.go index 06516f8..cf51deb 100644 --- a/chains/evm/listener/handlers/deposit.go +++ b/chains/evm/listener/handlers/deposit.go @@ -89,15 +89,15 @@ func (h *DepositEventHandler) HandleEvents(destination uint8, startBlock *big.In return err } - h.log.Debug().Uint8("destination", d.DestinationDomainID).Msg("Sending transfer message") - + msgID := fmt.Sprintf("%d-%d-%d-%d", slot, h.domainID, d.DestinationDomainID, d.DepositNonce) + h.log.Debug().Str("messageID", msgID).Uint8("destination", d.DestinationDomainID).Msg("Sending transfer message") msgs[d.DestinationDomainID] = append(msgs[d.DestinationDomainID], evmMessage.NewEVMTransferMessage(h.domainID, d.DestinationDomainID, evmMessage.TransferData{ Deposit: d, Slot: slot, AccountProof: accountProof, StorageProof: storageProof, Type: h.transferType(d), - })) + }, msgID)) } if len(msgs) == 0 { log.Debug().Msgf("No deposits found for block range %s-%s", startBlock, endBlock) diff --git a/chains/evm/listener/handlers/hashi.go b/chains/evm/listener/handlers/hashi.go index b2779d8..e0c5ab5 100644 --- a/chains/evm/listener/handlers/hashi.go +++ b/chains/evm/listener/handlers/hashi.go @@ -95,6 +95,7 @@ func (h *HashiEventHandler) HandleEvents(destination uint8, startBlock *big.Int, continue } + log.Info().Str("messageID", msg.ID).Msgf("Found hashi message log in block: %d, TxHash: %s, %+v", l.BlockNumber, l.TxHash, msg) msgs = append(msgs, msg) } @@ -160,7 +161,7 @@ func (h *HashiEventHandler) handleMessage(l types.Log, destination uint8, slot * ReceiptRoot: block.ReceiptHash(), TxIndexRLPEncoded: txIndexRLP, LogIndex: h.logIndex(receipt, l), - }), nil + }, fmt.Sprintf("%s-%d", l.TxHash, h.logIndex(receipt, l))), nil } func (h *HashiEventHandler) slotChild(slot *big.Int) (*big.Int, error) { diff --git a/chains/evm/listener/handlers/stateRoot.go b/chains/evm/listener/handlers/stateRoot.go index f7ecff3..234961a 100644 --- a/chains/evm/listener/handlers/stateRoot.go +++ b/chains/evm/listener/handlers/stateRoot.go @@ -6,6 +6,7 @@ package handlers import ( "context" "encoding/hex" + "fmt" "math/big" "strings" @@ -62,7 +63,7 @@ func (h *StateRootEventHandler) HandleEvents(startBlock *big.Int, endBlock *big. h.msgChan <- []*message.Message{evmMessage.NewEvmStateRootMessage(h.domainID, sr.SourceDomainID, evmMessage.StateRootData{ StateRoot: sr.StateRoot, Slot: sr.Slot, - })} + }, fmt.Sprintf("%d-%s", sr.Slot, hex.EncodeToString(sr.StateRoot[:])))} } return nil } @@ -80,7 +81,7 @@ func (h *StateRootEventHandler) fetchStateRoots(startBlock *big.Int, endBlock *b log.Error().Msgf("Failed unpacking state root event log: %v", err) continue } - log.Debug().Uint8("domainID", h.domainID).Uint8("sourceDomainID", sr.SourceDomainID).Msgf( + log.Debug().Str("messageID", fmt.Sprintf("%d-%s", sr.Slot, hex.EncodeToString(sr.StateRoot[:]))).Uint8("domainID", h.domainID).Uint8("sourceDomainID", sr.SourceDomainID).Msgf( "Found state root %s in block: %d", hex.EncodeToString(sr.StateRoot[:]), l.BlockNumber) stateRoots = append(stateRoots, sr) } diff --git a/chains/evm/message/hashi.go b/chains/evm/message/hashi.go index 18bf121..13a3552 100644 --- a/chains/evm/message/hashi.go +++ b/chains/evm/message/hashi.go @@ -25,12 +25,13 @@ type HashiData struct { LogIndex *big.Int } -func NewHashiMessage(source uint8, destination uint8, data HashiData) *message.Message { +func NewHashiMessage(source uint8, destination uint8, data HashiData, messageID string) *message.Message { return &message.Message{ Source: source, Destination: destination, Data: data, Type: HashiMessage, + ID: messageID, } } diff --git a/chains/evm/message/stateRoot.go b/chains/evm/message/stateRoot.go index 773e285..42cd10c 100644 --- a/chains/evm/message/stateRoot.go +++ b/chains/evm/message/stateRoot.go @@ -25,12 +25,13 @@ type StateRootData struct { Slot *big.Int } -func NewEvmStateRootMessage(source uint8, destination uint8, stateRoot StateRootData) *message.Message { +func NewEvmStateRootMessage(source uint8, destination uint8, stateRoot StateRootData, messageID string) *message.Message { return &message.Message{ Source: source, Destination: destination, Data: stateRoot, Type: EVMStateRootMessage, + ID: messageID, } } @@ -78,7 +79,7 @@ func (h *StateRootHandler) HandleMessage(m *message.Message) (*proposal.Proposal log.Debug().Uint8( "domainID", m.Destination).Str( "stateRoot", hex.EncodeToString(stateRoot.StateRoot[:]), - ).Msgf("Received state root message from domain %d", m.Source) + ).Str("messageID", m.ID).Msgf("Received state root message from domain %d", m.Source) block, err := h.blockFetcher.SignedBeaconBlock(context.Background(), &api.SignedBeaconBlockOpts{ Block: stateRoot.Slot.String(), }) diff --git a/chains/evm/message/transfer.go b/chains/evm/message/transfer.go index f23d1f4..cc6e9d1 100644 --- a/chains/evm/message/transfer.go +++ b/chains/evm/message/transfer.go @@ -29,11 +29,12 @@ type TransferData struct { Type TransferType } -func NewEVMTransferMessage(source uint8, destination uint8, transfer TransferData) *message.Message { +func NewEVMTransferMessage(source uint8, destination uint8, transfer TransferData, messageID string) *message.Message { return &message.Message{ Source: source, Destination: destination, Data: transfer, + ID: messageID, Type: EVMTransferMessage, } } From 4c622923717f95c4281505d29a9cb64e09d39f23 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Thu, 3 Oct 2024 17:00:21 +0200 Subject: [PATCH 2/2] Fix linter --- chains/evm/listener/handlers/stateRoot_test.go | 4 ++-- chains/evm/message/stateRoot_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/chains/evm/listener/handlers/stateRoot_test.go b/chains/evm/listener/handlers/stateRoot_test.go index 74e9591..9b68d18 100644 --- a/chains/evm/listener/handlers/stateRoot_test.go +++ b/chains/evm/listener/handlers/stateRoot_test.go @@ -111,13 +111,13 @@ func (s *StateRootHandlerTestSuite) Test_HandleEvents_ValidRoots() { s.Equal(msg, []*message.Message{evmMessage.NewEvmStateRootMessage(s.sourceDomain, 1, evmMessage.StateRootData{ StateRoot: util.SliceTo32Bytes(expectedStateRoot), Slot: big.NewInt(987232), - })}) + }, msg[0].ID)}) msg, err = readFromChannel(s.msgChan) s.Nil(err) s.Equal(msg, []*message.Message{evmMessage.NewEvmStateRootMessage(s.sourceDomain, 1, evmMessage.StateRootData{ StateRoot: util.SliceTo32Bytes(expectedStateRoot), Slot: big.NewInt(987232), - })}) + }, msg[0].ID)}) _, err = readFromChannel(s.msgChan) s.NotNil(err) } diff --git a/chains/evm/message/stateRoot_test.go b/chains/evm/message/stateRoot_test.go index 90e7f03..613b09b 100644 --- a/chains/evm/message/stateRoot_test.go +++ b/chains/evm/message/stateRoot_test.go @@ -61,7 +61,7 @@ func (s *StateRootHandlerTestSuite) Test_HandleEvents_InvalidBlock() { _, err := s.stateRootHandler.HandleMessage(message.NewEvmStateRootMessage(2, s.sourceDomain, message.StateRootData{ Slot: big.NewInt(10), - })) + }, "id")) s.NotNil(err) } @@ -91,7 +91,7 @@ func (s *StateRootHandlerTestSuite) Test_HandleEvents_MissingStartBlock() { _, err := s.stateRootHandler.HandleMessage(message.NewEvmStateRootMessage(2, s.sourceDomain, message.StateRootData{ Slot: big.NewInt(1000), - })) + }, "id")) s.Nil(err) } @@ -121,7 +121,7 @@ func (s *StateRootHandlerTestSuite) Test_HandleEvents_ExistingStartBlock() { _, err := s.stateRootHandler.HandleMessage(message.NewEvmStateRootMessage(2, s.sourceDomain, message.StateRootData{ Slot: big.NewInt(1000), - })) + }, "id")) s.Nil(err) }