diff --git a/.github/workflows/_02_retrieve-bins.yml b/.github/workflows/_02_retrieve-bins.yml index 2562c8f491..c1dbc1b18d 100644 --- a/.github/workflows/_02_retrieve-bins.yml +++ b/.github/workflows/_02_retrieve-bins.yml @@ -51,7 +51,7 @@ jobs: ./ci/scripts/check_binary_version.sh ./chainflip-cli ${{ github.ref_name }} - name: Re-upload binary artifacts - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: chainflip-backend-bin-ubuntu-${{ matrix.ubuntu_version }} path: | @@ -64,7 +64,7 @@ jobs: generate-genesis-keys - name: Re-upload runtime artifacts - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: chainflip-node-runtime-production path: | diff --git a/.github/workflows/_20_build.yml b/.github/workflows/_20_build.yml index 5bcb9d5f08..f114306a02 100644 --- a/.github/workflows/_20_build.yml +++ b/.github/workflows/_20_build.yml @@ -46,7 +46,7 @@ jobs: sccache --show-stats - name: Upload binary artifacts - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: ${{ inputs.upload-name }}-ubuntu-${{ matrix.ubuntu_version }} path: | @@ -59,8 +59,9 @@ jobs: ./target/${{ inputs.binary-subdir }}/chainflip-ingress-egress-tracker - name: Upload runtime artifacts - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 + if: ${{ matrix.ubuntu_version == '22.04' }} # Only upload runtime once as it is the same for both versions with: - name: chainflip-node-runtime-${{ inputs.profile }}-ubuntu-${{ matrix.ubuntu_version }} + name: chainflip-node-runtime-${{ inputs.profile }} path: | ./target/${{ inputs.binary-subdir }}/wbuild/state-chain-runtime/state_chain_runtime*.wasm diff --git a/.github/workflows/_24_docker.yml b/.github/workflows/_24_docker.yml index 5037f51f24..5d0fedd2e7 100644 --- a/.github/workflows/_24_docker.yml +++ b/.github/workflows/_24_docker.yml @@ -91,7 +91,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Download binaries 📥 - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-bin-ubuntu-22.04 @@ -151,7 +151,7 @@ jobs: - name: Upload image 📤 if: inputs.save_tags != '' - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: chainflip-backend-private-images path: private @@ -176,7 +176,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Download binaries 📥 - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-bin-ubuntu-22.04 @@ -234,7 +234,7 @@ jobs: - name: Upload image 📤 if: inputs.save_tags != '' - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: chainflip-backend-public-images path: public diff --git a/.github/workflows/_25_package.yml b/.github/workflows/_25_package.yml index fea82c6a42..265c8eb93f 100644 --- a/.github/workflows/_25_package.yml +++ b/.github/workflows/_25_package.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Download binaries from same run - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-bin-ubuntu-${{ matrix.ubuntu_version }} path: ./target/release @@ -45,7 +45,7 @@ jobs: cargo deb -v --no-build --no-strip -p chainflip-lp-api --deb-revision "${{ steps.get-date.outputs.date }}" - name: Upload packages - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: chainflip-backend-packages-ubuntu-${{ matrix.ubuntu_version }} path: | diff --git a/.github/workflows/_30_publish.yml b/.github/workflows/_30_publish.yml index fad484aef6..1d7412d235 100644 --- a/.github/workflows/_30_publish.yml +++ b/.github/workflows/_30_publish.yml @@ -32,7 +32,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Download packages - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-packages-ubuntu-${{ matrix.ubuntu_version }} path: packages diff --git a/.github/workflows/_40_post_check.yml b/.github/workflows/_40_post_check.yml index 2017dcced3..c93a2916e0 100644 --- a/.github/workflows/_40_post_check.yml +++ b/.github/workflows/_40_post_check.yml @@ -57,7 +57,7 @@ jobs: npm install -g wscat - name: Download binaries 📥 - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-bin-ubuntu-22.04 @@ -129,7 +129,7 @@ jobs: - name: Upload Localnet Logs 💾 if: always() continue-on-error: true - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: localnet-logs path: | diff --git a/.github/workflows/_50_release.yml b/.github/workflows/_50_release.yml index e4ae04c087..43fa8f3030 100644 --- a/.github/workflows/_50_release.yml +++ b/.github/workflows/_50_release.yml @@ -24,7 +24,7 @@ jobs: echo "RELEASE_DIR=chainflip_${{ github.ref_name }}_ubuntu_${{ matrix.ubuntu_version }}_amd64" >> $GITHUB_ENV - name: Download binaries - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-bin-ubuntu-${{ matrix.ubuntu_version }} path: ${{ env.RELEASE_DIR }} @@ -33,7 +33,7 @@ jobs: run: tar -czf ${{ env.RELEASE_DIR }}.tar.gz ${{ env.RELEASE_DIR }} - name: Upload binaries - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: chainflip-backend-bin path: ${{ env.RELEASE_DIR }}.tar.gz @@ -47,7 +47,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Download binaries - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-bin diff --git a/.github/workflows/_60_upload.yml b/.github/workflows/_60_upload.yml index 23c39af8ec..de3cf74702 100644 --- a/.github/workflows/_60_upload.yml +++ b/.github/workflows/_60_upload.yml @@ -21,7 +21,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Download binaries - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-bin-ubuntu-22.04 path: assets/bin @@ -33,25 +33,25 @@ jobs: rm -f assets/bin/generate-genesis-keys - name: Download packages - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-packages-ubuntu-22.04 path: assets/debian - name: Download runtime - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-node-runtime-production path: assets/runtime - name: Download public images - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-public-images path: assets/docker/public - name: Download private images - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-backend-private-images path: assets/docker/private diff --git a/.github/workflows/ci-benchmarks.yml b/.github/workflows/ci-benchmarks.yml index 6c777d2f31..7ffd177f81 100644 --- a/.github/workflows/ci-benchmarks.yml +++ b/.github/workflows/ci-benchmarks.yml @@ -30,7 +30,7 @@ jobs: sccache --show-stats - name: Upload chainflip-node binary artifact with benchmarks - uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 with: name: chainflip-node-ubuntu-${{ matrix.ubuntu_version }}-benchmarks-${{ matrix.profile }} path: | @@ -49,7 +49,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - name: Download previously built binaries - uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a with: name: chainflip-node-ubuntu-${{ matrix.ubuntu_version }}-benchmarks-${{ matrix.profile }} diff --git a/.github/workflows/upgrade-test.yml b/.github/workflows/upgrade-test.yml index dc32a75a84..0d29ee77c5 100644 --- a/.github/workflows/upgrade-test.yml +++ b/.github/workflows/upgrade-test.yml @@ -118,7 +118,7 @@ jobs: uses: dawidd6/action-download-artifact@v2 with: workflow: ${{ inputs.upgrade-to-workflow-name }} - name: chainflip-node-runtime-try-runtime-ubuntu-22.04 + name: chainflip-node-runtime-try-runtime path: main-runtime commit: ${{ inputs.upgrade-to-commit }} diff --git a/Cargo.lock b/Cargo.lock index 3258d61c4b..f3f69208b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12349,6 +12349,7 @@ dependencies = [ "cf-amm", "cf-chains", "cf-primitives", + "cf-runtime-upgrade-utilities", "cf-runtime-utilities", "cf-session-benchmarking", "cf-test-utilities", diff --git a/engine/src/dot/retry_rpc.rs b/engine/src/dot/retry_rpc.rs index a6f3e57f01..f2cd23278c 100644 --- a/engine/src/dot/retry_rpc.rs +++ b/engine/src/dot/retry_rpc.rs @@ -176,7 +176,7 @@ impl DotRetryRpcApi for DotRetryRpcClient { ) -> anyhow::Result { let log = RequestLog::new( "submit_raw_encoded_extrinsic".to_string(), - Some(format!("{encoded_bytes:?}")), + Some(format!("0x{}", hex::encode(&encoded_bytes[..]))), ); self.rpc_retry_client .request_with_limit( diff --git a/engine/src/witness/dot.rs b/engine/src/witness/dot.rs index 63f46db297..002500f119 100644 --- a/engine/src/witness/dot.rs +++ b/engine/src/witness/dot.rs @@ -290,7 +290,7 @@ fn proxy_addeds( continue } - tracing::info!("Witnessing ProxyAdded. new delegatee: {delegatee:?} at block number {block_number} and extrinsic_index; {extrinsic_index}"); + tracing::info!("Witnessing ProxyAdded. new delegatee: {delegatee} at block number {block_number} and extrinsic_index; {extrinsic_index}"); extrinsic_indices.insert(extrinsic_index); } diff --git a/state-chain/pallets/cf-threshold-signature/src/lib.rs b/state-chain/pallets/cf-threshold-signature/src/lib.rs index 26ef02bb7e..0e6e763538 100644 --- a/state-chain/pallets/cf-threshold-signature/src/lib.rs +++ b/state-chain/pallets/cf-threshold-signature/src/lib.rs @@ -156,7 +156,7 @@ pub enum KeyRotationStatus, I: 'static = ()> { }, } -pub const PALLET_VERSION: StorageVersion = StorageVersion::new(4); +pub const PALLET_VERSION: StorageVersion = StorageVersion::new(5); const THRESHOLD_SIGNATURE_RESPONSE_TIMEOUT_DEFAULT: u32 = 10; const KEYGEN_CEREMONY_RESPONSE_TIMEOUT_BLOCKS_DEFAULT: u32 = 90; diff --git a/state-chain/pallets/cf-threshold-signature/src/migrations.rs b/state-chain/pallets/cf-threshold-signature/src/migrations.rs index ee03a3740f..93d38d6094 100644 --- a/state-chain/pallets/cf-threshold-signature/src/migrations.rs +++ b/state-chain/pallets/cf-threshold-signature/src/migrations.rs @@ -1,5 +1,9 @@ use crate::Pallet; +use cf_runtime_upgrade_utilities::{migration_template, VersionedMigration}; -use cf_runtime_upgrade_utilities::{migration_template::Migration, VersionedMigration}; +mod v4; -pub type PalletMigration = VersionedMigration, Migration, 3, 4>; +pub type PalletMigration = ( + VersionedMigration, v4::Migration, 4, 5>, + VersionedMigration, migration_template::Migration, 5, 6>, +); diff --git a/state-chain/pallets/cf-threshold-signature/src/migrations/v4.rs b/state-chain/pallets/cf-threshold-signature/src/migrations/v4.rs new file mode 100644 index 0000000000..dc9beb2e01 --- /dev/null +++ b/state-chain/pallets/cf-threshold-signature/src/migrations/v4.rs @@ -0,0 +1,101 @@ +use cf_traits::{Chainflip, EpochInfo}; +use frame_support::traits::OnRuntimeUpgrade; +use sp_std::marker::PhantomData; + +#[cfg(feature = "try-runtime")] +mod try_runtime_includes { + pub use codec::{Decode, DecodeLength, Encode}; + pub use frame_support::{ + ensure, pallet_prelude::DispatchError, storage, traits::PalletInfoAccess, + }; + pub use sp_std::prelude::*; +} +#[cfg(feature = "try-runtime")] +use try_runtime_includes::*; + +use crate::{CurrentKeyEpoch, KeyRotationStatus, PendingKeyRotation}; + +mod old { + use cf_primitives::EpochIndex; + use frame_support::{storage_alias, Blake2_128Concat}; + + use crate::{AggKeyFor, Config, Pallet}; + + #[storage_alias] + pub type Vaults, I: 'static> = + StorageMap, Blake2_128Concat, EpochIndex, AggKeyFor>; +} + +/// The V4 migration is partly implemented in the runtime/lib.rs +/// `ThresholdSignatureRefactorMigration` struct. +pub struct Migration(PhantomData<(T, I)>); + +impl, I: 'static> OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + log::info!("Running V4 threshold migration"); + for (k, v) in old::Vaults::::drain() { + crate::Keys::::insert(k, v); + } + CurrentKeyEpoch::::put(::EpochInfo::epoch_index()); + // Assume we don't migrate during a rotation. + PendingKeyRotation::::put(KeyRotationStatus::Complete); + Default::default() + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, DispatchError> { + // The old vault should have been moved here from the vaults pallet. + ensure!(old::Vaults::::iter().count() > 0, "Vaults should exist!"); + ensure!( + old::Vaults::::contains_key(::EpochInfo::epoch_index()), + "Current Epoch Vault should exist!" + ); + Ok(Default::default()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), DispatchError> { + // NOTE Most of the below migrations are run by the vaults pallet or in the + // ThresholdSignatureRefactorMigration in the runtime. + ensure!(crate::CeremonyIdCounter::::exists(), "CeremonyIdCounter was not migrated!"); + ensure!( + crate::KeyHandoverFailureVoters::::decode_len().is_none(), + "KeyHandoverFailureVoters should be empty!" + ); + ensure!( + crate::KeyHandoverSuccessVoters::::iter().count() == 0, + "KeyHandoverSuccessVoters should be empty!" + ); + ensure!( + crate::KeygenFailureVoters::::decode_len().is_none(), + "KeygenFailureVoters should be empty!" + ); + ensure!( + crate::KeygenSuccessVoters::::iter().count() == 0, + "KeygenSuccessVoters should be empty!" + ); + ensure!( + !crate::KeygenResolutionPendingSince::::exists(), + "KeygenResolutionPendingSince should be empty!" + ); + ensure!( + crate::KeygenResponseTimeout::::get() > 0u32.into(), + "KeygenResponseTimeout should be set!" + ); + ensure!(crate::KeygenSlashAmount::::get() > 0, "KeygenSlashAmount should be set!"); + ensure!(old::Vaults::::iter().count() == 0, "Vaults should be deleted!"); + ensure!( + !old::Vaults::::contains_key(::EpochInfo::epoch_index()), + "Current Epoch Vault should not exist!" + ); + ensure!( + CurrentKeyEpoch::::get().unwrap() == ::EpochInfo::epoch_index(), + "CurrentKeyEpoch was not migrated!" + ); + ensure!( + crate::Keys::::contains_key(::EpochInfo::epoch_index()), + "Keys were not migrated!" + ); + Ok(()) + } +} diff --git a/state-chain/pallets/cf-threshold-signature/src/mock.rs b/state-chain/pallets/cf-threshold-signature/src/mock.rs index cab66aa74c..d993b0ebd9 100644 --- a/state-chain/pallets/cf-threshold-signature/src/mock.rs +++ b/state-chain/pallets/cf-threshold-signature/src/mock.rs @@ -5,8 +5,6 @@ use crate::{ EnsureThresholdSigned, Origin, Pallet, PalletOffence, PendingCeremonies, RequestId, }; use cf_chains::{ - btc, - evm::SchnorrVerificationComponents, mocks::{MockAggKey, MockEthereumChainCrypto, MockThresholdSignature}, ChainCrypto, }; @@ -30,11 +28,6 @@ type Block = frame_system::mocking::MockBlock; pub type ValidatorId = u64; -pub const ETH_DUMMY_SIG: SchnorrVerificationComponents = - SchnorrVerificationComponents { s: [0xcf; 32], k_times_g_address: [0xcf; 20] }; - -pub const BTC_DUMMY_SIG: btc::Signature = [0xcf; 64]; - // Configure a mock runtime to test the pallet. frame_support::construct_runtime!( pub enum Test { diff --git a/state-chain/pallets/cf-vaults/src/benchmarking.rs b/state-chain/pallets/cf-vaults/src/benchmarking.rs index 3f64344d7e..f2682d40d4 100644 --- a/state-chain/pallets/cf-vaults/src/benchmarking.rs +++ b/state-chain/pallets/cf-vaults/src/benchmarking.rs @@ -19,28 +19,6 @@ mod benchmarks { use super::*; use sp_std::vec; - #[benchmark] - fn vault_key_rotated() { - let new_public_key = AggKeyFor::::benchmark_value(); - PendingVaultActivation::::put(VaultActivationStatus::::AwaitingActivation { - new_public_key, - }); - let call = Call::::vault_key_rotated { - block_number: 5u32.into(), - tx_id: Decode::decode(&mut &TX_HASH[..]).unwrap(), - }; - let origin = T::EnsureWitnessedAtCurrentEpoch::try_successful_origin().unwrap(); - - #[block] - { - assert_ok!(call.dispatch_bypass_filter(origin)); - } - - assert!(VaultStartBlockNumbers::::contains_key( - T::EpochInfo::epoch_index().saturating_add(1) - )); - } - #[benchmark] fn vault_key_rotated_externally() { let origin = T::EnsureWitnessedAtCurrentEpoch::try_successful_origin().unwrap(); @@ -65,9 +43,6 @@ mod benchmarks { #[test] fn benchmark_works() { - new_test_ext().execute_with(|| { - _vault_key_rotated::(true); - }); new_test_ext().execute_with(|| { _vault_key_rotated_externally::(true); }); diff --git a/state-chain/pallets/cf-vaults/src/lib.rs b/state-chain/pallets/cf-vaults/src/lib.rs index f87e4b3d22..f803ee34c4 100644 --- a/state-chain/pallets/cf-vaults/src/lib.rs +++ b/state-chain/pallets/cf-vaults/src/lib.rs @@ -19,6 +19,7 @@ pub use pallet::*; use sp_std::prelude::*; mod benchmarking; +pub mod migrations; mod vault_activator; @@ -27,7 +28,7 @@ pub use weights::WeightInfo; mod mock; mod tests; -pub const PALLET_VERSION: StorageVersion = StorageVersion::new(3); +pub const PALLET_VERSION: StorageVersion = StorageVersion::new(4); pub type PayloadFor = <>::Chain as ChainCrypto>::Payload; @@ -131,21 +132,6 @@ pub mod pallet { #[pallet::call] impl, I: 'static> Pallet { - /// Deprecated! This extrinsic does nothing - #[pallet::call_index(3)] - #[pallet::weight(Weight::zero())] - pub fn vault_key_rotated( - origin: OriginFor, - _block_number: ChainBlockNumberFor, - - // This field is primarily required to ensure the witness calls are unique per - // transaction (on the external chain) - _tx_id: TransactionInIdFor, - ) -> DispatchResultWithPostInfo { - T::EnsureWitnessedAtCurrentEpoch::ensure_origin(origin)?; - Ok(().into()) - } - /// The vault's key has been updated externally, outside of the rotation /// cycle. This is an unexpected event as far as our chain is concerned, and /// the only thing we can do is to halt and wait for further governance diff --git a/state-chain/pallets/cf-vaults/src/migrations.rs b/state-chain/pallets/cf-vaults/src/migrations.rs index ff045df8cb..46e7f6576b 100644 --- a/state-chain/pallets/cf-vaults/src/migrations.rs +++ b/state-chain/pallets/cf-vaults/src/migrations.rs @@ -1,5 +1,9 @@ use crate::Pallet; +use cf_runtime_upgrade_utilities::{migration_template, VersionedMigration}; -use cf_runtime_upgrade_utilities::{migration_template::Migration, VersionedMigration}; +mod v3; -pub type PalletMigration = VersionedMigration, Migration, 2, 3>; +pub type PalletMigration = ( + VersionedMigration, v3::Migration, 3, 4>, + VersionedMigration, migration_template::Migration, 4, 5>, +); diff --git a/state-chain/pallets/cf-vaults/src/migrations/v3.rs b/state-chain/pallets/cf-vaults/src/migrations/v3.rs new file mode 100644 index 0000000000..4b1f0bfa02 --- /dev/null +++ b/state-chain/pallets/cf-vaults/src/migrations/v3.rs @@ -0,0 +1,83 @@ +use frame_support::traits::OnRuntimeUpgrade; +use sp_std::marker::PhantomData; + +#[cfg(feature = "try-runtime")] +mod try_runtime_includes { + pub use codec::{Decode, DecodeLength, Encode}; + pub use frame_support::{ensure, pallet_prelude::DispatchError}; + pub use sp_std::prelude::*; +} +#[cfg(feature = "try-runtime")] +use try_runtime_includes::*; + +use crate::{PendingVaultActivation, VaultActivationStatus, VaultStartBlockNumbers}; + +mod old { + use cf_chains::{Chain, ChainCrypto}; + use cf_primitives::EpochIndex; + use codec::{Decode, Encode}; + use frame_support::{storage_alias, Blake2_128Concat}; + + use crate::{Config, Pallet}; + + /// A single vault. + #[derive(Default, PartialEq, Eq, Clone, Encode, Decode)] + pub struct Vault { + /// The vault's public key. + pub public_key: <::ChainCrypto as ChainCrypto>::AggKey, + /// The first active block for this vault + pub active_from_block: T::ChainBlockNumber, + } + + #[storage_alias] + pub type Vaults, I: 'static> = + StorageMap, Blake2_128Concat, EpochIndex, Vault<>::Chain>>; +} + +mod new { + use cf_chains::{Chain, ChainCrypto}; + use cf_primitives::EpochIndex; + use frame_support::{storage_alias, Blake2_128Concat}; + + use crate::{Config, Pallet}; + + // Temporary - should be erased after the threshols signature part of the migration. + #[storage_alias] + pub type Vaults, I: 'static> = StorageMap< + Pallet, + Blake2_128Concat, + EpochIndex, + <<>::Chain as Chain>::ChainCrypto as ChainCrypto>::AggKey, + >; +} + +/// The V3 migration is partly implemented in the runtime/lib.rs +/// `ThresholdSignatureRefactorMigration` struct. +pub struct Migration(PhantomData<(T, I)>); + +impl, I: 'static> OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + PendingVaultActivation::::put(VaultActivationStatus::Complete); + // We don't drain the old storage, it's required for the other part of the migration + // (threhsold signer pallet). + + for (epoch_index, old::Vault { active_from_block, .. }) in old::Vaults::::iter() { + VaultStartBlockNumbers::::insert(epoch_index, active_from_block); + } + new::Vaults::::translate::, _>(|_, old_vault| { + Some(old_vault.public_key) + }); + + Default::default() + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, DispatchError> { + Ok(Default::default()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), DispatchError> { + Ok(()) + } +} diff --git a/state-chain/runtime-upgrade-utilities/src/helper_functions.rs b/state-chain/runtime-upgrade-utilities/src/helper_functions.rs index 0ac4f32ed0..e65b50dfe9 100644 --- a/state-chain/runtime-upgrade-utilities/src/helper_functions.rs +++ b/state-chain/runtime-upgrade-utilities/src/helper_functions.rs @@ -1,18 +1,12 @@ -use frame_support::storage::{storage_prefix, unhashed}; +use frame_support::{migration::move_storage_from_pallet, traits::PalletInfoAccess}; -/// Not to be confused with [move_prefix]. This function move the storage identified by the given -/// pallet and storage names. -pub fn move_storage( - old_pallet_name: &[u8], - old_storage_name: &[u8], - new_pallet_name: &[u8], - new_storage_name: &[u8], -) { - let new_prefix = storage_prefix(new_pallet_name, new_storage_name); - let old_prefix = storage_prefix(old_pallet_name, old_storage_name); - - if let Some(value) = unhashed::get_raw(&old_prefix) { - unhashed::put_raw(&new_prefix, &value); - unhashed::kill(&old_prefix); - } +/// Move storage between pallets. +pub fn move_pallet_storage(storage_name: &[u8]) { + log::info!( + "⏫ Moving storage {} from {} to {}.", + sp_std::str::from_utf8(storage_name).expect("storage names are all valid utf8"), + From::name(), + To::name(), + ); + move_storage_from_pallet(storage_name, From::name().as_bytes(), To::name().as_bytes()); } diff --git a/state-chain/runtime/Cargo.toml b/state-chain/runtime/Cargo.toml index 086a398d68..a3987219fc 100644 --- a/state-chain/runtime/Cargo.toml +++ b/state-chain/runtime/Cargo.toml @@ -29,6 +29,7 @@ cf-chains = { path = '../chains', default-features = false } cf-primitives = { path = '../primitives', default-features = false } cf-session-benchmarking = { path = '../cf-session-benchmarking', optional = true, default-features = false } cf-runtime-utilities = { path = '../runtime-utilities', default-features = false } +cf-runtime-upgrade-utilities = { path = '../runtime-upgrade-utilities', default-features = false } cf-traits = { path = '../traits', default-features = false } cf-utilities = { package = 'utilities', path = '../../utilities', default-features = false } @@ -141,6 +142,7 @@ std = [ 'cf-chains/std', 'cf-primitives/std', 'cf-runtime-utilities/std', + 'cf-runtime-upgrade-utilities/std', 'cf-traits/std', 'cf-utilities/std', 'codec/std', @@ -199,6 +201,7 @@ std = [ 'dep:cf-test-utilities', ] try-runtime = [ + 'cf-runtime-upgrade-utilities/try-runtime', 'frame-executive/try-runtime', 'frame-try-runtime/try-runtime', 'frame-system/try-runtime', diff --git a/state-chain/runtime/src/lib.rs b/state-chain/runtime/src/lib.rs index a2874e142c..b451c26623 100644 --- a/state-chain/runtime/src/lib.rs +++ b/state-chain/runtime/src/lib.rs @@ -161,7 +161,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("chainflip-node"), impl_name: create_runtime_str!("chainflip-node"), authoring_version: 1, - spec_version: 120, + spec_version: 130, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 12, @@ -889,12 +889,14 @@ type PalletMigrations = ( pallet_cf_chain_tracking::migrations::PalletMigration, pallet_cf_chain_tracking::migrations::PalletMigration, pallet_cf_chain_tracking::migrations::PalletMigration, - // pallet_cf_vaults::migrations::PalletMigration, - // pallet_cf_vaults::migrations::PalletMigration, - // pallet_cf_vaults::migrations::PalletMigration, - // pallet_cf_threshold_signature::migrations::PalletMigration, - // pallet_cf_threshold_signature::migrations::PalletMigration, - // pallet_cf_threshold_signature::migrations::PalletMigration, + pallet_cf_vaults::migrations::PalletMigration, + pallet_cf_vaults::migrations::PalletMigration, + pallet_cf_vaults::migrations::PalletMigration, + // TODO: Remove this after version 1.3 release. + ThresholdSignatureRefactorMigration, + pallet_cf_threshold_signature::migrations::PalletMigration, + pallet_cf_threshold_signature::migrations::PalletMigration, + pallet_cf_threshold_signature::migrations::PalletMigration, pallet_cf_broadcast::migrations::PalletMigration, pallet_cf_broadcast::migrations::PalletMigration, pallet_cf_broadcast::migrations::PalletMigration, @@ -906,6 +908,51 @@ type PalletMigrations = ( // pallet_cf_pools::migrations::PalletMigration, ); +pub struct ThresholdSignatureRefactorMigration; + +mod threshold_signature_refactor_migration { + use super::Runtime; + use cf_runtime_upgrade_utilities::move_pallet_storage; + use frame_support::traits::GetStorageVersion; + + pub fn migrate_instance() + where + Runtime: pallet_cf_threshold_signature::Config, + Runtime: pallet_cf_vaults::Config, + { + // The migration needs to be run *after* the vaults pallet migration (3 -> 4) and *before* + // the threshold signer pallet migration (4 -> 5). + if as GetStorageVersion>::on_chain_storage_version() == 4 && + as GetStorageVersion>::on_chain_storage_version() == 4 { + + log::info!("✅ Applying threshold signature refactor storage migration."); + for storage_name in [ + "CeremonyIdCounter", + "KeygenSlashAmount", + "Vaults", + ] { + move_pallet_storage::< + pallet_cf_vaults::Pallet, + pallet_cf_threshold_signature::Pallet, + >(storage_name.as_bytes()); + } + } else { + log::info!("⏭ Skipping threshold signature refactor migration."); + } + } +} + +impl frame_support::traits::OnRuntimeUpgrade for ThresholdSignatureRefactorMigration { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + log::info!("⏫ Applying threshold signature refactor storage migration."); + threshold_signature_refactor_migration::migrate_instance::(); + threshold_signature_refactor_migration::migrate_instance::(); + threshold_signature_refactor_migration::migrate_instance::(); + + Default::default() + } +} + #[cfg(feature = "runtime-benchmarks")] #[macro_use] extern crate frame_benchmarking;