Use Slot and Epoch type aliases instead of raw u64 (#6693)

automerge
This commit is contained in:
Michael Vines 2019-11-02 00:38:30 -07:00 committed by Grimes
parent f9a9b7f610
commit 50a17fc00b
41 changed files with 583 additions and 473 deletions

View File

@ -1,11 +1,12 @@
use serde_json::{json, Value};
use solana_sdk::clock::{Epoch, Slot};
use std::{error, fmt};
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RpcEpochInfo {
/// The current epoch
pub epoch: u64,
pub epoch: Epoch,
/// The current slot, relative to the start of the current epoch
pub slot_index: u64,
@ -14,7 +15,7 @@ pub struct RpcEpochInfo {
pub slots_in_epoch: u64,
/// The absolute current slot
pub absolute_slot: u64,
pub absolute_slot: Slot,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
@ -46,7 +47,7 @@ pub struct RpcVoteAccountInfo {
pub last_vote: u64,
/// Current root slot for this vote account (0 if not root slot exists)
pub root_slot: u64,
pub root_slot: Slot,
}
#[derive(Debug, PartialEq)]

View File

@ -7,9 +7,11 @@ extern crate test;
extern crate solana_ledger;
use rand::Rng;
use solana_ledger::blocktree::{entries_to_test_shreds, get_tmp_ledger_path, Blocktree};
use solana_ledger::entry::{create_ticks, Entry};
use solana_sdk::hash::Hash;
use solana_ledger::{
blocktree::{entries_to_test_shreds, get_tmp_ledger_path, Blocktree},
entry::{create_ticks, Entry},
};
use solana_sdk::{clock::Slot, hash::Hash};
use std::path::Path;
use test::Bencher;
@ -30,7 +32,7 @@ fn setup_read_bench(
blocktree: &mut Blocktree,
num_small_shreds: u64,
num_large_shreds: u64,
slot: u64,
slot: Slot,
) {
// Make some big and small entries
let entries = create_ticks(

View File

@ -1,54 +1,58 @@
use crate::chacha::{chacha_cbc_encrypt_ledger, CHACHA_BLOCK_SIZE};
use crate::cluster_info::{ClusterInfo, Node, VALIDATOR_PORT_RANGE};
use crate::contact_info::ContactInfo;
use crate::gossip_service::GossipService;
use crate::packet::to_shared_blob;
use crate::recycler::Recycler;
use crate::repair_service;
use crate::repair_service::{RepairService, RepairSlotRange, RepairStrategy};
use crate::result::{Error, Result};
use crate::service::Service;
use crate::shred_fetch_stage::ShredFetchStage;
use crate::sigverify_stage::{DisabledSigVerifier, SigVerifyStage};
use crate::storage_stage::NUM_STORAGE_SAMPLES;
use crate::streamer::{receiver, responder, PacketReceiver};
use crate::window_service::WindowService;
use crate::{
chacha::{chacha_cbc_encrypt_ledger, CHACHA_BLOCK_SIZE},
cluster_info::{ClusterInfo, Node, VALIDATOR_PORT_RANGE},
contact_info::ContactInfo,
gossip_service::GossipService,
packet::to_shared_blob,
recycler::Recycler,
repair_service,
repair_service::{RepairService, RepairSlotRange, RepairStrategy},
result::{Error, Result},
service::Service,
shred_fetch_stage::ShredFetchStage,
sigverify_stage::{DisabledSigVerifier, SigVerifyStage},
storage_stage::NUM_STORAGE_SAMPLES,
streamer::{receiver, responder, PacketReceiver},
window_service::WindowService,
};
use bincode::deserialize;
use crossbeam_channel::unbounded;
use rand::thread_rng;
use rand::Rng;
use rand::SeedableRng;
use rand::{thread_rng, Rng, SeedableRng};
use rand_chacha::ChaChaRng;
use solana_client::rpc_client::RpcClient;
use solana_client::rpc_request::RpcRequest;
use solana_client::thin_client::ThinClient;
use solana_client::{rpc_client::RpcClient, rpc_request::RpcRequest, thin_client::ThinClient};
use solana_ed25519_dalek as ed25519_dalek;
use solana_ledger::blocktree::Blocktree;
use solana_ledger::leader_schedule_cache::LeaderScheduleCache;
use solana_ledger::shred::Shred;
use solana_ledger::{
blocktree::Blocktree, leader_schedule_cache::LeaderScheduleCache, shred::Shred,
};
use solana_netutil::bind_in_range;
use solana_sdk::account_utils::State;
use solana_sdk::client::{AsyncClient, SyncClient};
use solana_sdk::clock::{get_complete_segment_from_slot, get_segment_from_slot};
use solana_sdk::hash::{Hash, Hasher};
use solana_sdk::message::Message;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::timing::timestamp;
use solana_sdk::transaction::Transaction;
use solana_sdk::transport::TransportError;
use solana_storage_api::storage_contract::StorageContract;
use solana_storage_api::storage_instruction::{self, StorageAccountType};
use std::fs::File;
use std::io::{self, BufReader, ErrorKind, Read, Seek, SeekFrom};
use std::mem::size_of;
use std::net::{SocketAddr, UdpSocket};
use std::path::{Path, PathBuf};
use std::result;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::sync::{Arc, RwLock};
use std::thread::{sleep, spawn, JoinHandle};
use std::time::Duration;
use solana_sdk::{
account_utils::State,
client::{AsyncClient, SyncClient},
clock::{get_complete_segment_from_slot, get_segment_from_slot, Slot},
hash::{Hash, Hasher},
message::Message,
signature::{Keypair, KeypairUtil, Signature},
timing::timestamp,
transaction::Transaction,
transport::TransportError,
};
use solana_storage_api::{
storage_contract::StorageContract,
storage_instruction::{self, StorageAccountType},
};
use std::{
fs::File,
io::{self, BufReader, ErrorKind, Read, Seek, SeekFrom},
mem::size_of,
net::{SocketAddr, UdpSocket},
path::{Path, PathBuf},
result,
sync::atomic::{AtomicBool, Ordering},
sync::mpsc::{channel, Receiver, Sender},
sync::{Arc, RwLock},
thread::{sleep, spawn, JoinHandle},
time::Duration,
};
static ENCRYPTED_FILENAME: &str = "ledger.enc";
@ -65,7 +69,7 @@ pub struct Archiver {
// Shared Archiver Meta struct used internally
#[derive(Default)]
struct ArchiverMeta {
slot: u64,
slot: Slot,
slots_per_segment: u64,
ledger_path: PathBuf,
signature: Signature,
@ -497,7 +501,7 @@ impl Archiver {
}
fn wait_for_segment_download(
start_slot: u64,
start_slot: Slot,
slots_per_segment: u64,
blocktree: &Arc<Blocktree>,
exit: &Arc<AtomicBool>,
@ -905,7 +909,7 @@ impl Archiver {
}
fn segment_complete(
start_slot: u64,
start_slot: Slot,
slots_per_segment: u64,
blocktree: &Arc<Blocktree>,
) -> bool {

View File

@ -23,7 +23,7 @@ use solana_runtime::{accounts_db::ErrorCounters, bank::Bank, transaction_batch::
use solana_sdk::clock::MAX_TRANSACTION_FORWARDING_DELAY_GPU;
use solana_sdk::{
clock::{
DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE,
Slot, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE,
MAX_TRANSACTION_FORWARDING_DELAY,
},
poh_config::PohConfig,
@ -428,7 +428,7 @@ impl BankingStage {
#[allow(clippy::match_wild_err_arm)]
fn record_transactions(
bank_slot: u64,
bank_slot: Slot,
txs: &[Transaction],
results: &[transaction::Result<()>],
poh: &Arc<Mutex<PohRecorder>>,

View File

@ -7,8 +7,7 @@ use bincode::serialize;
use chrono::{SecondsFormat, Utc};
use serde_json::json;
use solana_ledger::entry::Entry;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{clock::Slot, hash::Hash, pubkey::Pubkey};
use std::cell::RefCell;
use std::path::{Path, PathBuf};
@ -72,14 +71,14 @@ impl EntryWriter for EntrySocket {
pub trait BlockstreamEvents {
fn emit_entry_event(
&self,
slot: u64,
slot: Slot,
tick_height: u64,
leader_pubkey: &Pubkey,
entries: &Entry,
) -> Result<()>;
fn emit_block_event(
&self,
slot: u64,
slot: Slot,
tick_height: u64,
leader_pubkey: &Pubkey,
blockhash: Hash,
@ -97,7 +96,7 @@ where
{
fn emit_entry_event(
&self,
slot: u64,
slot: Slot,
tick_height: u64,
leader_pubkey: &Pubkey,
entry: &Entry,
@ -123,7 +122,7 @@ where
fn emit_block_event(
&self,
slot: u64,
slot: Slot,
tick_height: u64,
leader_pubkey: &Pubkey,
blockhash: Hash,

View File

@ -2,9 +2,12 @@ use crate::poh_recorder::WorkingBankEntry;
use crate::result::Result;
use solana_ledger::entry::Entry;
use solana_runtime::bank::Bank;
use std::sync::mpsc::Receiver;
use std::sync::Arc;
use std::time::{Duration, Instant};
use solana_sdk::clock::Slot;
use std::{
sync::mpsc::Receiver,
sync::Arc,
time::{Duration, Instant},
};
pub(super) struct ReceiveResults {
pub entries: Vec<Entry>,
@ -16,8 +19,8 @@ pub(super) struct ReceiveResults {
#[derive(Copy, Clone)]
pub struct UnfinishedSlotInfo {
pub next_shred_index: u32,
pub slot: u64,
pub parent: u64,
pub slot: Slot,
pub parent: Slot,
}
/// This parameter tunes how many entries are received in one iteration of recv loop

View File

@ -282,17 +282,22 @@ mod test {
use super::*;
use crate::cluster_info::{ClusterInfo, Node};
use crate::genesis_utils::create_genesis_block;
use solana_ledger::blocktree::{get_tmp_ledger_path, Blocktree};
use solana_ledger::entry::create_ticks;
use solana_ledger::shred::max_ticks_per_n_shreds;
use solana_ledger::{
blocktree::{get_tmp_ledger_path, Blocktree},
entry::create_ticks,
shred::max_ticks_per_n_shreds,
};
use solana_runtime::bank::Bank;
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::{
clock::Slot,
genesis_block::GenesisBlock,
signature::{Keypair, KeypairUtil},
};
use std::sync::{Arc, RwLock};
use std::time::Duration;
fn setup(
num_shreds_per_slot: u64,
num_shreds_per_slot: Slot,
) -> (
Arc<Blocktree>,
GenesisBlock,

View File

@ -1,4 +1,5 @@
use solana_ledger::blocktree::Blocktree;
use solana_sdk::clock::Slot;
use std::fs::File;
use std::io;
use std::io::{BufWriter, Write};
@ -12,7 +13,7 @@ pub const CHACHA_KEY_SIZE: usize = 32;
pub fn chacha_cbc_encrypt_ledger(
blocktree: &Arc<Blocktree>,
start_slot: u64,
start_slot: Slot,
slots_per_segment: u64,
out_path: &Path,
ivec: &mut [u8; CHACHA_BLOCK_SIZE],

View File

@ -12,43 +12,48 @@
//! * layer 2 - Everyone else, if layer 1 is `2^10`, layer 2 should be able to fit `2^20` number of nodes.
//!
//! Bank needs to provide an interface for us to query the stake weight
use crate::contact_info::ContactInfo;
use crate::crds_gossip::CrdsGossip;
use crate::crds_gossip_error::CrdsGossipError;
use crate::crds_gossip_pull::{CrdsFilter, CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS};
use crate::crds_value::{CrdsValue, CrdsValueLabel, EpochSlots, Vote};
use crate::packet::{to_shared_blob, Blob, Packet, SharedBlob};
use crate::repair_service::RepairType;
use crate::result::{Error, Result};
use crate::sendmmsg::{multicast, send_mmsg};
use crate::streamer::{BlobReceiver, BlobSender};
use crate::weighted_shuffle::{weighted_best, weighted_shuffle};
use crate::{
contact_info::ContactInfo,
crds_gossip::CrdsGossip,
crds_gossip_error::CrdsGossipError,
crds_gossip_pull::{CrdsFilter, CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS},
crds_value::{CrdsValue, CrdsValueLabel, EpochSlots, Vote},
packet::{to_shared_blob, Blob, Packet, SharedBlob},
repair_service::RepairType,
result::{Error, Result},
sendmmsg::{multicast, send_mmsg},
streamer::{BlobReceiver, BlobSender},
weighted_shuffle::{weighted_best, weighted_shuffle},
};
use bincode::{deserialize, serialize, serialized_size};
use core::cmp;
use itertools::Itertools;
use rand::{thread_rng, Rng};
use solana_ledger::bank_forks::BankForks;
use solana_ledger::blocktree::Blocktree;
use solana_ledger::staking_utils;
use solana_ledger::{bank_forks::BankForks, blocktree::Blocktree, staking_utils};
use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_error};
use solana_netutil::{
bind_common, bind_common_in_range, bind_in_range, find_available_port_in_range,
multi_bind_in_range, PortRange,
};
use solana_sdk::packet::PACKET_DATA_SIZE;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil, Signable, Signature};
use solana_sdk::timing::{duration_as_ms, timestamp};
use solana_sdk::transaction::Transaction;
use std::borrow::Cow;
use std::cmp::min;
use std::collections::{BTreeSet, HashMap, HashSet};
use std::fmt;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener, UdpSocket};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock};
use std::thread::{sleep, Builder, JoinHandle};
use std::time::{Duration, Instant};
use solana_sdk::{
clock::Slot,
packet::PACKET_DATA_SIZE,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil, Signable, Signature},
timing::{duration_as_ms, timestamp},
transaction::Transaction,
};
use std::{
borrow::Cow,
cmp::min,
collections::{BTreeSet, HashMap, HashSet},
fmt,
net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener, UdpSocket},
sync::atomic::{AtomicBool, Ordering},
sync::{Arc, RwLock},
thread::{sleep, Builder, JoinHandle},
time::{Duration, Instant},
};
pub const VALIDATOR_PORT_RANGE: PortRange = (8000, 10_000);
@ -776,19 +781,19 @@ impl ClusterInfo {
Ok(())
}
pub fn window_index_request_bytes(&self, slot: u64, blob_index: u64) -> Result<Vec<u8>> {
pub fn window_index_request_bytes(&self, slot: Slot, blob_index: u64) -> Result<Vec<u8>> {
let req = Protocol::RequestWindowIndex(self.my_data().clone(), slot, blob_index);
let out = serialize(&req)?;
Ok(out)
}
fn window_highest_index_request_bytes(&self, slot: u64, blob_index: u64) -> Result<Vec<u8>> {
fn window_highest_index_request_bytes(&self, slot: Slot, blob_index: u64) -> Result<Vec<u8>> {
let req = Protocol::RequestHighestWindowIndex(self.my_data().clone(), slot, blob_index);
let out = serialize(&req)?;
Ok(out)
}
fn orphan_bytes(&self, slot: u64) -> Result<Vec<u8>> {
fn orphan_bytes(&self, slot: Slot) -> Result<Vec<u8>> {
let req = Protocol::RequestOrphan(self.my_data().clone(), slot);
let out = serialize(&req)?;
Ok(out)
@ -1043,7 +1048,7 @@ impl ClusterInfo {
fn get_data_shred_as_blob(
blocktree: &Arc<Blocktree>,
slot: u64,
slot: Slot,
shred_index: u64,
) -> Result<Option<Blob>> {
let bytes = blocktree.get_data_shred(slot, shred_index)?;
@ -1055,7 +1060,7 @@ impl ClusterInfo {
from_addr: &SocketAddr,
blocktree: Option<&Arc<Blocktree>>,
me: &ContactInfo,
slot: u64,
slot: Slot,
blob_index: u64,
) -> Vec<SharedBlob> {
if let Some(blocktree) = blocktree {
@ -1085,7 +1090,7 @@ impl ClusterInfo {
fn run_highest_window_request(
from_addr: &SocketAddr,
blocktree: Option<&Arc<Blocktree>>,
slot: u64,
slot: Slot,
highest_index: u64,
) -> Vec<SharedBlob> {
if let Some(blocktree) = blocktree {
@ -1111,7 +1116,7 @@ impl ClusterInfo {
fn run_orphan(
from_addr: &SocketAddr,
blocktree: Option<&Arc<Blocktree>>,
mut slot: u64,
mut slot: Slot,
max_responses: usize,
) -> Vec<SharedBlob> {
let mut res = vec![];

View File

@ -1,14 +1,18 @@
use crate::result::{Error, Result};
use crate::service::Service;
use crate::{
result::{Error, Result},
service::Service,
};
use solana_runtime::bank::Bank;
use solana_vote_api::vote_state::VoteState;
use solana_vote_api::vote_state::MAX_LOCKOUT_HISTORY;
use std::collections::HashMap;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
use std::sync::{Arc, RwLock};
use std::thread::{self, Builder, JoinHandle};
use std::time::Duration;
use solana_sdk::clock::Slot;
use solana_vote_api::{vote_state::VoteState, vote_state::MAX_LOCKOUT_HISTORY};
use std::{
collections::HashMap,
sync::atomic::{AtomicBool, Ordering},
sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender},
sync::{Arc, RwLock},
thread::{self, Builder, JoinHandle},
time::Duration,
};
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
pub struct BankConfidence {
@ -33,20 +37,20 @@ impl BankConfidence {
#[derive(Debug, Default)]
pub struct ForkConfidenceCache {
bank_confidence: HashMap<u64, BankConfidence>,
bank_confidence: HashMap<Slot, BankConfidence>,
total_stake: u64,
}
impl ForkConfidenceCache {
pub fn new(bank_confidence: HashMap<u64, BankConfidence>, total_stake: u64) -> Self {
pub fn new(bank_confidence: HashMap<Slot, BankConfidence>, total_stake: u64) -> Self {
Self {
bank_confidence,
total_stake,
}
}
pub fn get_fork_confidence(&self, fork: u64) -> Option<&BankConfidence> {
self.bank_confidence.get(&fork)
pub fn get_fork_confidence(&self, slot: Slot) -> Option<&BankConfidence> {
self.bank_confidence.get(&slot)
}
pub fn total_stake(&self) -> u64 {
@ -57,7 +61,7 @@ impl ForkConfidenceCache {
&self,
minimum_depth: usize,
minimum_stake_percentage: f64,
) -> Option<u64> {
) -> Option<Slot> {
self.bank_confidence
.iter()
.filter(|&(_, bank_confidence)| {
@ -160,7 +164,7 @@ impl AggregateConfidenceService {
}
}
pub fn aggregate_confidence(ancestors: &[u64], bank: &Bank) -> HashMap<u64, BankConfidence> {
pub fn aggregate_confidence(ancestors: &[Slot], bank: &Bank) -> HashMap<Slot, BankConfidence> {
assert!(!ancestors.is_empty());
// Check ancestors is sorted
@ -191,9 +195,9 @@ impl AggregateConfidenceService {
}
fn aggregate_confidence_for_vote_account(
confidence: &mut HashMap<u64, BankConfidence>,
confidence: &mut HashMap<Slot, BankConfidence>,
vote_state: &VoteState,
ancestors: &[u64],
ancestors: &[Slot],
lamports: u64,
) {
assert!(!ancestors.is_empty());

View File

@ -1,12 +1,12 @@
use solana_ledger::bank_forks::BankForks;
use solana_metrics::datapoint_debug;
use solana_runtime::bank::Bank;
use solana_sdk::account::Account;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{account::Account, clock::Slot, hash::Hash, pubkey::Pubkey};
use solana_vote_api::vote_state::{Lockout, Vote, VoteState, MAX_LOCKOUT_HISTORY};
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};
pub const VOTE_THRESHOLD_DEPTH: usize = 8;
pub const VOTE_THRESHOLD_SIZE: f64 = 2f64 / 3f64;
@ -66,8 +66,8 @@ impl Tower {
&self,
bank_slot: u64,
vote_accounts: F,
ancestors: &HashMap<u64, HashSet<u64>>,
) -> (HashMap<u64, StakeLockout>, u64)
ancestors: &HashMap<Slot, HashSet<u64>>,
) -> (HashMap<Slot, StakeLockout>, u64)
where
F: Iterator<Item = (Pubkey, (u64, Account))>,
{
@ -167,11 +167,12 @@ impl Tower {
.map(|lockout| (lockout.stake as f64 / total_staked as f64) > self.threshold_size)
.unwrap_or(false)
}
fn new_vote(
local_vote_state: &VoteState,
slot: u64,
hash: Hash,
last_bank_slot: Option<u64>,
last_bank_slot: Option<Slot>,
) -> Vote {
let mut local_vote_state = local_vote_state.clone();
let vote = Vote {
@ -179,12 +180,12 @@ impl Tower {
hash,
};
local_vote_state.process_vote_unchecked(&vote);
let slots = if let Some(lbs) = last_bank_slot {
let slots = if let Some(last_bank_slot) = last_bank_slot {
local_vote_state
.votes
.iter()
.map(|v| v.slot)
.skip_while(|s| *s <= lbs)
.skip_while(|s| *s <= last_bank_slot)
.collect()
} else {
local_vote_state.votes.iter().map(|v| v.slot).collect()
@ -197,7 +198,8 @@ impl Tower {
);
Vote { slots, hash }
}
fn last_bank_vote(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option<u64> {
fn last_bank_vote(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option<Slot> {
let vote_account = bank.vote_accounts().get(vote_account_pubkey)?.1.clone();
let bank_vote_state = VoteState::deserialize(&vote_account.data).ok()?;
bank_vote_state.votes.iter().map(|v| v.slot).last()
@ -207,7 +209,8 @@ impl Tower {
let last_vote = Self::last_bank_vote(bank, vote_account_pubkey);
Self::new_vote(&self.lockouts, bank.slot(), bank.hash(), last_vote)
}
pub fn record_bank_vote(&mut self, vote: Vote) -> Option<u64> {
pub fn record_bank_vote(&mut self, vote: Vote) -> Option<Slot> {
let slot = *vote.slots.last().unwrap_or(&0);
trace!("{} record_vote for {}", self.node_pubkey, slot);
let root_slot = self.lockouts.root_slot;
@ -225,7 +228,8 @@ impl Tower {
None
}
}
pub fn record_vote(&mut self, slot: u64, hash: Hash) -> Option<u64> {
pub fn record_vote(&mut self, slot: Slot, hash: Hash) -> Option<Slot> {
let vote = Vote {
slots: vec![slot],
hash,
@ -237,11 +241,11 @@ impl Tower {
self.last_vote.clone()
}
pub fn root(&self) -> Option<u64> {
pub fn root(&self) -> Option<Slot> {
self.lockouts.root_slot
}
pub fn calculate_weight(&self, stake_lockouts: &HashMap<u64, StakeLockout>) -> u128 {
pub fn calculate_weight(&self, stake_lockouts: &HashMap<Slot, StakeLockout>) -> u128 {
let mut sum = 0u128;
let root_slot = self.lockouts.root_slot.unwrap_or(0);
for (slot, stake_lockout) in stake_lockouts {
@ -272,7 +276,7 @@ impl Tower {
false
}
pub fn is_locked_out(&self, slot: u64, ancestors: &HashMap<u64, HashSet<u64>>) -> bool {
pub fn is_locked_out(&self, slot: Slot, ancestors: &HashMap<Slot, HashSet<Slot>>) -> bool {
assert!(ancestors.contains_key(&slot));
if !self.is_recent(slot) {
@ -290,11 +294,11 @@ impl Tower {
return true;
}
}
if let Some(root) = lockouts.root_slot {
if let Some(root_slot) = lockouts.root_slot {
// This case should never happen because bank forks purges all
// non-descendants of the root every time root is set
if slot != root {
assert!(ancestors[&slot].contains(&root));
if slot != root_slot {
assert!(ancestors[&slot].contains(&root_slot));
}
}
@ -323,9 +327,9 @@ impl Tower {
/// Update lockouts for all the ancestors
fn update_ancestor_lockouts(
stake_lockouts: &mut HashMap<u64, StakeLockout>,
stake_lockouts: &mut HashMap<Slot, StakeLockout>,
vote: &Lockout,
ancestors: &HashMap<u64, HashSet<u64>>,
ancestors: &HashMap<Slot, HashSet<Slot>>,
) {
// If there's no ancestors, that means this slot must be from before the current root,
// in which case the lockouts won't be calculated in bank_weight anyways, so ignore
@ -345,10 +349,10 @@ impl Tower {
/// Update stake for all the ancestors.
/// Note, stake is the same for all the ancestor.
fn update_ancestor_stakes(
stake_lockouts: &mut HashMap<u64, StakeLockout>,
slot: u64,
stake_lockouts: &mut HashMap<Slot, StakeLockout>,
slot: Slot,
lamports: u64,
ancestors: &HashMap<u64, HashSet<u64>>,
ancestors: &HashMap<Slot, HashSet<Slot>>,
) {
// If there's no ancestors, that means this slot must be from before the current root,
// in which case the lockouts won't be calculated in bank_weight anyways, so ignore
@ -365,7 +369,7 @@ impl Tower {
}
}
fn bank_weight(&self, bank: &Bank, ancestors: &HashMap<u64, HashSet<u64>>) -> u128 {
fn bank_weight(&self, bank: &Bank, ancestors: &HashMap<Slot, HashSet<Slot>>) -> u128 {
let (stake_lockouts, _) =
self.collect_vote_lockouts(bank.slot(), bank.vote_accounts().into_iter(), ancestors);
self.calculate_weight(&stake_lockouts)

View File

@ -1,28 +1,32 @@
//! The `packet` module defines data structures and methods to pull data from the network.
use crate::cuda_runtime::PinnedVec;
use crate::recvmmsg::{recv_mmsg, NUM_RCVMMSGS};
use crate::recycler::{Recycler, Reset};
use crate::result::{Error, Result};
use crate::{
cuda_runtime::PinnedVec,
recvmmsg::{recv_mmsg, NUM_RCVMMSGS},
recycler::{Recycler, Reset},
result::{Error, Result},
};
use bincode;
use byteorder::{ByteOrder, LittleEndian};
use serde::Serialize;
use solana_ledger::erasure::ErasureConfig;
use solana_metrics::inc_new_counter_debug;
pub use solana_sdk::packet::{Meta, Packet, PACKET_DATA_SIZE};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signable;
use solana_sdk::signature::Signature;
use std::borrow::Cow;
use std::cmp;
use std::fmt;
use std::io;
use std::io::Cursor;
use std::mem;
use std::mem::size_of;
use std::net::{SocketAddr, UdpSocket};
use std::ops::{Deref, DerefMut};
use std::sync::{Arc, RwLock};
use std::time::Instant;
use solana_sdk::{
clock::Slot,
pubkey::Pubkey,
signature::{Signable, Signature},
};
use std::{
borrow::Cow,
cmp, fmt, io,
io::Cursor,
mem,
mem::size_of,
net::{SocketAddr, UdpSocket},
ops::{Deref, DerefMut},
sync::{Arc, RwLock},
time::Instant,
};
pub type SharedBlob = Arc<RwLock<Blob>>;
pub type SharedBlobs = Vec<SharedBlob>;
@ -531,7 +535,13 @@ impl Signable for Blob {
}
}
pub fn index_blobs(blobs: &[SharedBlob], id: &Pubkey, mut blob_index: u64, slot: u64, parent: u64) {
pub fn index_blobs(
blobs: &[SharedBlob],
id: &Pubkey,
mut blob_index: u64,
slot: Slot,
parent: Slot,
) {
// enumerate all the blobs, those are the indices
for blob in blobs.iter() {
let mut blob = blob.write().unwrap();

View File

@ -4,9 +4,11 @@ use crate::{
cluster_info::ClusterInfo, cluster_info_repair_listener::ClusterInfoRepairListener,
result::Result, service::Service,
};
use solana_ledger::bank_forks::BankForks;
use solana_ledger::blocktree::{Blocktree, CompletedSlotsReceiver, SlotMeta};
use solana_sdk::{epoch_schedule::EpochSchedule, pubkey::Pubkey};
use solana_ledger::{
bank_forks::BankForks,
blocktree::{Blocktree, CompletedSlotsReceiver, SlotMeta},
};
use solana_sdk::{clock::Slot, epoch_schedule::EpochSchedule, pubkey::Pubkey};
use std::{
collections::BTreeSet,
net::UdpSocket,
@ -241,7 +243,7 @@ impl RepairService {
fn generate_repairs_for_slot(
blocktree: &Blocktree,
slot: u64,
slot: Slot,
slot_meta: &SlotMeta,
max_repairs: usize,
) -> Vec<RepairType> {
@ -272,7 +274,7 @@ impl RepairService {
blocktree: &Blocktree,
repairs: &mut Vec<RepairType>,
max_repairs: usize,
slot: u64,
slot: Slot,
) {
let mut pending_slots = vec![slot];
while repairs.len() < max_repairs && !pending_slots.is_empty() {

View File

@ -9,30 +9,37 @@ use crate::poh_recorder::PohRecorder;
use crate::result::{Error, Result};
use crate::rpc_subscriptions::RpcSubscriptions;
use crate::service::Service;
use solana_ledger::bank_forks::BankForks;
use solana_ledger::block_error::BlockError;
use solana_ledger::blocktree::{Blocktree, BlocktreeError};
use solana_ledger::blocktree_processor;
use solana_ledger::entry::{Entry, EntrySlice};
use solana_ledger::leader_schedule_cache::LeaderScheduleCache;
use solana_ledger::snapshot_package::SnapshotPackageSender;
use solana_ledger::{
bank_forks::BankForks,
block_error::BlockError,
blocktree::{Blocktree, BlocktreeError},
blocktree_processor,
entry::{Entry, EntrySlice},
leader_schedule_cache::LeaderScheduleCache,
snapshot_package::SnapshotPackageSender,
};
use solana_measure::measure::Measure;
use solana_metrics::{datapoint_warn, inc_new_counter_info};
use solana_runtime::bank::Bank;
use solana_sdk::hash::Hash;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::KeypairUtil;
use solana_sdk::timing::{self, duration_as_ms};
use solana_sdk::transaction::Transaction;
use solana_sdk::{
clock::Slot,
hash::Hash,
pubkey::Pubkey,
signature::KeypairUtil,
timing::{self, duration_as_ms},
transaction::Transaction,
};
use solana_vote_api::vote_instruction;
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
use std::sync::{Arc, Mutex, RwLock};
use std::thread::{self, Builder, JoinHandle};
use std::time::Duration;
use std::time::Instant;
use std::{
collections::HashMap,
collections::HashSet,
sync::atomic::{AtomicBool, Ordering},
sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender},
sync::{Arc, Mutex, RwLock},
thread::{self, Builder, JoinHandle},
time::Duration,
time::Instant,
};
pub const MAX_ENTRY_RECV_PER_ITER: usize = 512;
@ -62,7 +69,7 @@ pub struct ReplayStage {
struct ReplaySlotStats {
// Per-slot elapsed time
slot: u64,
slot: Slot,
fetch_entries_elapsed: u64,
fetch_entries_fail_elapsed: u64,
entry_verification_elapsed: u64,
@ -71,7 +78,7 @@ struct ReplaySlotStats {
}
impl ReplaySlotStats {
pub fn new(slot: u64) -> Self {
pub fn new(slot: Slot) -> Self {
Self {
slot,
fetch_entries_elapsed: 0,
@ -120,7 +127,7 @@ struct ForkProgress {
}
impl ForkProgress {
pub fn new(slot: u64, last_entry: Hash) -> Self {
pub fn new(slot: Slot, last_entry: Hash) -> Self {
Self {
last_entry,
num_shreds: 0,
@ -300,7 +307,7 @@ impl ReplayStage {
fn log_leader_change(
my_pubkey: &Pubkey,
bank_slot: u64,
bank_slot: Slot,
current_leader: &mut Option<Pubkey>,
new_leader: &Pubkey,
) {
@ -451,7 +458,11 @@ impl ReplayStage {
(replay_result, tx_count)
}
fn mark_dead_slot(slot: u64, blocktree: &Blocktree, progress: &mut HashMap<u64, ForkProgress>) {
fn mark_dead_slot(
slot: Slot,
blocktree: &Blocktree,
progress: &mut HashMap<u64, ForkProgress>,
) {
// Remove from progress map so we no longer try to replay this bank
let mut progress_entry = progress
.get_mut(&slot)

View File

@ -18,6 +18,7 @@ use solana_ledger::bank_forks::BankForks;
use solana_runtime::bank::Bank;
use solana_sdk::{
account::Account,
clock::Slot,
epoch_schedule::EpochSchedule,
fee_calculator::FeeCalculator,
hash::Hash,
@ -215,7 +216,7 @@ impl JsonRpcRequestProcessor {
Ok(self.bank().slots_per_segment())
}
fn get_storage_pubkeys_for_slot(&self, slot: u64) -> Result<Vec<Pubkey>> {
fn get_storage_pubkeys_for_slot(&self, slot: Slot) -> Result<Vec<Pubkey>> {
Ok(self
.storage_state
.get_pubkeys_for_slot(slot, &self.bank_forks))
@ -710,7 +711,11 @@ impl RpcSol for RpcSolImpl {
.get_slots_per_segment()
}
fn get_storage_pubkeys_for_slot(&self, meta: Self::Metadata, slot: u64) -> Result<Vec<Pubkey>> {
fn get_storage_pubkeys_for_slot(
&self,
meta: Self::Metadata,
slot: Slot,
) -> Result<Vec<Pubkey>> {
meta.request_processor
.read()
.unwrap()

View File

@ -2,15 +2,13 @@
use core::hash::Hash;
use jsonrpc_core::futures::Future;
use jsonrpc_pubsub::typed::Sink;
use jsonrpc_pubsub::SubscriptionId;
use jsonrpc_pubsub::{typed::Sink, SubscriptionId};
use serde::Serialize;
use solana_ledger::bank_forks::BankForks;
use solana_runtime::bank::Bank;
use solana_sdk::account::Account;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::transaction;
use solana_sdk::{
account::Account, clock::Slot, pubkey::Pubkey, signature::Signature, transaction,
};
use solana_vote_api::vote_state::MAX_LOCKOUT_HISTORY;
use std::collections::HashMap;
use std::sync::{Arc, RwLock};
@ -74,7 +72,7 @@ where
fn check_confirmations_and_notify<K, S, F, N, X>(
subscriptions: &HashMap<K, HashMap<SubscriptionId, (Sink<S>, Confirmations)>>,
hashmap_key: &K,
current_slot: u64,
current_slot: Slot,
bank_forks: &Arc<RwLock<BankForks>>,
bank_method: F,
notify: N,
@ -169,7 +167,7 @@ impl RpcSubscriptions {
pub fn check_account(
&self,
pubkey: &Pubkey,
current_slot: u64,
current_slot: Slot,
bank_forks: &Arc<RwLock<BankForks>>,
) {
let subscriptions = self.account_subscriptions.read().unwrap();
@ -186,7 +184,7 @@ impl RpcSubscriptions {
pub fn check_program(
&self,
program_id: &Pubkey,
current_slot: u64,
current_slot: Slot,
bank_forks: &Arc<RwLock<BankForks>>,
) {
let subscriptions = self.program_subscriptions.write().unwrap();
@ -203,7 +201,7 @@ impl RpcSubscriptions {
pub fn check_signature(
&self,
signature: &Signature,
current_slot: u64,
current_slot: Slot,
bank_forks: &Arc<RwLock<BankForks>>,
) {
let mut subscriptions = self.signature_subscriptions.write().unwrap();
@ -268,7 +266,7 @@ impl RpcSubscriptions {
/// Notify subscribers of changes to any accounts or new signatures since
/// the bank's last checkpoint.
pub fn notify_subscribers(&self, current_slot: u64, bank_forks: &Arc<RwLock<BankForks>>) {
pub fn notify_subscribers(&self, current_slot: Slot, bank_forks: &Arc<RwLock<BankForks>>) {
let pubkeys: Vec<_> = {
let subs = self.account_subscriptions.read().unwrap();
subs.keys().cloned().collect()

View File

@ -2,38 +2,45 @@
// for storage mining. Archivers submit storage proofs, validator then bundles them
// to submit its proof for mining to be rewarded.
use crate::chacha_cuda::chacha_cbc_encrypt_file_many_keys;
use crate::cluster_info::ClusterInfo;
use crate::contact_info::ContactInfo;
use crate::result::{Error, Result};
use crate::service::Service;
use crate::{
chacha_cuda::chacha_cbc_encrypt_file_many_keys,
cluster_info::ClusterInfo,
contact_info::ContactInfo,
result::{Error, Result},
service::Service,
};
use rand::{Rng, SeedableRng};
use rand_chacha::ChaChaRng;
use solana_ledger::bank_forks::BankForks;
use solana_ledger::blocktree::Blocktree;
use solana_runtime::bank::Bank;
use solana_runtime::storage_utils::archiver_accounts;
use solana_sdk::account::Account;
use solana_sdk::account_utils::State;
use solana_sdk::clock::get_segment_from_slot;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::Instruction;
use solana_sdk::message::Message;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::transaction::Transaction;
use solana_storage_api::storage_contract::{Proof, ProofStatus, StorageContract};
use solana_storage_api::storage_instruction;
use solana_storage_api::storage_instruction::proof_validation;
use std::collections::HashMap;
use std::mem::size_of;
use std::net::UdpSocket;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
use std::sync::{Arc, RwLock};
use std::thread::{self, sleep, Builder, JoinHandle};
use std::time::{Duration, Instant};
use std::{cmp, io};
use solana_ledger::{bank_forks::BankForks, blocktree::Blocktree};
use solana_runtime::{bank::Bank, storage_utils::archiver_accounts};
use solana_sdk::{
account::Account,
account_utils::State,
clock::{get_segment_from_slot, Slot},
hash::Hash,
instruction::Instruction,
message::Message,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil, Signature},
transaction::Transaction,
};
use solana_storage_api::{
storage_contract::{Proof, ProofStatus, StorageContract},
storage_instruction,
storage_instruction::proof_validation,
};
use std::{
cmp,
collections::HashMap,
io,
mem::size_of,
net::UdpSocket,
sync::atomic::{AtomicBool, Ordering},
sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender},
sync::{Arc, RwLock},
thread::{self, sleep, Builder, JoinHandle},
time::{Duration, Instant},
};
// Block of hash answers to validate against
// Vec of [ledger blocks] x [keys]
@ -47,7 +54,7 @@ pub struct StorageStateInner {
pub storage_keys: StorageKeys,
archiver_map: ArchiverMap,
storage_blockhash: Hash,
slot: u64,
slot: Slot,
slots_per_segment: u64,
slots_per_turn: u64,
}
@ -133,7 +140,7 @@ impl StorageState {
pub fn get_pubkeys_for_slot(
&self,
slot: u64,
slot: Slot,
bank_forks: &Arc<RwLock<BankForks>>,
) -> Vec<Pubkey> {
// TODO: keep track of age?
@ -364,7 +371,7 @@ impl StorageStage {
state: &Arc<RwLock<StorageStateInner>>,
_blocktree: &Arc<Blocktree>,
blockhash: Hash,
slot: u64,
slot: Slot,
slots_per_segment: u64,
instruction_sender: &InstructionSender,
) -> Result<()> {
@ -440,7 +447,7 @@ impl StorageStage {
}
fn collect_proofs(
slot: u64,
slot: Slot,
slots_per_segment: u64,
account_id: Pubkey,
account: Account,

View File

@ -295,6 +295,7 @@ mod test {
shred::Shredder,
};
use solana_sdk::{
clock::Slot,
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
hash::Hash,
signature::{Keypair, KeypairUtil},
@ -310,8 +311,8 @@ mod test {
fn local_entries_to_shred(
entries: &[Entry],
slot: u64,
parent: u64,
slot: Slot,
parent: Slot,
keypair: &Arc<Keypair>,
) -> Vec<Shred> {
let shredder = Shredder::new(slot, parent, 0.0, keypair.clone())

View File

@ -5,26 +5,36 @@ mod tests {
use bincode::serialize_into;
use fs_extra::dir::CopyOptions;
use itertools::Itertools;
use solana_core::genesis_utils::{create_genesis_block, GenesisBlockInfo};
use solana_core::service::Service;
use solana_core::snapshot_packager_service::SnapshotPackagerService;
use solana_ledger::bank_forks::{BankForks, SnapshotConfig};
use solana_ledger::snapshot_utils;
use solana_runtime::bank::Bank;
use solana_runtime::status_cache::SlotDelta;
use solana_runtime::status_cache::MAX_CACHE_ENTRIES;
use solana_sdk::hash::hashv;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::system_transaction;
use solana_sdk::transaction::Result as TransactionResult;
use std::fs;
use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::channel;
use std::sync::Arc;
use solana_core::{
genesis_utils::{create_genesis_block, GenesisBlockInfo},
service::Service,
snapshot_packager_service::SnapshotPackagerService,
};
use solana_ledger::{
bank_forks::{BankForks, SnapshotConfig},
snapshot_utils,
};
use solana_runtime::{
bank::Bank,
status_cache::{SlotDelta, MAX_CACHE_ENTRIES},
};
use solana_sdk::{
clock::Slot,
hash::hashv,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
system_transaction,
transaction::Result as TransactionResult,
};
use std::{
fs,
fs::File,
io::{BufWriter, Write},
path::PathBuf,
sync::atomic::AtomicBool,
sync::mpsc::channel,
sync::Arc,
};
use tempfile::TempDir;
struct SnapshotTestConfig {
@ -100,7 +110,7 @@ mod tests {
// also marks each bank as root and generates snapshots
// finally tries to restore from the last bank's snapshot and compares the restored bank to the
// `last_slot` bank
fn run_bank_forks_snapshot_n<F>(last_slot: u64, f: F, set_root_interval: u64)
fn run_bank_forks_snapshot_n<F>(last_slot: Slot, f: F, set_root_interval: u64)
where
F: Fn(&mut Bank, &Keypair),
{

View File

@ -17,7 +17,7 @@ enum LedgerOutputMethod {
Json,
}
fn output_slot(blocktree: &Blocktree, slot: u64, method: &LedgerOutputMethod) {
fn output_slot(blocktree: &Blocktree, slot: Slot, method: &LedgerOutputMethod) {
let entries = blocktree
.get_slot_entries(slot, 0, None)
.unwrap_or_else(|err| {
@ -36,7 +36,7 @@ fn output_slot(blocktree: &Blocktree, slot: u64, method: &LedgerOutputMethod) {
}
}
fn output_ledger(blocktree: Blocktree, starting_slot: u64, method: LedgerOutputMethod) {
fn output_ledger(blocktree: Blocktree, starting_slot: Slot, method: LedgerOutputMethod) {
let rooted_slot_iterator =
RootedSlotIterator::new(starting_slot, &blocktree).unwrap_or_else(|err| {
eprintln!(

View File

@ -5,14 +5,15 @@ use crate::snapshot_utils::{self, SnapshotError};
use log::*;
use solana_measure::measure::Measure;
use solana_metrics::inc_new_counter_info;
use solana_runtime::bank::Bank;
use solana_runtime::status_cache::MAX_CACHE_ENTRIES;
use solana_sdk::timing;
use std::collections::{HashMap, HashSet};
use std::ops::Index;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Instant;
use solana_runtime::{bank::Bank, status_cache::MAX_CACHE_ENTRIES};
use solana_sdk::{clock::Slot, timing};
use std::{
collections::{HashMap, HashSet},
ops::Index,
path::{Path, PathBuf},
sync::Arc,
time::Instant,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SnapshotConfig {
@ -46,22 +47,22 @@ impl std::convert::From<SnapshotPackageSendError> for BankForksError {
}
pub struct BankForks {
pub banks: HashMap<u64, Arc<Bank>>,
pub banks: HashMap<Slot, Arc<Bank>>,
working_bank: Arc<Bank>,
root: u64,
root: Slot,
pub snapshot_config: Option<SnapshotConfig>,
last_snapshot_slot: u64,
last_snapshot_slot: Slot,
}
impl Index<u64> for BankForks {
type Output = Arc<Bank>;
fn index(&self, bank_slot: u64) -> &Arc<Bank> {
fn index(&self, bank_slot: Slot) -> &Arc<Bank> {
&self.banks[&bank_slot]
}
}
impl BankForks {
pub fn new(bank_slot: u64, bank: Bank) -> Self {
pub fn new(bank_slot: Slot, bank: Bank) -> Self {
let mut banks = HashMap::new();
let working_bank = Arc::new(bank);
banks.insert(bank_slot, working_bank.clone());
@ -75,11 +76,11 @@ impl BankForks {
}
/// Create a map of bank slot id to the set of ancestors for the bank slot.
pub fn ancestors(&self) -> HashMap<u64, HashSet<u64>> {
pub fn ancestors(&self) -> HashMap<Slot, HashSet<Slot>> {
let mut ancestors = HashMap::new();
let root = self.root;
for bank in self.banks.values() {
let mut set: HashSet<u64> = bank
let mut set: HashSet<Slot> = bank
.ancestors
.keys()
.filter(|k| **k >= root)
@ -93,11 +94,11 @@ impl BankForks {
/// Create a map of bank slot id to the set of all of its descendants
#[allow(clippy::or_fun_call)]
pub fn descendants(&self) -> HashMap<u64, HashSet<u64>> {
pub fn descendants(&self) -> HashMap<Slot, HashSet<Slot>> {
let mut descendants = HashMap::new();
for bank in self.banks.values() {
let _ = descendants.entry(bank.slot()).or_insert(HashSet::new());
let mut set: HashSet<u64> = bank.ancestors.keys().cloned().collect();
let mut set: HashSet<Slot> = bank.ancestors.keys().cloned().collect();
set.remove(&bank.slot());
for parent in set {
descendants
@ -109,7 +110,7 @@ impl BankForks {
descendants
}
pub fn frozen_banks(&self) -> HashMap<u64, Arc<Bank>> {
pub fn frozen_banks(&self) -> HashMap<Slot, Arc<Bank>> {
self.banks
.iter()
.filter(|(_, b)| b.is_frozen())
@ -117,7 +118,7 @@ impl BankForks {
.collect()
}
pub fn active_banks(&self) -> Vec<u64> {
pub fn active_banks(&self) -> Vec<Slot> {
self.banks
.iter()
.filter(|(_, v)| !v.is_frozen())
@ -125,11 +126,11 @@ impl BankForks {
.collect()
}
pub fn get(&self, bank_slot: u64) -> Option<&Arc<Bank>> {
pub fn get(&self, bank_slot: Slot) -> Option<&Arc<Bank>> {
self.banks.get(&bank_slot)
}
pub fn new_from_banks(initial_forks: &[Arc<Bank>], rooted_path: Vec<u64>) -> Self {
pub fn new_from_banks(initial_forks: &[Arc<Bank>], rooted_path: Vec<Slot>) -> Self {
let mut banks = HashMap::new();
let working_bank = initial_forks[0].clone();
@ -169,7 +170,11 @@ impl BankForks {
self.working_bank.clone()
}
pub fn set_root(&mut self, root: u64, snapshot_package_sender: &Option<SnapshotPackageSender>) {
pub fn set_root(
&mut self,
root: Slot,
snapshot_package_sender: &Option<SnapshotPackageSender>,
) {
self.root = root;
let set_root_start = Instant::now();
let root_bank = self
@ -190,7 +195,7 @@ impl BankForks {
if self.snapshot_config.is_some() && snapshot_package_sender.is_some() {
let config = self.snapshot_config.as_ref().unwrap();
info!("setting snapshot root: {}", root);
if root - self.last_snapshot_slot >= config.snapshot_interval_slots as u64 {
if root - self.last_snapshot_slot >= config.snapshot_interval_slots as Slot {
let mut snapshot_time = Measure::start("total-snapshot-ms");
let r = self.generate_snapshot(
root,
@ -223,7 +228,7 @@ impl BankForks {
);
}
pub fn root(&self) -> u64 {
pub fn root(&self) -> Slot {
self.root
}
@ -242,8 +247,8 @@ impl BankForks {
pub fn generate_snapshot<P: AsRef<Path>>(
&self,
root: u64,
slots_to_snapshot: &[u64],
root: Slot,
slots_to_snapshot: &[Slot],
snapshot_package_sender: &SnapshotPackageSender,
tar_output_file: P,
) -> Result<()> {
@ -281,7 +286,7 @@ impl BankForks {
Ok(())
}
fn prune_non_root(&mut self, root: u64) {
fn prune_non_root(&mut self, root: Slot) {
let descendants = self.descendants();
self.banks
.retain(|slot, _| slot == &root || descendants[&root].contains(slot));

View File

@ -201,11 +201,11 @@ impl Blocktree {
Database::destroy(&blocktree_path)
}
pub fn meta(&self, slot: u64) -> Result<Option<SlotMeta>> {
pub fn meta(&self, slot: Slot) -> Result<Option<SlotMeta>> {
self.meta_cf.get(slot)
}
pub fn is_full(&self, slot: u64) -> bool {
pub fn is_full(&self, slot: Slot) -> bool {
if let Ok(meta) = self.meta_cf.get(slot) {
if let Some(meta) = meta {
return meta.is_full();
@ -293,17 +293,17 @@ impl Blocktree {
Ok(end)
}
pub fn erasure_meta(&self, slot: u64, set_index: u64) -> Result<Option<ErasureMeta>> {
pub fn erasure_meta(&self, slot: Slot, set_index: u64) -> Result<Option<ErasureMeta>> {
self.erasure_meta_cf.get((slot, set_index))
}
pub fn orphan(&self, slot: u64) -> Result<Option<bool>> {
pub fn orphan(&self, slot: Slot) -> Result<Option<bool>> {
self.orphans_cf.get(slot)
}
pub fn slot_meta_iterator<'a>(
&'a self,
slot: u64,
slot: Slot,
) -> Result<impl Iterator<Item = (u64, SlotMeta)> + 'a> {
let meta_iter = self
.db
@ -319,7 +319,7 @@ impl Blocktree {
pub fn slot_data_iterator<'a>(
&'a self,
slot: u64,
slot: Slot,
) -> Result<impl Iterator<Item = ((u64, u64), Box<[u8]>)> + 'a> {
let slot_iterator = self
.db
@ -837,13 +837,13 @@ impl Blocktree {
Ok(())
}
pub fn get_data_shred(&self, slot: u64, index: u64) -> Result<Option<Vec<u8>>> {
pub fn get_data_shred(&self, slot: Slot, index: u64) -> Result<Option<Vec<u8>>> {
self.data_shred_cf.get_bytes((slot, index))
}
pub fn get_data_shreds(
&self,
slot: u64,
slot: Slot,
from_index: u64,
to_index: u64,
buffer: &mut [u8],
@ -880,13 +880,13 @@ impl Blocktree {
Ok((last_index, buffer_offset))
}
pub fn get_coding_shred(&self, slot: u64, index: u64) -> Result<Option<Vec<u8>>> {
pub fn get_coding_shred(&self, slot: Slot, index: u64) -> Result<Option<Vec<u8>>> {
self.code_shred_cf.get_bytes((slot, index))
}
pub fn write_entries(
&self,
start_slot: u64,
start_slot: Slot,
num_ticks_in_start_slot: u64,
start_index: u32,
ticks_per_slot: u64,
@ -946,14 +946,14 @@ impl Blocktree {
Ok(num_shreds)
}
pub fn get_index(&self, slot: u64) -> Result<Option<Index>> {
pub fn get_index(&self, slot: Slot) -> Result<Option<Index>> {
self.index_cf.get(slot)
}
/// Manually update the meta for a slot.
/// Can interfere with automatic meta update and potentially break chaining.
/// Dangerous. Use with care.
pub fn put_meta_bytes(&self, slot: u64, bytes: &[u8]) -> Result<()> {
pub fn put_meta_bytes(&self, slot: Slot, bytes: &[u8]) -> Result<()> {
self.meta_cf.put_bytes(slot, bytes)
}
@ -962,7 +962,7 @@ impl Blocktree {
// for the slot with the specified slot
fn find_missing_indexes<C>(
db_iterator: &mut DBRawIterator,
slot: u64,
slot: Slot,
start_index: u64,
end_index: u64,
max_missing: usize,
@ -1027,7 +1027,7 @@ impl Blocktree {
pub fn find_missing_data_indexes(
&self,
slot: u64,
slot: Slot,
start_index: u64,
end_index: u64,
max_missing: usize,
@ -1051,7 +1051,7 @@ impl Blocktree {
/// Returns the entry vector for the slot starting with `shred_start_index`
pub fn get_slot_entries(
&self,
slot: u64,
slot: Slot,
shred_start_index: u64,
_max_entries: Option<u64>,
) -> Result<Vec<Entry>> {
@ -1061,7 +1061,7 @@ impl Blocktree {
pub fn get_slot_entries_with_shred_count(
&self,
slot: u64,
slot: Slot,
start_index: u64,
) -> Result<(Vec<Entry>, usize)> {
let slot_meta_cf = self.db.column::<cf::SlotMeta>();
@ -1127,7 +1127,7 @@ impl Blocktree {
fn get_entries_in_data_block(
&self,
slot: u64,
slot: Slot,
start_index: u32,
end_index: u32,
) -> Result<Vec<Entry>> {
@ -1196,7 +1196,7 @@ impl Blocktree {
Ok(result)
}
pub fn is_root(&self, slot: u64) -> bool {
pub fn is_root(&self, slot: Slot) -> bool {
if let Ok(Some(true)) = self.db.get::<cf::Root>(slot) {
true
} else {
@ -1220,7 +1220,7 @@ impl Blocktree {
Ok(())
}
pub fn is_dead(&self, slot: u64) -> bool {
pub fn is_dead(&self, slot: Slot) -> bool {
if let Some(true) = self
.db
.get::<cf::DeadSlots>(slot)
@ -1232,7 +1232,7 @@ impl Blocktree {
}
}
pub fn set_dead_slot(&self, slot: u64) -> Result<()> {
pub fn set_dead_slot(&self, slot: Slot) -> Result<()> {
self.dead_slots_cf.put(slot, &true)
}
@ -1258,7 +1258,7 @@ impl Blocktree {
/// Prune blocktree such that slots higher than `target_slot` are deleted and all references to
/// higher slots are removed
pub fn prune(&self, target_slot: u64) {
pub fn prune(&self, target_slot: Slot) {
let mut meta = self
.meta(target_slot)
.expect("couldn't read slot meta")
@ -1332,7 +1332,7 @@ fn update_slot_meta(
fn get_index_meta_entry<'a>(
db: &Database,
slot: u64,
slot: Slot,
index_working_set: &'a mut HashMap<u64, IndexMetaWorkingSetEntry>,
index_meta_time: &mut u64,
) -> &'a mut IndexMetaWorkingSetEntry {
@ -1356,8 +1356,8 @@ fn get_index_meta_entry<'a>(
fn get_slot_meta_entry<'a>(
db: &Database,
slot_meta_working_set: &'a mut HashMap<u64, SlotMetaWorkingSetEntry>,
slot: u64,
parent_slot: u64,
slot: Slot,
parent_slot: Slot,
) -> &'a mut SlotMetaWorkingSetEntry {
let meta_cf = db.column::<cf::SlotMeta>();
@ -1384,7 +1384,7 @@ fn get_slot_meta_entry<'a>(
})
}
fn is_valid_write_to_slot_0(slot_to_write: u64, parent_slot: u64, last_root: u64) -> bool {
fn is_valid_write_to_slot_0(slot_to_write: u64, parent_slot: Slot, last_root: u64) -> bool {
slot_to_write == 0 && last_root == 0 && parent_slot == 0
}
@ -1475,7 +1475,7 @@ fn find_slot_meta_else_create<'a>(
// create a dummy orphan slot in the database
fn find_slot_meta_in_db_else_create<'a>(
db: &Database,
slot: u64,
slot: Slot,
insert_map: &'a mut HashMap<u64, Rc<RefCell<SlotMeta>>>,
) -> Result<Rc<RefCell<SlotMeta>>> {
if let Some(slot_meta) = db.column::<cf::SlotMeta>().get(slot)? {
@ -1497,7 +1497,7 @@ fn find_slot_meta_in_db_else_create<'a>(
fn find_slot_meta_in_cached_state<'a>(
working_set: &'a HashMap<u64, SlotMetaWorkingSetEntry>,
chained_slots: &'a HashMap<u64, Rc<RefCell<SlotMeta>>>,
slot: u64,
slot: Slot,
) -> Result<Option<Rc<RefCell<SlotMeta>>>> {
if let Some(entry) = working_set.get(&slot) {
Ok(Some(entry.new_slot_meta.clone()))
@ -1535,7 +1535,7 @@ fn handle_chaining_for_slot(
write_batch: &mut WriteBatch,
working_set: &HashMap<u64, SlotMetaWorkingSetEntry>,
new_chained_slots: &mut HashMap<u64, Rc<RefCell<SlotMeta>>>,
slot: u64,
slot: Slot,
) -> Result<()> {
let slot_meta_entry = working_set
.get(&slot)
@ -1614,7 +1614,7 @@ fn handle_chaining_for_slot(
fn traverse_children_mut<F>(
db: &Database,
slot: u64,
slot: Slot,
slot_meta: &Rc<RefCell<(SlotMeta)>>,
working_set: &HashMap<u64, SlotMetaWorkingSetEntry>,
new_chained_slots: &mut HashMap<u64, Rc<RefCell<SlotMeta>>>,
@ -1654,7 +1654,7 @@ fn is_orphan(meta: &SlotMeta) -> bool {
// 2) Determine whether to set the is_connected flag
fn chain_new_slot_to_prev_slot(
prev_slot_meta: &mut SlotMeta,
current_slot: u64,
current_slot: Slot,
current_slot_meta: &mut SlotMeta,
) {
prev_slot_meta.next_slots.push(current_slot);
@ -1747,7 +1747,7 @@ macro_rules! create_new_tmp_ledger {
};
}
pub fn verify_shred_slots(slot: u64, parent_slot: u64, last_root: u64) -> bool {
pub fn verify_shred_slots(slot: Slot, parent_slot: Slot, last_root: u64) -> bool {
if !is_valid_write_to_slot_0(slot, parent_slot, last_root) {
// Check that the parent_slot < slot
if parent_slot >= slot {
@ -1777,8 +1777,8 @@ pub fn create_new_tmp_ledger(name: &str, genesis_block: &GenesisBlock) -> (PathB
pub fn entries_to_test_shreds(
entries: Vec<Entry>,
slot: u64,
parent_slot: u64,
slot: Slot,
parent_slot: Slot,
is_full_slot: bool,
) -> Vec<Shred> {
let shredder = Shredder::new(slot, parent_slot, 0.0, Arc::new(Keypair::new()))
@ -1789,8 +1789,8 @@ pub fn entries_to_test_shreds(
// used for tests only
pub fn make_slot_entries(
slot: u64,
parent_slot: u64,
slot: Slot,
parent_slot: Slot,
num_entries: u64,
) -> (Vec<Shred>, Vec<Entry>) {
let entries = create_ticks(num_entries, 0, Hash::default());
@ -1800,7 +1800,7 @@ pub fn make_slot_entries(
// used for tests only
pub fn make_many_slot_entries(
start_slot: u64,
start_slot: Slot,
num_slots: u64,
entries_per_slot: u64,
) -> (Vec<Shred>, Vec<Entry>) {

View File

@ -299,7 +299,7 @@ impl Column for columns::Index {
const NAME: &'static str = INDEX_CF;
type Index = u64;
fn key(slot: u64) -> Vec<u8> {
fn key(slot: Slot) -> Vec<u8> {
let mut key = vec![0; 8];
BigEndian::write_u64(&mut key[..], slot);
key
@ -326,7 +326,7 @@ impl Column for columns::DeadSlots {
const NAME: &'static str = DEAD_SLOTS_CF;
type Index = u64;
fn key(slot: u64) -> Vec<u8> {
fn key(slot: Slot) -> Vec<u8> {
let mut key = vec![0; 8];
BigEndian::write_u64(&mut key[..], slot);
key
@ -353,7 +353,7 @@ impl Column for columns::Orphans {
const NAME: &'static str = ORPHANS_CF;
type Index = u64;
fn key(slot: u64) -> Vec<u8> {
fn key(slot: Slot) -> Vec<u8> {
let mut key = vec![0; 8];
BigEndian::write_u64(&mut key[..], slot);
key
@ -380,7 +380,7 @@ impl Column for columns::Root {
const NAME: &'static str = ROOT_CF;
type Index = u64;
fn key(slot: u64) -> Vec<u8> {
fn key(slot: Slot) -> Vec<u8> {
let mut key = vec![0; 8];
BigEndian::write_u64(&mut key[..], slot);
key
@ -407,7 +407,7 @@ impl Column for columns::SlotMeta {
const NAME: &'static str = META_CF;
type Index = u64;
fn key(slot: u64) -> Vec<u8> {
fn key(slot: Slot) -> Vec<u8> {
let mut key = vec![0; 8];
BigEndian::write_u64(&mut key[..], slot);
key

View File

@ -1,6 +1,7 @@
use crate::erasure::ErasureConfig;
use serde::{Deserialize, Serialize};
use solana_metrics::datapoint;
use solana_sdk::clock::Slot;
use std::{collections::BTreeSet, ops::RangeBounds};
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
@ -8,7 +9,7 @@ use std::{collections::BTreeSet, ops::RangeBounds};
pub struct SlotMeta {
// The number of slots above the root (the genesis block). The first
// slot has slot 0.
pub slot: u64,
pub slot: Slot,
// The total number of consecutive blobs starting from index 0
// we have received for this slot.
pub consumed: u64,
@ -19,10 +20,10 @@ pub struct SlotMeta {
// The index of the blob that is flagged as the last blob for this slot.
pub last_index: u64,
// The slot height of the block this one derives from.
pub parent_slot: u64,
// The list of slot heights, each of which contains a block that derives
pub parent_slot: Slot,
// The list of slots, each of which contains a block that derives
// from this one.
pub next_slots: Vec<u64>,
pub next_slots: Vec<Slot>,
// True if this slot is full (consumed == last_index + 1) and if every
// slot that is a parent of this slot is also connected.
pub is_connected: bool,
@ -33,7 +34,7 @@ pub struct SlotMeta {
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
/// Index recording presence/absence of blobs
pub struct Index {
pub slot: u64,
pub slot: Slot,
data: DataIndex,
coding: CodingIndex,
}
@ -70,7 +71,7 @@ pub enum ErasureMetaStatus {
}
impl Index {
pub(crate) fn new(slot: u64) -> Self {
pub(crate) fn new(slot: Slot) -> Self {
Index {
slot,
data: DataIndex::default(),
@ -174,7 +175,7 @@ impl SlotMeta {
self.parent_slot != std::u64::MAX
}
pub(crate) fn new(slot: u64, parent_slot: u64) -> Self {
pub(crate) fn new(slot: Slot, parent_slot: Slot) -> Self {
SlotMeta {
slot,
consumed: 0,

View File

@ -132,6 +132,7 @@ impl Default for Session {
pub mod test {
use super::*;
use log::*;
use solana_sdk::clock::Slot;
/// Specifies the contents of a 16-data-blob and 4-coding-blob erasure set
/// Exists to be passed to `generate_blocktree_with_coding`
@ -147,7 +148,7 @@ pub mod test {
/// Exists to be passed to `generate_blocktree_with_coding`
#[derive(Debug, Clone)]
pub struct SlotSpec {
pub slot: u64,
pub slot: Slot,
pub set_specs: Vec<ErasureSpec>,
}

View File

@ -1,13 +1,17 @@
use crate::{blocktree::Blocktree, leader_schedule::LeaderSchedule, leader_schedule_utils};
use log::*;
use solana_runtime::bank::Bank;
use solana_sdk::{epoch_schedule::EpochSchedule, pubkey::Pubkey};
use solana_sdk::{
clock::{Epoch, Slot},
epoch_schedule::EpochSchedule,
pubkey::Pubkey,
};
use std::{
collections::{hash_map::Entry, HashMap, VecDeque},
sync::{Arc, RwLock},
};
type CachedSchedules = (HashMap<u64, Arc<LeaderSchedule>>, VecDeque<u64>);
type CachedSchedules = (HashMap<Epoch, Arc<LeaderSchedule>>, VecDeque<u64>);
const MAX_SCHEDULES: usize = 10;
struct CacheCapacity(usize);
@ -22,7 +26,7 @@ pub struct LeaderScheduleCache {
// Map from an epoch to a leader schedule for that epoch
pub cached_schedules: RwLock<CachedSchedules>,
epoch_schedule: EpochSchedule,
max_epoch: RwLock<u64>,
max_epoch: RwLock<Epoch>,
max_schedules: CacheCapacity,
}
@ -79,7 +83,7 @@ impl LeaderScheduleCache {
}
}
pub fn slot_leader_at(&self, slot: u64, bank: Option<&Bank>) -> Option<Pubkey> {
pub fn slot_leader_at(&self, slot: Slot, bank: Option<&Bank>) -> Option<Pubkey> {
if let Some(bank) = bank {
self.slot_leader_at_else_compute(slot, bank)
} else if self.epoch_schedule.slots_per_epoch == 0 {
@ -93,10 +97,10 @@ impl LeaderScheduleCache {
pub fn next_leader_slot(
&self,
pubkey: &Pubkey,
mut current_slot: u64,
mut current_slot: Slot,
bank: &Bank,
blocktree: Option<&Blocktree>,
) -> Option<(u64, u64)> {
) -> Option<(Slot, Slot)> {
let (mut epoch, mut start_index) = bank.get_epoch_and_slot_index(current_slot + 1);
let mut first_slot = None;
let mut last_slot = current_slot;
@ -149,7 +153,7 @@ impl LeaderScheduleCache {
first_slot.and_then(|slot| Some((slot, last_slot)))
}
fn slot_leader_at_no_compute(&self, slot: u64) -> Option<Pubkey> {
fn slot_leader_at_no_compute(&self, slot: Slot) -> Option<Pubkey> {
let (epoch, slot_index) = self.epoch_schedule.get_epoch_and_slot_index(slot);
self.cached_schedules
.read()
@ -159,7 +163,7 @@ impl LeaderScheduleCache {
.map(|schedule| schedule[slot_index])
}
fn slot_leader_at_else_compute(&self, slot: u64, bank: &Bank) -> Option<Pubkey> {
fn slot_leader_at_else_compute(&self, slot: Slot, bank: &Bank) -> Option<Pubkey> {
let cache_result = self.slot_leader_at_no_compute(slot);
// Forbid asking for slots in an unconfirmed epoch
let bank_epoch = self.epoch_schedule.get_epoch_and_slot_index(slot).0;
@ -184,7 +188,7 @@ impl LeaderScheduleCache {
fn get_epoch_schedule_else_compute(
&self,
epoch: u64,
epoch: Epoch,
bank: &Bank,
) -> Option<Arc<LeaderSchedule>> {
let epoch_schedule = self.cached_schedules.read().unwrap().0.get(&epoch).cloned();
@ -198,7 +202,7 @@ impl LeaderScheduleCache {
}
}
fn compute_epoch_schedule(&self, epoch: u64, bank: &Bank) -> Option<Arc<LeaderSchedule>> {
fn compute_epoch_schedule(&self, epoch: Epoch, bank: &Bank) -> Option<Arc<LeaderSchedule>> {
let leader_schedule = leader_schedule_utils::leader_schedule(epoch, bank);
leader_schedule.map(|leader_schedule| {
let leader_schedule = Arc::new(leader_schedule);
@ -216,7 +220,7 @@ impl LeaderScheduleCache {
}
fn retain_latest(
schedules: &mut HashMap<u64, Arc<LeaderSchedule>>,
schedules: &mut HashMap<Epoch, Arc<LeaderSchedule>>,
order: &mut VecDeque<u64>,
max_schedules: usize,
) {

View File

@ -1,11 +1,13 @@
use crate::leader_schedule::LeaderSchedule;
use crate::staking_utils;
use solana_runtime::bank::Bank;
use solana_sdk::clock::NUM_CONSECUTIVE_LEADER_SLOTS;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::{
clock::{Epoch, Slot, NUM_CONSECUTIVE_LEADER_SLOTS},
pubkey::Pubkey,
};
/// Return the leader schedule for the given epoch.
pub fn leader_schedule(epoch: u64, bank: &Bank) -> Option<LeaderSchedule> {
pub fn leader_schedule(epoch: Epoch, bank: &Bank) -> Option<LeaderSchedule> {
staking_utils::staked_nodes_at_epoch(bank, epoch).map(|stakes| {
let mut seed = [0u8; 32];
seed[0..8].copy_from_slice(&epoch.to_le_bytes());
@ -21,7 +23,7 @@ pub fn leader_schedule(epoch: u64, bank: &Bank) -> Option<LeaderSchedule> {
}
/// Return the leader for the given slot.
pub fn slot_leader_at(slot: u64, bank: &Bank) -> Option<Pubkey> {
pub fn slot_leader_at(slot: Slot, bank: &Bank) -> Option<Pubkey> {
let (epoch, slot_index) = bank.get_epoch_and_slot_index(slot);
leader_schedule(epoch, bank).map(|leader_schedule| leader_schedule[slot_index])

View File

@ -1,14 +1,14 @@
use crate::blocktree::*;
use crate::blocktree_meta::SlotMeta;
use crate::{blocktree::*, blocktree_meta::SlotMeta};
use log::*;
use solana_sdk::clock::Slot;
pub struct RootedSlotIterator<'a> {
next_slots: Vec<u64>,
next_slots: Vec<Slot>,
blocktree: &'a Blocktree,
}
impl<'a> RootedSlotIterator<'a> {
pub fn new(start_slot: u64, blocktree: &'a Blocktree) -> Result<Self> {
pub fn new(start_slot: Slot, blocktree: &'a Blocktree) -> Result<Self> {
if blocktree.is_root(start_slot) {
Ok(Self {
next_slots: vec![start_slot],
@ -20,7 +20,7 @@ impl<'a> RootedSlotIterator<'a> {
}
}
impl<'a> Iterator for RootedSlotIterator<'a> {
type Item = (u64, SlotMeta);
type Item = (Slot, SlotMeta);
fn next(&mut self) -> Option<Self::Item> {
// Clone b/c passing the closure to the map below requires exclusive access to

View File

@ -1,19 +1,25 @@
//! The `shred` module defines data structures and methods to pull MTU sized data frames from the network.
use crate::entry::{create_ticks, Entry};
use crate::erasure::Session;
use crate::{
entry::{create_ticks, Entry},
erasure::Session,
};
use core::cell::RefCell;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator};
use rayon::slice::ParallelSlice;
use rayon::ThreadPool;
use rayon::{
iter::{IndexedParallelIterator, IntoParallelRefMutIterator, ParallelIterator},
slice::ParallelSlice,
ThreadPool,
};
use serde::{Deserialize, Serialize};
use solana_metrics::datapoint_debug;
use solana_rayon_threadlimit::get_thread_count;
use solana_sdk::hash::Hash;
use solana_sdk::packet::PACKET_DATA_SIZE;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use std::sync::Arc;
use std::time::Instant;
use solana_sdk::{
clock::Slot,
hash::Hash,
packet::PACKET_DATA_SIZE,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil, Signature},
};
use std::{sync::Arc, time::Instant};
/// The following constants are computed by hand, and hardcoded.
/// `test_shred_constants` ensures that the values are correct.
@ -52,7 +58,7 @@ pub const DATA_COMPLETE_SHRED: u8 = 0b0000_0010;
pub enum ShredError {
InvalidShredType,
InvalidFecRate(f32), // FEC rate must be more than 0.0 and less than 1.0
SlotTooLow { slot: u64, parent_slot: u64 }, // "Current slot must be > Parent slot, but the difference must not be > u16::MAX
SlotTooLow { slot: Slot, parent_slot: Slot }, // "Current slot must be > Parent slot, but the difference must not be > u16::MAX
Serialize(std::boxed::Box<bincode::ErrorKind>),
}
@ -77,7 +83,7 @@ impl Default for ShredType {
pub struct ShredCommonHeader {
pub signature: Signature,
pub shred_type: ShredType,
pub slot: u64,
pub slot: Slot,
pub index: u32,
}
@ -129,7 +135,7 @@ impl Shred {
}
pub fn new_from_data(
slot: u64,
slot: Slot,
index: u32,
parent_offset: u16,
data: Option<&[u8]>,
@ -256,11 +262,11 @@ impl Shred {
)
}
pub fn slot(&self) -> u64 {
pub fn slot(&self) -> Slot {
self.common_header.slot
}
pub fn parent(&self) -> u64 {
pub fn parent(&self) -> Slot {
if self.is_data() {
self.common_header.slot - u64::from(self.data_header.parent_offset)
} else {
@ -280,7 +286,7 @@ impl Shred {
/// This is not a safe function. It only changes the meta information.
/// Use this only for test code which doesn't care about actual shred
pub fn set_slot(&mut self, slot: u64) {
pub fn set_slot(&mut self, slot: Slot) {
self.common_header.slot = slot
}
@ -335,15 +341,20 @@ impl Shred {
#[derive(Debug)]
pub struct Shredder {
slot: u64,
parent_slot: u64,
slot: Slot,
parent_slot: Slot,
fec_rate: f32,
keypair: Arc<Keypair>,
pub signing_coding_time: u128,
}
impl Shredder {
pub fn new(slot: u64, parent_slot: u64, fec_rate: f32, keypair: Arc<Keypair>) -> Result<Self> {
pub fn new(
slot: Slot,
parent_slot: Slot,
fec_rate: f32,
keypair: Arc<Keypair>,
) -> Result<Self> {
if fec_rate > 1.0 || fec_rate < 0.0 {
Err(ShredError::InvalidFecRate(fec_rate))
} else if slot < parent_slot || slot - parent_slot > u64::from(std::u16::MAX) {
@ -450,7 +461,7 @@ impl Shredder {
}
pub fn new_coding_shred_header(
slot: u64,
slot: Slot,
index: u32,
num_data: usize,
num_code: usize,
@ -472,7 +483,7 @@ impl Shredder {
/// Generates coding shreds for the data shreds in the current FEC set
pub fn generate_coding_shreds(
slot: u64,
slot: Slot,
fec_rate: f32,
data_shred_batch: &[Shred],
) -> Vec<Shred> {
@ -583,7 +594,7 @@ impl Shredder {
num_data: usize,
num_coding: usize,
first_index: usize,
slot: u64,
slot: Slot,
) -> std::result::Result<Vec<Shred>, reed_solomon_erasure::Error> {
let mut recovered_data = vec![];
let fec_set_size = num_data + num_coding;
@ -760,8 +771,8 @@ pub mod tests {
fn verify_test_data_shred(
shred: &Shred,
index: u32,
slot: u64,
parent: u64,
slot: Slot,
parent: Slot,
pk: &Pubkey,
verify: bool,
is_last_in_slot: bool,
@ -785,7 +796,7 @@ pub mod tests {
}
}
fn verify_test_code_shred(shred: &Shred, index: u32, slot: u64, pk: &Pubkey, verify: bool) {
fn verify_test_code_shred(shred: &Shred, index: u32, slot: Slot, pk: &Pubkey, verify: bool) {
assert_eq!(shred.payload.len(), PACKET_DATA_SIZE);
assert!(!shred.is_data());
assert_eq!(shred.index(), index);

View File

@ -4,14 +4,15 @@ use bzip2::bufread::BzDecoder;
use fs_extra::dir::CopyOptions;
use log::*;
use solana_measure::measure::Measure;
use solana_runtime::bank::Bank;
use solana_runtime::status_cache::SlotDelta;
use solana_sdk::transaction;
use std::cmp::Ordering;
use std::fs;
use std::fs::File;
use std::io::{BufReader, BufWriter, Error as IOError, ErrorKind};
use std::path::{Path, PathBuf};
use solana_runtime::{bank::Bank, status_cache::SlotDelta};
use solana_sdk::{clock::Slot, transaction};
use std::{
cmp::Ordering,
fs,
fs::File,
io::{BufReader, BufWriter, Error as IOError, ErrorKind},
path::{Path, PathBuf},
};
use tar::Archive;
pub const SNAPSHOT_STATUS_CACHE_FILE_NAME: &str = "status_cache";
@ -20,7 +21,7 @@ pub const TAR_ACCOUNTS_DIR: &str = "accounts";
#[derive(PartialEq, Ord, Eq, Debug)]
pub struct SlotSnapshotPaths {
pub slot: u64,
pub slot: Slot,
pub snapshot_file_path: PathBuf,
}
@ -77,7 +78,7 @@ pub fn package_snapshot<P: AsRef<Path>, Q: AsRef<Path>>(
snapshot_files: &SlotSnapshotPaths,
snapshot_package_output_file: P,
snapshot_path: Q,
slots_to_snapshot: &[u64],
slots_to_snapshot: &[Slot],
) -> Result<SnapshotPackage> {
// Hard link all the snapshots we need for this package
let snapshot_hard_links_dir = tempfile::tempdir_in(snapshot_path)?;
@ -183,7 +184,7 @@ pub fn add_snapshot<P: AsRef<Path>>(snapshot_path: P, bank: &Bank) -> Result<()>
Ok(())
}
pub fn remove_snapshot<P: AsRef<Path>>(slot: u64, snapshot_path: P) -> Result<()> {
pub fn remove_snapshot<P: AsRef<Path>>(slot: Slot, snapshot_path: P) -> Result<()> {
let slot_snapshot_dir = get_bank_snapshot_dir(&snapshot_path, slot);
// Remove the snapshot directory for this slot
fs::remove_dir_all(slot_snapshot_dir)?;
@ -295,11 +296,11 @@ where
Ok(bank)
}
fn get_snapshot_file_name(slot: u64) -> String {
fn get_snapshot_file_name(slot: Slot) -> String {
slot.to_string()
}
fn get_bank_snapshot_dir<P: AsRef<Path>>(path: P, slot: u64) -> PathBuf {
fn get_bank_snapshot_dir<P: AsRef<Path>>(path: P, slot: Slot) -> PathBuf {
path.as_ref().join(slot.to_string())
}

View File

@ -1,13 +1,17 @@
use solana_runtime::bank::Bank;
use solana_sdk::{account::Account, pubkey::Pubkey};
use solana_sdk::{
account::Account,
clock::{Epoch, Slot},
pubkey::Pubkey,
};
use solana_vote_api::vote_state::VoteState;
use std::{borrow::Borrow, collections::HashMap};
/// Looks through vote accounts, and finds the latest slot that has achieved
/// supermajority lockout
pub fn get_supermajority_slot(bank: &Bank, epoch_height: u64) -> Option<u64> {
pub fn get_supermajority_slot(bank: &Bank, epoch: Epoch) -> Option<u64> {
// Find the amount of stake needed for supermajority
let stakes_and_lockouts = epoch_stakes_and_lockouts(bank, epoch_height);
let stakes_and_lockouts = epoch_stakes_and_lockouts(bank, epoch);
let total_stake: u64 = stakes_and_lockouts.iter().map(|s| s.0).sum();
let supermajority_stake = total_stake * 2 / 3;
@ -29,8 +33,8 @@ pub fn staked_nodes(bank: &Bank) -> HashMap<Pubkey, u64> {
/// At the specified epoch, collect the delegate account balance and vote states for delegates
/// that have non-zero balance in any of their managed staking accounts
pub fn staked_nodes_at_epoch(bank: &Bank, epoch_height: u64) -> Option<HashMap<Pubkey, u64>> {
bank.epoch_vote_accounts(epoch_height)
pub fn staked_nodes_at_epoch(bank: &Bank, epoch: Epoch) -> Option<HashMap<Pubkey, u64>> {
bank.epoch_vote_accounts(epoch)
.map(|vote_accounts| to_staked_nodes(to_vote_states(vote_accounts.iter())))
}
@ -58,9 +62,9 @@ fn to_staked_nodes(
map
}
fn epoch_stakes_and_lockouts(bank: &Bank, epoch_height: u64) -> Vec<(u64, Option<u64>)> {
fn epoch_stakes_and_lockouts(bank: &Bank, epoch: Epoch) -> Vec<(u64, Option<u64>)> {
let node_staked_accounts = bank
.epoch_vote_accounts(epoch_height)
.epoch_vote_accounts(epoch)
.expect("Bank state for epoch is missing")
.iter();
@ -69,7 +73,7 @@ fn epoch_stakes_and_lockouts(bank: &Bank, epoch_height: u64) -> Vec<(u64, Option
.collect()
}
fn find_supermajority_slot<'a, I>(supermajority_stake: u64, stakes_and_lockouts: I) -> Option<u64>
fn find_supermajority_slot<'a, I>(supermajority_stake: u64, stakes_and_lockouts: I) -> Option<Slot>
where
I: Iterator<Item = &'a (u64, Option<u64>)>,
{
@ -111,7 +115,7 @@ pub(crate) mod tests {
use solana_vote_api::{vote_instruction, vote_state::VoteInit};
use std::sync::Arc;
fn new_from_parent(parent: &Arc<Bank>, slot: u64) -> Bank {
fn new_from_parent(parent: &Arc<Bank>, slot: Slot) -> Bank {
Bank::new_from_parent(parent, &Pubkey::default(), slot)
}

View File

@ -14,7 +14,7 @@ use solana_ledger::{
};
use solana_sdk::{
client::SyncClient,
clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS},
clock::{Slot, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS},
epoch_schedule::MINIMUM_SLOTS_PER_EPOCH,
hash::Hash,
poh_config::PohConfig,
@ -282,7 +282,7 @@ fn poll_all_nodes_for_signature(
Ok(())
}
fn get_and_verify_slot_entries(blocktree: &Blocktree, slot: u64, last_entry: &Hash) -> Vec<Entry> {
fn get_and_verify_slot_entries(blocktree: &Blocktree, slot: Slot, last_entry: &Hash) -> Vec<Entry> {
let entries = blocktree.get_slot_entries(slot, 0, None).unwrap();
assert!(entries.verify(last_entry));
entries
@ -290,7 +290,7 @@ fn get_and_verify_slot_entries(blocktree: &Blocktree, slot: u64, last_entry: &Ha
fn verify_slot_ticks(
blocktree: &Blocktree,
slot: u64,
slot: Slot,
last_entry: &Hash,
expected_num_ticks: Option<usize>,
) -> Hash {

View File

@ -424,7 +424,7 @@ impl Stake {
}
}
fn deactivate(&mut self, epoch: u64) -> Result<(), StakeError> {
fn deactivate(&mut self, epoch: Epoch) -> Result<(), StakeError> {
if self.deactivation_epoch != std::u64::MAX {
Err(StakeError::AlreadyDeactivated)
} else {

View File

@ -2,14 +2,16 @@ use crate::storage_instruction::StorageAccountType;
use log::*;
use num_derive::FromPrimitive;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::account::Account;
use solana_sdk::account::KeyedAccount;
use solana_sdk::account_utils::State;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::InstructionError;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::Signature;
use solana_sdk::sysvar;
use solana_sdk::{
account::{Account, KeyedAccount},
account_utils::State,
clock::Epoch,
hash::Hash,
instruction::InstructionError,
pubkey::Pubkey,
signature::Signature,
sysvar,
};
use std::collections::BTreeMap;
// Todo Tune this for actual use cases when PoRep is feature complete
@ -19,15 +21,15 @@ pub const MAX_PROOFS_PER_SEGMENT: usize = 80;
#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct Credits {
// current epoch
epoch: u64,
epoch: Epoch,
// currently pending credits
pub current_epoch: u64,
pub current_epoch: Epoch,
// credits ready to be claimed
pub redeemable: u64,
}
impl Credits {
pub fn update_epoch(&mut self, current_epoch: u64) {
pub fn update_epoch(&mut self, current_epoch: Epoch) {
if self.epoch != current_epoch {
self.epoch = current_epoch;
self.redeemable += self.current_epoch;

View File

@ -313,7 +313,7 @@ impl VoteState {
self.epoch_credits.iter()
}
fn pop_expired_votes(&mut self, slot: u64) {
fn pop_expired_votes(&mut self, slot: Slot) {
loop {
if self.votes.back().map_or(false, |v| v.is_expired(slot)) {
self.votes.pop_back();
@ -465,9 +465,7 @@ pub fn create_account(
mod tests {
use super::*;
use crate::vote_state;
use solana_sdk::account::Account;
use solana_sdk::account_utils::State;
use solana_sdk::hash::hash;
use solana_sdk::{account::Account, account_utils::State, hash::hash};
const MAX_RECENT_VOTES: usize = 16;
@ -528,7 +526,7 @@ mod tests {
vote_account: &mut Account,
vote: &Vote,
slot_hashes: &[SlotHash],
epoch: u64,
epoch: Epoch,
) -> Result<VoteState, InstructionError> {
process_vote(
&mut KeyedAccount::new(vote_pubkey, true, vote_account),

View File

@ -673,7 +673,12 @@ impl Accounts {
}
}
pub fn create_test_accounts(accounts: &Accounts, pubkeys: &mut Vec<Pubkey>, num: usize, slot: u64) {
pub fn create_test_accounts(
accounts: &Accounts,
pubkeys: &mut Vec<Pubkey>,
num: usize,
slot: Slot,
) {
for t in 0..num {
let pubkey = Pubkey::new_rand();
let account = Account::new((t + 1) as u64, 0, &Account::default().owner);

View File

@ -115,10 +115,10 @@ impl<'de> Visitor<'de> for AccountStorageVisitor {
pub struct AccountStorageSerialize<'a> {
account_storage: &'a AccountStorage,
slot: u64,
slot: Slot,
}
impl<'a> AccountStorageSerialize<'a> {
pub fn new(account_storage: &'a AccountStorage, slot: u64) -> Self {
pub fn new(account_storage: &'a AccountStorage, slot: Slot) -> Self {
Self {
account_storage,
slot,
@ -323,11 +323,11 @@ pub fn get_temp_accounts_paths(count: u32) -> IOResult<(Vec<TempDir>, String)> {
pub struct AccountsDBSerialize<'a> {
accounts_db: &'a AccountsDB,
slot: u64,
slot: Slot,
}
impl<'a> AccountsDBSerialize<'a> {
pub fn new(accounts_db: &'a AccountsDB, slot: u64) -> Self {
pub fn new(accounts_db: &'a AccountsDB, slot: Slot) -> Self {
Self { accounts_db, slot }
}
}

View File

@ -64,11 +64,11 @@ pub struct BankRc {
parent: RwLock<Option<Arc<Bank>>>,
/// Current slot
slot: u64,
slot: Slot,
}
impl BankRc {
pub fn new(account_paths: String, id: AppendVecId, slot: u64) -> Self {
pub fn new(account_paths: String, id: AppendVecId, slot: Slot) -> Self {
let accounts = Accounts::new(Some(account_paths));
accounts
.accounts_db
@ -133,7 +133,7 @@ impl StatusCacheRc {
sc.slot_deltas(slots)
}
pub fn roots(&self) -> Vec<u64> {
pub fn roots(&self) -> Vec<Slot> {
self.status_cache
.read()
.unwrap()
@ -166,7 +166,7 @@ pub struct Bank {
blockhash_queue: RwLock<BlockhashQueue>,
/// The set of parents including this bank
pub ancestors: HashMap<u64, usize>,
pub ancestors: HashMap<Slot, usize>,
/// Hash of this Bank's state. Only meaningful after freezing.
hash: RwLock<Hash>,
@ -246,7 +246,7 @@ pub struct Bank {
/// staked nodes on epoch boundaries, saved off when a bank.slot() is at
/// a leader schedule calculation boundary
epoch_stakes: HashMap<u64, Stakes>,
epoch_stakes: HashMap<Epoch, Stakes>,
/// A boolean reflecting whether any entries were recorded into the PoH
/// stream for the slot == self.slot
@ -295,7 +295,7 @@ impl Bank {
}
/// Create a new bank that points to an immutable checkpoint of another bank.
pub fn new_from_parent(parent: &Arc<Bank>, collector_id: &Pubkey, slot: u64) -> Self {
pub fn new_from_parent(parent: &Arc<Bank>, collector_id: &Pubkey, slot: Slot) -> Self {
parent.freeze();
assert_ne!(slot, parent.slot());
@ -408,11 +408,11 @@ impl Bank {
bank
}
pub fn slot(&self) -> u64 {
pub fn slot(&self) -> Slot {
self.slot
}
pub fn epoch(&self) -> u64 {
pub fn epoch(&self) -> Epoch {
self.epoch
}
@ -772,7 +772,7 @@ impl Bank {
/// tick that has achieved confirmation
pub fn get_confirmation_timestamp(
&self,
mut slots_and_stakes: Vec<(u64, u64)>,
mut slots_and_stakes: Vec<(Slot, u64)>,
supermajority_stake: u64,
) -> Option<u64> {
// Sort by slot height
@ -1473,7 +1473,7 @@ impl Bank {
/// returns the epoch for which this bank's leader_schedule_slot_offset and slot would
/// need to cache leader_schedule
pub fn get_leader_schedule_epoch(&self, slot: u64) -> u64 {
pub fn get_leader_schedule_epoch(&self, slot: Slot) -> Epoch {
self.epoch_schedule.get_leader_schedule_epoch(slot)
}
@ -1544,7 +1544,7 @@ impl Bank {
///
/// ( slot/slots_per_epoch, slot % slots_per_epoch )
///
pub fn get_epoch_and_slot_index(&self, slot: u64) -> (u64, u64) {
pub fn get_epoch_and_slot_index(&self, slot: Slot) -> (u64, u64) {
self.epoch_schedule.get_epoch_and_slot_index(slot)
}

View File

@ -7,15 +7,18 @@
//! Asynchronous implementations are expected to create transactions, sign them, and send
//! them but without waiting to see if the server accepted it.
use crate::account::Account;
use crate::fee_calculator::FeeCalculator;
use crate::hash::Hash;
use crate::instruction::Instruction;
use crate::message::Message;
use crate::pubkey::Pubkey;
use crate::signature::{Keypair, Signature};
use crate::transaction;
use crate::transport::Result;
use crate::{
account::Account,
clock::Slot,
fee_calculator::FeeCalculator,
hash::Hash,
instruction::Instruction,
message::Message,
pubkey::Pubkey,
signature::{Keypair, Signature},
transaction,
transport::Result,
};
use std::io;
pub trait Client: SyncClient + AsyncClient {
@ -54,7 +57,7 @@ pub trait SyncClient {
) -> Result<Option<transaction::Result<()>>>;
/// Get last known slot
fn get_slot(&self) -> Result<u64>;
fn get_slot(&self) -> Result<Slot>;
/// Get transaction count
fn get_transaction_count(&self) -> Result<u64>;

View File

@ -45,7 +45,7 @@ impl EpochSchedule {
pub fn new(slots_per_epoch: u64) -> Self {
Self::custom(slots_per_epoch, slots_per_epoch, true)
}
pub fn custom(slots_per_epoch: u64, leader_schedule_slot_offset: u64, warmup: bool) -> Self {
pub fn custom(slots_per_epoch: Epoch, leader_schedule_slot_offset: u64, warmup: bool) -> Self {
assert!(slots_per_epoch >= MINIMUM_SLOTS_PER_EPOCH as u64);
let (first_normal_epoch, first_normal_slot) = if warmup {
let next_power_of_two = slots_per_epoch.next_power_of_two();
@ -70,7 +70,7 @@ impl EpochSchedule {
}
/// get the length of the given epoch (in slots)
pub fn get_slots_in_epoch(&self, epoch: u64) -> u64 {
pub fn get_slots_in_epoch(&self, epoch: Epoch) -> u64 {
if epoch < self.first_normal_epoch {
2u64.pow(epoch as u32 + MINIMUM_SLOTS_PER_EPOCH.trailing_zeros() as u32)
} else {
@ -80,7 +80,7 @@ impl EpochSchedule {
/// get the epoch for which the given slot should save off
/// information about stakers
pub fn get_leader_schedule_epoch(&self, slot: u64) -> u64 {
pub fn get_leader_schedule_epoch(&self, slot: Slot) -> Epoch {
if slot < self.first_normal_slot {
// until we get to normal slots, behave as if leader_schedule_slot_offset == slots_per_epoch
self.get_epoch_and_slot_index(slot).0 + 1
@ -92,12 +92,12 @@ impl EpochSchedule {
}
/// get epoch for the given slot
pub fn get_epoch(&self, slot: u64) -> u64 {
pub fn get_epoch(&self, slot: Slot) -> Epoch {
self.get_epoch_and_slot_index(slot).0
}
/// get epoch and offset into the epoch for the given slot
pub fn get_epoch_and_slot_index(&self, slot: u64) -> (u64, u64) {
pub fn get_epoch_and_slot_index(&self, slot: Slot) -> (Epoch, u64) {
if slot < self.first_normal_slot {
let epoch = (slot + MINIMUM_SLOTS_PER_EPOCH + 1)
.next_power_of_two()
@ -119,7 +119,7 @@ impl EpochSchedule {
}
}
pub fn get_first_slot_in_epoch(&self, epoch: u64) -> u64 {
pub fn get_first_slot_in_epoch(&self, epoch: Epoch) -> Slot {
if epoch <= self.first_normal_epoch {
(2u64.pow(epoch as u32) - 1) * MINIMUM_SLOTS_PER_EPOCH
} else {
@ -127,7 +127,7 @@ impl EpochSchedule {
}
}
pub fn get_last_slot_in_epoch(&self, epoch: u64) -> u64 {
pub fn get_last_slot_in_epoch(&self, epoch: Epoch) -> Slot {
self.get_first_slot_in_epoch(epoch) + self.get_slots_in_epoch(epoch) - 1
}
}

View File

@ -1,3 +1,4 @@
use crate::clock::Slot;
use std::fmt;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
@ -18,7 +19,7 @@ pub struct Meta {
pub port: u16,
pub v6: bool,
pub seed: [u8; 32],
pub slot: u64,
pub slot: Slot,
}
#[derive(Clone)]