Skip to content

Commit 10be70a

Browse files
authored
Enable 10 Mb PoV for moonbase and moonriver (#3228)
* Enable 10 Mb PoV for moonbase * code improvement * improvements * fix comment * fix tests * revert BlockLength change * fix tests * add comment * final test fixes * update polkadot-sdk pin * update max pov to 10mb for moonriver * set GasLimitPovSizeRatio to 8 on moonriver * improve comment
1 parent 397e9ef commit 10be70a

41 files changed

Lines changed: 489 additions & 399 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

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

precompiles/proxy/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ where
182182
// Proxies:
183183
// Twox64Concat(8) + AccountId(20) + BoundedVec(ProxyDefinition * MaxProxies) + Balance(16)
184184
handle.record_db_read::<Runtime>(
185-
28 + (29 * (<Runtime as pallet_proxy::Config>::MaxProxies::get() as usize)) + 8,
185+
28 + (29 * (<Runtime as pallet_proxy::Config>::MaxProxies::get() as usize)) + 16,
186186
)?;
187187
if ProxyPallet::<Runtime>::proxies(origin.clone())
188188
.0
@@ -340,7 +340,7 @@ where
340340
// Proxies:
341341
// Twox64Concat(8) + AccountId(20) + BoundedVec(ProxyDefinition * MaxProxies) + Balance(16)
342342
handle.record_db_read::<Runtime>(
343-
28 + (29 * (<Runtime as pallet_proxy::Config>::MaxProxies::get() as usize)) + 8,
343+
28 + (29 * (<Runtime as pallet_proxy::Config>::MaxProxies::get() as usize)) + 16,
344344
)?;
345345
let is_proxy = ProxyPallet::<Runtime>::proxies(real)
346346
.0
@@ -368,7 +368,7 @@ where
368368
// Proxies:
369369
// Twox64Concat(8) + AccountId(20) + BoundedVec(ProxyDefinition * MaxProxies) + Balance(16)
370370
handle.record_db_read::<Runtime>(
371-
28 + (29 * (<Runtime as pallet_proxy::Config>::MaxProxies::get() as usize)) + 8,
371+
28 + (29 * (<Runtime as pallet_proxy::Config>::MaxProxies::get() as usize)) + 16,
372372
)?;
373373
let def =
374374
pallet_proxy::Pallet::<Runtime>::find_proxy(&real_account_id, &who, force_proxy_type)

runtime/moonbase/src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,15 @@ pub mod currency {
159159
}
160160
}
161161

162+
/// Maximum PoV size we support right now.
163+
// Reference: https://github.com/polkadot-fellows/runtimes/pull/553
164+
pub const MAX_POV_SIZE: u32 = 10 * 1024 * 1024;
165+
162166
/// Maximum weight per block
163-
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX)
164-
.saturating_mul(2)
165-
.set_proof_size(relay_chain::MAX_POV_SIZE as u64);
167+
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
168+
WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
169+
MAX_POV_SIZE as u64,
170+
);
166171

167172
pub const MILLISECS_PER_BLOCK: u64 = 6_000;
168173
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
@@ -393,8 +398,12 @@ pub const GAS_PER_SECOND: u64 = 40_000_000;
393398
/// Approximate ratio of the amount of Weight per Gas.
394399
/// u64 works for approximations because Weight is a very small unit compared to gas.
395400
pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;
401+
396402
/// The highest amount of new storage that can be created in a block (160KB).
403+
/// Originally 40KB, then multiplied by 4 when the block deadline was increased from 500ms to 2000ms.
404+
/// Reference: https://github.com/moonbeam-foundation/moonbeam/blob/master/MBIPS/MBIP-5.md#specification
397405
pub const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024;
406+
398407
parameter_types! {
399408
pub BlockGasLimit: U256
400409
= U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
@@ -414,13 +423,13 @@ parameter_types! {
414423
pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128);
415424
pub PrecompilesValue: MoonbasePrecompiles<Runtime> = MoonbasePrecompiles::<_>::new();
416425
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
417-
/// The amount of gas per pov. A ratio of 16 if we convert ref_time to gas and we compare
426+
/// The amount of gas per pov. A ratio of 8 if we convert ref_time to gas and we compare
418427
/// it with the pov_size for a block. E.g.
419428
/// ceil(
420429
/// (max_extrinsic.ref_time() / max_extrinsic.proof_size()) / WEIGHT_PER_GAS
421430
/// )
422431
/// We should re-check `xcm_config::Erc20XcmBridgeTransferGasLimit` when changing this value
423-
pub const GasLimitPovSizeRatio: u64 = 16;
432+
pub const GasLimitPovSizeRatio: u64 = 8;
424433
/// The amount of gas per storage (in bytes): BLOCK_GAS_LIMIT / BLOCK_STORAGE_LIMIT
425434
/// (60_000_000 / 160 kb)
426435
pub GasLimitStorageGrowthRatio: u64 = 366;
@@ -696,6 +705,7 @@ impl pallet_ethereum_xcm::Config for Runtime {
696705
}
697706

698707
parameter_types! {
708+
// Reserved weight is 1/4 of MAXIMUM_BLOCK_WEIGHT
699709
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
700710
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
701711
pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;

runtime/moonbase/src/xcm_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ parameter_types! {
672672

673673
// To be able to support almost all erc20 implementations,
674674
// we provide a sufficiently hight gas limit.
675-
pub Erc20XcmBridgeTransferGasLimit: u64 = 800_000;
675+
pub Erc20XcmBridgeTransferGasLimit: u64 = 400_000;
676676
}
677677

678678
impl pallet_erc20_xcm_bridge::Config for Runtime {

runtime/moonbase/tests/xcm_mock/parachain.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,16 +829,12 @@ impl pallet_timestamp::Config for Runtime {
829829

830830
use sp_core::U256;
831831

832-
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
833-
/// Block storage limit in bytes. Set to 40 KB.
834-
const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;
835-
836832
parameter_types! {
837833
pub BlockGasLimit: U256 = U256::from(u64::MAX);
838834
pub WeightPerGas: Weight = Weight::from_parts(1, 0);
839835
pub GasLimitPovSizeRatio: u64 = {
840836
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
841-
block_gas_limit.saturating_div(MAX_POV_SIZE)
837+
block_gas_limit.saturating_div(MAX_POV_SIZE as u64)
842838
};
843839
pub GasLimitStorageGrowthRatio: u64 =
844840
BlockGasLimit::get().min(u64::MAX.into()).low_u64().saturating_div(BLOCK_STORAGE_LIMIT);
@@ -1088,7 +1084,7 @@ pub(crate) fn para_events() -> Vec<RuntimeEvent> {
10881084

10891085
use frame_support::traits::tokens::{PayFromAccount, UnityAssetBalanceConversion};
10901086
use frame_support::traits::{OnFinalize, OnInitialize, UncheckedOnRuntimeUpgrade};
1091-
use moonbase_runtime::EvmForeignAssets;
1087+
use moonbase_runtime::{EvmForeignAssets, BLOCK_STORAGE_LIMIT, MAX_POV_SIZE};
10921088
use pallet_evm::FrameSystemAccountProvider;
10931089
use xcm_primitives::AsAssetType;
10941090

runtime/moonbeam/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,14 @@ pub mod currency {
155155
}
156156
}
157157

158+
/// Maximum PoV size we support right now.
159+
pub const MAX_POV_SIZE: u32 = relay_chain::MAX_POV_SIZE;
160+
158161
/// Maximum weight per block
159-
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX)
160-
.saturating_mul(2)
161-
.set_proof_size(relay_chain::MAX_POV_SIZE as u64);
162+
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
163+
WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
164+
MAX_POV_SIZE as u64,
165+
);
162166

163167
pub const MILLISECS_PER_BLOCK: u64 = 6_000;
164168
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
@@ -381,6 +385,11 @@ pub const GAS_PER_SECOND: u64 = 40_000_000;
381385
/// u64 works for approximations because Weight is a very small unit compared to gas.
382386
pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;
383387

388+
/// The highest amount of new storage that can be created in a block (160KB).
389+
/// Originally 40KB, then multiplied by 4 when the block deadline was increased from 500ms to 2000ms.
390+
/// Reference: https://github.com/moonbeam-foundation/moonbeam/blob/master/MBIPS/MBIP-5.md#specification
391+
pub const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024;
392+
384393
parameter_types! {
385394
pub BlockGasLimit: U256
386395
= U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
@@ -710,6 +719,7 @@ impl pallet_ethereum_xcm::Config for Runtime {
710719
}
711720

712721
parameter_types! {
722+
// Reserved weight is 1/4 of MAXIMUM_BLOCK_WEIGHT
713723
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
714724
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
715725
pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;

runtime/moonriver/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,16 @@ pub mod currency {
161161
}
162162
}
163163

164+
/// Maximum PoV size we support right now.
165+
// Kusama relay already supports 10Mb maximum PoV
166+
// Reference: https://github.com/polkadot-fellows/runtimes/pull/553
167+
pub const MAX_POV_SIZE: u32 = 10 * 1024 * 1024;
168+
164169
/// Maximum weight per block
165-
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX)
166-
.saturating_mul(2)
167-
.set_proof_size(relay_chain::MAX_POV_SIZE as u64);
170+
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(
171+
WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2),
172+
MAX_POV_SIZE as u64,
173+
);
168174

169175
pub const MILLISECS_PER_BLOCK: u64 = 6_000;
170176
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
@@ -386,6 +392,11 @@ pub const GAS_PER_SECOND: u64 = 40_000_000;
386392
/// u64 works for approximations because Weight is a very small unit compared to gas.
387393
pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;
388394

395+
/// The highest amount of new storage that can be created in a block (160KB).
396+
/// Originally 40KB, then multiplied by 4 when the block deadline was increased from 500ms to 2000ms.
397+
/// Reference: https://github.com/moonbeam-foundation/moonbeam/blob/master/MBIPS/MBIP-5.md#specification
398+
pub const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024;
399+
389400
parameter_types! {
390401
pub BlockGasLimit: U256
391402
= U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
@@ -406,13 +417,13 @@ parameter_types! {
406417
pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128);
407418
pub PrecompilesValue: MoonriverPrecompiles<Runtime> = MoonriverPrecompiles::<_>::new();
408419
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
409-
/// The amount of gas per pov. A ratio of 16 if we convert ref_time to gas and we compare
420+
/// The amount of gas per pov. A ratio of 8 if we convert ref_time to gas and we compare
410421
/// it with the pov_size for a block. E.g.
411422
/// ceil(
412423
/// (max_extrinsic.ref_time() / max_extrinsic.proof_size()) / WEIGHT_PER_GAS
413424
/// )
414425
/// We should re-check `xcm_config::Erc20XcmBridgeTransferGasLimit` when changing this value
415-
pub const GasLimitPovSizeRatio: u64 = 16;
426+
pub const GasLimitPovSizeRatio: u64 = 8;
416427
/// The amount of gas per storage (in bytes): BLOCK_GAS_LIMIT / BLOCK_STORAGE_LIMIT
417428
/// The current definition of BLOCK_STORAGE_LIMIT is 160 KB, resulting in a value of 366.
418429
pub GasLimitStorageGrowthRatio: u64 = 366;
@@ -689,6 +700,7 @@ impl pallet_ethereum_xcm::Config for Runtime {
689700
}
690701

691702
parameter_types! {
703+
// Reserved weight is 1/4 of MAXIMUM_BLOCK_WEIGHT
692704
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
693705
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
694706
pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent;

runtime/moonriver/src/xcm_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ parameter_types! {
673673

674674
// To be able to support almost all erc20 implementations,
675675
// we provide a sufficiently hight gas limit.
676-
pub Erc20XcmBridgeTransferGasLimit: u64 = 800_000;
676+
pub Erc20XcmBridgeTransferGasLimit: u64 = 400_000;
677677
}
678678

679679
impl pallet_erc20_xcm_bridge::Config for Runtime {

runtime/moonriver/tests/xcm_mock/parachain.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -820,16 +820,12 @@ impl pallet_timestamp::Config for Runtime {
820820

821821
use sp_core::U256;
822822

823-
const MAX_POV_SIZE: u64 = 5 * 1024 * 1024;
824-
/// Block storage limit in bytes. Set to 160 KB.
825-
const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024;
826-
827823
parameter_types! {
828824
pub BlockGasLimit: U256 = U256::from(u64::MAX);
829825
pub WeightPerGas: Weight = Weight::from_parts(1, 0);
830826
pub GasLimitPovSizeRatio: u64 = {
831827
let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64();
832-
block_gas_limit.saturating_div(MAX_POV_SIZE)
828+
block_gas_limit.saturating_div(MAX_POV_SIZE as u64)
833829
};
834830
pub GasLimitStorageGrowthRatio: u64 =
835831
BlockGasLimit::get().min(u64::MAX.into()).low_u64().saturating_div(BLOCK_STORAGE_LIMIT);
@@ -1080,7 +1076,7 @@ pub(crate) fn para_events() -> Vec<RuntimeEvent> {
10801076

10811077
use frame_support::traits::tokens::{PayFromAccount, UnityAssetBalanceConversion};
10821078
use frame_support::traits::{OnFinalize, OnInitialize, UncheckedOnRuntimeUpgrade};
1083-
use moonriver_runtime::EvmForeignAssets;
1079+
use moonriver_runtime::{EvmForeignAssets, BLOCK_STORAGE_LIMIT, MAX_POV_SIZE};
10841080
use pallet_evm::FrameSystemAccountProvider;
10851081
use xcm_primitives::AsAssetType;
10861082

test/helpers/constants.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ export const RUNTIME_CONSTANTS = {
101101
// minus the block initialization (10%) and minus the extrinsic base cost.
102102
EXTRINSIC_GAS_LIMIT: new RuntimeConstant({ 2900: 52_000_000n, 0: 13_000_000n }),
103103
// Maximum Gas to PoV ratio used in the gasometer
104-
GAS_PER_POV_BYTES: new RuntimeConstant({ 2900: 16n, 0: 4n }),
104+
GAS_PER_POV_BYTES: new RuntimeConstant({ 3600: 8n, 2900: 16n, 0: 4n }),
105+
// Maximum PoV size in bytes allowed by the gasometer for one ethereum transaction
106+
// MAX_ETH_POV_PER_TX = EXTRINSIC_GAS_LIMIT / GAS_PER_POV_BYTES
107+
MAX_ETH_POV_PER_TX: new RuntimeConstant({ 3600: 6_500_000n, 0: 3_250_000n }),
105108
// Storage read/write costs
106109
STORAGE_READ_COST: 41_742_000n,
107110
// Weight to gas conversion ratio
@@ -143,6 +146,9 @@ export const RUNTIME_CONSTANTS = {
143146
}),
144147
// Maximum Gas to PoV ratio used in the gasometer
145148
GAS_PER_POV_BYTES: new RuntimeConstant({ 3100: 16n, 3000: 8n, 0: 4n }),
149+
// Maximum PoV size in bytes allowed by the gasometer for one ethereum transaction
150+
// MAX_ETH_POV_PER_TX = EXTRINSIC_GAS_LIMIT / GAS_PER_POV_BYTES
151+
MAX_ETH_POV_PER_TX: new RuntimeConstant({ 0: 3_250_000n }),
146152
},
147153
MOONBEAM: {
148154
...MOONBEAM_CONSTANTS,
@@ -180,14 +186,12 @@ export const RUNTIME_CONSTANTS = {
180186
}),
181187
// Maximum Gas to PoV ratio used in the gasometer
182188
GAS_PER_POV_BYTES: new RuntimeConstant({ 3200: 16n, 3100: 8n, 0: 4n }),
189+
// Maximum PoV size in bytes allowed by the gasometer for one ethereum transaction
190+
// MAX_ETH_POV_PER_TX = EXTRINSIC_GAS_LIMIT / GAS_PER_POV_BYTES
191+
MAX_ETH_POV_PER_TX: new RuntimeConstant({ 0: 3_250_000n }),
183192
},
184193
} as const;
185194

186-
export const GAS_LIMIT_POV_RATIO = 16;
187-
188-
// Maximum PoV size in bytes allowed by the gasometer for one ethereum transaction
189-
export const MAX_ETH_POV_PER_TX = 3_250_000n;
190-
191195
type ConstantStoreType = (typeof RUNTIME_CONSTANTS)["MOONBASE"];
192196

193197
export function ConstantStore(context: GenericContext): ConstantStoreType {

0 commit comments

Comments
 (0)