-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: add initiated_at block number for egresses #4046
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub mod add_initiated_at; | ||
|
||
use cf_runtime_upgrade_utilities::VersionedMigration; | ||
|
||
pub type PalletMigration<T, I> = | ||
(VersionedMigration<crate::Pallet<T, I>, add_initiated_at::Migration<T, I>, 0, 1>,); |
53 changes: 53 additions & 0 deletions
53
state-chain/pallets/cf-broadcast/src/migrations/add_initiated_at.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use crate::*; | ||
#[cfg(feature = "try-runtime")] | ||
use frame_support::dispatch::DispatchError; | ||
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight}; | ||
use sp_std::marker::PhantomData; | ||
|
||
mod old { | ||
use frame_support::pallet_prelude::OptionQuery; | ||
|
||
use super::*; | ||
|
||
#[frame_support::storage_alias] | ||
pub type TransactionOutIdToBroadcastId<T: Config<I>, I: 'static> = | ||
StorageMap<Pallet<T, I>, Twox64Concat, TransactionOutIdFor<T, I>, BroadcastId, OptionQuery>; | ||
} | ||
|
||
pub struct Migration<T: Config<I>, I: 'static>(PhantomData<(T, I)>); | ||
|
||
impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Migration<T, I> { | ||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
let chain_height = T::ChainTracking::get_block_height(); | ||
|
||
TransactionOutIdToBroadcastId::<T, I>::translate::<BroadcastId, _>(|_id, old| { | ||
Some((old, chain_height)) | ||
}); | ||
|
||
Weight::zero() | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> { | ||
use frame_support::ensure; | ||
|
||
let chain_height = T::ChainTracking::get_block_height(); | ||
// If it's at 0 something went wrong with the initialisation. Also since initiated_at is the | ||
// last thing being decoded, this acts as a check that the rest of the decoding worked. | ||
ensure!(chain_height > 0u32.into(), "chain_height is 0"); | ||
Ok(chain_height.encode()) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> { | ||
use frame_support::ensure; | ||
|
||
let pre_upgrade_height = ChainBlockNumberFor::<T, I>::decode(&mut &state[..]) | ||
.map_err(|_| "Failed to decode pre-upgrade state.")?; | ||
|
||
for (_out_id, (_b_id, initiated_at)) in TransactionOutIdToBroadcastId::<T, I>::iter() { | ||
ensure!(initiated_at >= pre_upgrade_height, "initiated_at is 0"); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: we should consider adding ChainTracking to the Chainflip trait - it's getting its tentacles in everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made me think that maybe it makes sense to merge the broadcast and ingress-egress pallet actually... after all, the broadcast is egressing transactions... something we can think about anyway.