Skip to content

Commit

Permalink
[dont merge] runtime upgrade to fix polkadot vault
Browse files Browse the repository at this point in the history
  • Loading branch information
dandanlen committed Sep 27, 2023
1 parent 0fbf186 commit 2130049
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions state-chain/chains/src/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ impl PolkadotExtrinsicBuilder {
Self { extrinsic_call, replay_protection, signer_and_signature: None }
}

pub fn force_nonce(&mut self, nonce: u32) {
self.replay_protection.nonce = nonce;
}

pub fn signature(&self) -> Option<PolkadotSignature> {
self.signer_and_signature.as_ref().map(|(_, sig)| sig.clone())
}
Expand Down
46 changes: 44 additions & 2 deletions state-chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,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: 16,
spec_version: 17,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down Expand Up @@ -818,9 +818,51 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(),
CustomUpgrade,
>;

// TODO: remove this after upgrade.
pub struct CustomUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for CustomUpgrade {
fn on_runtime_upgrade() -> Weight {
let mut nonce = 1;
let api_calls =
pallet_cf_broadcast::ThresholdSignatureData::<Runtime, PolkadotInstance>::iter()
.drain()
.filter(id > 3)
.collect::<Vec<_>>();

let mut nonce = 1;
// transfers first
for (id, (ref mut api_call, _signature)) in api_calls {
match api_call {
transfer @ cf_chains::dot::api::PolkadotApi::BatchFetchAndTransfer(
ref mut ext_builder,
) => {
ext_builder.force_nonce(nonce);
nonce += 1;
PolkadotBroadcaster::threshold_sign_and_broadcast(transfer);
},
_ => continue,
}
}
// then the rotation
for (id, (ref mut api_call, _signature)) in api_calls {
match api_call {
rotate
@ cf_chains::dot::api::PolkadotApi::RotateVaultProxy(ref mut ext_builder) => {
ext_builder.force_nonce(nonce);
nonce += 1;
PolkadotBroadcaster::threshold_sign_and_broadcast(rotate);
},
_ => (),
}
}

Weight::zero()
}
}

#[cfg(feature = "runtime-benchmarks")]
#[macro_use]
extern crate frame_benchmarking;
Expand Down

0 comments on commit 2130049

Please sign in to comment.