mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Fix an off-by-one: revert rather than revert-to (#3991)
* fix off-by-one in disputes reversion code * bump Rococo spec version
This commit is contained in:
committed by
GitHub
parent
44e9482596
commit
547d166f20
@@ -109,4 +109,5 @@ Frozen: Option<BlockNumber>,
|
|||||||
|
|
||||||
* `revert_and_freeze(BlockNumber)`:
|
* `revert_and_freeze(BlockNumber)`:
|
||||||
1. If `is_frozen()` return.
|
1. If `is_frozen()` return.
|
||||||
1. Set `Frozen` to `Some(BlockNumber)` to indicate a rollback to the given block number is necessary.
|
1. Set `Frozen` to `Some(BlockNumber)` to indicate a rollback to the block number.
|
||||||
|
1. Issue a `Revert(BlockNumber + 1)` log to indicate a rollback of the block's child in the header chain, which is the same as a rollback to the block number.
|
||||||
|
|||||||
@@ -304,8 +304,8 @@ pub mod pallet {
|
|||||||
DisputeTimedOut(CandidateHash),
|
DisputeTimedOut(CandidateHash),
|
||||||
/// A dispute has concluded with supermajority against a candidate.
|
/// A dispute has concluded with supermajority against a candidate.
|
||||||
/// Block authors should no longer build on top of this head and should
|
/// Block authors should no longer build on top of this head and should
|
||||||
/// instead revert to the block at the given height which is the last
|
/// instead revert the block at the given height. This should be the
|
||||||
/// known valid block in this chain.
|
/// number of the child of the last known valid block in the chain.
|
||||||
Revert(T::BlockNumber),
|
Revert(T::BlockNumber),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1127,9 +1127,14 @@ impl<T: Config> Pallet<T> {
|
|||||||
pub(crate) fn revert_and_freeze(revert_to: T::BlockNumber) {
|
pub(crate) fn revert_and_freeze(revert_to: T::BlockNumber) {
|
||||||
if Self::last_valid_block().map_or(true, |last| last > revert_to) {
|
if Self::last_valid_block().map_or(true, |last| last > revert_to) {
|
||||||
Frozen::<T>::set(Some(revert_to));
|
Frozen::<T>::set(Some(revert_to));
|
||||||
Self::deposit_event(Event::Revert(revert_to));
|
|
||||||
|
// The `Revert` log is about reverting a block, not reverting to a block.
|
||||||
|
// If we want to revert to block X in the current chain, we need to revert
|
||||||
|
// block X+1.
|
||||||
|
let revert = revert_to + One::one();
|
||||||
|
Self::deposit_event(Event::Revert(revert));
|
||||||
frame_system::Pallet::<T>::deposit_log(
|
frame_system::Pallet::<T>::deposit_log(
|
||||||
ConsensusLog::Revert(revert_to.saturated_into()).into(),
|
ConsensusLog::Revert(revert.saturated_into()).into(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2284,8 +2289,8 @@ mod tests {
|
|||||||
Pallet::<Test>::revert_and_freeze(0);
|
Pallet::<Test>::revert_and_freeze(0);
|
||||||
|
|
||||||
assert_eq!(Frozen::<Test>::get(), Some(0));
|
assert_eq!(Frozen::<Test>::get(), Some(0));
|
||||||
assert_eq!(System::digest().logs[0], ConsensusLog::Revert(0).into());
|
assert_eq!(System::digest().logs[0], ConsensusLog::Revert(1).into());
|
||||||
System::assert_has_event(Event::Revert(0).into());
|
System::assert_has_event(Event::Revert(1).into());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
|||||||
spec_name: create_runtime_str!("rococo"),
|
spec_name: create_runtime_str!("rococo"),
|
||||||
impl_name: create_runtime_str!("parity-rococo-v1.8"),
|
impl_name: create_runtime_str!("parity-rococo-v1.8"),
|
||||||
authoring_version: 0,
|
authoring_version: 0,
|
||||||
spec_version: 9103,
|
spec_version: 9104,
|
||||||
impl_version: 0,
|
impl_version: 0,
|
||||||
#[cfg(not(feature = "disable-runtime-api"))]
|
#[cfg(not(feature = "disable-runtime-api"))]
|
||||||
apis: RUNTIME_API_VERSIONS,
|
apis: RUNTIME_API_VERSIONS,
|
||||||
|
|||||||
Reference in New Issue
Block a user