From a77775cb58f5eff93acf7a4e04b8830600bf7bb5 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Mon, 3 Jun 2019 18:27:06 -0700 Subject: [PATCH] Move validation submissions into its own fn (#4528) automerge --- core/src/storage_stage.rs | 92 ++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/core/src/storage_stage.rs b/core/src/storage_stage.rs index be5b26a06e..0624c91ffd 100644 --- a/core/src/storage_stage.rs +++ b/core/src/storage_stage.rs @@ -483,53 +483,63 @@ impl StorageStage { slot, instruction_sender, )?; - // bundle up mining submissions from replicators - // and submit them in a tx to the leader to get rewarded. - let mut w_state = storage_state.write().unwrap(); - let instructions: Vec<_> = w_state - .replicator_map - .iter_mut() - .enumerate() - .flat_map(|(segment, proof_map)| { - let checked_proofs = proof_map - .iter_mut() - .map(|(id, proofs)| { - ( - *id, - proofs - .drain(..) - .map(|proof| CheckedProof { - proof, - status: ProofStatus::Valid, - }) - .collect::>(), - ) - }) - .collect::>(); - if !checked_proofs.is_empty() { - let ix = proof_validation( - &storage_keypair.pubkey(), - segment as u64, - checked_proofs, - ); - Some(ix) - } else { - None - } - }) - .collect(); - // TODO Avoid AccountInUse errors in this loop - let res: std::result::Result<_, _> = instructions - .into_iter() - .map(|ix| instruction_sender.send(ix)) - .collect(); - res? + Self::submit_verifications( + &storage_state, + &storage_keypair, + instruction_sender, + )? } } } } Ok(()) } + + fn submit_verifications( + storage_state: &Arc>, + storage_keypair: &Arc, + ix_sender: &Sender, + ) -> Result<()> { + // bundle up mining submissions from replicators + // and submit them in a tx to the leader to get rewarded. + let mut w_state = storage_state.write().unwrap(); + let instructions: Vec<_> = w_state + .replicator_map + .iter_mut() + .enumerate() + .flat_map(|(segment, proof_map)| { + let checked_proofs = proof_map + .iter_mut() + .map(|(id, proofs)| { + ( + *id, + proofs + .drain(..) + .map(|proof| CheckedProof { + proof, + status: ProofStatus::Valid, + }) + .collect::>(), + ) + }) + .collect::>(); + if !checked_proofs.is_empty() { + let ix = + proof_validation(&storage_keypair.pubkey(), segment as u64, checked_proofs); + Some(ix) + } else { + None + } + }) + .collect(); + // TODO Avoid AccountInUse errors in this loop + let res: std::result::Result<_, _> = instructions + .into_iter() + .map(|ix| ix_sender.send(ix)) + .collect(); + res?; + Ok(()) + } } impl Service for StorageStage {