Add CommitmentSlots::new_from_slot() (#11600)
This commit is contained in:
parent
6c887c2b87
commit
574c356863
|
@ -88,12 +88,7 @@ impl BanksServer {
|
|||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::new(
|
||||
HashMap::default(),
|
||||
0,
|
||||
CommitmentSlots {
|
||||
slot,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
CommitmentSlots::new_from_slot(slot),
|
||||
)));
|
||||
Builder::new()
|
||||
.name("solana-bank-forks-client".to_string())
|
||||
|
|
|
@ -218,12 +218,7 @@ impl JsonRpcRequestProcessor {
|
|||
block_commitment_cache: Arc::new(RwLock::new(BlockCommitmentCache::new(
|
||||
HashMap::new(),
|
||||
0,
|
||||
CommitmentSlots {
|
||||
slot: bank.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
CommitmentSlots::new_from_slot(bank.slot()),
|
||||
))),
|
||||
blockstore,
|
||||
validator_exit: create_validator_exit(&exit),
|
||||
|
@ -2547,12 +2542,7 @@ pub mod tests {
|
|||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
10,
|
||||
CommitmentSlots {
|
||||
slot: bank.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
CommitmentSlots::new_from_slot(bank.slot()),
|
||||
)));
|
||||
|
||||
// Add timestamp vote to blockstore
|
||||
|
@ -4153,12 +4143,7 @@ pub mod tests {
|
|||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
42,
|
||||
CommitmentSlots {
|
||||
slot: bank_forks.read().unwrap().highest_slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
CommitmentSlots::new_from_slot(bank_forks.read().unwrap().highest_slot()),
|
||||
)));
|
||||
|
||||
let mut config = JsonRpcConfig::default();
|
||||
|
@ -4502,12 +4487,7 @@ pub mod tests {
|
|||
let mut new_block_commitment = BlockCommitmentCache::new(
|
||||
HashMap::new(),
|
||||
0,
|
||||
CommitmentSlots {
|
||||
root: 0,
|
||||
slot: bank_forks.read().unwrap().highest_slot(),
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
CommitmentSlots::new_from_slot(bank_forks.read().unwrap().highest_slot()),
|
||||
);
|
||||
let mut w_block_commitment_cache = block_commitment_cache.write().unwrap();
|
||||
std::mem::swap(&mut *w_block_commitment_cache, &mut new_block_commitment);
|
||||
|
@ -4707,9 +4687,8 @@ pub mod tests {
|
|||
50,
|
||||
CommitmentSlots {
|
||||
slot: bank.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root,
|
||||
..CommitmentSlots::default()
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -1228,9 +1228,7 @@ pub(crate) mod tests {
|
|||
10,
|
||||
CommitmentSlots {
|
||||
slot: bank1.slot(),
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
..CommitmentSlots::default()
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -206,6 +206,15 @@ pub struct CommitmentSlots {
|
|||
pub highest_confirmed_root: Slot,
|
||||
}
|
||||
|
||||
impl CommitmentSlots {
|
||||
pub fn new_from_slot(slot: Slot) -> Self {
|
||||
Self {
|
||||
slot,
|
||||
..Self::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
@ -275,16 +284,9 @@ mod tests {
|
|||
block_commitment.entry(1).or_insert_with(|| cache0.clone()); // Slot 1, conf 2
|
||||
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
|
||||
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
||||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
);
|
||||
let commitment_slots = CommitmentSlots::new_from_slot(bank_slot_5);
|
||||
let block_commitment_cache =
|
||||
BlockCommitmentCache::new(block_commitment, total_stake, commitment_slots);
|
||||
|
||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 2);
|
||||
|
||||
|
@ -293,16 +295,8 @@ mod tests {
|
|||
block_commitment.entry(1).or_insert_with(|| cache1.clone()); // Slot 1, conf 1
|
||||
block_commitment.entry(2).or_insert_with(|| cache1.clone()); // Slot 2, conf 1
|
||||
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
||||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
);
|
||||
let block_commitment_cache =
|
||||
BlockCommitmentCache::new(block_commitment, total_stake, commitment_slots);
|
||||
|
||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 2);
|
||||
|
||||
|
@ -311,16 +305,8 @@ mod tests {
|
|||
block_commitment.entry(1).or_insert_with(|| cache1.clone()); // Slot 1, conf 1
|
||||
block_commitment.entry(3).or_insert(cache1); // Slot 3, conf 1
|
||||
block_commitment.entry(5).or_insert_with(|| cache2.clone()); // Slot 5, conf 0
|
||||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
);
|
||||
let block_commitment_cache =
|
||||
BlockCommitmentCache::new(block_commitment, total_stake, commitment_slots);
|
||||
|
||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 3);
|
||||
|
||||
|
@ -329,16 +315,8 @@ mod tests {
|
|||
block_commitment.entry(1).or_insert(cache0); // Slot 1, conf 2
|
||||
block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0
|
||||
block_commitment.entry(3).or_insert_with(|| cache2.clone()); // Slot 3, conf 0
|
||||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
);
|
||||
let block_commitment_cache =
|
||||
BlockCommitmentCache::new(block_commitment, total_stake, commitment_slots);
|
||||
|
||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 1);
|
||||
|
||||
|
@ -347,16 +325,8 @@ mod tests {
|
|||
block_commitment.entry(1).or_insert_with(|| cache2.clone()); // Slot 1, conf 0
|
||||
block_commitment.entry(2).or_insert_with(|| cache2.clone()); // Slot 2, conf 0
|
||||
block_commitment.entry(3).or_insert(cache2); // Slot 3, conf 0
|
||||
let block_commitment_cache = BlockCommitmentCache::new(
|
||||
block_commitment,
|
||||
total_stake,
|
||||
CommitmentSlots {
|
||||
slot: bank_slot_5,
|
||||
root: 0,
|
||||
highest_confirmed_slot: 0,
|
||||
highest_confirmed_root: 0,
|
||||
},
|
||||
);
|
||||
let block_commitment_cache =
|
||||
BlockCommitmentCache::new(block_commitment, total_stake, commitment_slots);
|
||||
|
||||
assert_eq!(block_commitment_cache.calculate_highest_confirmed_slot(), 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue