Split SDK's timing.rs (#5823)

This commit is contained in:
Jack May 2019-09-06 14:30:56 -07:00 committed by GitHub
parent cc8575dd96
commit e8d88f3237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 169 additions and 163 deletions

View File

@ -781,7 +781,7 @@ fn process_delegate_stake(
)),
Some(root_slot) => {
let slot = rpc_client.get_slot()?;
if root_slot + solana_sdk::timing::DEFAULT_SLOTS_PER_TURN < slot {
if root_slot + solana_sdk::clock::DEFAULT_SLOTS_PER_TURN < slot {
Err(WalletError::BadParameter(
format!(
"Unable to delegate. Vote account root slot ({}) is too old, the current slot is {}", root_slot, slot
@ -1307,8 +1307,8 @@ fn process_ping(
// Sleep for half a slot
if signal_receiver
.recv_timeout(Duration::from_millis(
500 * solana_sdk::timing::DEFAULT_TICKS_PER_SLOT
/ solana_sdk::timing::DEFAULT_TICKS_PER_SECOND,
500 * solana_sdk::clock::DEFAULT_TICKS_PER_SLOT
/ solana_sdk::clock::DEFAULT_TICKS_PER_SECOND,
))
.is_ok()
{

View File

@ -7,12 +7,12 @@ use bincode::serialize;
use log::*;
use serde_json::{json, Value};
use solana_sdk::account::Account;
use solana_sdk::clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT};
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::hash::Hash;
use solana_sdk::inflation::Inflation;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{KeypairUtil, Signature};
use solana_sdk::timing::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT};
use solana_sdk::transaction::{self, Transaction, TransactionError};
use std::error;
use std::io;

View File

@ -2,7 +2,7 @@ use crate::client_error::ClientError;
use crate::generic_rpc_client_request::GenericRpcClientRequest;
use crate::rpc_request::{RpcError, RpcRequest};
use log::*;
use solana_sdk::timing::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT};
use solana_sdk::clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT};
use std::io::{Error as IoError, ErrorKind};
use std::thread::sleep;
use std::time::Duration;

View File

@ -8,6 +8,7 @@ use bincode::{serialize_into, serialized_size};
use log::*;
use solana_sdk::account::Account;
use solana_sdk::client::{AsyncClient, Client, SyncClient};
use solana_sdk::clock::MAX_PROCESSING_AGE;
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::hash::Hash;
use solana_sdk::instruction::Instruction;
@ -16,7 +17,7 @@ use solana_sdk::packet::PACKET_DATA_SIZE;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
use solana_sdk::system_instruction;
use solana_sdk::timing::{duration_as_ms, MAX_PROCESSING_AGE};
use solana_sdk::timing::duration_as_ms;
use solana_sdk::transaction::{self, Transaction};
use solana_sdk::transport::Result as TransportResult;
use std::io;

View File

@ -22,12 +22,13 @@ use solana_metrics::{inc_new_counter_debug, inc_new_counter_info, inc_new_counte
use solana_runtime::accounts_db::ErrorCounters;
use solana_runtime::bank::Bank;
use solana_runtime::locked_accounts_results::LockedAccountsResults;
use solana_sdk::poh_config::PohConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::timing::{
self, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE,
use solana_sdk::clock::{
DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE,
MAX_TRANSACTION_FORWARDING_DELAY,
};
use solana_sdk::poh_config::PohConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::timing::{duration_as_ms, timestamp};
use solana_sdk::transaction::{self, Transaction, TransactionError};
use std::cmp;
use std::env;
@ -222,7 +223,7 @@ impl BankingStage {
debug!(
"@{:?} done processing buffered batches: {} time: {:?}ms tx count: {} tx/s: {}",
timing::timestamp(),
timestamp(),
buffered_len,
proc_start.as_ms(),
new_tx_count,
@ -808,8 +809,8 @@ impl BankingStage {
let count: usize = mms.iter().map(|x| x.1.len()).sum();
debug!(
"@{:?} process start stalled for: {:?}ms txs: {} id: {}",
timing::timestamp(),
timing::duration_as_ms(&recv_start.elapsed()),
timestamp(),
duration_as_ms(&recv_start.elapsed()),
count,
id,
);
@ -878,7 +879,7 @@ impl BankingStage {
inc_new_counter_debug!("banking_stage-time_ms", proc_start.as_ms() as usize);
debug!(
"@{:?} done processing transaction batches: {} time: {:?}ms tx count: {} tx/s: {} total count: {} id: {}",
timing::timestamp(),
timestamp(),
mms_len,
proc_start.as_ms(),
new_tx_count,

View File

@ -34,7 +34,7 @@ use std::sync::{Arc, RwLock};
pub use self::meta::*;
pub use self::rooted_slot_iterator::*;
use crate::leader_schedule_cache::LeaderScheduleCache;
use solana_sdk::timing::Slot;
use solana_sdk::clock::Slot;
mod db;
mod meta;

View File

@ -5,7 +5,7 @@ use bincode::{deserialize, serialize};
use serde::de::DeserializeOwned;
use serde::Serialize;
use solana_sdk::timing::Slot;
use solana_sdk::clock::Slot;
use std::borrow::Borrow;
use std::collections::HashMap;
use std::marker::PhantomData;

View File

@ -4,7 +4,7 @@ use crate::blocktree::db::{
};
use crate::blocktree::BlocktreeError;
use crate::result::{Error, Result};
use solana_sdk::timing::Slot;
use solana_sdk::clock::Slot;
use byteorder::{BigEndian, ByteOrder};

View File

@ -7,9 +7,10 @@ use rayon::ThreadPool;
use solana_metrics::{datapoint, datapoint_error, inc_new_counter_debug};
use solana_runtime::bank::Bank;
use solana_runtime::locked_accounts_results::LockedAccountsResults;
use solana_sdk::clock::{Slot, MAX_RECENT_BLOCKHASHES};
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::hash::Hash;
use solana_sdk::timing::{duration_as_ms, Slot, MAX_RECENT_BLOCKHASHES};
use solana_sdk::timing::duration_as_ms;
use solana_sdk::transaction::Result;
use std::result;
use std::sync::Arc;

View File

@ -120,9 +120,9 @@ mod tests {
use crate::chacha_cuda::chacha_cbc_encrypt_file_many_keys;
use crate::entry::make_tiny_test_entries;
use crate::replicator::sample_file;
use solana_sdk::clock::DEFAULT_SLOTS_PER_SEGMENT;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::DEFAULT_SLOTS_PER_SEGMENT;
use std::fs::{remove_dir_all, remove_file};
use std::path::Path;
use std::sync::Arc;

View File

@ -1769,9 +1769,9 @@ mod tests {
use crate::result::Error;
use crate::shred::{DataShred, Shred};
use crate::test_tx::test_tx;
use solana_sdk::clock::DEFAULT_TICKS_PER_SLOT;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr};
use std::sync::{Arc, RwLock};

View File

@ -7,7 +7,7 @@ use crate::result::{Error, Result};
use crate::service::Service;
use crate::streamer::{self, PacketReceiver, PacketSender};
use solana_metrics::{inc_new_counter_debug, inc_new_counter_info};
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
use solana_sdk::clock::DEFAULT_TICKS_PER_SLOT;
use std::net::UdpSocket;
use std::sync::atomic::AtomicBool;
use std::sync::mpsc::{channel, RecvTimeoutError};

View File

@ -1,8 +1,8 @@
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::timing::NUM_CONSECUTIVE_LEADER_SLOTS;
/// Return the leader schedule for the given epoch.
pub fn leader_schedule(epoch: u64, bank: &Bank) -> Option<LeaderSchedule> {

View File

@ -3,8 +3,8 @@
use crate::blocktree::Blocktree;
use crate::result::{Error, Result};
use crate::service::Service;
use solana_sdk::clock::DEFAULT_SLOTS_PER_EPOCH;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::timing::DEFAULT_SLOTS_PER_EPOCH;
use std::string::ToString;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::{Receiver, RecvTimeoutError};

View File

@ -16,12 +16,12 @@ use crate::leader_schedule_cache::LeaderScheduleCache;
use crate::poh::Poh;
use crate::result::{Error, Result};
use solana_runtime::bank::Bank;
pub use solana_sdk::clock::Slot;
use solana_sdk::clock::NUM_CONSECUTIVE_LEADER_SLOTS;
use solana_sdk::hash::Hash;
use solana_sdk::poh_config::PohConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::timing;
pub use solana_sdk::timing::Slot;
use solana_sdk::timing::NUM_CONSECUTIVE_LEADER_SLOTS;
use solana_sdk::transaction::Transaction;
use std::cmp;
use std::sync::mpsc::{channel, Receiver, Sender, SyncSender};
@ -447,8 +447,8 @@ mod tests {
use crate::blocktree::{get_tmp_ledger_path, Blocktree};
use crate::genesis_utils::{create_genesis_block, GenesisBlockInfo};
use crate::test_tx::test_tx;
use solana_sdk::clock::DEFAULT_TICKS_PER_SLOT;
use solana_sdk::hash::hash;
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
use std::sync::mpsc::sync_channel;
#[test]

View File

@ -27,10 +27,11 @@ use solana_ed25519_dalek as ed25519_dalek;
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::{get_complete_segment_from_slot, get_segment_from_slot, timestamp};
use solana_sdk::timing::timestamp;
use solana_sdk::transaction::Transaction;
use solana_sdk::transport::TransportError;
use solana_storage_api::storage_contract::StorageContract;

View File

@ -15,12 +15,12 @@ use solana_runtime::bank::Bank;
use solana_runtime::storage_utils::replicator_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::timing::get_segment_from_slot;
use solana_sdk::transaction::Transaction;
use solana_storage_api::storage_contract::{Proof, ProofStatus, StorageContract};
use solana_storage_api::storage_instruction;
@ -638,10 +638,10 @@ mod tests {
use crate::{blocktree_processor, entry};
use rayon::prelude::*;
use solana_runtime::bank::Bank;
use solana_sdk::clock::DEFAULT_TICKS_PER_SLOT;
use solana_sdk::hash::{Hash, Hasher};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
use std::cmp::{max, min};
use std::fs::remove_dir_all;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

View File

@ -21,12 +21,14 @@ use crate::storage_stage::StorageState;
use crate::tpu::Tpu;
use crate::tvu::{Sockets, Tvu};
use solana_metrics::datapoint_info;
use solana_sdk::clock::{Slot, DEFAULT_SLOTS_PER_TURN};
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::hash::Hash;
use solana_sdk::poh_config::PohConfig;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, KeypairUtil};
use solana_sdk::timing::{timestamp, Slot, DEFAULT_SLOTS_PER_TURN};
use solana_sdk::timing::timestamp;
use std::fs;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::path::{Path, PathBuf};

View File

@ -63,7 +63,7 @@ fn test_rpc_send_tx() {
"params": [signature],
});
for _ in 0..solana_sdk::timing::DEFAULT_TICKS_PER_SLOT {
for _ in 0..solana_sdk::clock::DEFAULT_TICKS_PER_SLOT {
let response = client
.post(&rpc_string)
.set("Content-Type", "application/json")

View File

@ -5,6 +5,7 @@ use clap::{crate_description, crate_name, crate_version, value_t_or_exit, App, A
use serde::{Deserialize, Serialize};
use solana_core::blocktree::create_new_ledger;
use solana_sdk::account::Account;
use solana_sdk::clock;
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::genesis_block::Builder;
use solana_sdk::hash::{hash, Hash};
@ -83,8 +84,8 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.to_string();
let default_target_tick_duration =
&timing::duration_as_ms(&PohConfig::default().target_tick_duration).to_string();
let default_ticks_per_slot = &timing::DEFAULT_TICKS_PER_SLOT.to_string();
let default_slots_per_epoch = &timing::DEFAULT_SLOTS_PER_EPOCH.to_string();
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
let default_slots_per_epoch = &clock::DEFAULT_SLOTS_PER_EPOCH.to_string();
let matches = App::new(crate_name!())
.about(crate_description!())

View File

@ -1,8 +1,8 @@
use clap::{crate_description, crate_name, crate_version, value_t_or_exit, App, Arg, SubCommand};
use solana_core::blocktree::Blocktree;
use solana_core::blocktree_processor::process_blocktree;
use solana_sdk::clock::Slot;
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::timing::Slot;
use std::collections::BTreeMap;
use std::fs::File;
use std::io::{stdout, Write};

View File

@ -15,15 +15,13 @@ use solana_core::{
use solana_runtime::epoch_schedule::MINIMUM_SLOTS_PER_EPOCH;
use solana_sdk::{
client::SyncClient,
clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS},
hash::Hash,
poh_config::PohConfig,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil, Signature},
system_transaction,
timing::{
duration_as_ms, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT,
NUM_CONSECUTIVE_LEADER_SLOTS,
},
timing::duration_as_ms,
transport::TransportError,
};
use std::{

View File

@ -12,14 +12,14 @@ use solana_core::{
};
use solana_sdk::{
client::SyncClient,
clock::DEFAULT_TICKS_PER_SLOT,
clock::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT},
genesis_block::GenesisBlock,
message::Message,
poh_config::PohConfig,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
system_transaction,
timing::DEFAULT_TICKS_PER_SLOT,
timing::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT},
transaction::Transaction,
};
use solana_stake_api::{config as stake_config, stake_instruction, stake_state::StakeState};

View File

@ -14,7 +14,7 @@ use solana_runtime::{
accounts_db::AccountsDB,
epoch_schedule::{EpochSchedule, MINIMUM_SLOTS_PER_EPOCH},
};
use solana_sdk::{client::SyncClient, poh_config::PohConfig, timing};
use solana_sdk::{client::SyncClient, clock, poh_config::PohConfig};
use std::path::PathBuf;
use std::{
collections::{HashMap, HashSet},
@ -267,14 +267,14 @@ fn test_restart_node() {
cluster_tests::sleep_n_epochs(
1.0,
&cluster.genesis_block.poh_config,
timing::DEFAULT_TICKS_PER_SLOT,
clock::DEFAULT_TICKS_PER_SLOT,
slots_per_epoch,
);
cluster.restart_node(nodes[0], &validator_config);
cluster_tests::sleep_n_epochs(
0.5,
&cluster.genesis_block.poh_config,
timing::DEFAULT_TICKS_PER_SLOT,
clock::DEFAULT_TICKS_PER_SLOT,
slots_per_epoch,
);
cluster_tests::send_many_transactions(

View File

@ -7,10 +7,10 @@ use log::*;
use serde_derive::{Deserialize, Serialize};
use solana_sdk::{
account::KeyedAccount,
clock::Slot,
instruction::{AccountMeta, Instruction, InstructionError},
pubkey::Pubkey,
system_instruction, sysvar,
timing::Slot,
};
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]

View File

@ -9,6 +9,7 @@ use serde_derive::{Deserialize, Serialize};
use solana_sdk::{
account::{Account, KeyedAccount},
account_utils::State,
clock::{Epoch, Slot},
instruction::InstructionError,
instruction_processor_utils::DecodeError,
pubkey::Pubkey,
@ -16,7 +17,6 @@ use solana_sdk::{
self,
stake_history::{StakeHistory, StakeHistoryEntry},
},
timing::{Epoch, Slot},
};
use solana_vote_api::vote_state::VoteState;

View File

@ -7,6 +7,7 @@ use solana_runtime::genesis_utils::{create_genesis_block, GenesisBlockInfo};
use solana_sdk::account::{create_keyed_accounts, Account, KeyedAccount};
use solana_sdk::account_utils::State;
use solana_sdk::client::SyncClient;
use solana_sdk::clock::{get_segment_from_slot, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT};
use solana_sdk::hash::{hash, Hash};
use solana_sdk::instruction::{Instruction, InstructionError};
use solana_sdk::message::Message;
@ -16,9 +17,6 @@ use solana_sdk::system_instruction;
use solana_sdk::sysvar::clock::Clock;
use solana_sdk::sysvar::rewards::Rewards;
use solana_sdk::sysvar::{clock, rewards};
use solana_sdk::timing::{
get_segment_from_slot, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT,
};
use solana_storage_api::id;
use solana_storage_api::storage_contract::StorageAccount;
use solana_storage_api::storage_contract::{ProofStatus, StorageContract, STORAGE_ACCOUNT_SPACE};

View File

@ -8,12 +8,12 @@ use serde_derive::{Deserialize, Serialize};
use solana_sdk::{
account::{Account, KeyedAccount},
account_utils::State,
clock::{Epoch, Slot},
hash::Hash,
instruction::InstructionError,
instruction_processor_utils::DecodeError,
pubkey::Pubkey,
sysvar::clock::Clock,
timing::{Epoch, Slot},
};
use std::collections::VecDeque;

View File

@ -1,7 +1,7 @@
use bincode::{deserialize_from, serialize_into, serialized_size};
use memmap::MmapMut;
use serde::{Deserialize, Serialize};
use solana_sdk::{account::Account, pubkey::Pubkey, timing::Epoch};
use solana_sdk::{account::Account, clock::Epoch, pubkey::Pubkey};
use std::fmt;
use std::fs::{create_dir_all, remove_file, OpenOptions};
use std::io;

View File

@ -33,6 +33,7 @@ use solana_metrics::{
};
use solana_sdk::{
account::Account,
clock::{get_segment_from_slot, Epoch, Slot, MAX_RECENT_BLOCKHASHES},
fee_calculator::FeeCalculator,
genesis_block::GenesisBlock,
hash::{hashv, Hash},
@ -46,7 +47,7 @@ use solana_sdk::{
slot_hashes::{self, SlotHashes},
stake_history,
},
timing::{duration_as_ns, get_segment_from_slot, Epoch, Slot, MAX_RECENT_BLOCKHASHES},
timing::duration_as_ns,
transaction::{Result, Transaction, TransactionError},
};
use std::collections::{HashMap, HashSet};
@ -1533,6 +1534,7 @@ mod tests {
create_genesis_block_with_leader, GenesisBlockInfo, BOOTSTRAP_LEADER_LAMPORTS,
};
use bincode::{deserialize_from, serialize_into, serialized_size};
use solana_sdk::clock::DEFAULT_TICKS_PER_SLOT;
use solana_sdk::genesis_block::create_genesis_block;
use solana_sdk::hash;
use solana_sdk::instruction::InstructionError;
@ -1541,7 +1543,6 @@ mod tests {
use solana_sdk::system_instruction;
use solana_sdk::system_transaction;
use solana_sdk::sysvar::{fees::Fees, rewards::Rewards};
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
use solana_stake_api::stake_state::Stake;
use solana_vote_api::vote_instruction;
use solana_vote_api::vote_state::{VoteState, MAX_LOCKOUT_HISTORY};

View File

@ -1,6 +1,6 @@
//! calculate and collect rent from Accounts
use crate::epoch_schedule::EpochSchedule;
use solana_sdk::{account::Account, rent::Rent, timing::Epoch};
use solana_sdk::{account::Account, clock::Epoch, rent::Rent};
#[derive(Default, Serialize, Deserialize, Clone)]
pub struct RentCollector {

View File

@ -1,9 +1,9 @@
//! Stakes serve as a cache of stake and vote accounts to derive
//! node stakes
use solana_sdk::account::Account;
use solana_sdk::clock::Epoch;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::sysvar::stake_history::StakeHistory;
use solana_sdk::timing::Epoch;
use solana_stake_api::stake_state::{new_stake_history_entry, StakeState};
use solana_vote_api::vote_state::VoteState;
use std::collections::HashMap;

View File

@ -1,13 +1,13 @@
use log::*;
use rand::{thread_rng, Rng};
use serde::Serialize;
use solana_sdk::clock::{Slot, MAX_HASH_AGE_IN_SECONDS};
use solana_sdk::hash::Hash;
use solana_sdk::signature::Signature;
use solana_sdk::timing::Slot;
use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex};
pub const MAX_CACHE_ENTRIES: usize = solana_sdk::timing::MAX_HASH_AGE_IN_SECONDS;
pub const MAX_CACHE_ENTRIES: usize = MAX_HASH_AGE_IN_SECONDS;
const CACHED_SIGNATURE_SIZE: usize = 20;
// Store forks in a single chunk of memory to avoid another lookup.

View File

@ -1,4 +1,4 @@
use crate::{pubkey::Pubkey, timing::Epoch};
use crate::{pubkey::Pubkey, clock::Epoch};
use std::{cmp, fmt};
/// An Account with data that is stored on chain

99
sdk/src/clock.rs Normal file
View File

@ -0,0 +1,99 @@
//! Provides information about the network's clock which is made up of ticks, slots, segments, etc...
// The default tick rate that the cluster attempts to achieve. Note that the actual tick
// rate at any given time should be expected to drift
pub const DEFAULT_TICKS_PER_SECOND: u64 = 10;
// At 10 ticks/s, 4 ticks per slot implies that leader rotation and voting will happen
// every 400 ms. A fast voting cadence ensures faster finality and convergence
pub const DEFAULT_TICKS_PER_SLOT: u64 = 4;
// 1 Epoch = 400 * 8192 ms ~= 55 minutes
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 8192;
// Storage segment configuration
pub const DEFAULT_SLOTS_PER_SEGMENT: u64 = 1024;
// 4 times longer than the max_lockout to allow enough time for PoRep (128 slots)
pub const DEFAULT_SLOTS_PER_TURN: u64 = 32 * 4;
pub const NUM_CONSECUTIVE_LEADER_SLOTS: u64 = 4;
/// The time window of recent block hash values that the bank will track the signatures
/// of over. Once the bank discards a block hash, it will reject any transactions that use
/// that `recent_blockhash` in a transaction. Lowering this value reduces memory consumption,
/// but requires clients to update its `recent_blockhash` more frequently. Raising the value
/// lengthens the time a client must wait to be certain a missing transaction will
/// not be processed by the network.
pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;
// This must be <= MAX_HASH_AGE_IN_SECONDS, otherwise there's risk for DuplicateSignature errors
pub const MAX_RECENT_BLOCKHASHES: usize = MAX_HASH_AGE_IN_SECONDS;
// The maximum age of a blockhash that will be accepted by the leader
pub const MAX_PROCESSING_AGE: usize = MAX_RECENT_BLOCKHASHES / 2;
/// This is maximum time consumed in forwarding a transaction from one node to next, before
/// it can be processed in the target node
#[cfg(feature = "cuda")]
pub const MAX_TRANSACTION_FORWARDING_DELAY: usize = 2;
/// More delay is expected if CUDA is not enabled (as signature verification takes longer)
#[cfg(not(feature = "cuda"))]
pub const MAX_TRANSACTION_FORWARDING_DELAY: usize = 6;
/// Converts a slot to a storage segment. Does not indicate that a segment is complete.
pub fn get_segment_from_slot(rooted_slot: Slot, slots_per_segment: u64) -> Segment {
((rooted_slot + (slots_per_segment - 1)) / slots_per_segment)
}
/// Given a slot returns the latest complete segment, if no segment could possibly be complete
/// for a given slot it returns `None` (i.e if `slot < slots_per_segment`)
pub fn get_complete_segment_from_slot(
rooted_slot: Slot,
slots_per_segment: u64,
) -> Option<Segment> {
let completed_segment = rooted_slot / slots_per_segment;
if rooted_slot < slots_per_segment {
None
} else {
Some(completed_segment)
}
}
/// Slot is a unit of time given to a leader for encoding,
/// is some some number of Ticks long.
pub type Slot = u64;
/// A segment is some number of slots stored by replicators
pub type Segment = u64;
/// Epoch is a unit of time a given leader schedule is honored,
/// some number of Slots.
pub type Epoch = u64;
#[cfg(test)]
mod tests {
use super::*;
fn get_segments(slot: Slot, slots_per_segment: u64) -> (Segment, Segment) {
(
get_segment_from_slot(slot, slots_per_segment),
get_complete_segment_from_slot(slot, slots_per_segment).unwrap(),
)
}
#[test]
fn test_complete_segment_impossible() {
// slot < slots_per_segment so there can be no complete segments
assert_eq!(get_complete_segment_from_slot(5, 10), None);
}
#[test]
fn test_segment_conversion() {
let (current, complete) = get_segments(2048, 1024);
assert_eq!(current, complete);
let (current, complete) = get_segments(2049, 1024);
assert!(complete < current);
}
}

View File

@ -1,5 +1,5 @@
use crate::message::Message;
use crate::timing::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT};
use crate::clock::{DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT};
use log::*;
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]

View File

@ -9,7 +9,7 @@ use crate::pubkey::Pubkey;
use crate::rent::Rent;
use crate::signature::{Keypair, KeypairUtil};
use crate::system_program::{self, solana_system_program};
use crate::timing::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT};
use crate::clock::{DEFAULT_SLOTS_PER_EPOCH, DEFAULT_SLOTS_PER_SEGMENT, DEFAULT_TICKS_PER_SLOT};
use bincode::{deserialize, serialize};
use memmap::Mmap;
use std::fs::{File, OpenOptions};

View File

@ -1,6 +1,7 @@
#[macro_use]
extern crate cfg_if;
pub mod clock;
pub mod pubkey;
// On-chain program modules

View File

@ -1,4 +1,4 @@
use crate::timing::DEFAULT_TICKS_PER_SECOND;
use crate::clock::DEFAULT_TICKS_PER_SECOND;
use std::time::Duration;
#[derive(Serialize, Deserialize, Clone, Debug)]

View File

@ -4,7 +4,7 @@ use crate::account::Account;
use crate::sysvar;
use bincode::serialized_size;
pub use crate::timing::{Epoch, Slot};
pub use crate::clock::{Epoch, Slot};
const ID: [u8; 32] = [
6, 167, 213, 23, 24, 199, 116, 201, 40, 86, 99, 152, 105, 29, 94, 182, 139, 94, 184, 163, 155,
@ -57,7 +57,7 @@ pub fn create_account(
use crate::account::KeyedAccount;
use crate::instruction::InstructionError;
use crate::timing::Segment;
use crate::clock::Segment;
pub fn from_keyed_account(account: &KeyedAccount) -> Result<Clock, InstructionError> {
if !check_id(account.unsigned_key()) {

View File

@ -8,7 +8,7 @@ use crate::sysvar;
use bincode::serialized_size;
use std::ops::Deref;
pub use crate::timing::Slot;
pub use crate::clock::Slot;
const ID: [u8; 32] = [
6, 167, 213, 23, 25, 47, 10, 175, 198, 242, 101, 227, 251, 119, 204, 122, 218, 130, 197, 41,

View File

@ -8,7 +8,7 @@ use bincode::serialized_size;
use std::collections::HashMap;
use std::ops::Deref;
pub use crate::timing::Epoch;
pub use crate::clock::Epoch;
const ID: [u8; 32] = [
6, 167, 213, 23, 25, 53, 132, 208, 254, 237, 155, 179, 67, 29, 19, 32, 107, 229, 68, 40, 27,

View File

@ -2,48 +2,6 @@
use std::time::Duration;
use std::time::{SystemTime, UNIX_EPOCH};
// The default tick rate that the cluster attempts to achieve. Note that the actual tick
// rate at any given time should be expected to drift
pub const DEFAULT_TICKS_PER_SECOND: u64 = 10;
// At 10 ticks/s, 4 ticks per slot implies that leader rotation and voting will happen
// every 400 ms. A fast voting cadence ensures faster finality and convergence
pub const DEFAULT_TICKS_PER_SLOT: u64 = 4;
// 1 Epoch = 400 * 8192 ms ~= 55 minutes
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 8192;
// Storage segment configuration
pub const DEFAULT_SLOTS_PER_SEGMENT: u64 = 1024;
// 4 times longer than the max_lockout to allow enough time for PoRep (128 slots)
pub const DEFAULT_SLOTS_PER_TURN: u64 = 32 * 4;
pub const NUM_CONSECUTIVE_LEADER_SLOTS: u64 = 4;
/// The time window of recent block hash values that the bank will track the signatures
/// of over. Once the bank discards a block hash, it will reject any transactions that use
/// that `recent_blockhash` in a transaction. Lowering this value reduces memory consumption,
/// but requires clients to update its `recent_blockhash` more frequently. Raising the value
/// lengthens the time a client must wait to be certain a missing transaction will
/// not be processed by the network.
pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;
// This must be <= MAX_HASH_AGE_IN_SECONDS, otherwise there's risk for DuplicateSignature errors
pub const MAX_RECENT_BLOCKHASHES: usize = MAX_HASH_AGE_IN_SECONDS;
// The maximum age of a blockhash that will be accepted by the leader
pub const MAX_PROCESSING_AGE: usize = MAX_RECENT_BLOCKHASHES / 2;
/// This is maximum time consumed in forwarding a transaction from one node to next, before
/// it can be processed in the target node
#[cfg(feature = "cuda")]
pub const MAX_TRANSACTION_FORWARDING_DELAY: usize = 2;
/// More delay is expected if CUDA is not enabled (as signature verification takes longer)
#[cfg(not(feature = "cuda"))]
pub const MAX_TRANSACTION_FORWARDING_DELAY: usize = 6;
pub fn duration_as_ns(d: &Duration) -> u64 {
d.as_secs() * 1_000_000_000 + u64::from(d.subsec_nanos())
}
@ -66,59 +24,3 @@ pub fn timestamp() -> u64 {
.expect("create timestamp in timing");
duration_as_ms(&now)
}
/// Converts a slot to a storage segment. Does not indicate that a segment is complete.
pub fn get_segment_from_slot(rooted_slot: Slot, slots_per_segment: u64) -> Segment {
((rooted_slot + (slots_per_segment - 1)) / slots_per_segment)
}
/// Given a slot returns the latest complete segment, if no segment could possibly be complete
/// for a given slot it returns `None` (i.e if `slot < slots_per_segment`)
pub fn get_complete_segment_from_slot(
rooted_slot: Slot,
slots_per_segment: u64,
) -> Option<Segment> {
let completed_segment = rooted_slot / slots_per_segment;
if rooted_slot < slots_per_segment {
None
} else {
Some(completed_segment)
}
}
/// Slot is a unit of time given to a leader for encoding,
/// is some some number of Ticks long. Use a u64 to count them.
pub type Slot = u64;
/// A segment is some number of slots stored by replicators
pub type Segment = u64;
/// Epoch is a unit of time a given leader schedule is honored,
/// some number of Slots. Use a u64 to count them.
pub type Epoch = u64;
#[cfg(test)]
mod tests {
use super::*;
fn get_segments(slot: Slot, slots_per_segment: u64) -> (Segment, Segment) {
(
get_segment_from_slot(slot, slots_per_segment),
get_complete_segment_from_slot(slot, slots_per_segment).unwrap(),
)
}
#[test]
fn test_complete_segment_impossible() {
// slot < slots_per_segment so there can be no complete segments
assert_eq!(get_complete_segment_from_slot(5, 10), None);
}
#[test]
fn test_segment_conversion() {
let (current, complete) = get_segments(2048, 1024);
assert_eq!(current, complete);
let (current, complete) = get_segments(2049, 1024);
assert!(complete < current);
}
}

View File

@ -12,9 +12,9 @@ use solana_core::ledger_cleanup_service::DEFAULT_MAX_LEDGER_SLOTS;
use solana_core::service::Service;
use solana_core::socketaddr;
use solana_core::validator::{Validator, ValidatorConfig};
use solana_sdk::clock::Slot;
use solana_sdk::hash::Hash;
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil};
use solana_sdk::timing::Slot;
use std::fs::{self, File};
use std::io::{self, Read};
use std::net::SocketAddr;