Skip to content

Commit

Permalink
fix: forester: rollover threshold check (#1215)
Browse files Browse the repository at this point in the history
Improved the condition checks for rolling over Merkle trees, ensuring they process a minimum number of transactions before rollover. Added a debug print statement to log address trees in end-to-end tests for better traceability.
  • Loading branch information
sergeytimoshin authored Sep 13, 2024
1 parent 8653bdf commit 5051d4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions forester/src/rollover/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub async fn is_tree_ready_for_rollover<R: RpcConnection>(
// TODO: (fix) check to avoid processing Merkle trees with rollover threshold 0 which haven't processed any transactions
// let lamports_in_account_are_sufficient_for_rollover = account_info.lamports
// > account.metadata.rollover_metadata.rollover_fee * (1 << height);
Ok(merkle_tree.next_index() >= threshold)
Ok(merkle_tree.next_index() >= threshold && merkle_tree.next_index() > 1)
}
TreeType::Address => {
let account = rpc
Expand Down Expand Up @@ -109,7 +109,11 @@ pub async fn is_tree_ready_for_rollover<R: RpcConnection>(
// current implementation is returns always true
// let lamports_in_account_are_sufficient_for_rollover = account_info.lamports
// > account.metadata.rollover_metadata.rollover_fee * (1 << height);
Ok(merkle_tree.next_index() >= threshold)

// Address Merkle trees are initialized with 2 leaves and with 3 as the next index.
// To make sure we roll over them after they have processed some transactions, we check
// if the next index is greater than 3.
Ok(merkle_tree.next_index() >= threshold && merkle_tree.next_index() > 3)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions forester/tests/e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ async fn test_epoch_monitor_with_2_foresters() {
.map(|x| x.accounts)
.collect();

println!("Address trees: {:?}", address_trees);

// Two rollovers plus other work
let mut total_expected_work = 2;
{
Expand Down

0 comments on commit 5051d4a

Please sign in to comment.