diff --git a/state-chain/chains/src/dot.rs b/state-chain/chains/src/dot.rs index 26c1cdd93e2..7ddedda44d5 100644 --- a/state-chain/chains/src/dot.rs +++ b/state-chain/chains/src/dot.rs @@ -267,10 +267,12 @@ impl Chain for Polkadot { type DepositChannelState = PolkadotChannelState; type DepositDetails = (); type Transaction = PolkadotTransactionData; - type ReplayProtectionParams = (); + type ReplayProtectionParams = ResetProxyAccountNonce; type ReplayProtection = PolkadotReplayProtection; } +pub type ResetProxyAccountNonce = bool; + #[derive(Clone, Encode, Decode, MaxEncodedLen, TypeInfo, Debug, PartialEq, Eq, Default)] pub struct PolkadotChannelState; diff --git a/state-chain/chains/src/dot/api.rs b/state-chain/chains/src/dot/api.rs index de5173a7374..8ce5b46bd50 100644 --- a/state-chain/chains/src/dot/api.rs +++ b/state-chain/chains/src/dot/api.rs @@ -66,7 +66,7 @@ where transfer_params: Vec>, ) -> Result { Ok(Self::BatchFetchAndTransfer(batch_fetch_and_transfer::extrinsic_builder( - E::replay_protection(()), + E::replay_protection(false), fetch_params, transfer_params, E::try_vault_account().ok_or(AllBatchError::Other)?, @@ -85,7 +85,7 @@ where let vault = E::try_vault_account().ok_or(())?; Ok(Self::ChangeGovKey(rotate_vault_proxy::extrinsic_builder( - E::replay_protection(()), + E::replay_protection(false), maybe_old_key, new_key, vault, @@ -104,7 +104,8 @@ where let vault = E::try_vault_account().ok_or(SetAggKeyWithAggKeyError::Failed)?; Ok(Self::RotateVaultProxy(rotate_vault_proxy::extrinsic_builder( - E::replay_protection(()), + // we reset the proxy account nonce on a rotation tx + E::replay_protection(true), maybe_old_key, new_key, vault, diff --git a/state-chain/pallets/cf-environment/src/lib.rs b/state-chain/pallets/cf-environment/src/lib.rs index 9fe556e7292..7feedffaa9b 100644 --- a/state-chain/pallets/cf-environment/src/lib.rs +++ b/state-chain/pallets/cf-environment/src/lib.rs @@ -387,15 +387,17 @@ impl Pallet { }) } - pub fn next_polkadot_proxy_account_nonce() -> PolkadotIndex { + pub fn next_polkadot_proxy_account_nonce(reset_nonce: bool) -> PolkadotIndex { PolkadotProxyAccountNonce::::mutate(|nonce| { - *nonce += 1; - *nonce - 1 - }) - } + let current_nonce = *nonce; - pub fn reset_polkadot_proxy_account_nonce() { - PolkadotProxyAccountNonce::::set(0); + if reset_nonce { + *nonce = 0; + } else { + *nonce += 1; + } + current_nonce + }) } pub fn add_bitcoin_utxo_to_list( diff --git a/state-chain/pallets/cf-vaults/src/lib.rs b/state-chain/pallets/cf-vaults/src/lib.rs index 5ef4649c508..4b153a60e81 100644 --- a/state-chain/pallets/cf-vaults/src/lib.rs +++ b/state-chain/pallets/cf-vaults/src/lib.rs @@ -9,7 +9,7 @@ use cf_traits::{ impl_pallet_safe_mode, offence_reporting::OffenceReporter, AccountRoleRegistry, AsyncResult, Broadcaster, Chainflip, CurrentEpochIndex, EpochKey, GetBlockHeight, KeyProvider, KeyState, SafeMode, SetSafeMode, Slashing, ThresholdSigner, VaultKeyWitnessedHandler, VaultRotator, - VaultStatus, VaultTransitionHandler, + VaultStatus, }; use frame_support::{ pallet_prelude::*, @@ -174,8 +174,6 @@ pub mod pallet { <>::Chain as Chain>::ChainCrypto, >; - type VaultTransitionHandler: VaultTransitionHandler; - /// The pallet dispatches calls, so it depends on the runtime's aggregated Call type. type RuntimeCall: From> + IsType<::RuntimeCall>; @@ -954,7 +952,6 @@ impl, I: 'static> Pallet { active_from_block: block_number.saturating_add(One::one()), }, ); - T::VaultTransitionHandler::on_new_vault(); Self::deposit_event(Event::VaultRotationCompleted); } } diff --git a/state-chain/pallets/cf-vaults/src/mock.rs b/state-chain/pallets/cf-vaults/src/mock.rs index 8436a54e609..f68917ef24c 100644 --- a/state-chain/pallets/cf-vaults/src/mock.rs +++ b/state-chain/pallets/cf-vaults/src/mock.rs @@ -133,11 +133,6 @@ impl ApiCall for MockSetAggKeyWithAggKey { } } -pub struct MockVaultTransitionHandler; -impl VaultTransitionHandler for MockVaultTransitionHandler { - fn on_new_vault() {} -} - pub struct MockBroadcaster; impl MockBroadcaster { @@ -214,7 +209,6 @@ impl pallet_cf_vaults::Config for Test { type ThresholdSigner = MockThresholdSigner; type OffenceReporter = MockOffenceReporter; type SetAggKeyWithAggKey = MockSetAggKeyWithAggKey; - type VaultTransitionHandler = MockVaultTransitionHandler; type WeightInfo = (); type Broadcaster = MockBroadcaster; type SafeMode = MockRuntimeSafeMode; diff --git a/state-chain/runtime/src/chainflip.rs b/state-chain/runtime/src/chainflip.rs index 5804088bbbb..979e709a695 100644 --- a/state-chain/runtime/src/chainflip.rs +++ b/state-chain/runtime/src/chainflip.rs @@ -26,7 +26,7 @@ use cf_chains::{ }, dot::{ api::PolkadotApi, Polkadot, PolkadotAccountId, PolkadotCrypto, PolkadotReplayProtection, - PolkadotTransactionData, RuntimeVersion, + PolkadotTransactionData, ResetProxyAccountNonce, RuntimeVersion, }, eth::{ self, @@ -47,7 +47,6 @@ use cf_traits::{ AccountRoleRegistry, BlockEmissions, BroadcastAnyChainGovKey, Broadcaster, Chainflip, CommKeyBroadcaster, DepositApi, DepositHandler, EgressApi, EpochInfo, Heartbeat, Issuance, KeyProvider, OnBroadcastReady, QualifyNode, RewardsDistribution, RuntimeUpgrade, - VaultTransitionHandler, }; use codec::{Decode, Encode}; use frame_support::{ @@ -330,10 +329,10 @@ pub struct DotEnvironment; impl ReplayProtectionProvider for DotEnvironment { // Get the Environment values for vault_account, NetworkChoice and the next nonce for the // proxy_account - fn replay_protection(_params: ()) -> PolkadotReplayProtection { + fn replay_protection(reset_nonce: ResetProxyAccountNonce) -> PolkadotReplayProtection { PolkadotReplayProtection { genesis_hash: Environment::polkadot_genesis_hash(), - nonce: Environment::next_polkadot_proxy_account_nonce(), + nonce: Environment::next_polkadot_proxy_account_nonce(reset_nonce), } } } @@ -376,18 +375,6 @@ impl ChainEnvironment<(), cf_chains::btc::AggKey> for BtcEnvironment { } } -pub struct EthVaultTransitionHandler; -impl VaultTransitionHandler for EthVaultTransitionHandler {} - -pub struct DotVaultTransitionHandler; -impl VaultTransitionHandler for DotVaultTransitionHandler { - fn on_new_vault() { - Environment::reset_polkadot_proxy_account_nonce(); - } -} -pub struct BtcVaultTransitionHandler; -impl VaultTransitionHandler for BtcVaultTransitionHandler {} - pub struct TokenholderGovernanceBroadcaster; impl TokenholderGovernanceBroadcaster { diff --git a/state-chain/runtime/src/lib.rs b/state-chain/runtime/src/lib.rs index 79ca0f2106b..da10cbad2f6 100644 --- a/state-chain/runtime/src/lib.rs +++ b/state-chain/runtime/src/lib.rs @@ -86,9 +86,8 @@ pub use cf_traits::{EpochInfo, QualifyNode, SessionKeysRegistered, SwappingApi}; pub use chainflip::chain_instances::*; use chainflip::{ all_vaults_rotator::AllVaultRotator, epoch_transition::ChainflipEpochTransitions, - BroadcastReadyProvider, BtcEnvironment, BtcVaultTransitionHandler, ChainAddressConverter, - ChainflipHeartbeat, DotEnvironment, DotVaultTransitionHandler, EthEnvironment, - EthVaultTransitionHandler, TokenholderGovernanceBroadcaster, + BroadcastReadyProvider, BtcEnvironment, ChainAddressConverter, ChainflipHeartbeat, + DotEnvironment, EthEnvironment, TokenholderGovernanceBroadcaster, }; use safe_mode::{RuntimeSafeMode, WitnesserCallPermission}; @@ -241,7 +240,6 @@ impl pallet_cf_vaults::Config for Runtime { type Offence = chainflip::Offence; type Chain = Ethereum; type SetAggKeyWithAggKey = eth::api::EthereumApi; - type VaultTransitionHandler = EthVaultTransitionHandler; type Broadcaster = EthereumBroadcaster; type OffenceReporter = Reputation; type WeightInfo = pallet_cf_vaults::weights::PalletWeight; @@ -259,7 +257,6 @@ impl pallet_cf_vaults::Config for Runtime { type Offence = chainflip::Offence; type Chain = Polkadot; type SetAggKeyWithAggKey = dot::api::PolkadotApi; - type VaultTransitionHandler = DotVaultTransitionHandler; type Broadcaster = PolkadotBroadcaster; type OffenceReporter = Reputation; type WeightInfo = pallet_cf_vaults::weights::PalletWeight; @@ -277,7 +274,6 @@ impl pallet_cf_vaults::Config for Runtime { type Offence = chainflip::Offence; type Chain = Bitcoin; type SetAggKeyWithAggKey = cf_chains::btc::api::BitcoinApi; - type VaultTransitionHandler = BtcVaultTransitionHandler; type Broadcaster = BitcoinBroadcaster; type OffenceReporter = Reputation; type WeightInfo = pallet_cf_vaults::weights::PalletWeight; diff --git a/state-chain/traits/src/lib.rs b/state-chain/traits/src/lib.rs index 02f53997b55..03beee6c858 100644 --- a/state-chain/traits/src/lib.rs +++ b/state-chain/traits/src/lib.rs @@ -725,9 +725,6 @@ impl EgressApi for T { } } -pub trait VaultTransitionHandler { - fn on_new_vault() {} -} pub trait VaultKeyWitnessedHandler { fn on_new_key_activated(block_number: C::ChainBlockNumber) -> DispatchResultWithPostInfo; }