From 930162a0790699a734c52fc2e4fe0016a529aeea Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Tue, 7 Jul 2020 20:13:30 -0600 Subject: [PATCH] Drop dependency on BlockCommitmentCache bank (#10946) * Drop dependency on BlockCommitmentCache bank * cargo fmt --- core/src/rpc.rs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index ebc517073..21f4f4161 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -67,15 +67,12 @@ fn new_response(bank: &Bank, value: T) -> RpcResponse { pub fn is_confirmed_rooted( block_commitment_cache: &BlockCommitmentCache, + bank: &Bank, blockstore: &Blockstore, slot: Slot, ) -> bool { slot <= block_commitment_cache.highest_confirmed_root() - && (blockstore.is_root(slot) - || block_commitment_cache - .bank() - .status_cache_ancestors() - .contains(&slot)) + && (blockstore.is_root(slot) || bank.status_cache_ancestors().contains(&slot)) } #[derive(Debug, Default, Clone)] @@ -693,7 +690,7 @@ impl JsonRpcRequestProcessor { let r_block_commitment_cache = self.block_commitment_cache.read().unwrap(); let confirmations = if r_block_commitment_cache.root() >= slot - && is_confirmed_rooted(&r_block_commitment_cache, &self.blockstore, slot) + && is_confirmed_rooted(&r_block_commitment_cache, bank, &self.blockstore, slot) { None } else { @@ -3827,18 +3824,36 @@ pub mod tests { block_commitment.entry(2).or_insert(cache1); block_commitment.entry(3).or_insert(cache2); let highest_confirmed_root = 1; - let block_commitment_cache = - BlockCommitmentCache::new(block_commitment, highest_confirmed_root, 50, bank, 0, 0); + let block_commitment_cache = BlockCommitmentCache::new( + block_commitment, + highest_confirmed_root, + 50, + bank.clone(), + 0, + 0, + ); - assert!(is_confirmed_rooted(&block_commitment_cache, &blockstore, 0)); - assert!(is_confirmed_rooted(&block_commitment_cache, &blockstore, 1)); + assert!(is_confirmed_rooted( + &block_commitment_cache, + &bank, + &blockstore, + 0 + )); + assert!(is_confirmed_rooted( + &block_commitment_cache, + &bank, + &blockstore, + 1 + )); assert!(!is_confirmed_rooted( &block_commitment_cache, + &bank, &blockstore, 2 )); assert!(!is_confirmed_rooted( &block_commitment_cache, + &bank, &blockstore, 3 ));