Skip to content

Commit

Permalink
fix: 🐛 Revert events order when reverting changes in a block
Browse files Browse the repository at this point in the history
  • Loading branch information
ffarall committed Jan 23, 2025
1 parent ceb5416 commit e072239
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/blockchain-service/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,19 @@ where
// Process the events in the block, specifically those that are related to the Forest root changes.
match get_events_at_block(&self.client, &block.hash) {
Ok(events) => {
// If we are reverting the Forest root changes in this block, we process the events in reverse order.
// Normally, the order for processing the events would be irrelevant, because adding or removing different
// file keys from the Forest is independent of the order in which they are processed. However, if for
// whatever unexpected reason, in the same block, we find two operations for the same file key (for instance,
// an addition first and a removal in a later transaction), we need to process them in reverse order (revert
// the removal first, by adding it, and revert the addition later, by removing it).
let events = if revert {
events.into_iter().rev().collect::<Vec<_>>()
} else {
events
};

// Iterate through the events and process them.
for ev in events {
match ev.event.clone() {
RuntimeEvent::ProofsDealer(
Expand Down

0 comments on commit e072239

Please sign in to comment.