Skip to content

Conversation

@ukint-vs
Copy link
Member

@ukint-vs ukint-vs commented Jul 17, 2025

Resolves #4744.

introduce the full squashed-commitment flow to the consensus. The core addition is a new aggregate_chain_commitment pipeline plus supporting changes across mocks, validators, and tests.
This let producers and participants work with the compact, per-actor representation needed by the router contract.

aggregate_chain_commitment:

  • Walks the announce chain from the current head back to the last committed announce, ensuring computed metadata and depth limits.
  • Collects announce outcomes, sorts them deterministically, and folds transitions per actor via an ActorAggregation helper. Each actor’s newest transition becomes the base; all earlier transitions contribute messages, value claims, accumulated balances, and exit/inheritor updates.
  • Returns a ChainCommitment plus the traversal depth, or None/errors when data is missing. Additional helpers (aggregate_code_commitments, create_batch_commitment) reuse this pipeline so every subsystem sees the same squashed data.
  • Ships with regression tests covering happy path, depth limits, “already committed” heads, message ordering, and saturating sums.

@gear-tech/dev

@ukint-vs ukint-vs requested a review from grishasobol July 17, 2025 16:41
@ukint-vs ukint-vs self-assigned this Jul 17, 2025
@ukint-vs ukint-vs added the A0-pleasereview PR is ready to be reviewed by the team label Jul 17, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Jul 17, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  ethexe/consensus/src/mock.rs  59% smaller
  ethexe/consensus/src/validator/participant.rs  50% smaller
  ethexe/consensus/src/utils.rs  2% smaller
  ethexe/consensus/src/validator/producer.rs  0% smaller

Copy link
Member

@grishasobol grishasobol left a comment

Choose a reason for hiding this comment

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

do you think equal transitions is not super rare case? I thought that optimisation is something like
program transitions: H1 -> H2, H2 -> H3, H3 -> H4
optimized: H1 -> H4

@breathx
Copy link
Member

breathx commented Jul 30, 2025

do you think equal transitions is not super rare case? I thought that optimisation is something like program transitions: H1 -> H2, H2 -> H3, H3 -> H4 optimized: H1 -> H4

totally

so vec<(pid, transition)> won't have pid duplicates

@ukint-vs ukint-vs changed the title feat(ethexe-consensus): optimize squash_chain_commitments feat(ethexe-consensus): squash transitions by actor Sep 12, 2025
@grishasobol grishasobol added the D8-ethexe ethexe-related PR label Sep 22, 2025
@ukint-vs ukint-vs requested review from ark0f and breathx September 27, 2025 06:34
);

let mut transitions = [cc1.transitions, cc2.transitions].concat();
transitions.sort_by_key(|t| t.actor_id);
Copy link
Member

Choose a reason for hiding this comment

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

why sort?

}

// Collect all transitions in true chronological order (oldest -> newest)
let all_transitions: Vec<StateTransition> = transitions.into_iter().rev().flatten().collect();
Copy link
Member

Choose a reason for hiding this comment

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

why aren't they from the very beginning in correct oldest -> newest order?

// Group transitions by actor_id and squash consecutive transitions for the same actor
let mut actor_transitions: std::collections::BTreeMap<ActorId, Vec<StateTransition>> =
std::collections::BTreeMap::new();
for transition in all_transitions {
Copy link
Member

Choose a reason for hiding this comment

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

you may avoid at least one allocation for vec of all_transitions var if you will be inserting the values in map in the same time

Copy link
Member

Choose a reason for hiding this comment

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

or even mutate in place (instead of collecting vec of transitions belonging to specific actor), so you will only have vec -> map -> into_vec()

}

// Pick the newest transition
let mut squashed = transitions_for_actor.last().unwrap().clone();
Copy link
Member

Choose a reason for hiding this comment

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

I'd add in debug assert check for choronological order:

A -> B -> C -> D etc

squashed.inheritor = inheritor;
}

squashed.messages = all_messages;
Copy link
Member

Choose a reason for hiding this comment

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

you may just create a new value instead of some mutations where it's possible to make a mistake in future extensions

Copy link
Member

Choose a reason for hiding this comment

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

e.g. forget about new field in transition


// Messages should be accumulated: [msg1, msg2]
assert_eq!(squashed.messages.len(), 2);
assert!(squashed.messages.contains(&msg1));
Copy link
Member

Choose a reason for hiding this comment

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

you actually don't have any order assertions here.

I'd suggest to go with 1) easier naming: why block2 sends message1 etc; 2) provide full exact assertions

Copy link
Member

Choose a reason for hiding this comment

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

so you may have just 1, but much more useful test instead of 4-5 of them

@breathx
Copy link
Member

breathx commented Oct 24, 2025

I'm also wondering why this action is performed only by participants, but not by block producer? he may want to specify if they're (validators) gonna have squashed commitment for this time etc??

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

Labels

A0-pleasereview PR is ready to be reviewed by the team D8-ethexe ethexe-related PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ethexe: improve squashing - removing redundant state transitions

4 participants