use ref for new_from_parent; test that transactions don't leak to parent
This commit is contained in:
parent
8166925f04
commit
54dfe708c1
11
src/bank.rs
11
src/bank.rs
|
@ -117,10 +117,10 @@ impl Bank {
|
||||||
bank
|
bank
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_parent(parent: Arc<Bank>) -> Self {
|
pub fn new_from_parent(parent: &Arc<Bank>) -> Self {
|
||||||
let mut bank = Self::default();
|
let mut bank = Self::default();
|
||||||
bank.last_id_queue = RwLock::new(parent.last_id_queue.read().unwrap().clone());
|
bank.last_id_queue = RwLock::new(parent.last_id_queue.read().unwrap().clone());
|
||||||
bank.parent = Some(parent);
|
bank.parent = Some(parent.clone());
|
||||||
bank
|
bank
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1097,7 +1097,7 @@ mod tests {
|
||||||
let (genesis_block, _) = GenesisBlock::new(1);
|
let (genesis_block, _) = GenesisBlock::new(1);
|
||||||
let parent = Arc::new(Bank::new(&genesis_block));
|
let parent = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let bank = Bank::new_from_parent(parent.clone());
|
let bank = Bank::new_from_parent(&parent);
|
||||||
assert!(Arc::ptr_eq(&bank.parents()[0], &parent));
|
assert!(Arc::ptr_eq(&bank.parents()[0], &parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,7 +1116,7 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
||||||
let bank = Bank::new_from_parent(parent);
|
let bank = Bank::new_from_parent(&parent);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(BankError::DuplicateSignature)
|
Err(BankError::DuplicateSignature)
|
||||||
|
@ -1139,9 +1139,10 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
||||||
let bank = Bank::new_from_parent(parent);
|
let bank = Bank::new_from_parent(&parent);
|
||||||
let tx = SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.last_id(), 0);
|
let tx = SystemTransaction::new_move(&key1, key2.pubkey(), 1, genesis_block.last_id(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
assert_eq!(parent.get_signature_status(&tx.signatures[0]), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ mod tests {
|
||||||
let bank = Bank::default();
|
let bank = Bank::default();
|
||||||
let finalized_bank_id = bank.tick_height();
|
let finalized_bank_id = bank.tick_height();
|
||||||
let mut bank_forks = BankForks::new(bank);
|
let mut bank_forks = BankForks::new(bank);
|
||||||
let child_bank = Bank::new_from_parent(bank_forks.working_bank());
|
let child_bank = Bank::new_from_parent(&bank_forks.working_bank());
|
||||||
child_bank.register_tick(&Hash::default());
|
child_bank.register_tick(&Hash::default());
|
||||||
let child_bank_id = bank_forks.insert(child_bank);
|
let child_bank_id = bank_forks.insert(child_bank);
|
||||||
bank_forks.set_working_bank_id(child_bank_id);
|
bank_forks.set_working_bank_id(child_bank_id);
|
||||||
|
|
|
@ -363,7 +363,7 @@ impl Fullnode {
|
||||||
}
|
}
|
||||||
None => FullnodeReturnType::LeaderToLeaderRotation, // value doesn't matter here...
|
None => FullnodeReturnType::LeaderToLeaderRotation, // value doesn't matter here...
|
||||||
};
|
};
|
||||||
let tpu_bank = Arc::new(Bank::new_from_parent(self.bank.clone()));
|
let tpu_bank = Arc::new(Bank::new_from_parent(&self.bank));
|
||||||
self.node_services.tpu.switch_to_leader(
|
self.node_services.tpu.switch_to_leader(
|
||||||
&tpu_bank,
|
&tpu_bank,
|
||||||
PohServiceConfig::default(),
|
PohServiceConfig::default(),
|
||||||
|
|
Loading…
Reference in New Issue