Skip to content

Commit

Permalink
prevent upgrade if we are using a nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellorigotti committed Sep 25, 2024
1 parent 36cd3bb commit c07cc38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions state-chain/pallets/cf-environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use cf_primitives::{
NetworkEnvironment, SemVer,
};
use cf_traits::{
CompatibleCfeVersions, GetBitcoinFeeInfo, KeyProvider, NetworkEnvironmentProvider, SafeMode,
SolanaNonceWatch,
CompatibleCfeVersions, ExecutionCondition, GetBitcoinFeeInfo, KeyProvider,
NetworkEnvironmentProvider, SafeMode, SolanaNonceWatch,
};
use frame_support::{pallet_prelude::*, traits::StorageVersion};
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -752,3 +752,11 @@ impl<T: Config> NetworkEnvironmentProvider for Pallet<T> {
Self::network_environment()
}
}

pub struct NoUsedNonce<T: Config>(PhantomData<T>);

impl<T: Config> ExecutionCondition for NoUsedNonce<T> {
fn is_satisfied() -> bool {
SolanaAvailableNonceAccounts::<T>::get().len() == 10
}
}
1 change: 1 addition & 0 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ impl pallet_cf_governance::Config for Runtime {
type UpgradeCondition = (
pallet_cf_validator::NotDuringRotation<Runtime>,
pallet_cf_swapping::NoPendingSwaps<Runtime>,
pallet_cf_environment::NoUsedNonce<Runtime>,
);
type RuntimeUpgrade = chainflip::RuntimeUpgradeManager;
type CompatibleCfeVersions = Environment;
Expand Down
5 changes: 3 additions & 2 deletions state-chain/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,14 @@ pub trait ExecutionCondition {
fn is_satisfied() -> bool;
}

impl<A, B> ExecutionCondition for (A, B)
impl<A, B, C> ExecutionCondition for (A, B, C)
where
A: ExecutionCondition,
B: ExecutionCondition,
C: ExecutionCondition,
{
fn is_satisfied() -> bool {
A::is_satisfied() && B::is_satisfied()
A::is_satisfied() && B::is_satisfied() && C::is_satisfied()
}
}

Expand Down

0 comments on commit c07cc38

Please sign in to comment.