Skip to content

Commit

Permalink
[Combined Net] Remove optimistic VID (#3797)
Browse files Browse the repository at this point in the history
* remove optimistic vid calculation for combined network

* clippy

* reduce contention on consensus lock while calculating vid

* fmt
  • Loading branch information
rob-maron authored Oct 24, 2024
1 parent 8068edc commit 05348f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 45 deletions.
40 changes: 1 addition & 39 deletions crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
use std::{marker::PhantomData, sync::Arc};

use async_broadcast::{Receiver, Sender};
use async_compatibility_layer::art::async_spawn;
use async_lock::RwLock;
#[cfg(async_executor_impl = "async-std")]
use async_std::task::spawn_blocking;
use async_trait::async_trait;
use hotshot_task::task::TaskState;
use hotshot_types::{
consensus::{Consensus, OuterConsensus, View},
consensus::{OuterConsensus, View},
data::{DaProposal, PackedBundle},
event::{Event, EventType},
message::{Proposal, UpgradeLock},
Expand All @@ -23,7 +22,6 @@ use hotshot_types::{
traits::{
block_contents::vid_commitment,
election::Membership,
network::ConnectedNetwork,
node_implementation::{NodeImplementation, NodeType, Versions},
signature_key::SignatureKey,
storage::Storage,
Expand Down Expand Up @@ -231,42 +229,6 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
) {
tracing::trace!("{e:?}");
}
// Optimistically calculate and update VID if we know that the primary network is down.
if self.network.is_primary_down() {
let consensus =
OuterConsensus::new(Arc::clone(&self.consensus.inner_consensus));
let membership = Arc::clone(&self.quorum_membership);
let pk = self.private_key.clone();
let public_key = self.public_key.clone();
let chan = event_stream.clone();
let current_epoch = self.cur_epoch;
async_spawn(async move {
Consensus::calculate_and_update_vid(
OuterConsensus::new(Arc::clone(&consensus.inner_consensus)),
view_number,
membership,
&pk,
current_epoch,
)
.await;
if let Some(Some(vid_share)) = consensus
.read()
.await
.vid_shares()
.get(&view_number)
.map(|shares| shares.get(&public_key).cloned())
{
broadcast_event(
Arc::new(HotShotEvent::VidShareRecv(
public_key.clone(),
vid_share.clone(),
)),
&chan,
)
.await;
}
});
}
}
HotShotEvent::DaVoteRecv(ref vote) => {
tracing::debug!("DA vote recv, Main Task {:?}", vote.view_number());
Expand Down
9 changes: 3 additions & 6 deletions crates/types/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,10 @@ impl<TYPES: NodeType> Consensus<TYPES> {
private_key: &<TYPES::SignatureKey as SignatureKey>::PrivateKey,
epoch: TYPES::Epoch,
) -> Option<()> {
let consensus = consensus.upgradable_read().await;
let txns = consensus.saved_payloads().get(&view)?;
let vid =
VidDisperse::calculate_vid_disperse(Arc::clone(txns), &membership, view, epoch, None)
.await;
let txns = Arc::clone(consensus.read().await.saved_payloads().get(&view)?);
let vid = VidDisperse::calculate_vid_disperse(txns, &membership, view, epoch, None).await;
let shares = VidDisperseShare::from_vid_disperse(vid);
let mut consensus = ConsensusUpgradableReadLockGuard::upgrade(consensus).await;
let mut consensus = consensus.write().await;
for share in shares {
if let Some(prop) = share.to_proposal(private_key) {
consensus.update_vid_shares(view, prop);
Expand Down

0 comments on commit 05348f0

Please sign in to comment.