Skip to content

Commit

Permalink
Version gate epoch safety check (#2637)
Browse files Browse the repository at this point in the history
* Version gate epoch safety check

* Epoch safety enabled based only on proposal's view
  • Loading branch information
lukaszrzasik authored Feb 18, 2025
1 parent 15d59a6 commit e8ea153
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions hotshot-task-impls/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,14 @@ pub async fn validate_proposal_safety_and_liveness<
proposed_leaf.parent_commitment() == parent_leaf.commit(),
"Proposed leaf does not extend the parent leaf."
);
let proposal_epoch =
epoch_from_block_number(proposed_leaf.height(), validation_info.epoch_height);
let proposal_epoch = option_epoch_from_block_number::<TYPES>(
validation_info
.upgrade_lock
.epochs_enabled(proposed_leaf.view_number())
.await,
proposed_leaf.height(),
validation_info.epoch_height,
);

let state = Arc::new(
<TYPES::ValidatedState as ValidatedState<TYPES>>::from_header(proposal.data.block_header()),
Expand All @@ -614,9 +620,7 @@ pub async fn validate_proposal_safety_and_liveness<
UpgradeCertificate::validate(
proposal.data.upgrade_certificate(),
&validation_info.membership,
proposed_leaf
.with_epoch
.then(|| TYPES::Epoch::new(proposal_epoch)), // #3967 how do we know if proposal_epoch should be Some() or None?
proposal_epoch,
&validation_info.upgrade_lock,
)
.await?;
Expand All @@ -639,8 +643,14 @@ pub async fn validate_proposal_safety_and_liveness<
// The proposal is safe if
// 1. the proposed block and the justify QC block belong to the same epoch or
// 2. the justify QC is the eQC for the previous block
let justify_qc_epoch =
epoch_from_block_number(parent_leaf.height(), validation_info.epoch_height);
let justify_qc_epoch = option_epoch_from_block_number::<TYPES>(
validation_info
.upgrade_lock
.epochs_enabled(proposed_leaf.view_number())
.await,
parent_leaf.height(),
validation_info.epoch_height,
);
ensure!(
proposal_epoch == justify_qc_epoch
|| consensus_reader.check_eqc(&proposed_leaf, &parent_leaf),
Expand Down

0 comments on commit e8ea153

Please sign in to comment.