Skip to content

Commit

Permalink
Reflow get_or_calc_vid_share (#3823)
Browse files Browse the repository at this point in the history
  • Loading branch information
pls148 authored Oct 30, 2024
1 parent 0761673 commit 84ae1f8
Showing 1 changed file with 27 additions and 34 deletions.
61 changes: 27 additions & 34 deletions crates/task-impls/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,52 +143,45 @@ impl<TYPES: NodeType> NetworkResponseState<TYPES> {
view: TYPES::View,
key: &TYPES::SignatureKey,
) -> Option<Proposal<TYPES, VidDisperseShare<TYPES>>> {
let contained = self
.consensus
.read()
.await
.vid_shares()
.get(&view)
.is_some_and(|m| m.contains_key(key));
if !contained {
let cur_epoch = self.consensus.read().await.cur_epoch();
if Consensus::calculate_and_update_vid(
let consensus_reader = self.consensus.read().await;
if let Some(view) = consensus_reader.vid_shares().get(&view) {
if let Some(share) = view.get(key) {
return Some(share.clone());
}
}

let cur_epoch = consensus_reader.cur_epoch();
drop(consensus_reader);

if Consensus::calculate_and_update_vid(
OuterConsensus::new(Arc::clone(&self.consensus)),
view,
Arc::clone(&self.quorum),
&self.private_key,
cur_epoch,
)
.await
.is_none()
{
// Sleep in hope we receive txns in the meantime
async_sleep(TXNS_TIMEOUT).await;
Consensus::calculate_and_update_vid(
OuterConsensus::new(Arc::clone(&self.consensus)),
view,
Arc::clone(&self.quorum),
&self.private_key,
cur_epoch,
)
.await
.is_none()
{
// Sleep in hope we receive txns in the meantime
async_sleep(TXNS_TIMEOUT).await;
Consensus::calculate_and_update_vid(
OuterConsensus::new(Arc::clone(&self.consensus)),
view,
Arc::clone(&self.quorum),
&self.private_key,
cur_epoch,
)
.await?;
}
return self
.consensus
.read()
.await
.vid_shares()
.get(&view)?
.get(key)
.cloned();
.await?;
}
self.consensus
return self
.consensus
.read()
.await
.vid_shares()
.get(&view)?
.get(key)
.cloned()
.cloned();
}

/// Makes sure the sender is allowed to send a request in the given epoch.
Expand Down

0 comments on commit 84ae1f8

Please sign in to comment.