Skip to content

Commit

Permalink
chore: assign message id to all messages (#41)
Browse files Browse the repository at this point in the history
* Assign message id to all messages

* Fix linter
  • Loading branch information
mpetrun5 authored Oct 3, 2024
1 parent b2ddf82 commit e72e4a6
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions chains/evm/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions chains/evm/listener/handlers/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion chains/evm/listener/handlers/hashi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions chains/evm/listener/handlers/stateRoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package handlers
import (
"context"
"encoding/hex"
"fmt"
"math/big"
"strings"

Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions chains/evm/listener/handlers/stateRoot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion chains/evm/message/hashi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
5 changes: 3 additions & 2 deletions chains/evm/message/stateRoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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(),
})
Expand Down
6 changes: 3 additions & 3 deletions chains/evm/message/stateRoot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
3 changes: 2 additions & 1 deletion chains/evm/message/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down

0 comments on commit e72e4a6

Please sign in to comment.