Skip to content

Commit c96ab37

Browse files
authored
Add Polygon Consensus Client to Nexus runtime (#492)
1 parent 794a60b commit c96ab37

File tree

9 files changed

+31
-21
lines changed

9 files changed

+31
-21
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/ismp/core/src/messaging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ use crate::{
3030
};
3131
use alloc::{string::ToString, vec::Vec};
3232
use codec::{Decode, DecodeWithMemTracking, Encode};
33-
use sp_weights::Weight;
3433
use primitive_types::H256;
34+
use sp_weights::Weight;
3535

3636
/// A consensus message is used to update the state of a consensus client and its children state
3737
/// machines.

modules/pallets/bridge-drop/src/lib.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,13 @@ pub mod pallet {
116116
beneficiary: T::AccountId,
117117
amount: <<T as Config>::Currency as Currency<T::AccountId>>::Balance,
118118
},
119+
/// Funds have been allocated
119120
Allocated {
120121
beneficiary: T::AccountId,
121122
amount: <<T as Config>::Currency as Currency<T::AccountId>>::Balance,
122123
},
124+
/// Start block for vesting has been set
125+
StartBlockSet { start_block: BlockNumberFor<T> },
123126
}
124127

125128
#[derive(
@@ -180,18 +183,6 @@ pub mod pallet {
180183
}
181184
}
182185

183-
#[pallet::hooks]
184-
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
185-
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
186-
if StartingBlock::<T>::get().is_none() {
187-
StartingBlock::<T>::put(n);
188-
return <T as frame_system::Config>::DbWeight::get().reads_writes(1, 1);
189-
}
190-
191-
<T as frame_system::Config>::DbWeight::get().reads(1)
192-
}
193-
}
194-
195186
#[pallet::call]
196187
impl<T: Config> Pallet<T>
197188
where
@@ -350,6 +341,20 @@ pub mod pallet {
350341

351342
Ok(())
352343
}
344+
345+
/// Set the start block for vesting
346+
#[pallet::call_index(4)]
347+
#[pallet::weight(<T as frame_system::Config>::DbWeight::get().reads_writes(1, 2))]
348+
pub fn set_start_block(
349+
origin: OriginFor<T>,
350+
start_block: BlockNumberFor<T>,
351+
) -> DispatchResult {
352+
T::BridgeDropOrigin::ensure_origin(origin)?;
353+
354+
StartingBlock::<T>::put(start_block);
355+
Self::deposit_event(Event::<T>::StartBlockSet { start_block });
356+
Ok(())
357+
}
353358
}
354359

355360
#[pallet::validate_unsigned]

modules/pallets/testsuite/src/tests/pallet_bridge_airdrop.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,14 @@ fn should_allocate_iro_correctly() {
144144
RuntimeOrigin::root(),
145145
beneficiary.clone(),
146146
amount,
147-
bonus_amount
147+
bonus_amount,
148148
)
149149
.unwrap();
150150

151151
let account_data = frame_system::Account::<Test>::get(beneficiary.clone());
152152

153153
let initial_unlocked = Permill::from_parts(250_000) * amount;
154-
let locked = amount
155-
.saturating_sub(initial_unlocked)
156-
.saturating_add(bonus_amount);
154+
let locked = amount.saturating_sub(initial_unlocked).saturating_add(bonus_amount);
157155

158156
assert_eq!(account_data.data.free, amount.saturating_add(bonus_amount));
159157

@@ -193,7 +191,7 @@ fn should_allocate_iro_correctly() {
193191
RuntimeOrigin::root(),
194192
beneficiary.clone(),
195193
amount.clone(),
196-
bonus_amount
194+
bonus_amount,
197195
);
198196

199197
assert_err!(res, pallet_bridge_airdrop::pallet::Error::<Test>::AlreadyAllocated);

modules/pallets/testsuite/src/tests/pallet_hyperbridge.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ fn test_dispatch_fees() {
9999
assert_eq!(Balances::balance(&account), Default::default());
100100

101101
// now pallet-ismp has it
102-
assert_eq!(Balances::balance(&RELAYER_FEE_ACCOUNT.into_account_truncating()), 65 * 10 * UNIT);
102+
assert_eq!(
103+
Balances::balance(&RELAYER_FEE_ACCOUNT.into_account_truncating()),
104+
65 * 10 * UNIT
105+
);
103106
});
104107
}
105108

parachain/runtimes/nexus/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ hyperbridge-client-machine = { workspace = true }
5050
pallet-bridge-airdrop = { workspace = true }
5151
ismp-arbitrum = { workspace = true }
5252
ismp-optimism = { workspace = true }
53+
ismp-polygon = { workspace = true }
5354
pallet-consensus-incentives = { workspace = true }
5455

5556
simnode-runtime-api = { workspace = true }
@@ -155,6 +156,7 @@ std = [
155156
"ismp-optimism/std",
156157
"pallet-consensus-incentives/std",
157158
"polkadot-sdk/std",
159+
"ismp-polygon/std"
158160
]
159161
runtime-benchmarks = [
160162
"hex-literal",

parachain/runtimes/nexus/src/ismp.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ impl pallet_ismp::Config for Runtime {
166166
>,
167167
ismp_arbitrum::ArbitrumConsensusClient<Ismp, Runtime>,
168168
ismp_optimism::OptimismConsensusClient<Ismp, Runtime>,
169+
ismp_polygon::PolygonClient<Ismp, Runtime>,
169170
);
170171
type OffchainDB = Mmr;
171172
type FeeHandler = pallet_ismp::fee_handler::WeightFeeHandler<

parachain/runtimes/nexus/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
226226
spec_name: Cow::Borrowed("nexus"),
227227
impl_name: Cow::Borrowed("nexus"),
228228
authoring_version: 1,
229-
spec_version: 3_700,
229+
spec_version: 3_800,
230230
impl_version: 0,
231231
apis: RUNTIME_API_VERSIONS,
232232
transaction_version: 1,

parachain/simtests/src/token_allocation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async fn should_perform_batch_allocations() -> Result<(), anyhow::Error> {
8181
let call = RuntimeCall::BridgeDrop(BridgeDropCall::allocate_iro_tokens {
8282
beneficiary: dest.into(),
8383
amount: record.amount,
84-
bonus_amount: record.bonus_amount.unwrap()
84+
bonus_amount: record.bonus_amount.unwrap(),
8585
});
8686
calls.push(call);
8787
records_to_check.push(record);

0 commit comments

Comments
 (0)