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