diff --git a/src/accounts.rs b/src/accounts.rs index d1916ceac8..3a962bb376 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -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 { self.accounts_db.read().unwrap().keys() } diff --git a/src/bank.rs b/src/bank.rs index 871b727d13..ac67b9d3d8 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -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); diff --git a/src/fullnode.rs b/src/fullnode.rs index 8b8d409837..ffd2290e62 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -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() diff --git a/src/status_deque.rs b/src/status_deque.rs index 8a44efcf9a..8335f71798 100644 --- a/src/status_deque.rs +++ b/src/status_deque.rs @@ -49,6 +49,7 @@ struct StatusEntry { statuses: StatusMap, } +#[derive(Clone)] pub struct StatusDeque { /// 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`