Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forester: rollover threshold check #1215

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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