Skip to content

Commit

Permalink
Merge pull request #2938 from subspace/trigger-epoch-by-new-block
Browse files Browse the repository at this point in the history
Use the head domain number to trigger epoch transition instead of confirmed domain block
  • Loading branch information
NingLin-P committed Jul 24, 2024
2 parents 600d582 + 3210b44 commit 13ec565
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,23 +1120,6 @@ mod pallet {
SlashedReason::InvalidBundle(confirmed_block_info.domain_block_number),
)
.map_err(Error::<T>::from)?;

if confirmed_block_info.domain_block_number % T::StakeEpochDuration::get()
== Zero::zero()
{
let epoch_transition_res =
do_finalize_domain_current_epoch::<T>(domain_id)
.map_err(Error::<T>::from)?;

Self::deposit_event(Event::DomainEpochCompleted {
domain_id,
completed_epoch_index: epoch_transition_res.completed_epoch_index,
});

actual_weight = actual_weight.saturating_add(
Self::actual_epoch_transition_weight(epoch_transition_res),
);
}
}
}
}
Expand All @@ -1159,6 +1142,22 @@ mod pallet {
.ok_or::<Error<T>>(BlockTreeError::MaxHeadDomainNumber.into())?
.checked_add(&missed_upgrade.into())
.ok_or::<Error<T>>(BlockTreeError::MaxHeadDomainNumber.into())?;

// Trigger epoch transition if any at the first bundle in the block
#[cfg(not(feature = "runtime-benchmarks"))]
if next_number % T::StakeEpochDuration::get() == Zero::zero() {
let epoch_transition_res = do_finalize_domain_current_epoch::<T>(domain_id)
.map_err(Error::<T>::from)?;

Self::deposit_event(Event::DomainEpochCompleted {
domain_id,
completed_epoch_index: epoch_transition_res.completed_epoch_index,
});

actual_weight = actual_weight
.saturating_add(Self::actual_epoch_transition_weight(epoch_transition_res));
}

HeadDomainNumber::<T>::set(domain_id, next_number);
}

Expand Down

0 comments on commit 13ec565

Please sign in to comment.