Fix memory blow-up with Arc<ChainSpec>

Previously it was cloning the ChainSpec, now it shares an Arc.
This commit is contained in:
Paul Hauner 2019-01-31 20:24:37 +11:00
parent 02a962d35d
commit becb81d842
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6
2 changed files with 6 additions and 5 deletions

View File

@ -19,7 +19,7 @@ pub struct BeaconChainHarness {
pub block_store: Arc<BeaconBlockStore<MemoryDB>>,
pub state_store: Arc<BeaconStateStore<MemoryDB>>,
pub validators: Vec<TestValidator>,
pub spec: ChainSpec,
pub spec: Arc<ChainSpec>,
}
impl BeaconChainHarness {
@ -74,12 +74,14 @@ impl BeaconChainHarness {
.unwrap(),
);
let spec = Arc::new(spec);
debug!("Creating validator producer and attester instances...");
// Spawn the test validator instances.
let validators: Vec<TestValidator> = keypairs
.par_iter()
.map(|keypair| TestValidator::new(keypair.clone(), beacon_chain.clone(), &spec))
.iter()
.map(|keypair| TestValidator::new(keypair.clone(), beacon_chain.clone(), spec.clone()))
.collect();
debug!("Created {} TestValidators", validators.len());

View File

@ -52,9 +52,8 @@ impl TestValidator {
pub fn new(
keypair: Keypair,
beacon_chain: Arc<BeaconChain<MemoryDB, TestingSlotClock>>,
spec: &ChainSpec,
spec: Arc<ChainSpec>,
) -> Self {
let spec = Arc::new(spec.clone());
let slot_clock = Arc::new(TestingSlotClock::new(spec.genesis_slot));
let signer = Arc::new(TestSigner::new(keypair.clone()));
let beacon_node = Arc::new(BenchingBeaconNode::new(beacon_chain.clone()));