Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lr/increment epoch #3828

Merged
merged 62 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d941ba9
Initial commit
lukaszrzasik Oct 23, 2024
0ea759a
Propose the same block at the end of the epoch
lukaszrzasik Oct 25, 2024
e6c6492
No VID and DAC required for the additional last block proposals
lukaszrzasik Oct 25, 2024
0db0add
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 25, 2024
d074292
Guard against division by 0
lukaszrzasik Oct 25, 2024
8505870
Traverse the leaves to check an eQC
lukaszrzasik Oct 28, 2024
cff7d76
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 28, 2024
5304ca5
Remove unneeded async in function definition
lukaszrzasik Oct 28, 2024
c6603af
Remove trace
lukaszrzasik Oct 28, 2024
de41a5a
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 28, 2024
680bab3
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 28, 2024
bca2f2b
Make sure proposal is for the same block if justify QC references the…
lukaszrzasik Oct 29, 2024
4ac1db5
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 29, 2024
4073351
Initial commit
lukaszrzasik Oct 30, 2024
7f7986d
Gate epoch proposal logic
lukaszrzasik Oct 30, 2024
2f3b23b
Gate epochs voting logic
lukaszrzasik Oct 30, 2024
eecb9f8
Create helper method to check if QC is part of 3-chain
lukaszrzasik Oct 30, 2024
e733582
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 30, 2024
8a03eeb
Merge branch 'lr/epoch-end' into lr/increment-epoch
lukaszrzasik Oct 30, 2024
4a51e13
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 30, 2024
1c8daf0
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Oct 30, 2024
1489fa0
Update epoch on `ViewChange` event
lukaszrzasik Oct 31, 2024
fab49f2
Merge branch 'main' into lr/epoch-end
lukaszrzasik Oct 31, 2024
073cca6
Merge branch 'lr/epoch-end' into lr/increment-epoch
lukaszrzasik Oct 31, 2024
8afbf58
Adjust tests
lukaszrzasik Oct 31, 2024
615d14e
Update view and epoch when QC is formed
lukaszrzasik Oct 31, 2024
224748b
Fixes after review
lukaszrzasik Nov 1, 2024
bd0d841
Get rid of nasty nested if-elses
lukaszrzasik Nov 1, 2024
6cec489
Fix fmt
lukaszrzasik Nov 1, 2024
687c5c7
Merge branch 'lr/epoch-end' into lr/increment-epoch
lukaszrzasik Nov 1, 2024
8cde052
Update VID that we reuse at the end of the epoch
lukaszrzasik Nov 1, 2024
7593cc6
Fix fmt
lukaszrzasik Nov 1, 2024
5b1be9f
Merge branch 'main' into lr/epoch-end
lukaszrzasik Nov 1, 2024
884a445
Merge branch 'lr/epoch-end' into lr/increment-epoch
lukaszrzasik Nov 1, 2024
cd4d315
Do not create VID and DAC dependencies when voting for the last block
lukaszrzasik Nov 4, 2024
3ded97f
Merge branch 'main' into lr/epoch-end
lukaszrzasik Nov 4, 2024
744ac1a
Merge branch 'lr/epoch-end' into lr/increment-epoch
lukaszrzasik Nov 4, 2024
f8b3a4a
Simplify how we get a header
lukaszrzasik Nov 4, 2024
7dc1ca6
Merge branch 'lr/epoch-end' into lr/increment-epoch
lukaszrzasik Nov 4, 2024
11bd731
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 4, 2024
df0730f
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 5, 2024
c5173fd
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 6, 2024
50d9306
Correctly update epoch when voting and forming QC
lukaszrzasik Nov 6, 2024
33e78e5
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 6, 2024
307e2c5
Send ViewChange event when voting after shared state's been updated
lukaszrzasik Nov 7, 2024
4a764ee
Adjust tests
lukaszrzasik Nov 7, 2024
6db7096
Remove an obsolete DA ViewChange code
lukaszrzasik Nov 7, 2024
1bd66cb
Fetch proposal if missing when changing view after forming QC
lukaszrzasik Nov 7, 2024
e1c5a1d
Fix deadlock
lukaszrzasik Nov 7, 2024
5294a83
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 7, 2024
e150806
Update epoch only when receiving or forming an eQC
lukaszrzasik Nov 8, 2024
34b271a
update logging (#3844)
ss-es Nov 7, 2024
4a1651d
[Tech debt] Remove `async-std` (#3845)
rob-maron Nov 8, 2024
e09dd6f
Fix fmt
lukaszrzasik Nov 8, 2024
a653525
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 8, 2024
de5a488
Simplify code
lukaszrzasik Nov 8, 2024
ab4293a
Move a helper function to types crate
lukaszrzasik Nov 8, 2024
0330ca4
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 8, 2024
8928fb0
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 12, 2024
0c70cc6
Rename storage method
lukaszrzasik Nov 12, 2024
f022612
Merge branch 'main' into lr/increment-epoch
lukaszrzasik Nov 13, 2024
759167d
Remove unused code
lukaszrzasik Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/example-types/src/node_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ impl Versions for TestVersions {
];

type Marketplace = StaticVersion<0, 3>;

type Epochs = StaticVersion<0, 4>;
}

#[derive(Clone, Debug, Copy)]
Expand All @@ -190,6 +192,8 @@ impl Versions for MarketplaceUpgradeTestVersions {
];

type Marketplace = StaticVersion<0, 3>;

type Epochs = StaticVersion<0, 4>;
}

#[derive(Clone, Debug, Copy)]
Expand All @@ -204,6 +208,24 @@ impl Versions for MarketplaceTestVersions {
];

type Marketplace = StaticVersion<0, 3>;

type Epochs = StaticVersion<0, 4>;
}

#[derive(Clone, Debug, Copy)]
pub struct EpochsTestVersions {}

impl Versions for EpochsTestVersions {
type Base = StaticVersion<0, 4>;
type Upgrade = StaticVersion<0, 4>;
const UPGRADE_HASH: [u8; 32] = [
1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0,
];

type Marketplace = StaticVersion<0, 3>;

type Epochs = StaticVersion<0, 4>;
}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions crates/example-types/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub struct TestStorageState<TYPES: NodeType> {
proposals: BTreeMap<TYPES::View, Proposal<TYPES, QuorumProposal<TYPES>>>,
high_qc: Option<hotshot_types::simple_certificate::QuorumCertificate<TYPES>>,
action: TYPES::View,
epoch: TYPES::Epoch,
}

impl<TYPES: NodeType> Default for TestStorageState<TYPES> {
Expand All @@ -50,6 +51,7 @@ impl<TYPES: NodeType> Default for TestStorageState<TYPES> {
proposals: BTreeMap::new(),
high_qc: None,
action: TYPES::View::genesis(),
epoch: TYPES::Epoch::genesis(),
}
}
}
Expand Down Expand Up @@ -99,6 +101,9 @@ impl<TYPES: NodeType> TestStorage<TYPES> {
pub async fn last_actioned_view(&self) -> TYPES::View {
self.inner.read().await.action
}
pub async fn last_epoch(&self) -> TYPES::Epoch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be last_actioned_epoch for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thank you!

self.inner.read().await.epoch
}
}

#[async_trait]
Expand Down
20 changes: 19 additions & 1 deletion crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ pub struct SystemContext<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versi
/// The view to enter when first starting consensus
start_view: TYPES::View,

/// The epoch to enter when first starting consensus
start_epoch: TYPES::Epoch,

/// Access to the output event stream.
output_event_stream: (Sender<Event<TYPES>>, InactiveReceiver<Event<TYPES>>),

Expand Down Expand Up @@ -168,6 +171,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> Clone
consensus: self.consensus.clone(),
instance_state: Arc::clone(&self.instance_state),
start_view: self.start_view,
start_epoch: self.start_epoch,
output_event_stream: self.output_event_stream.clone(),
external_event_stream: self.external_event_stream.clone(),
anchored_leaf: self.anchored_leaf.clone(),
Expand Down Expand Up @@ -325,6 +329,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
saved_payloads,
initializer.high_qc,
Arc::clone(&consensus_metrics),
config.epoch_height,
);

let consensus = Arc::new(RwLock::new(consensus));
Expand All @@ -341,6 +346,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
private_key,
config,
start_view: initializer.start_view,
start_epoch: initializer.start_epoch,
network,
memberships: Arc::new(memberships),
metrics: Arc::clone(&consensus_metrics),
Expand Down Expand Up @@ -371,7 +377,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
#[allow(clippy::panic)]
self.internal_event_stream
.0
.broadcast_direct(Arc::new(HotShotEvent::ViewChange(self.start_view)))
.broadcast_direct(Arc::new(HotShotEvent::ViewChange(
self.start_view,
self.start_epoch,
)))
.await
.unwrap_or_else(|_| {
panic!(
Expand Down Expand Up @@ -652,6 +661,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
storage: Arc::clone(&self.storage),
network: Arc::clone(&self.network),
memberships: Arc::clone(&self.memberships),
epoch_height: self.config.epoch_height,
};

add_network_tasks::<TYPES, I, V>(&mut handle).await;
Expand Down Expand Up @@ -765,6 +775,7 @@ where
SystemContextHandle<TYPES, I, V>,
SystemContextHandle<TYPES, I, V>,
) {
let epoch_height = config.epoch_height;
let left_system_context = SystemContext::new(
public_key.clone(),
private_key.clone(),
Expand Down Expand Up @@ -832,6 +843,7 @@ where
storage: Arc::clone(&left_system_context.storage),
network: Arc::clone(&left_system_context.network),
memberships: Arc::clone(&left_system_context.memberships),
epoch_height,
};

let mut right_handle = SystemContextHandle {
Expand All @@ -843,6 +855,7 @@ where
storage: Arc::clone(&right_system_context.storage),
network: Arc::clone(&right_system_context.network),
memberships: Arc::clone(&right_system_context.memberships),
epoch_height,
};

// add consensus tasks to each handle, using their individual internal event streams
Expand Down Expand Up @@ -977,6 +990,8 @@ pub struct HotShotInitializer<TYPES: NodeType> {

/// Starting view number that should be equivelant to the view the node shut down with last.
start_view: TYPES::View,
/// Starting epoch number that should be equivelant to the epoch the node shut down with last.
start_epoch: TYPES::Epoch,
/// The view we last performed an action in. An action is Proposing or voting for
/// Either the quorum or DA.
actioned_view: TYPES::View,
Expand Down Expand Up @@ -1010,6 +1025,7 @@ impl<TYPES: NodeType> HotShotInitializer<TYPES> {
validated_state: Some(Arc::new(validated_state)),
state_delta: Some(Arc::new(state_delta)),
start_view: TYPES::View::new(0),
start_epoch: TYPES::Epoch::new(0),
actioned_view: TYPES::View::new(0),
saved_proposals: BTreeMap::new(),
high_qc,
Expand All @@ -1033,6 +1049,7 @@ impl<TYPES: NodeType> HotShotInitializer<TYPES> {
instance_state: TYPES::InstanceState,
validated_state: Option<Arc<TYPES::ValidatedState>>,
start_view: TYPES::View,
start_epoch: TYPES::Epoch,
actioned_view: TYPES::View,
saved_proposals: BTreeMap<TYPES::View, Proposal<TYPES, QuorumProposal<TYPES>>>,
high_qc: QuorumCertificate<TYPES>,
Expand All @@ -1046,6 +1063,7 @@ impl<TYPES: NodeType> HotShotInitializer<TYPES> {
validated_state,
state_delta: None,
start_view,
start_epoch,
actioned_view,
saved_proposals,
high_qc,
Expand Down
2 changes: 2 additions & 0 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ where
storage: I::Storage,
marketplace_config: MarketplaceConfig<TYPES, I>,
) -> SystemContextHandle<TYPES, I, V> {
let epoch_height = config.epoch_height;
let hotshot = SystemContext::new(
public_key,
private_key,
Expand Down Expand Up @@ -355,6 +356,7 @@ where
storage: Arc::clone(&hotshot.storage),
network: Arc::clone(&hotshot.network),
memberships: Arc::clone(&hotshot.memberships),
epoch_height,
};

add_consensus_tasks::<TYPES, I, V>(&mut handle).await;
Expand Down
3 changes: 3 additions & 0 deletions crates/hotshot/src/tasks/task_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
id: handle.hotshot.id,
formed_upgrade_certificate: None,
upgrade_lock: handle.hotshot.upgrade_lock.clone(),
epoch_height: handle.hotshot.config.epoch_height,
}
}
}
Expand Down Expand Up @@ -298,6 +299,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
instance_state: handle.hotshot.instance_state(),
id: handle.hotshot.id,
upgrade_lock: handle.hotshot.upgrade_lock.clone(),
epoch_height: handle.hotshot.config.epoch_height,
}
}
}
Expand Down Expand Up @@ -330,6 +332,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState
last_decided_view: handle.cur_view().await,
id: handle.hotshot.id,
upgrade_lock: handle.hotshot.upgrade_lock.clone(),
epoch_height: handle.hotshot.config.epoch_height,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/hotshot/src/types/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub struct SystemContextHandle<TYPES: NodeType, I: NodeImplementation<TYPES>, V:

/// Memberships used by consensus
pub memberships: Arc<Memberships<TYPES>>,

/// Number of blocks in an epoch, zero means there are no epochs
pub epoch_height: u64,
}

impl<TYPES: NodeType, I: NodeImplementation<TYPES> + 'static, V: Versions>
Expand Down
4 changes: 4 additions & 0 deletions crates/task-impls/src/consensus/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub(crate) async fn handle_view_change<
V: Versions,
>(
new_view_number: TYPES::View,
epoch_number: TYPES::Epoch,
sender: &Sender<Arc<HotShotEvent<TYPES>>>,
task_state: &mut ConsensusTaskState<TYPES, I, V>,
) -> Result<()> {
Expand All @@ -128,6 +129,9 @@ pub(crate) async fn handle_view_change<

// Move this node to the next view
task_state.cur_view = new_view_number;
if epoch_number > task_state.cur_epoch {
task_state.cur_epoch = epoch_number;
}

// If we have a decided upgrade certificate, the protocol version may also have been upgraded.
let decided_upgrade_certificate_read = task_state
Expand Down
11 changes: 8 additions & 3 deletions crates/task-impls/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,13 @@ pub struct ConsensusTaskState<TYPES: NodeType, I: NodeImplementation<TYPES>, V:

/// Lock for a decided upgrade
pub upgrade_lock: UpgradeLock<TYPES, V>,

/// Number of blocks in an epoch, zero means there are no epochs
pub epoch_height: u64,
}
impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> ConsensusTaskState<TYPES, I, V> {
/// Handles a consensus event received on the event stream
#[instrument(skip_all, fields(id = self.id, cur_view = *self.cur_view, last_decided_view = *self.last_decided_view), name = "Consensus replica task", level = "error", target = "ConsensusTaskState")]
#[instrument(skip_all, fields(id = self.id, cur_view = *self.cur_view, cur_epoch = *self.cur_epoch, last_decided_view = *self.last_decided_view), name = "Consensus replica task", level = "error", target = "ConsensusTaskState")]
pub async fn handle(
&mut self,
event: Arc<HotShotEvent<TYPES>>,
Expand All @@ -122,8 +125,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> ConsensusTaskSt
tracing::debug!("Failed to handle TimeoutVoteRecv event; error = {e}");
}
}
HotShotEvent::ViewChange(new_view_number) => {
if let Err(e) = handle_view_change(*new_view_number, &sender, self).await {
HotShotEvent::ViewChange(new_view_number, epoch_number) => {
if let Err(e) =
handle_view_change(*new_view_number, *epoch_number, &sender, self).await
{
tracing::trace!("Failed to handle ViewChange event; error = {e}");
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct DaTaskState<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Version

impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYPES, I, V> {
/// main task event handler
#[instrument(skip_all, fields(id = self.id, view = *self.cur_view), name = "DA Main Task", level = "error", target = "DaTaskState")]
#[instrument(skip_all, fields(id = self.id, view = *self.cur_view, epoch = *self.cur_epoch), name = "DA Main Task", level = "error", target = "DaTaskState")]
pub async fn handle(
&mut self,
event: Arc<HotShotEvent<TYPES>>,
Expand Down Expand Up @@ -259,7 +259,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
)
.await?;
}
HotShotEvent::ViewChange(view) => {
HotShotEvent::ViewChange(view, epoch) => {
let view = *view;

ensure!(
Expand All @@ -271,6 +271,9 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> DaTaskState<TYP
tracing::info!("View changed by more than 1 going to view {:?}", view);
}
self.cur_view = view;
if *epoch > self.cur_epoch {
self.cur_epoch = *epoch;
}

// If we are not the next leader (DA leader for this view) immediately exit
ensure!(
Expand Down
11 changes: 7 additions & 4 deletions crates/task-impls/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub enum HotShotEvent<TYPES: NodeType> {
/// The DA leader has collected enough votes to form a DAC; emitted by the DA leader in the DA task; sent to the entire network via the networking task
DacSend(DaCertificate<TYPES>, TYPES::SignatureKey),
/// The current view has changed; emitted by the replica in the consensus task or replica in the view sync task; received by almost all other tasks
ViewChange(TYPES::View),
ViewChange(TYPES::View, TYPES::Epoch),
/// Timeout for the view sync protocol; emitted by a replica in the view sync task
ViewSyncTimeout(TYPES::View, u64, ViewSyncPhase),

Expand Down Expand Up @@ -317,7 +317,7 @@ impl<TYPES: NodeType> HotShotEvent<TYPES> {
HotShotEvent::QuorumProposalRequestSend(req, _)
| HotShotEvent::QuorumProposalRequestRecv(req, _) => Some(req.view_number),
HotShotEvent::QuorumVoteDependenciesValidated(view_number)
| HotShotEvent::ViewChange(view_number)
| HotShotEvent::ViewChange(view_number, _)
| HotShotEvent::ViewSyncTimeout(view_number, _, _)
| HotShotEvent::ViewSyncTrigger(view_number)
| HotShotEvent::Timeout(view_number)
Expand Down Expand Up @@ -415,8 +415,11 @@ impl<TYPES: NodeType> Display for HotShotEvent<TYPES> {
HotShotEvent::DacSend(cert, _) => {
write!(f, "DacSend(view_number={:?})", cert.view_number())
}
HotShotEvent::ViewChange(view_number) => {
write!(f, "ViewChange(view_number={view_number:?})")
HotShotEvent::ViewChange(view_number, epoch_number) => {
write!(
f,
"ViewChange(view_number={view_number:?}, epoch_number={epoch_number:?})"
)
}
HotShotEvent::ViewSyncTimeout(view_number, _, _) => {
write!(f, "ViewSyncTimeout(view_number={view_number:?})")
Expand Down
22 changes: 21 additions & 1 deletion crates/task-impls/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ pub async fn validate_proposal_view_and_certs<
/// Returns an [`utils::anytrace::Error`] when the new view is not greater than the current view.
pub(crate) async fn update_view<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions>(
new_view: TYPES::View,
epoch_number: TYPES::Epoch,
event_stream: &Sender<Arc<HotShotEvent<TYPES>>>,
task_state: &mut QuorumProposalRecvTaskState<TYPES, I, V>,
) -> Result<()> {
Expand All @@ -693,12 +694,15 @@ pub(crate) async fn update_view<TYPES: NodeType, I: NodeImplementation<TYPES>, V
}

task_state.cur_view = new_view;
if epoch_number > task_state.cur_epoch {
task_state.cur_epoch = epoch_number;
}

// The next view is just the current view + 1
let next_view = task_state.cur_view + 1;

futures::join! {
broadcast_event(Arc::new(HotShotEvent::ViewChange(new_view)), event_stream),
broadcast_event(Arc::new(HotShotEvent::ViewChange(new_view, epoch_number)), event_stream),
broadcast_event(
Event {
view_number: old_view,
Expand Down Expand Up @@ -768,6 +772,10 @@ pub(crate) async fn update_view<TYPES: NodeType, I: NodeImplementation<TYPES>, V
}
tracing::trace!("View updated successfully");

if let Err(e) = consensus_writer.update_epoch(epoch_number) {
tracing::trace!("{e:?}");
}

Ok(())
}

Expand Down Expand Up @@ -797,3 +805,15 @@ pub async fn broadcast_event<E: Clone + std::fmt::Debug>(event: E, sender: &Send
}
}
}

/// Returns an epoch number given a block number and an epoch height
#[must_use]
pub fn epoch_from_block_number(block_number: u64, epoch_height: u64) -> u64 {
if epoch_height == 0 {
0
} else if block_number % epoch_height == 0 {
block_number / epoch_height
} else {
block_number / epoch_height + 1
}
}
3 changes: 2 additions & 1 deletion crates/task-impls/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,9 @@ impl<
TransmitType::Direct(leader),
))
}
HotShotEvent::ViewChange(view) => {
HotShotEvent::ViewChange(view, epoch) => {
self.view = view;
self.epoch = epoch;
self.network
.update_view::<TYPES>(
self.view.u64(),
Expand Down
Loading