Drop dependency on BlockCommitmentCache bank (#10946)

* Drop dependency on BlockCommitmentCache bank

* cargo fmt
This commit is contained in:
Greg Fitzgerald 2020-07-07 20:13:30 -06:00 committed by GitHub
parent 2fdbb97244
commit 930162a079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 10 deletions

View File

@ -67,15 +67,12 @@ fn new_response<T>(bank: &Bank, value: T) -> RpcResponse<T> {
pub fn is_confirmed_rooted( pub fn is_confirmed_rooted(
block_commitment_cache: &BlockCommitmentCache, block_commitment_cache: &BlockCommitmentCache,
bank: &Bank,
blockstore: &Blockstore, blockstore: &Blockstore,
slot: Slot, slot: Slot,
) -> bool { ) -> bool {
slot <= block_commitment_cache.highest_confirmed_root() slot <= block_commitment_cache.highest_confirmed_root()
&& (blockstore.is_root(slot) && (blockstore.is_root(slot) || bank.status_cache_ancestors().contains(&slot))
|| block_commitment_cache
.bank()
.status_cache_ancestors()
.contains(&slot))
} }
#[derive(Debug, Default, Clone)] #[derive(Debug, Default, Clone)]
@ -693,7 +690,7 @@ impl JsonRpcRequestProcessor {
let r_block_commitment_cache = self.block_commitment_cache.read().unwrap(); let r_block_commitment_cache = self.block_commitment_cache.read().unwrap();
let confirmations = if r_block_commitment_cache.root() >= slot 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 None
} else { } else {
@ -3827,18 +3824,36 @@ pub mod tests {
block_commitment.entry(2).or_insert(cache1); block_commitment.entry(2).or_insert(cache1);
block_commitment.entry(3).or_insert(cache2); block_commitment.entry(3).or_insert(cache2);
let highest_confirmed_root = 1; let highest_confirmed_root = 1;
let block_commitment_cache = let block_commitment_cache = BlockCommitmentCache::new(
BlockCommitmentCache::new(block_commitment, highest_confirmed_root, 50, bank, 0, 0); block_commitment,
highest_confirmed_root,
50,
bank.clone(),
0,
0,
);
assert!(is_confirmed_rooted(&block_commitment_cache, &blockstore, 0)); assert!(is_confirmed_rooted(
assert!(is_confirmed_rooted(&block_commitment_cache, &blockstore, 1)); &block_commitment_cache,
&bank,
&blockstore,
0
));
assert!(is_confirmed_rooted(
&block_commitment_cache,
&bank,
&blockstore,
1
));
assert!(!is_confirmed_rooted( assert!(!is_confirmed_rooted(
&block_commitment_cache, &block_commitment_cache,
&bank,
&blockstore, &blockstore,
2 2
)); ));
assert!(!is_confirmed_rooted( assert!(!is_confirmed_rooted(
&block_commitment_cache, &block_commitment_cache,
&bank,
&blockstore, &blockstore,
3 3
)); ));