Rename confidence to commitment (#6714)
This commit is contained in:
parent
c138d692b1
commit
33f4aaf3fd
|
@ -17,7 +17,7 @@ To interact with a Solana node inside a JavaScript application, use the [solana-
|
|||
* [confirmTransaction](jsonrpc-api.md#confirmtransaction)
|
||||
* [getAccountInfo](jsonrpc-api.md#getaccountinfo)
|
||||
* [getBalance](jsonrpc-api.md#getbalance)
|
||||
* [getBlockConfidence](jsonrpc-api.md#getblockconfidence)
|
||||
* [getBlockCommitment](jsonrpc-api.md#getblockcommitment)
|
||||
* [getClusterNodes](jsonrpc-api.md#getclusternodes)
|
||||
* [getEpochInfo](jsonrpc-api.md#getepochinfo)
|
||||
* [getEpochSchedule](jsonrpc-api.md#getepochschedule)
|
||||
|
@ -151,9 +151,9 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "
|
|||
{"jsonrpc":"2.0","result":0,"id":1}
|
||||
```
|
||||
|
||||
### getBlockConfidence
|
||||
### getBlockCommitment
|
||||
|
||||
Returns confidence for particular block
|
||||
Returns commitment for particular block
|
||||
|
||||
#### Parameters:
|
||||
|
||||
|
@ -163,20 +163,20 @@ Returns confidence for particular block
|
|||
|
||||
The result field will be an array with two fields:
|
||||
|
||||
* Confidence
|
||||
* Commitment
|
||||
* `null` - Unknown block
|
||||
* `object` - BankConfidence
|
||||
* `array` - confidence, array of u64 integers logging the amount of cluster stake in lamports that has voted on the block at each depth from 0 to `MAX_LOCKOUT_HISTORY`
|
||||
* `object` - BlockCommitment
|
||||
* `array` - commitment, array of u64 integers logging the amount of cluster stake in lamports that has voted on the block at each depth from 0 to `MAX_LOCKOUT_HISTORY`
|
||||
* 'integer' - total active stake, in lamports, of the current epoch
|
||||
|
||||
#### Example:
|
||||
|
||||
```bash
|
||||
// Request
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getBlockConfidence","params":[5]}' http://localhost:8899
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getBlockCommitment","params":[5]}' http://localhost:8899
|
||||
|
||||
// Result
|
||||
{"jsonrpc":"2.0","result":[{"confidence":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,32]},42],"id":1}
|
||||
{"jsonrpc":"2.0","result":[{"commitment":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,32]},42],"id":1}
|
||||
```
|
||||
|
||||
### getClusterNodes
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# Commitment
|
||||
|
||||
The commitment metric aims to give clients a measure of the network confirmation
|
||||
and stake levels on a particular block. Clients can then use this information to
|
||||
derive their own measures of confidence.
|
||||
and stake levels on a particular block. Clients can then use this information to
|
||||
derive their own measures of commitment.
|
||||
|
||||
# Calculation RPC
|
||||
|
||||
|
|
|
@ -15,57 +15,57 @@ use std::{
|
|||
};
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct BankConfidence {
|
||||
confidence: [u64; MAX_LOCKOUT_HISTORY],
|
||||
pub struct BlockCommitment {
|
||||
commitment: [u64; MAX_LOCKOUT_HISTORY],
|
||||
}
|
||||
|
||||
impl BankConfidence {
|
||||
impl BlockCommitment {
|
||||
pub fn increase_confirmation_stake(&mut self, confirmation_count: usize, stake: u64) {
|
||||
assert!(confirmation_count > 0 && confirmation_count <= MAX_LOCKOUT_HISTORY);
|
||||
self.confidence[confirmation_count - 1] += stake;
|
||||
self.commitment[confirmation_count - 1] += stake;
|
||||
}
|
||||
|
||||
pub fn get_confirmation_stake(&mut self, confirmation_count: usize) -> u64 {
|
||||
assert!(confirmation_count > 0 && confirmation_count <= MAX_LOCKOUT_HISTORY);
|
||||
self.confidence[confirmation_count - 1]
|
||||
self.commitment[confirmation_count - 1]
|
||||
}
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new(confidence: [u64; MAX_LOCKOUT_HISTORY]) -> Self {
|
||||
Self { confidence }
|
||||
pub(crate) fn new(commitment: [u64; MAX_LOCKOUT_HISTORY]) -> Self {
|
||||
Self { commitment }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct ForkConfidenceCache {
|
||||
bank_confidence: HashMap<Slot, BankConfidence>,
|
||||
pub struct BlockCommitmentCache {
|
||||
block_commitment: HashMap<Slot, BlockCommitment>,
|
||||
total_stake: u64,
|
||||
}
|
||||
|
||||
impl ForkConfidenceCache {
|
||||
pub fn new(bank_confidence: HashMap<Slot, BankConfidence>, total_stake: u64) -> Self {
|
||||
impl BlockCommitmentCache {
|
||||
pub fn new(block_commitment: HashMap<Slot, BlockCommitment>, total_stake: u64) -> Self {
|
||||
Self {
|
||||
bank_confidence,
|
||||
block_commitment,
|
||||
total_stake,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_fork_confidence(&self, slot: Slot) -> Option<&BankConfidence> {
|
||||
self.bank_confidence.get(&slot)
|
||||
pub fn get_block_commitment(&self, slot: Slot) -> Option<&BlockCommitment> {
|
||||
self.block_commitment.get(&slot)
|
||||
}
|
||||
|
||||
pub fn total_stake(&self) -> u64 {
|
||||
self.total_stake
|
||||
}
|
||||
|
||||
pub fn get_fork_with_depth_confidence(
|
||||
pub fn get_block_with_depth_commitment(
|
||||
&self,
|
||||
minimum_depth: usize,
|
||||
minimum_stake_percentage: f64,
|
||||
) -> Option<Slot> {
|
||||
self.bank_confidence
|
||||
self.block_commitment
|
||||
.iter()
|
||||
.filter(|&(_, bank_confidence)| {
|
||||
let fork_stake_minimum_depth: u64 = bank_confidence.confidence[minimum_depth..]
|
||||
.filter(|&(_, block_commitment)| {
|
||||
let fork_stake_minimum_depth: u64 = block_commitment.commitment[minimum_depth..]
|
||||
.iter()
|
||||
.cloned()
|
||||
.sum();
|
||||
|
@ -76,52 +76,52 @@ impl ForkConfidenceCache {
|
|||
.max()
|
||||
}
|
||||
|
||||
pub fn get_rooted_fork_with_confidence(&self, minimum_stake_percentage: f64) -> Option<u64> {
|
||||
self.get_fork_with_depth_confidence(MAX_LOCKOUT_HISTORY - 1, minimum_stake_percentage)
|
||||
pub fn get_rooted_block_with_commitment(&self, minimum_stake_percentage: f64) -> Option<u64> {
|
||||
self.get_block_with_depth_commitment(MAX_LOCKOUT_HISTORY - 1, minimum_stake_percentage)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ConfidenceAggregationData {
|
||||
pub struct CommitmentAggregationData {
|
||||
bank: Arc<Bank>,
|
||||
total_staked: u64,
|
||||
}
|
||||
|
||||
impl ConfidenceAggregationData {
|
||||
impl CommitmentAggregationData {
|
||||
pub fn new(bank: Arc<Bank>, total_staked: u64) -> Self {
|
||||
Self { bank, total_staked }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AggregateConfidenceService {
|
||||
t_confidence: JoinHandle<()>,
|
||||
pub struct AggregateCommitmentService {
|
||||
t_commitment: JoinHandle<()>,
|
||||
}
|
||||
|
||||
impl AggregateConfidenceService {
|
||||
impl AggregateCommitmentService {
|
||||
pub fn new(
|
||||
exit: &Arc<AtomicBool>,
|
||||
fork_confidence_cache: Arc<RwLock<ForkConfidenceCache>>,
|
||||
) -> (Sender<ConfidenceAggregationData>, Self) {
|
||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||
) -> (Sender<CommitmentAggregationData>, Self) {
|
||||
let (sender, receiver): (
|
||||
Sender<ConfidenceAggregationData>,
|
||||
Receiver<ConfidenceAggregationData>,
|
||||
Sender<CommitmentAggregationData>,
|
||||
Receiver<CommitmentAggregationData>,
|
||||
) = channel();
|
||||
let exit_ = exit.clone();
|
||||
(
|
||||
sender,
|
||||
Self {
|
||||
t_confidence: Builder::new()
|
||||
t_commitment: Builder::new()
|
||||
.name("solana-aggregate-stake-lockouts".to_string())
|
||||
.spawn(move || loop {
|
||||
if exit_.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
||||
if let Err(e) = Self::run(&receiver, &fork_confidence_cache, &exit_) {
|
||||
if let Err(e) = Self::run(&receiver, &block_commitment_cache, &exit_) {
|
||||
match e {
|
||||
Error::RecvTimeoutError(RecvTimeoutError::Disconnected) => break,
|
||||
Error::RecvTimeoutError(RecvTimeoutError::Timeout) => (),
|
||||
_ => info!(
|
||||
"Unexpected error from AggregateConfidenceService: {:?}",
|
||||
"Unexpected error from AggregateCommitmentService: {:?}",
|
||||
e
|
||||
),
|
||||
}
|
||||
|
@ -133,8 +133,8 @@ impl AggregateConfidenceService {
|
|||
}
|
||||
|
||||
fn run(
|
||||
receiver: &Receiver<ConfidenceAggregationData>,
|
||||
fork_confidence_cache: &RwLock<ForkConfidenceCache>,
|
||||
receiver: &Receiver<CommitmentAggregationData>,
|
||||
block_commitment_cache: &RwLock<BlockCommitmentCache>,
|
||||
exit: &Arc<AtomicBool>,
|
||||
) -> Result<()> {
|
||||
loop {
|
||||
|
@ -153,18 +153,18 @@ impl AggregateConfidenceService {
|
|||
continue;
|
||||
}
|
||||
|
||||
let bank_confidence = Self::aggregate_confidence(&ancestors, &aggregation_data.bank);
|
||||
let block_commitment = Self::aggregate_commitment(&ancestors, &aggregation_data.bank);
|
||||
|
||||
let mut new_fork_confidence =
|
||||
ForkConfidenceCache::new(bank_confidence, aggregation_data.total_staked);
|
||||
let mut new_block_commitment =
|
||||
BlockCommitmentCache::new(block_commitment, aggregation_data.total_staked);
|
||||
|
||||
let mut w_fork_confidence_cache = fork_confidence_cache.write().unwrap();
|
||||
let mut w_block_commitment_cache = block_commitment_cache.write().unwrap();
|
||||
|
||||
std::mem::swap(&mut *w_fork_confidence_cache, &mut new_fork_confidence);
|
||||
std::mem::swap(&mut *w_block_commitment_cache, &mut new_block_commitment);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn aggregate_confidence(ancestors: &[Slot], bank: &Bank) -> HashMap<Slot, BankConfidence> {
|
||||
pub fn aggregate_commitment(ancestors: &[Slot], bank: &Bank) -> HashMap<Slot, BlockCommitment> {
|
||||
assert!(!ancestors.is_empty());
|
||||
|
||||
// Check ancestors is sorted
|
||||
|
@ -172,7 +172,7 @@ impl AggregateConfidenceService {
|
|||
assert!(a[0] < a[1]);
|
||||
}
|
||||
|
||||
let mut confidence = HashMap::new();
|
||||
let mut commitment = HashMap::new();
|
||||
for (_, (lamports, account)) in bank.vote_accounts().into_iter() {
|
||||
if lamports == 0 {
|
||||
continue;
|
||||
|
@ -183,19 +183,19 @@ impl AggregateConfidenceService {
|
|||
}
|
||||
|
||||
let vote_state = vote_state.unwrap();
|
||||
Self::aggregate_confidence_for_vote_account(
|
||||
&mut confidence,
|
||||
Self::aggregate_commitment_for_vote_account(
|
||||
&mut commitment,
|
||||
&vote_state,
|
||||
ancestors,
|
||||
lamports,
|
||||
);
|
||||
}
|
||||
|
||||
confidence
|
||||
commitment
|
||||
}
|
||||
|
||||
fn aggregate_confidence_for_vote_account(
|
||||
confidence: &mut HashMap<Slot, BankConfidence>,
|
||||
fn aggregate_commitment_for_vote_account(
|
||||
commitment: &mut HashMap<Slot, BlockCommitment>,
|
||||
vote_state: &VoteState,
|
||||
ancestors: &[Slot],
|
||||
lamports: u64,
|
||||
|
@ -205,9 +205,9 @@ impl AggregateConfidenceService {
|
|||
if let Some(root) = vote_state.root_slot {
|
||||
for (i, a) in ancestors.iter().enumerate() {
|
||||
if *a <= root {
|
||||
confidence
|
||||
commitment
|
||||
.entry(*a)
|
||||
.or_insert_with(BankConfidence::default)
|
||||
.or_insert_with(BlockCommitment::default)
|
||||
.increase_confirmation_stake(MAX_LOCKOUT_HISTORY, lamports);
|
||||
} else {
|
||||
ancestors_index = i;
|
||||
|
@ -218,9 +218,9 @@ impl AggregateConfidenceService {
|
|||
|
||||
for vote in &vote_state.votes {
|
||||
while ancestors[ancestors_index] <= vote.slot {
|
||||
confidence
|
||||
commitment
|
||||
.entry(ancestors[ancestors_index])
|
||||
.or_insert_with(BankConfidence::default)
|
||||
.or_insert_with(BlockCommitment::default)
|
||||
.increase_confirmation_stake(vote.confirmation_count as usize, lamports);
|
||||
ancestors_index += 1;
|
||||
|
||||
|
@ -232,11 +232,11 @@ impl AggregateConfidenceService {
|
|||
}
|
||||
}
|
||||
|
||||
impl Service for AggregateConfidenceService {
|
||||
impl Service for AggregateCommitmentService {
|
||||
type JoinReturnType = ();
|
||||
|
||||
fn join(self) -> thread::Result<()> {
|
||||
self.t_confidence.join()
|
||||
self.t_commitment.join()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,8 +249,8 @@ mod tests {
|
|||
use solana_vote_api::vote_state;
|
||||
|
||||
#[test]
|
||||
fn test_bank_confidence() {
|
||||
let mut cache = BankConfidence::default();
|
||||
fn test_block_commitment() {
|
||||
let mut cache = BlockCommitment::default();
|
||||
assert_eq!(cache.get_confirmation_stake(1), 0);
|
||||
cache.increase_confirmation_stake(1, 10);
|
||||
assert_eq!(cache.get_confirmation_stake(1), 10);
|
||||
|
@ -259,121 +259,121 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_fork_with_depth_confidence() {
|
||||
// Build ForkConfidenceCache with votes at depths 0 and 1 for 2 slots
|
||||
let mut cache0 = BankConfidence::default();
|
||||
fn test_get_block_with_depth_commitment() {
|
||||
// Build BlockCommitmentCache with votes at depths 0 and 1 for 2 slots
|
||||
let mut cache0 = BlockCommitment::default();
|
||||
cache0.increase_confirmation_stake(1, 15);
|
||||
cache0.increase_confirmation_stake(2, 25);
|
||||
|
||||
let mut cache1 = BankConfidence::default();
|
||||
let mut cache1 = BlockCommitment::default();
|
||||
cache1.increase_confirmation_stake(1, 10);
|
||||
cache1.increase_confirmation_stake(2, 20);
|
||||
|
||||
let mut bank_confidence = HashMap::new();
|
||||
bank_confidence.entry(0).or_insert(cache0.clone());
|
||||
bank_confidence.entry(1).or_insert(cache1.clone());
|
||||
let fork_confidence_cache = ForkConfidenceCache::new(bank_confidence, 50);
|
||||
let mut block_commitment = HashMap::new();
|
||||
block_commitment.entry(0).or_insert(cache0.clone());
|
||||
block_commitment.entry(1).or_insert(cache1.clone());
|
||||
let block_commitment_cache = BlockCommitmentCache::new(block_commitment, 50);
|
||||
|
||||
// Neither slot has rooted votes
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_rooted_fork_with_confidence(0.1),
|
||||
block_commitment_cache.get_rooted_block_with_commitment(0.1),
|
||||
None
|
||||
);
|
||||
// Neither slot meets the minimum level of confidence 0.6 at depth 1
|
||||
// Neither slot meets the minimum level of commitment 0.6 at depth 1
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_fork_with_depth_confidence(1, 0.6),
|
||||
block_commitment_cache.get_block_with_depth_commitment(1, 0.6),
|
||||
None
|
||||
);
|
||||
// Only slot 0 meets the minimum level of confidence 0.5 at depth 1
|
||||
// Only slot 0 meets the minimum level of commitment 0.5 at depth 1
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_fork_with_depth_confidence(1, 0.5),
|
||||
block_commitment_cache.get_block_with_depth_commitment(1, 0.5),
|
||||
Some(0)
|
||||
);
|
||||
// If multiple slots meet the minimum level of confidence, method should return the most recent
|
||||
// If multiple slots meet the minimum level of commitment, method should return the most recent
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_fork_with_depth_confidence(1, 0.4),
|
||||
block_commitment_cache.get_block_with_depth_commitment(1, 0.4),
|
||||
Some(1)
|
||||
);
|
||||
// If multiple slots meet the minimum level of confidence, method should return the most recent
|
||||
// If multiple slots meet the minimum level of commitment, method should return the most recent
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_fork_with_depth_confidence(0, 0.6),
|
||||
block_commitment_cache.get_block_with_depth_commitment(0, 0.6),
|
||||
Some(1)
|
||||
);
|
||||
// Neither slot meets the minimum level of confidence 0.9 at depth 0
|
||||
// Neither slot meets the minimum level of commitment 0.9 at depth 0
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_fork_with_depth_confidence(0, 0.9),
|
||||
block_commitment_cache.get_block_with_depth_commitment(0, 0.9),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_rooted_fork_with_confidence() {
|
||||
// Build ForkConfidenceCache with rooted votes
|
||||
let mut cache0 = BankConfidence::new([0; MAX_LOCKOUT_HISTORY]);
|
||||
fn test_get_rooted_block_with_commitment() {
|
||||
// Build BlockCommitmentCache with rooted votes
|
||||
let mut cache0 = BlockCommitment::new([0; MAX_LOCKOUT_HISTORY]);
|
||||
cache0.increase_confirmation_stake(MAX_LOCKOUT_HISTORY, 40);
|
||||
cache0.increase_confirmation_stake(MAX_LOCKOUT_HISTORY - 1, 10);
|
||||
let mut cache1 = BankConfidence::new([0; MAX_LOCKOUT_HISTORY]);
|
||||
let mut cache1 = BlockCommitment::new([0; MAX_LOCKOUT_HISTORY]);
|
||||
cache1.increase_confirmation_stake(MAX_LOCKOUT_HISTORY, 30);
|
||||
cache1.increase_confirmation_stake(MAX_LOCKOUT_HISTORY - 1, 10);
|
||||
cache1.increase_confirmation_stake(MAX_LOCKOUT_HISTORY - 2, 10);
|
||||
|
||||
let mut bank_confidence = HashMap::new();
|
||||
bank_confidence.entry(0).or_insert(cache0.clone());
|
||||
bank_confidence.entry(1).or_insert(cache1.clone());
|
||||
let fork_confidence_cache = ForkConfidenceCache::new(bank_confidence, 50);
|
||||
let mut block_commitment = HashMap::new();
|
||||
block_commitment.entry(0).or_insert(cache0.clone());
|
||||
block_commitment.entry(1).or_insert(cache1.clone());
|
||||
let block_commitment_cache = BlockCommitmentCache::new(block_commitment, 50);
|
||||
|
||||
// Only slot 0 meets the minimum level of confidence 0.66 at root
|
||||
// Only slot 0 meets the minimum level of commitment 0.66 at root
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_rooted_fork_with_confidence(0.66),
|
||||
block_commitment_cache.get_rooted_block_with_commitment(0.66),
|
||||
Some(0)
|
||||
);
|
||||
// If multiple slots meet the minimum level of confidence, method should return the most recent
|
||||
// If multiple slots meet the minimum level of commitment, method should return the most recent
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_rooted_fork_with_confidence(0.6),
|
||||
block_commitment_cache.get_rooted_block_with_commitment(0.6),
|
||||
Some(1)
|
||||
);
|
||||
// Neither slot meets the minimum level of confidence 0.9 at root
|
||||
// Neither slot meets the minimum level of commitment 0.9 at root
|
||||
assert_eq!(
|
||||
fork_confidence_cache.get_rooted_fork_with_confidence(0.9),
|
||||
block_commitment_cache.get_rooted_block_with_commitment(0.9),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aggregate_confidence_for_vote_account_1() {
|
||||
fn test_aggregate_commitment_for_vote_account_1() {
|
||||
let ancestors = vec![3, 4, 5, 7, 9, 11];
|
||||
let mut confidence = HashMap::new();
|
||||
let mut commitment = HashMap::new();
|
||||
let lamports = 5;
|
||||
let mut vote_state = VoteState::default();
|
||||
|
||||
let root = ancestors.last().unwrap();
|
||||
vote_state.root_slot = Some(*root);
|
||||
AggregateConfidenceService::aggregate_confidence_for_vote_account(
|
||||
&mut confidence,
|
||||
AggregateCommitmentService::aggregate_commitment_for_vote_account(
|
||||
&mut commitment,
|
||||
&vote_state,
|
||||
&ancestors,
|
||||
lamports,
|
||||
);
|
||||
|
||||
for a in ancestors {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(MAX_LOCKOUT_HISTORY, lamports);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aggregate_confidence_for_vote_account_2() {
|
||||
fn test_aggregate_commitment_for_vote_account_2() {
|
||||
let ancestors = vec![3, 4, 5, 7, 9, 11];
|
||||
let mut confidence = HashMap::new();
|
||||
let mut commitment = HashMap::new();
|
||||
let lamports = 5;
|
||||
let mut vote_state = VoteState::default();
|
||||
|
||||
let root = ancestors[2];
|
||||
vote_state.root_slot = Some(root);
|
||||
vote_state.process_slot_vote_unchecked(*ancestors.last().unwrap());
|
||||
AggregateConfidenceService::aggregate_confidence_for_vote_account(
|
||||
&mut confidence,
|
||||
AggregateCommitmentService::aggregate_commitment_for_vote_account(
|
||||
&mut commitment,
|
||||
&vote_state,
|
||||
&ancestors,
|
||||
lamports,
|
||||
|
@ -381,21 +381,21 @@ mod tests {
|
|||
|
||||
for a in ancestors {
|
||||
if a <= root {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(MAX_LOCKOUT_HISTORY, lamports);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
} else {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(1, lamports);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aggregate_confidence_for_vote_account_3() {
|
||||
fn test_aggregate_commitment_for_vote_account_3() {
|
||||
let ancestors = vec![3, 4, 5, 7, 9, 10, 11];
|
||||
let mut confidence = HashMap::new();
|
||||
let mut commitment = HashMap::new();
|
||||
let lamports = 5;
|
||||
let mut vote_state = VoteState::default();
|
||||
|
||||
|
@ -404,8 +404,8 @@ mod tests {
|
|||
assert!(ancestors[4] + 2 >= ancestors[6]);
|
||||
vote_state.process_slot_vote_unchecked(ancestors[4]);
|
||||
vote_state.process_slot_vote_unchecked(ancestors[6]);
|
||||
AggregateConfidenceService::aggregate_confidence_for_vote_account(
|
||||
&mut confidence,
|
||||
AggregateCommitmentService::aggregate_commitment_for_vote_account(
|
||||
&mut commitment,
|
||||
&vote_state,
|
||||
&ancestors,
|
||||
lamports,
|
||||
|
@ -413,23 +413,23 @@ mod tests {
|
|||
|
||||
for (i, a) in ancestors.iter().enumerate() {
|
||||
if *a <= root {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(MAX_LOCKOUT_HISTORY, lamports);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
} else if i <= 4 {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(2, lamports);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
} else if i <= 6 {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(1, lamports);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_aggregate_confidence_validity() {
|
||||
fn test_aggregate_commitment_validity() {
|
||||
let ancestors = vec![3, 4, 5, 7, 9, 10, 11];
|
||||
let GenesisBlockInfo {
|
||||
mut genesis_block, ..
|
||||
|
@ -466,28 +466,28 @@ mod tests {
|
|||
vote_state2.to(&mut vote_account2).unwrap();
|
||||
bank.store_account(&pk2, &vote_account2);
|
||||
|
||||
let confidence = AggregateConfidenceService::aggregate_confidence(&ancestors, &bank);
|
||||
let commitment = AggregateCommitmentService::aggregate_commitment(&ancestors, &bank);
|
||||
|
||||
for a in ancestors {
|
||||
if a <= 3 {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(2, 150);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
} else if a <= 5 {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(1, 100);
|
||||
expected.increase_confirmation_stake(2, 50);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
} else if a <= 9 {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(2, 50);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
} else if a <= 10 {
|
||||
let mut expected = BankConfidence::default();
|
||||
let mut expected = BlockCommitment::default();
|
||||
expected.increase_confirmation_stake(1, 50);
|
||||
assert_eq!(*confidence.get(&a).unwrap(), expected);
|
||||
assert_eq!(*commitment.get(&a).unwrap(), expected);
|
||||
} else {
|
||||
assert!(confidence.get(&a).is_none());
|
||||
assert!(commitment.get(&a).is_none());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ pub mod broadcast_stage;
|
|||
pub mod chacha;
|
||||
pub mod chacha_cuda;
|
||||
pub mod cluster_info_vote_listener;
|
||||
pub mod confidence;
|
||||
pub mod commitment;
|
||||
pub mod recycler;
|
||||
pub mod shred_fetch_stage;
|
||||
#[macro_use]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
//! The `replay_stage` replays transactions broadcast by the leader.
|
||||
|
||||
use crate::cluster_info::ClusterInfo;
|
||||
use crate::confidence::{
|
||||
AggregateConfidenceService, ConfidenceAggregationData, ForkConfidenceCache,
|
||||
use crate::commitment::{
|
||||
AggregateCommitmentService, BlockCommitmentCache, CommitmentAggregationData,
|
||||
};
|
||||
use crate::consensus::{StakeLockout, Tower};
|
||||
use crate::poh_recorder::PohRecorder;
|
||||
|
@ -64,7 +64,7 @@ impl Drop for Finalizer {
|
|||
|
||||
pub struct ReplayStage {
|
||||
t_replay: JoinHandle<Result<()>>,
|
||||
confidence_service: AggregateConfidenceService,
|
||||
commitment_service: AggregateCommitmentService,
|
||||
}
|
||||
|
||||
struct ReplaySlotStats {
|
||||
|
@ -160,7 +160,7 @@ impl ReplayStage {
|
|||
leader_schedule_cache: &Arc<LeaderScheduleCache>,
|
||||
slot_full_senders: Vec<Sender<(u64, Pubkey)>>,
|
||||
snapshot_package_sender: Option<SnapshotPackageSender>,
|
||||
fork_confidence_cache: Arc<RwLock<ForkConfidenceCache>>,
|
||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||
) -> (Self, Receiver<Vec<Arc<Bank>>>)
|
||||
where
|
||||
T: 'static + KeypairUtil + Send + Sync,
|
||||
|
@ -178,8 +178,8 @@ impl ReplayStage {
|
|||
let vote_account = *vote_account;
|
||||
let voting_keypair = voting_keypair.cloned();
|
||||
|
||||
let (lockouts_sender, confidence_service) =
|
||||
AggregateConfidenceService::new(exit, fork_confidence_cache);
|
||||
let (lockouts_sender, commitment_service) =
|
||||
AggregateCommitmentService::new(exit, block_commitment_cache);
|
||||
|
||||
let t_replay = Builder::new()
|
||||
.name("solana-replay-stage".to_string())
|
||||
|
@ -299,7 +299,7 @@ impl ReplayStage {
|
|||
(
|
||||
Self {
|
||||
t_replay,
|
||||
confidence_service,
|
||||
commitment_service,
|
||||
},
|
||||
root_bank_receiver,
|
||||
)
|
||||
|
@ -486,7 +486,7 @@ impl ReplayStage {
|
|||
leader_schedule_cache: &Arc<LeaderScheduleCache>,
|
||||
root_bank_sender: &Sender<Vec<Arc<Bank>>>,
|
||||
total_staked: u64,
|
||||
lockouts_sender: &Sender<ConfidenceAggregationData>,
|
||||
lockouts_sender: &Sender<CommitmentAggregationData>,
|
||||
snapshot_package_sender: &Option<SnapshotPackageSender>,
|
||||
) -> Result<()>
|
||||
where
|
||||
|
@ -524,7 +524,7 @@ impl ReplayStage {
|
|||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
Self::update_confidence_cache(bank.clone(), total_staked, lockouts_sender);
|
||||
Self::update_commitment_cache(bank.clone(), total_staked, lockouts_sender);
|
||||
|
||||
if let Some(ref voting_keypair) = voting_keypair {
|
||||
let node_keypair = cluster_info.read().unwrap().keypair.clone();
|
||||
|
@ -544,12 +544,12 @@ impl ReplayStage {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn update_confidence_cache(
|
||||
fn update_commitment_cache(
|
||||
bank: Arc<Bank>,
|
||||
total_staked: u64,
|
||||
lockouts_sender: &Sender<ConfidenceAggregationData>,
|
||||
lockouts_sender: &Sender<CommitmentAggregationData>,
|
||||
) {
|
||||
if let Err(e) = lockouts_sender.send(ConfidenceAggregationData::new(bank, total_staked)) {
|
||||
if let Err(e) = lockouts_sender.send(CommitmentAggregationData::new(bank, total_staked)) {
|
||||
trace!("lockouts_sender failed: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
@ -917,7 +917,7 @@ impl Service for ReplayStage {
|
|||
type JoinReturnType = ();
|
||||
|
||||
fn join(self) -> thread::Result<()> {
|
||||
self.confidence_service.join()?;
|
||||
self.commitment_service.join()?;
|
||||
self.t_replay.join().map(|_| ())
|
||||
}
|
||||
}
|
||||
|
@ -925,7 +925,7 @@ impl Service for ReplayStage {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::confidence::BankConfidence;
|
||||
use crate::commitment::BlockCommitment;
|
||||
use crate::genesis_utils::{create_genesis_block, create_genesis_block_with_leader};
|
||||
use crate::replay_stage::ReplayStage;
|
||||
use solana_ledger::blocktree::make_slot_entries;
|
||||
|
@ -1196,7 +1196,7 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_replay_confidence_cache() {
|
||||
fn test_replay_commitment_cache() {
|
||||
fn leader_vote(bank: &Arc<Bank>, pubkey: &Pubkey) {
|
||||
let mut leader_vote_account = bank.get_account(&pubkey).unwrap();
|
||||
let mut vote_state = VoteState::from(&leader_vote_account).unwrap();
|
||||
|
@ -1205,10 +1205,10 @@ mod test {
|
|||
bank.store_account(&pubkey, &leader_vote_account);
|
||||
}
|
||||
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let (lockouts_sender, _) = AggregateConfidenceService::new(
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
let (lockouts_sender, _) = AggregateCommitmentService::new(
|
||||
&Arc::new(AtomicBool::new(false)),
|
||||
fork_confidence_cache.clone(),
|
||||
block_commitment_cache.clone(),
|
||||
);
|
||||
|
||||
let leader_pubkey = Pubkey::new_rand();
|
||||
|
@ -1230,15 +1230,15 @@ mod test {
|
|||
vec![0],
|
||||
)));
|
||||
|
||||
assert!(fork_confidence_cache
|
||||
assert!(block_commitment_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_fork_confidence(0)
|
||||
.get_block_commitment(0)
|
||||
.is_none());
|
||||
assert!(fork_confidence_cache
|
||||
assert!(block_commitment_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_fork_confidence(1)
|
||||
.get_block_commitment(1)
|
||||
.is_none());
|
||||
|
||||
let bank1 = Bank::new_from_parent(&arc_bank0, &Pubkey::default(), arc_bank0.slot() + 1);
|
||||
|
@ -1250,7 +1250,7 @@ mod test {
|
|||
bank_forks.write().unwrap().insert(bank1);
|
||||
let arc_bank1 = bank_forks.read().unwrap().get(1).unwrap().clone();
|
||||
leader_vote(&arc_bank1, &leader_voting_pubkey);
|
||||
ReplayStage::update_confidence_cache(arc_bank1.clone(), leader_lamports, &lockouts_sender);
|
||||
ReplayStage::update_commitment_cache(arc_bank1.clone(), leader_lamports, &lockouts_sender);
|
||||
|
||||
let bank2 = Bank::new_from_parent(&arc_bank1, &Pubkey::default(), arc_bank1.slot() + 1);
|
||||
let _res = bank2.transfer(10, &genesis_block_info.mint_keypair, &Pubkey::new_rand());
|
||||
|
@ -1261,36 +1261,36 @@ mod test {
|
|||
bank_forks.write().unwrap().insert(bank2);
|
||||
let arc_bank2 = bank_forks.read().unwrap().get(2).unwrap().clone();
|
||||
leader_vote(&arc_bank2, &leader_voting_pubkey);
|
||||
ReplayStage::update_confidence_cache(arc_bank2.clone(), leader_lamports, &lockouts_sender);
|
||||
ReplayStage::update_commitment_cache(arc_bank2.clone(), leader_lamports, &lockouts_sender);
|
||||
thread::sleep(Duration::from_millis(200));
|
||||
|
||||
let mut expected0 = BankConfidence::default();
|
||||
let mut expected0 = BlockCommitment::default();
|
||||
expected0.increase_confirmation_stake(2, leader_lamports);
|
||||
assert_eq!(
|
||||
fork_confidence_cache
|
||||
block_commitment_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_fork_confidence(0)
|
||||
.get_block_commitment(0)
|
||||
.unwrap(),
|
||||
&expected0,
|
||||
);
|
||||
let mut expected1 = BankConfidence::default();
|
||||
let mut expected1 = BlockCommitment::default();
|
||||
expected1.increase_confirmation_stake(2, leader_lamports);
|
||||
assert_eq!(
|
||||
fork_confidence_cache
|
||||
block_commitment_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_fork_confidence(1)
|
||||
.get_block_commitment(1)
|
||||
.unwrap(),
|
||||
&expected1
|
||||
);
|
||||
let mut expected2 = BankConfidence::default();
|
||||
let mut expected2 = BlockCommitment::default();
|
||||
expected2.increase_confirmation_stake(1, leader_lamports);
|
||||
assert_eq!(
|
||||
fork_confidence_cache
|
||||
block_commitment_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_fork_confidence(2)
|
||||
.get_block_commitment(2)
|
||||
.unwrap(),
|
||||
&expected2
|
||||
);
|
||||
|
|
120
core/src/rpc.rs
120
core/src/rpc.rs
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::{
|
||||
cluster_info::ClusterInfo,
|
||||
confidence::{BankConfidence, ForkConfidenceCache},
|
||||
commitment::{BlockCommitment, BlockCommitmentCache},
|
||||
contact_info::ContactInfo,
|
||||
packet::PACKET_DATA_SIZE,
|
||||
storage_stage::StorageState,
|
||||
|
@ -53,7 +53,7 @@ impl Default for JsonRpcConfig {
|
|||
#[derive(Clone)]
|
||||
pub struct JsonRpcRequestProcessor {
|
||||
bank_forks: Arc<RwLock<BankForks>>,
|
||||
fork_confidence_cache: Arc<RwLock<ForkConfidenceCache>>,
|
||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||
storage_state: StorageState,
|
||||
config: JsonRpcConfig,
|
||||
validator_exit: Arc<RwLock<Option<ValidatorExit>>>,
|
||||
|
@ -68,12 +68,12 @@ impl JsonRpcRequestProcessor {
|
|||
storage_state: StorageState,
|
||||
config: JsonRpcConfig,
|
||||
bank_forks: Arc<RwLock<BankForks>>,
|
||||
fork_confidence_cache: Arc<RwLock<ForkConfidenceCache>>,
|
||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||
validator_exit: &Arc<RwLock<Option<ValidatorExit>>>,
|
||||
) -> Self {
|
||||
JsonRpcRequestProcessor {
|
||||
bank_forks,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
storage_state,
|
||||
config,
|
||||
validator_exit: validator_exit.clone(),
|
||||
|
@ -116,11 +116,11 @@ impl JsonRpcRequestProcessor {
|
|||
(blockhash.to_string(), fee_calculator)
|
||||
}
|
||||
|
||||
fn get_block_confidence(&self, block: u64) -> (Option<BankConfidence>, u64) {
|
||||
let r_fork_confidence = self.fork_confidence_cache.read().unwrap();
|
||||
fn get_block_commitment(&self, block: u64) -> (Option<BlockCommitment>, u64) {
|
||||
let r_block_commitment = self.block_commitment_cache.read().unwrap();
|
||||
(
|
||||
r_fork_confidence.get_fork_confidence(block).cloned(),
|
||||
r_fork_confidence.total_stake(),
|
||||
r_block_commitment.get_block_commitment(block).cloned(),
|
||||
r_block_commitment.total_stake(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -307,12 +307,12 @@ pub trait RpcSol {
|
|||
#[rpc(meta, name = "getEpochInfo")]
|
||||
fn get_epoch_info(&self, _: Self::Metadata) -> Result<RpcEpochInfo>;
|
||||
|
||||
#[rpc(meta, name = "getBlockConfidence")]
|
||||
fn get_block_confidence(
|
||||
#[rpc(meta, name = "getBlockCommitment")]
|
||||
fn get_block_commitment(
|
||||
&self,
|
||||
_: Self::Metadata,
|
||||
_: u64,
|
||||
) -> Result<(Option<BankConfidence>, u64)>;
|
||||
) -> Result<(Option<BlockCommitment>, u64)>;
|
||||
|
||||
#[rpc(meta, name = "getGenesisBlockhash")]
|
||||
fn get_genesis_blockhash(&self, _: Self::Metadata) -> Result<String>;
|
||||
|
@ -504,16 +504,16 @@ impl RpcSol for RpcSolImpl {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_block_confidence(
|
||||
fn get_block_commitment(
|
||||
&self,
|
||||
meta: Self::Metadata,
|
||||
block: u64,
|
||||
) -> Result<(Option<BankConfidence>, u64)> {
|
||||
) -> Result<(Option<BlockCommitment>, u64)> {
|
||||
Ok(meta
|
||||
.request_processor
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_block_confidence(block))
|
||||
.get_block_commitment(block))
|
||||
}
|
||||
|
||||
fn get_genesis_blockhash(&self, meta: Self::Metadata) -> Result<String> {
|
||||
|
@ -769,20 +769,24 @@ pub mod tests {
|
|||
blockhash: Hash,
|
||||
alice: Keypair,
|
||||
leader_pubkey: Pubkey,
|
||||
fork_confidence_cache: Arc<RwLock<ForkConfidenceCache>>,
|
||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||
}
|
||||
|
||||
fn start_rpc_handler_with_tx(pubkey: &Pubkey) -> RpcHandler {
|
||||
let (bank_forks, alice) = new_bank_forks();
|
||||
let bank = bank_forks.read().unwrap().working_bank();
|
||||
|
||||
let confidence_slot0 = BankConfidence::new([8; MAX_LOCKOUT_HISTORY]);
|
||||
let confidence_slot1 = BankConfidence::new([9; MAX_LOCKOUT_HISTORY]);
|
||||
let mut bank_confidence: HashMap<u64, BankConfidence> = HashMap::new();
|
||||
bank_confidence.entry(0).or_insert(confidence_slot0.clone());
|
||||
bank_confidence.entry(1).or_insert(confidence_slot1.clone());
|
||||
let fork_confidence_cache =
|
||||
Arc::new(RwLock::new(ForkConfidenceCache::new(bank_confidence, 42)));
|
||||
let commitment_slot0 = BlockCommitment::new([8; MAX_LOCKOUT_HISTORY]);
|
||||
let commitment_slot1 = BlockCommitment::new([9; MAX_LOCKOUT_HISTORY]);
|
||||
let mut block_commitment: HashMap<u64, BlockCommitment> = HashMap::new();
|
||||
block_commitment
|
||||
.entry(0)
|
||||
.or_insert(commitment_slot0.clone());
|
||||
block_commitment
|
||||
.entry(1)
|
||||
.or_insert(commitment_slot1.clone());
|
||||
let block_commitment_cache =
|
||||
Arc::new(RwLock::new(BlockCommitmentCache::new(block_commitment, 42)));
|
||||
|
||||
let leader_pubkey = *bank.collector_id();
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
|
@ -799,7 +803,7 @@ pub mod tests {
|
|||
StorageState::default(),
|
||||
JsonRpcConfig::default(),
|
||||
bank_forks,
|
||||
fork_confidence_cache.clone(),
|
||||
block_commitment_cache.clone(),
|
||||
&validator_exit,
|
||||
)));
|
||||
let cluster_info = Arc::new(RwLock::new(ClusterInfo::new_with_invalid_keypair(
|
||||
|
@ -829,7 +833,7 @@ pub mod tests {
|
|||
blockhash,
|
||||
alice,
|
||||
leader_pubkey,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -840,12 +844,12 @@ pub mod tests {
|
|||
let validator_exit = create_validator_exit(&exit);
|
||||
let (bank_forks, alice) = new_bank_forks();
|
||||
let bank = bank_forks.read().unwrap().working_bank();
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
let request_processor = JsonRpcRequestProcessor::new(
|
||||
StorageState::default(),
|
||||
JsonRpcConfig::default(),
|
||||
bank_forks,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
&validator_exit,
|
||||
);
|
||||
thread::spawn(move || {
|
||||
|
@ -1255,7 +1259,7 @@ pub mod tests {
|
|||
fn test_rpc_send_bad_tx() {
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let validator_exit = create_validator_exit(&exit);
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
|
||||
let mut io = MetaIoHandler::default();
|
||||
let rpc = RpcSolImpl;
|
||||
|
@ -1266,7 +1270,7 @@ pub mod tests {
|
|||
StorageState::default(),
|
||||
JsonRpcConfig::default(),
|
||||
new_bank_forks().0,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
&validator_exit,
|
||||
);
|
||||
Arc::new(RwLock::new(request_processor))
|
||||
|
@ -1353,12 +1357,12 @@ pub mod tests {
|
|||
fn test_rpc_request_processor_config_default_trait_validator_exit_fails() {
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let validator_exit = create_validator_exit(&exit);
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
let request_processor = JsonRpcRequestProcessor::new(
|
||||
StorageState::default(),
|
||||
JsonRpcConfig::default(),
|
||||
new_bank_forks().0,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
&validator_exit,
|
||||
);
|
||||
assert_eq!(request_processor.validator_exit(), Ok(false));
|
||||
|
@ -1369,14 +1373,14 @@ pub mod tests {
|
|||
fn test_rpc_request_processor_allow_validator_exit_config() {
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let validator_exit = create_validator_exit(&exit);
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
let mut config = JsonRpcConfig::default();
|
||||
config.enable_validator_exit = true;
|
||||
let request_processor = JsonRpcRequestProcessor::new(
|
||||
StorageState::default(),
|
||||
config,
|
||||
new_bank_forks().0,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
&validator_exit,
|
||||
);
|
||||
assert_eq!(request_processor.validator_exit(), Ok(true));
|
||||
|
@ -1405,16 +1409,20 @@ pub mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_rpc_processor_get_block_confidence() {
|
||||
fn test_rpc_processor_get_block_commitment() {
|
||||
let exit = Arc::new(AtomicBool::new(false));
|
||||
let validator_exit = create_validator_exit(&exit);
|
||||
let confidence_slot0 = BankConfidence::new([8; MAX_LOCKOUT_HISTORY]);
|
||||
let confidence_slot1 = BankConfidence::new([9; MAX_LOCKOUT_HISTORY]);
|
||||
let mut bank_confidence: HashMap<u64, BankConfidence> = HashMap::new();
|
||||
bank_confidence.entry(0).or_insert(confidence_slot0.clone());
|
||||
bank_confidence.entry(1).or_insert(confidence_slot1.clone());
|
||||
let fork_confidence_cache =
|
||||
Arc::new(RwLock::new(ForkConfidenceCache::new(bank_confidence, 42)));
|
||||
let commitment_slot0 = BlockCommitment::new([8; MAX_LOCKOUT_HISTORY]);
|
||||
let commitment_slot1 = BlockCommitment::new([9; MAX_LOCKOUT_HISTORY]);
|
||||
let mut block_commitment: HashMap<u64, BlockCommitment> = HashMap::new();
|
||||
block_commitment
|
||||
.entry(0)
|
||||
.or_insert(commitment_slot0.clone());
|
||||
block_commitment
|
||||
.entry(1)
|
||||
.or_insert(commitment_slot1.clone());
|
||||
let block_commitment_cache =
|
||||
Arc::new(RwLock::new(BlockCommitmentCache::new(block_commitment, 42)));
|
||||
|
||||
let mut config = JsonRpcConfig::default();
|
||||
config.enable_validator_exit = true;
|
||||
|
@ -1422,36 +1430,36 @@ pub mod tests {
|
|||
StorageState::default(),
|
||||
config,
|
||||
new_bank_forks().0,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
&validator_exit,
|
||||
);
|
||||
assert_eq!(
|
||||
request_processor.get_block_confidence(0),
|
||||
(Some(confidence_slot0), 42)
|
||||
request_processor.get_block_commitment(0),
|
||||
(Some(commitment_slot0), 42)
|
||||
);
|
||||
assert_eq!(
|
||||
request_processor.get_block_confidence(1),
|
||||
(Some(confidence_slot1), 42)
|
||||
request_processor.get_block_commitment(1),
|
||||
(Some(commitment_slot1), 42)
|
||||
);
|
||||
assert_eq!(request_processor.get_block_confidence(2), (None, 42));
|
||||
assert_eq!(request_processor.get_block_commitment(2), (None, 42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rpc_get_block_confidence() {
|
||||
fn test_rpc_get_block_commitment() {
|
||||
let bob_pubkey = Pubkey::new_rand();
|
||||
let RpcHandler {
|
||||
io,
|
||||
meta,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
..
|
||||
} = start_rpc_handler_with_tx(&bob_pubkey);
|
||||
|
||||
let req =
|
||||
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getBlockConfidence","params":[0]}}"#);
|
||||
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getBlockCommitment","params":[0]}}"#);
|
||||
let res = io.handle_request_sync(&req, meta.clone());
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let (confidence, total_staked): (Option<BankConfidence>, u64) =
|
||||
let (commitment, total_staked): (Option<BlockCommitment>, u64) =
|
||||
if let Response::Single(res) = result {
|
||||
if let Output::Success(res) = res {
|
||||
serde_json::from_value(res.result).unwrap()
|
||||
|
@ -1462,21 +1470,21 @@ pub mod tests {
|
|||
panic!("Expected single response");
|
||||
};
|
||||
assert_eq!(
|
||||
confidence,
|
||||
fork_confidence_cache
|
||||
commitment,
|
||||
block_commitment_cache
|
||||
.read()
|
||||
.unwrap()
|
||||
.get_fork_confidence(0)
|
||||
.get_block_commitment(0)
|
||||
.cloned()
|
||||
);
|
||||
assert_eq!(total_staked, 42);
|
||||
|
||||
let req =
|
||||
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getBlockConfidence","params":[2]}}"#);
|
||||
format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getBlockCommitment","params":[2]}}"#);
|
||||
let res = io.handle_request_sync(&req, meta);
|
||||
let result: Response = serde_json::from_str(&res.expect("actual response"))
|
||||
.expect("actual response deserialization");
|
||||
let (confidence, total_staked): (Option<BankConfidence>, u64) =
|
||||
let (commitment, total_staked): (Option<BlockCommitment>, u64) =
|
||||
if let Response::Single(res) = result {
|
||||
if let Output::Success(res) = res {
|
||||
serde_json::from_value(res.result).unwrap()
|
||||
|
@ -1486,7 +1494,7 @@ pub mod tests {
|
|||
} else {
|
||||
panic!("Expected single response");
|
||||
};
|
||||
assert_eq!(confidence, None);
|
||||
assert_eq!(commitment, None);
|
||||
assert_eq!(total_staked, 42);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! The `rpc_service` module implements the Solana JSON RPC service.
|
||||
|
||||
use crate::{
|
||||
cluster_info::ClusterInfo, confidence::ForkConfidenceCache, rpc::*, service::Service,
|
||||
cluster_info::ClusterInfo, commitment::BlockCommitmentCache, rpc::*, service::Service,
|
||||
storage_stage::StorageState, validator::ValidatorExit,
|
||||
};
|
||||
use jsonrpc_core::MetaIoHandler;
|
||||
|
@ -91,7 +91,7 @@ impl JsonRpcService {
|
|||
storage_state: StorageState,
|
||||
config: JsonRpcConfig,
|
||||
bank_forks: Arc<RwLock<BankForks>>,
|
||||
fork_confidence_cache: Arc<RwLock<ForkConfidenceCache>>,
|
||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||
ledger_path: &Path,
|
||||
genesis_blockhash: Hash,
|
||||
validator_exit: &Arc<RwLock<Option<ValidatorExit>>>,
|
||||
|
@ -102,7 +102,7 @@ impl JsonRpcService {
|
|||
storage_state,
|
||||
config,
|
||||
bank_forks,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
validator_exit,
|
||||
)));
|
||||
let request_processor_ = request_processor.clone();
|
||||
|
@ -199,14 +199,14 @@ mod tests {
|
|||
solana_netutil::find_available_port_in_range((10000, 65535)).unwrap(),
|
||||
);
|
||||
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank.slot(), bank)));
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
let mut rpc_service = JsonRpcService::new(
|
||||
&cluster_info,
|
||||
rpc_addr,
|
||||
StorageState::default(),
|
||||
JsonRpcConfig::default(),
|
||||
bank_forks,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
&PathBuf::from("farf"),
|
||||
Hash::default(),
|
||||
&validator_exit,
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
use crate::blockstream_service::BlockstreamService;
|
||||
use crate::cluster_info::ClusterInfo;
|
||||
use crate::confidence::ForkConfidenceCache;
|
||||
use crate::commitment::BlockCommitmentCache;
|
||||
use crate::ledger_cleanup_service::LedgerCleanupService;
|
||||
use crate::poh_recorder::PohRecorder;
|
||||
use crate::replay_stage::ReplayStage;
|
||||
|
@ -82,7 +82,7 @@ impl Tvu {
|
|||
leader_schedule_cache: &Arc<LeaderScheduleCache>,
|
||||
exit: &Arc<AtomicBool>,
|
||||
completed_slots_receiver: CompletedSlotsReceiver,
|
||||
fork_confidence_cache: Arc<RwLock<ForkConfidenceCache>>,
|
||||
block_commitment_cache: Arc<RwLock<BlockCommitmentCache>>,
|
||||
sigverify_disabled: bool,
|
||||
) -> Self
|
||||
where
|
||||
|
@ -171,7 +171,7 @@ impl Tvu {
|
|||
leader_schedule_cache,
|
||||
vec![blockstream_slot_sender, ledger_cleanup_slot_sender],
|
||||
snapshot_package_sender,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
);
|
||||
|
||||
let blockstream_service = if let Some(blockstream_unix_socket) = blockstream_unix_socket {
|
||||
|
@ -279,7 +279,7 @@ pub mod tests {
|
|||
let voting_keypair = Keypair::new();
|
||||
let storage_keypair = Arc::new(Keypair::new());
|
||||
let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank(&bank));
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
let tvu = Tvu::new(
|
||||
&voting_keypair.pubkey(),
|
||||
Some(&Arc::new(voting_keypair)),
|
||||
|
@ -304,7 +304,7 @@ pub mod tests {
|
|||
&leader_schedule_cache,
|
||||
&exit,
|
||||
completed_slots_receiver,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
false,
|
||||
);
|
||||
exit.store(true, Ordering::Relaxed);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use crate::{
|
||||
broadcast_stage::BroadcastStageType,
|
||||
cluster_info::{ClusterInfo, Node},
|
||||
confidence::ForkConfidenceCache,
|
||||
commitment::BlockCommitmentCache,
|
||||
contact_info::ContactInfo,
|
||||
gossip_service::{discover_cluster, GossipService},
|
||||
poh_recorder::PohRecorder,
|
||||
|
@ -181,7 +181,7 @@ impl Validator {
|
|||
let bank_info = &bank_forks_info[0];
|
||||
let bank = bank_forks[bank_info.bank_slot].clone();
|
||||
let bank_forks = Arc::new(RwLock::new(bank_forks));
|
||||
let fork_confidence_cache = Arc::new(RwLock::new(ForkConfidenceCache::default()));
|
||||
let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default()));
|
||||
|
||||
let mut validator_exit = ValidatorExit::default();
|
||||
let exit_ = exit.clone();
|
||||
|
@ -209,7 +209,7 @@ impl Validator {
|
|||
storage_state.clone(),
|
||||
config.rpc_config.clone(),
|
||||
bank_forks.clone(),
|
||||
fork_confidence_cache.clone(),
|
||||
block_commitment_cache.clone(),
|
||||
ledger_path,
|
||||
genesis_blockhash,
|
||||
&validator_exit,
|
||||
|
@ -340,7 +340,7 @@ impl Validator {
|
|||
&leader_schedule_cache,
|
||||
&exit,
|
||||
completed_slots_receiver,
|
||||
fork_confidence_cache,
|
||||
block_commitment_cache,
|
||||
config.dev_sigverify_disabled,
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue