Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ tree --no-default-features --depth 1 --edges=features,normal
# - RUSTSEC-2023-0091: Low severity, difficult to exploit of wasmtime, dependency of substrate.
# - RUSTSEC-2024-0438: Wasmtime security issue for Windows devices, so not applicable. Dependency of substrate.
# - RUSTSEC-2024-0442: Wasmtime jit debugger issue.
# - RUSTSEC-2025-0057: fxhash is unmaintained, but we can't remove it because it's used in substrate.
cf-audit = '''
audit -D unmaintained -D unsound
--ignore RUSTSEC-2021-0139
Expand All @@ -72,6 +73,7 @@ audit -D unmaintained -D unsound
--ignore RUSTSEC-2023-0091
--ignore RUSTSEC-2024-0438
--ignore RUSTSEC-2024-0442
--ignore RUSTSEC-2025-0057
'''

[build]
Expand Down
1 change: 1 addition & 0 deletions bouncer/shared/try_runtime_upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async function tryRuntimeCommand(
--runtime ${runtimePath} on-runtime-upgrade \
--blocktime 6000 \
--disable-spec-version-check \
--disable-mbm-checks \
--checks all ${blockParam} \
--uri ${networkUrl}`.split(' '),
`try-runtime-${blockHash}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for VoteStorageMigration<T, I> {
// this will cause the validator to re-vote for the same elections again,
// which is fine since the worst it can happen is some delayed consensus which is fine since
// we are in safe mode
SharedDataReferenceCount::<T, I>::drain();
SharedData::<T, I>::drain();
BitmapComponents::<T, I>::drain();
IndividualComponents::<T, I>::drain();
ElectionConsensusHistory::<T, I>::drain();
ElectionConsensusHistoryUpToDate::<T, I>::drain();
let _ = SharedDataReferenceCount::<T, I>::clear(u32::MAX, None);
let _ = SharedData::<T, I>::clear(u32::MAX, None);
let _ = BitmapComponents::<T, I>::clear(u32::MAX, None);
let _ = IndividualComponents::<T, I>::clear(u32::MAX, None);
let _ = ElectionConsensusHistory::<T, I>::clear(u32::MAX, None);
let _ = ElectionConsensusHistoryUpToDate::<T, I>::clear(u32::MAX, None);

Weight::zero()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ impl<T> UncheckedOnRuntimeUpgrade for Migration<T>
where
T: Config,
{
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, frame_support::pallet_prelude::DispatchError> {
assert!(old::BackupNodeEmissionInflation::<T>::exists());
assert!(old::BackupNodeEmissionPerBlock::<T>::exists());
Ok(Default::default())
}

fn on_runtime_upgrade() -> frame_support::pallet_prelude::Weight {
old::BackupNodeEmissionInflation::<T>::kill();
old::BackupNodeEmissionPerBlock::<T>::kill();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,7 @@ impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for ChannelActionCcmRef
log::info!("🍩 Running migration for Ingress-Egress pallet: Updating Refund Parameters.");
crate::DepositChannelLookup::<T, I>::translate_values::<old::DepositChannelDetails<T, I>, _>(
|old| {
match old.action.clone() {
old::ChannelAction::Swap { refund_params, .. } =>
// Convert Refund param into Checked version.
Some(ChannelRefundParametersCheckedInternal {
retry_duration: refund_params.retry_duration,
refund_address: AccountOrAddress::ExternalAddress(
refund_params.refund_address,
),
min_price: refund_params.min_price,
refund_ccm_metadata: None,
max_oracle_price_slippage: None,
}),
_ => None,
}
.map(|checked_refund_params| DepositChannelDetails {
Some(DepositChannelDetails {
owner: old.owner,
deposit_channel: old.deposit_channel,
opened_at: old.opened_at,
Expand All @@ -119,14 +105,22 @@ impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for ChannelActionCcmRef
destination_address,
broker_fees,
channel_metadata,
refund_params: _,
refund_params,
dca_params,
} => ChannelAction::Swap {
destination_asset,
destination_address: destination_address.clone(),
broker_fees,
channel_metadata,
refund_params: checked_refund_params,
refund_params: ChannelRefundParametersCheckedInternal {
retry_duration: refund_params.retry_duration,
refund_address: AccountOrAddress::ExternalAddress(
refund_params.refund_address,
),
min_price: refund_params.min_price,
refund_ccm_metadata: None,
max_oracle_price_slippage: None,
},
dca_params,
},
old::ChannelAction::LiquidityProvision { lp_account, refund_address } =>
Expand Down Expand Up @@ -156,7 +150,14 @@ impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for ChannelActionCcmRef

let post_deposit_channels =
DepositChannelLookup::<T, I>::iter_keys().collect::<BTreeSet<_>>();
assert_eq!(pre_deposit_channels, post_deposit_channels);
assert_eq!(
pre_deposit_channels,
post_deposit_channels,
"Deposit channels should remain the same after migration. Diff: {:?}",
pre_deposit_channels
.symmetric_difference(&post_deposit_channels)
.collect::<Vec<_>>()
);

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
// SPDX-License-Identifier: Apache-2.0

use cf_primitives::Price;
use frame_support::traits::UncheckedOnRuntimeUpgrade;

use crate::Config;
Expand All @@ -29,21 +30,38 @@ pub mod old {
use super::*;

#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct Swap<T: Config> {
pub enum FeeType<AccountId> {
NetworkFee(NetworkFeeTracker),
BrokerFee(Beneficiaries<AccountId>),
}
Comment on lines +33 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this shouldn't be necessary, so I'm curious why it was?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not necessary in the end, but I wanted to narrow down the issue so I defined everything explicitly without referring to type params indirectly via <T: Config>.


#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct SwapRefundParameters {
pub refund_block: cf_primitives::BlockNumber,
pub min_output: cf_primitives::AssetAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct Swap<AccountId> {
pub swap_id: SwapId,
pub swap_request_id: SwapRequestId,
pub from: Asset,
pub to: Asset,
pub input_amount: AssetAmount,
pub fees: Vec<FeeType<T>>,
pub fees: Vec<FeeType<AccountId>>,
pub refund_params: Option<SwapRefundParameters>,
// Migration is adding an execute_at field here
}

#[frame_support::storage_alias]
// Migration is also renaming this storage item to ScheduledSwaps
pub type SwapQueue<T: Config> =
StorageMap<Pallet<T>, Twox64Concat, BlockNumberFor<T>, Vec<Swap<T>>, ValueQuery>;
pub type SwapQueue<T: Config> = StorageMap<
Pallet<T>,
Twox64Concat,
BlockNumberFor<T>,
Vec<Swap<<T as frame_system::Config>::AccountId>>,
ValueQuery,
>;
}
use sp_std::collections::btree_map::BTreeMap;

Expand All @@ -58,28 +76,51 @@ impl<T: Config> UncheckedOnRuntimeUpgrade for Migration<T> {
}

fn on_runtime_upgrade() -> Weight {
let swaps_map: BTreeMap<SwapId, Swap<T>> = <old::SwapQueue<T>>::iter()
.flat_map(|(block, swaps)| {
swaps.into_iter().map(move |swap| {
log::info!("🧜‍♂️ migrating swap with id {:?}, block {:?}", swap.swap_id, block);
let new_swap = Swap::new(
swap.swap_id,
swap.swap_request_id,
swap.from,
swap.to,
swap.input_amount,
swap.refund_params,
swap.fees,
block,
);
(swap.swap_id, new_swap)
})
})
.collect();
let blocks = <old::SwapQueue<T>>::iter_keys().collect::<Vec<_>>();
log::info!("🧜‍♂️ migrating swap queue with {} blocks", blocks.len());
let mut scheduled_swaps = BTreeMap::<_, Swap<T>>::new();
for block in &blocks {
log::info!("🧜‍♂️ migrating block {:?}", block);
let swaps = old::SwapQueue::<T>::take(block);
log::info!("🧜‍♂️ found {} swaps in block {:?}", swaps.len(), block);
scheduled_swaps.extend(swaps.into_iter().map(|old_swap| {
(
old_swap.swap_id,
Swap::new(
old_swap.swap_id,
old_swap.swap_request_id,
old_swap.from,
old_swap.to,
old_swap.input_amount,
old_swap.refund_params.map(|old_params| SwapRefundParameters {
refund_block: old_params.refund_block,
price_limits: PriceLimits {
min_price: cf_amm::math::mul_div_floor(
Price::one(),
Price::from(old_params.min_output),
Price::from(old_swap.input_amount),
),
max_oracle_price_slippage: None,
},
}),
old_swap
.fees
.iter()
.map(|fee| match fee {
old::FeeType::BrokerFee(inner) => FeeType::BrokerFee(inner.clone()),
old::FeeType::NetworkFee(inner) =>
FeeType::NetworkFee(inner.clone()),
})
.collect::<Vec<_>>(),
*block,
),
)
}));
}

let _result = <old::SwapQueue<T>>::clear(u32::MAX, None);

crate::ScheduledSwaps::<T>::put(swaps_map);
crate::ScheduledSwaps::<T>::put(scheduled_swaps);

Weight::zero()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ impl<T> UncheckedOnRuntimeUpgrade for Migration<T>
where
T: Config,
{
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, frame_support::pallet_prelude::DispatchError> {
assert!(old::Backups::<T>::exists());
assert!(old::BackupRewardNodePercentage::<T>::exists());
assert!(old::AuctionBidCutoffPercentage::<T>::exists());
assert!(old::RegistrationBondPercentage::<T>::exists());
Ok(Default::default())
}

fn on_runtime_upgrade() -> frame_support::pallet_prelude::Weight {
old::Backups::<T>::kill();
old::BackupRewardNodePercentage::<T>::kill();
Expand Down
2 changes: 1 addition & 1 deletion state-chain/runtime/src/migrations/bitcoin_elections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl UncheckedOnRuntimeUpgrade for BitcoinElectionMigration {
.unwrap()
.4;

assert_eq!(current_unsynchronised_settings, 10);
assert_eq!(current_unsynchronised_settings, 20);

pallet_cf_elections::ElectoralSettings::<Runtime, BitcoinInstance>::iter().for_each(
|(_id, settings)| {
Expand Down