Skip to content

Commit a5a3f80

Browse files
svyatonikbkchr
authored andcommitted
fixed TODOs for weights v2 (#1860)
1 parent 795a049 commit a5a3f80

File tree

13 files changed

+35
-96
lines changed

13 files changed

+35
-96
lines changed

bridges/bin/millau/runtime/src/rialto_messages.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
3030
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
3131
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
3232
/// tests, confirming that we don't break encoding somewhere between.
33-
pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT;
33+
pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::xcm_config::BaseXcmWeight::get().saturating_mul(2);
3434

3535
parameter_types! {
3636
/// Weight credit for our test messages.
3737
///
3838
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
3939
/// (it is prepended with `UniversalOrigin` instruction).
40-
pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE);
40+
pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE;
4141
}
4242

4343
/// Message payload for Millau -> Rialto messages.

bridges/bin/millau/runtime/src/rialto_parachain_messages.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
3030
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
3131
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
3232
/// tests, confirming that we don't break encoding somewhere between.
33-
pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT;
33+
pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::xcm_config::BaseXcmWeight::get().saturating_mul(2);
3434

3535
parameter_types! {
3636
/// Weight credit for our test messages.
3737
///
3838
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
3939
/// (it is prepended with `UniversalOrigin` instruction).
40-
pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE);
40+
pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE;
4141
}
4242

4343
/// Message payload for Millau -> RialtoParachain messages.

bridges/bin/millau/runtime/src/xcm_config.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,9 @@ type LocalOriginConverter = (
9393
SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
9494
);
9595

96-
/// The amount of weight an XCM operation takes. This is a safe overestimate.
97-
pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000;
98-
9996
parameter_types! {
10097
/// The amount of weight an XCM operation takes. This is a safe overestimate.
101-
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026?
102-
pub const BaseXcmWeight: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0);
98+
pub const BaseXcmWeight: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
10399
/// Maximum number of instructions in a single XCM fragment. A sanity check against weight
104100
/// calculations getting too crazy.
105101
pub const MaxInstructions: u32 = 100;
@@ -314,17 +310,14 @@ mod tests {
314310
};
315311

316312
let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message);
317-
assert_eq!(
318-
dispatch_weight,
319-
frame_support::weights::Weight::from_ref_time(1_000_000_000)
320-
);
313+
assert_eq!(dispatch_weight, BaseXcmWeight::get());
321314

322315
let dispatch_result =
323316
MessageDispatcher::dispatch(&AccountId::from([0u8; 32]), incoming_message);
324317
assert_eq!(
325318
dispatch_result,
326319
MessageDispatchResult {
327-
unspent_weight: frame_support::weights::Weight::from_ref_time(0),
320+
unspent_weight: frame_support::weights::Weight::zero(),
328321
dispatch_level_result: (),
329322
}
330323
);

bridges/bin/rialto-parachain/runtime/src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,9 @@ pub type XcmOriginToTransactDispatchOrigin = (
368368
// TODO: until https://github.com/paritytech/parity-bridges-common/issues/1417 is fixed (in either way),
369369
// the following constant must match the similar constant in the Millau runtime.
370370

371-
/// One XCM operation is `1_000_000_000` weight - almost certainly a conservative estimate.
372-
pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000;
373-
374371
parameter_types! {
375372
/// The amount of weight an XCM operation takes. This is a safe overestimate.
376-
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026?
377-
pub UnitWeightCost: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0);
373+
pub const UnitWeightCost: Weight = Weight::from_parts(1_000_000, 64 * 1024);
378374
// One UNIT buys 1 second of weight.
379375
pub const WeightPrice: (MultiLocation, u128) = (MultiLocation::parent(), UNIT);
380376
pub const MaxInstructions: u32 = 100;
@@ -902,17 +898,14 @@ mod tests {
902898
};
903899

904900
let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message);
905-
assert_eq!(
906-
dispatch_weight,
907-
frame_support::weights::Weight::from_ref_time(1_000_000_000)
908-
);
901+
assert_eq!(dispatch_weight, UnitWeightCost::get());
909902

910903
let dispatch_result =
911904
MessageDispatcher::dispatch(&AccountId::from([0u8; 32]), incoming_message);
912905
assert_eq!(
913906
dispatch_result,
914907
MessageDispatchResult {
915-
unspent_weight: frame_support::weights::Weight::from_ref_time(0),
908+
unspent_weight: frame_support::weights::Weight::zero(),
916909
dispatch_level_result: (),
917910
}
918911
);

bridges/bin/rialto-parachain/runtime/src/millau_messages.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
3333
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
3434
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
3535
/// tests, confirming that we don't break encoding somewhere between.
36-
pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::BASE_XCM_WEIGHT;
36+
pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::UnitWeightCost::get().saturating_mul(2);
3737

3838
parameter_types! {
3939
/// Weight credit for our test messages.
4040
///
4141
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
4242
/// (it is prepended with `UniversalOrigin` instruction).
43-
pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE);
43+
pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE;
4444
}
4545

4646
/// Message payload for RialtoParachain -> Millau messages.

bridges/bin/rialto/node/src/chain_spec.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ fn testnet_genesis(
253253
max_upward_queue_count: 8,
254254
max_upward_queue_size: 1024 * 1024,
255255
max_downward_message_size: 1024 * 1024,
256-
ump_service_total_weight: Weight::from_ref_time(100_000_000_000),
256+
ump_service_total_weight: Weight::from_parts(
257+
100_000_000_000,
258+
polkadot_primitives::v2::MAX_POV_SIZE as u64,
259+
),
257260
max_upward_message_size: 50 * 1024,
258261
max_upward_message_num_per_candidate: 5,
259262
hrmp_sender_deposit: 0,

bridges/bin/rialto/runtime/src/millau_messages.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ pub const XCM_LANE: LaneId = LaneId([0, 0, 0, 0]);
3030
/// Weight of 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
3131
/// (it is prepended with `UniversalOrigin` instruction). It is used just for simplest manual
3232
/// tests, confirming that we don't break encoding somewhere between.
33-
pub const BASE_XCM_WEIGHT_TWICE: u64 = 2 * crate::xcm_config::BASE_XCM_WEIGHT;
33+
pub const BASE_XCM_WEIGHT_TWICE: Weight = crate::xcm_config::BaseXcmWeight::get().saturating_mul(2);
3434

3535
parameter_types! {
3636
/// Weight credit for our test messages.
3737
///
3838
/// 2 XCM instructions is for simple `Trap(42)` program, coming through bridge
3939
/// (it is prepended with `UniversalOrigin` instruction).
40-
pub const WeightCredit: Weight = Weight::from_ref_time(BASE_XCM_WEIGHT_TWICE);
40+
pub const WeightCredit: Weight = BASE_XCM_WEIGHT_TWICE;
4141
}
4242

4343
/// Message payload for Rialto -> Millau messages.

bridges/bin/rialto/runtime/src/parachains.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
RuntimeOrigin, ShiftSessionManager, Slots, UncheckedExtrinsic,
2222
};
2323

24-
use frame_support::{parameter_types, traits::KeyOwnerProofSystem, weights::Weight};
24+
use frame_support::{parameter_types, traits::KeyOwnerProofSystem};
2525
use frame_system::EnsureRoot;
2626
use polkadot_primitives::v2::{ValidatorId, ValidatorIndex};
2727
use polkadot_runtime_common::{paras_registrar, paras_sudo_wrapper, slots};
@@ -163,44 +163,3 @@ impl slots::Config for Runtime {
163163
}
164164

165165
impl paras_sudo_wrapper::Config for Runtime {}
166-
167-
pub struct ZeroWeights;
168-
169-
impl polkadot_runtime_common::paras_registrar::WeightInfo for ZeroWeights {
170-
fn reserve() -> Weight {
171-
Weight::from_ref_time(0)
172-
}
173-
fn register() -> Weight {
174-
Weight::from_ref_time(0)
175-
}
176-
fn force_register() -> Weight {
177-
Weight::from_ref_time(0)
178-
}
179-
fn deregister() -> Weight {
180-
Weight::from_ref_time(0)
181-
}
182-
fn swap() -> Weight {
183-
Weight::from_ref_time(0)
184-
}
185-
fn schedule_code_upgrade(_: u32) -> Weight {
186-
Weight::from_ref_time(0)
187-
}
188-
fn set_current_head(_: u32) -> Weight {
189-
Weight::from_ref_time(0)
190-
}
191-
}
192-
193-
impl polkadot_runtime_common::slots::WeightInfo for ZeroWeights {
194-
fn force_lease() -> Weight {
195-
Weight::from_ref_time(0)
196-
}
197-
fn manage_lease_period_start(_c: u32, _t: u32) -> Weight {
198-
Weight::from_ref_time(0)
199-
}
200-
fn clear_all_leases() -> Weight {
201-
Weight::from_ref_time(0)
202-
}
203-
fn trigger_onboard() -> Weight {
204-
Weight::from_ref_time(0)
205-
}
206-
}

bridges/bin/rialto/runtime/src/xcm_config.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,9 @@ type LocalOriginConverter = (
8787
SignedAccountId32AsNative<ThisNetwork, RuntimeOrigin>,
8888
);
8989

90-
/// The amount of weight an XCM operation takes. This is a safe overestimate.
91-
pub const BASE_XCM_WEIGHT: u64 = 1_000_000_000;
92-
9390
parameter_types! {
9491
/// The amount of weight an XCM operation takes. This is a safe overestimate.
95-
// TODO: https://github.com/paritytech/parity-bridges-common/issues/1543 - check `set_proof_size` 0 or 64*1024 or 1026?
96-
pub const BaseXcmWeight: Weight = Weight::from_parts(BASE_XCM_WEIGHT, 0);
92+
pub const BaseXcmWeight: Weight = Weight::from_parts(1_000_000_000, 64 * 1024);
9793
/// Maximum number of instructions in a single XCM fragment. A sanity check against weight
9894
/// calculations getting too crazy.
9995
pub const MaxInstructions: u32 = 100;
@@ -273,17 +269,14 @@ mod tests {
273269
};
274270

275271
let dispatch_weight = MessageDispatcher::dispatch_weight(&mut incoming_message);
276-
assert_eq!(
277-
dispatch_weight,
278-
frame_support::weights::Weight::from_ref_time(1_000_000_000)
279-
);
272+
assert_eq!(dispatch_weight, BaseXcmWeight::get());
280273

281274
let dispatch_result =
282275
MessageDispatcher::dispatch(&AccountId::from([0u8; 32]), incoming_message);
283276
assert_eq!(
284277
dispatch_result,
285278
MessageDispatchResult {
286-
unspent_weight: frame_support::weights::Weight::from_ref_time(0),
279+
unspent_weight: frame_support::weights::Weight::zero(),
287280
dispatch_level_result: (),
288281
}
289282
);

bridges/modules/messages/src/lib.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ mod tests {
12711271
TEST_RELAYER_A,
12721272
Err(()).into(),
12731273
1,
1274-
Weight::from_ref_time(0),
1274+
Weight::zero(),
12751275
),
12761276
Error::<TestRuntime, ()>::InvalidMessagesProof,
12771277
);
@@ -1287,7 +1287,7 @@ mod tests {
12871287
TEST_RELAYER_A,
12881288
Ok(vec![message(1, REGULAR_PAYLOAD)]).into(),
12891289
u32::MAX,
1290-
Weight::from_ref_time(0),
1290+
Weight::zero(),
12911291
),
12921292
Error::<TestRuntime, ()>::TooManyMessagesInTheProof,
12931293
);
@@ -1479,8 +1479,8 @@ mod tests {
14791479
TEST_RELAYER_A,
14801480
Ok(vec![invalid_message]).into(),
14811481
1,
1482-
Weight::from_ref_time(0), /* weight may be zero in this case (all messages are
1483-
* improperly encoded) */
1482+
Weight::zero(), /* weight may be zero in this case (all messages are
1483+
* improperly encoded) */
14841484
),);
14851485

14861486
assert_eq!(InboundLanes::<TestRuntime>::get(TEST_LANE_ID).last_delivered_nonce(), 1,);
@@ -1710,11 +1710,7 @@ mod tests {
17101710
Pallet::<TestRuntime>::inbound_message_data(
17111711
TEST_LANE_ID,
17121712
REGULAR_PAYLOAD.encode(),
1713-
OutboundMessageDetails {
1714-
nonce: 0,
1715-
dispatch_weight: Weight::from_ref_time(0),
1716-
size: 0,
1717-
},
1713+
OutboundMessageDetails { nonce: 0, dispatch_weight: Weight::zero(), size: 0 },
17181714
),
17191715
InboundMessageDetails { dispatch_weight: REGULAR_PAYLOAD.declared_weight },
17201716
);

0 commit comments

Comments
 (0)