copy bank for TPU

This commit is contained in:
Rob Walker 2019-01-29 11:18:56 -08:00 committed by Grimes
parent 3e1a926aa6
commit 1f9ab7f58f
4 changed files with 29 additions and 2 deletions

View File

@ -251,6 +251,21 @@ impl AccountsDB {
}
impl Accounts {
// TODO use a fork
pub fn copy_for_tpu(&self) -> Self {
let copy = Accounts::default();
{
let mut accounts_db = copy.accounts_db.write().unwrap();
for (key, val) in self.accounts_db.read().unwrap().accounts.iter() {
accounts_db.accounts.insert(key.clone(), val.clone());
}
accounts_db.transaction_count = self.transaction_count();
}
copy
}
pub fn keys(&self) -> Vec<Pubkey> {
self.accounts_db.read().unwrap().keys()
}

View File

@ -137,6 +137,17 @@ impl Bank {
*sub = subscriptions
}
pub fn copy_for_tpu(&self) -> Self {
Self {
accounts: self.accounts.copy_for_tpu(),
last_ids: RwLock::new(self.last_ids.read().unwrap().clone()),
confirmation_time: AtomicUsize::new(self.confirmation_time()),
leader_scheduler: self.leader_scheduler.clone(),
storage_state: StorageState::new(),
subscriptions: RwLock::new(Box::new(Arc::new(LocalSubscriptions::default()))),
}
}
fn process_genesis_block(&self, genesis_block: &GenesisBlock) {
assert!(genesis_block.mint_id != Pubkey::default());
assert!(genesis_block.tokens >= genesis_block.bootstrap_leader_tokens);

View File

@ -278,7 +278,7 @@ impl Fullnode {
};
let tpu = Tpu::new(
&bank,
&Arc::new(bank.copy_for_tpu()),
Default::default(),
node.sockets
.tpu
@ -360,7 +360,7 @@ impl Fullnode {
let (to_validator_sender, to_validator_receiver) = channel();
self.role_notifiers.1 = to_validator_receiver;
self.node_services.tpu.switch_to_leader(
&self.bank,
&Arc::new(self.bank.copy_for_tpu()),
Default::default(),
self.tpu_sockets
.iter()

View File

@ -49,6 +49,7 @@ struct StatusEntry<T> {
statuses: StatusMap<T>,
}
#[derive(Clone)]
pub struct StatusDeque<T> {
/// A FIFO queue of `last_id` items, where each item is a set of signatures
/// that have been processed using that `last_id`. Rejected `last_id`