Skip to content

Conversation

@ganeshvanahalli
Copy link
Contributor

This PR implements delayed message accumulation logic for native mode of MEL. We introduce a new data structure DelayedMessageBacklog to enable validation of seen but not-yet-read delayed messages against the current merkle root formed by accumulating all the delayed messages seen by MEL up until now.

For optimization, future messages that are prefetched for generating the merkle root are also pre-validated (or pre-read) i.e we don't re-validate them again when we read them in the future, instead we check that the pre-validated message's hash matches the hash of delayed message we fetch from the DB using the same delayed message index.

This PR also brings in necessary changes needed to other parts of MEL code to successfully test it.

)

// InitializeDelayedMessageBacklog is to be only called by the Start fsm step of MEL. This function fills the backlog based on the seen and read count from the given mel state
func InitializeDelayedMessageBacklog(ctx context.Context, d *mel.DelayedMessageBacklog, db *Database, state *mel.State, finalizedAndReadIndexFetcher func(context.Context) (uint64, error)) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only called by the FSM, why is it a public method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is used in system_tests later on, we can track this in linear to maybe clean it up later on?

var err error
delayedMsgIndexToParentChainBlockNum := make(map[uint64]uint64)
curr := state
for i := state.ParentChainBlockNumber - 1; i > 0; i-- {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In prod, this will go all the way back to block num 0. Is that intended behavior? What if this is arb1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this loop rewinds and finds corresponding mel states for parent chain block numbers, so even assuming l2 chain genesis was seen in block=1 of parent chain, this loop should be able to find the melstate corresponding to that.

For arb1, the upgrade process is a bit different- I would prefer our first mel state to have DelayedMessagedSeen = DelayedMessagesRead and do the upgrade after the parent chain block containing last batch is finalized to prevent complexities with reorg.

func (d *DelayedMessageBacklog) setInitMsg(msg *DelayedInboxMessage) { d.initMessage = msg }

// clear removes from backlog (if exceeds capacity) the entries that correspond to the delayed messages that are both READ and belong to finalized parent chain blocks
func (d *DelayedMessageBacklog) clear() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is more idiomatic for clear to take in a context rather than storing a context in the struct, IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought a lot about this, the ctx would have to trickle down from AccumulateDelayedMessage function of the state itself! I didnt want that method to take in context solely to trim entries from the backlog- this should be the responsibility of backlog alone. We could make the backlog a stopwaiter, but it seemed overkill

rauljordan
rauljordan previously approved these changes Jul 15, 2025
Base automatically changed from mel-database-impl to master July 17, 2025 15:36
@rauljordan rauljordan dismissed their stale review July 17, 2025 15:36

The base branch was changed.

@ganeshvanahalli ganeshvanahalli assigned rauljordan and unassigned tsahee Jul 29, 2025
rauljordan
rauljordan previously approved these changes Jul 29, 2025
@rauljordan rauljordan enabled auto-merge July 29, 2025 18:54
@rauljordan rauljordan assigned tsahee and unassigned rauljordan Jul 29, 2025
@codecov
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 0.96774% with 614 lines in your changes missing coverage. Please review.
✅ Project coverage is 22.43%. Comparing base (16c01f8) to head (4329432).
⚠️ Report is 221 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3389      +/-   ##
==========================================
- Coverage   22.67%   22.43%   -0.25%     
==========================================
  Files         383      390       +7     
  Lines       58109    59058     +949     
==========================================
+ Hits        13177    13250      +73     
- Misses      42903    43767     +864     
- Partials     2029     2041      +12     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants