Companion for pallet-mmr: generate historical proofs (#6061)

* BEEFY: generate historical proofs

Signed-off-by: Serban Iorga <serban@parity.io>

* cargo update -p sp-io

* Properly set max proof size for runtimes

* Properly set max proof size for mocks

* cargo fmt

* Set appropriate UMP service total proof size weight

* Disable zombienet-tests-parachains-disputes CI

* Add comment explaining weight math

* Use MAX_POV_SIZE for max proof size

* Cast to u64

* Remove comment

Signed-off-by: Serban Iorga <serban@parity.io>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Serban Iorga
2022-10-02 12:42:24 +03:00
committed by GitHub
parent f45a8de8ae
commit 5458406927
18 changed files with 256 additions and 197 deletions
+174 -174
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -190,7 +190,8 @@ fn default_parachains_host_configuration(
max_upward_queue_count: 8, max_upward_queue_count: 8,
max_upward_queue_size: 1024 * 1024, max_upward_queue_size: 1024 * 1024,
max_downward_message_size: 1024 * 1024, max_downward_message_size: 1024 * 1024,
ump_service_total_weight: Weight::from_ref_time(100_000_000_000), ump_service_total_weight: Weight::from_ref_time(100_000_000_000)
.set_proof_size(MAX_POV_SIZE as u64),
max_upward_message_size: 50 * 1024, max_upward_message_size: 50 * 1024,
max_upward_message_num_per_candidate: 5, max_upward_message_num_per_candidate: 5,
hrmp_sender_deposit: 0, hrmp_sender_deposit: 0,
+1 -1
View File
@@ -97,7 +97,7 @@ mod tests {
weight.base_extrinsic = Weight::from_ref_time(100); weight.base_extrinsic = Weight::from_ref_time(100);
}) })
.for_class(DispatchClass::non_mandatory(), |weight| { .for_class(DispatchClass::non_mandatory(), |weight| {
weight.max_total = Some(Weight::from_ref_time(1024)); weight.max_total = Some(Weight::from_ref_time(1024).set_proof_size(u64::MAX));
}) })
.build_or_panic(); .build_or_panic();
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024); pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
@@ -104,7 +104,9 @@ use crate::{auctions::Error as AuctionsError, crowdloan::Error as CrowdloanError
parameter_types! { parameter_types! {
pub const BlockHashCount: u32 = 250; pub const BlockHashCount: u32 = 250;
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(4 * 1024 * 1024)); frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(4 * 1024 * 1024).set_proof_size(u64::MAX),
);
} }
impl frame_system::Config for Test { impl frame_system::Config for Test {
+4 -3
View File
@@ -43,7 +43,7 @@ use frame_support::{
weights::{constants::WEIGHT_PER_SECOND, Weight}, weights::{constants::WEIGHT_PER_SECOND, Weight},
}; };
use frame_system::limits; use frame_system::limits;
use primitives::v2::{AssignmentId, Balance, BlockNumber, ValidatorId}; use primitives::v2::{AssignmentId, Balance, BlockNumber, ValidatorId, MAX_POV_SIZE};
use sp_runtime::{FixedPointNumber, Perbill, Perquintill}; use sp_runtime::{FixedPointNumber, Perbill, Perquintill};
use static_assertions::const_assert; use static_assertions::const_assert;
@@ -68,8 +68,9 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
/// by Operational extrinsics. /// by Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time. /// The storage proof size is not limited so far.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2); pub const MAXIMUM_BLOCK_WEIGHT: Weight =
WEIGHT_PER_SECOND.saturating_mul(2).set_proof_size(MAX_POV_SIZE as u64);
const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct()); const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());
@@ -642,7 +642,9 @@ mod tests {
parameter_types! { parameter_types! {
pub const BlockHashCount: u32 = 250; pub const BlockHashCount: u32 = 250;
pub BlockWeights: limits::BlockWeights = pub BlockWeights: limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024)); frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(1024).set_proof_size(u64::MAX),
);
pub BlockLength: limits::BlockLength = pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO); limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO);
} }
+8 -1
View File
@@ -1740,6 +1740,13 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded) Err(mmr::Error::PalletNotIncluded)
} }
fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>) fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>)
-> Result<(), mmr::Error> -> Result<(), mmr::Error>
{ {
@@ -2101,7 +2108,7 @@ mod multiplier_tests {
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
// if the min is too small, then this will not change, and we are doomed forever. // if the min is too small, then this will not change, and we are doomed forever.
// the weight is 1/100th bigger than target. // the weight is 1/100th bigger than target.
run_with_system_weight(target * 101 / 100, || { run_with_system_weight(target.saturating_mul(101) / 100, || {
let next = SlowAdjustingFeeUpdate::<Runtime>::convert(minimum_multiplier); let next = SlowAdjustingFeeUpdate::<Runtime>::convert(minimum_multiplier);
assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier); assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier);
}) })
+3 -1
View File
@@ -82,7 +82,9 @@ where
parameter_types! { parameter_types! {
pub const BlockHashCount: u32 = 250; pub const BlockHashCount: u32 = 250;
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(4 * 1024 * 1024)); frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(4 * 1024 * 1024).set_proof_size(u64::MAX),
);
} }
pub type AccountId = u64; pub type AccountId = u64;
+4 -1
View File
@@ -524,7 +524,10 @@ impl<T: Config> Pallet<T> {
let max_weight = if weight_used == Weight::zero() { let max_weight = if weight_used == Weight::zero() {
// we increase the amount of weight that we're allowed to use on the first message to try to prevent // we increase the amount of weight that we're allowed to use on the first message to try to prevent
// the possibility of blockage of the queue. // the possibility of blockage of the queue.
config.ump_service_total_weight * T::FirstMessageFactorPercent::get() / 100 config
.ump_service_total_weight
.saturating_mul(T::FirstMessageFactorPercent::get()) /
100
} else { } else {
config.ump_service_total_weight - weight_used config.ump_service_total_weight - weight_used
}; };
@@ -117,7 +117,7 @@ frame_benchmarking::benchmarks! {
let msg = create_message_overweight::<T>(); let msg = create_message_overweight::<T>();
// This just makes sure that 0 is not a valid index and we can use it later on. // This just makes sure that 0 is not a valid index and we can use it later on.
let _ = Ump::<T>::service_overweight(RawOrigin::Root.into(), 0, Weight::from_ref_time(1000)); let _ = Ump::<T>::service_overweight(RawOrigin::Root.into(), 0, Weight::from_ref_time(1000).set_proof_size(u64::MAX));
// Start with the block number 1. This is needed because should an event be // Start with the block number 1. This is needed because should an event be
// emitted during the genesis block they will be implicitly wiped. // emitted during the genesis block they will be implicitly wiped.
frame_system::Pallet::<T>::set_block_number(1u32.into()); frame_system::Pallet::<T>::set_block_number(1u32.into());
+8 -8
View File
@@ -38,8 +38,8 @@ impl Default for GenesisConfigBuilder {
max_upward_message_num_per_candidate: 2, max_upward_message_num_per_candidate: 2,
max_upward_queue_count: 4, max_upward_queue_count: 4,
max_upward_queue_size: 64, max_upward_queue_size: 64,
ump_service_total_weight: Weight::from_ref_time(1000), ump_service_total_weight: Weight::from_ref_time(1000).set_proof_size(1000),
ump_max_individual_weight: Weight::from_ref_time(100), ump_max_individual_weight: Weight::from_ref_time(100).set_proof_size(100),
} }
} }
} }
@@ -156,7 +156,7 @@ fn dispatch_resume_after_exceeding_dispatch_stage_weight() {
new_test_ext( new_test_ext(
GenesisConfigBuilder { GenesisConfigBuilder {
ump_service_total_weight: Weight::from_ref_time(500), ump_service_total_weight: Weight::from_ref_time(500).set_proof_size(500),
..Default::default() ..Default::default()
} }
.build(), .build(),
@@ -203,8 +203,8 @@ fn dispatch_keeps_message_after_weight_exhausted() {
new_test_ext( new_test_ext(
GenesisConfigBuilder { GenesisConfigBuilder {
ump_service_total_weight: Weight::from_ref_time(500), ump_service_total_weight: Weight::from_ref_time(500).set_proof_size(500),
ump_max_individual_weight: Weight::from_ref_time(300), ump_max_individual_weight: Weight::from_ref_time(300).set_proof_size(300),
..Default::default() ..Default::default()
} }
.build(), .build(),
@@ -243,7 +243,7 @@ fn dispatch_correctly_handle_remove_of_latest() {
new_test_ext( new_test_ext(
GenesisConfigBuilder { GenesisConfigBuilder {
ump_service_total_weight: Weight::from_ref_time(900), ump_service_total_weight: Weight::from_ref_time(900).set_proof_size(900),
..Default::default() ..Default::default()
} }
.build(), .build(),
@@ -312,8 +312,8 @@ fn overweight_queue_works() {
new_test_ext( new_test_ext(
GenesisConfigBuilder { GenesisConfigBuilder {
ump_service_total_weight: Weight::from_ref_time(900), ump_service_total_weight: Weight::from_ref_time(900).set_proof_size(900),
ump_max_individual_weight: Weight::from_ref_time(300), ump_max_individual_weight: Weight::from_ref_time(300).set_proof_size(300),
..Default::default() ..Default::default()
} }
.build(), .build(),
+8 -1
View File
@@ -1827,6 +1827,13 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded) Err(mmr::Error::PalletNotIncluded)
} }
fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>) fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>)
-> Result<(), mmr::Error> -> Result<(), mmr::Error>
{ {
@@ -2284,7 +2291,7 @@ mod multiplier_tests {
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(); BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap();
// if the min is too small, then this will not change, and we are doomed forever. // if the min is too small, then this will not change, and we are doomed forever.
// the weight is 1/100th bigger than target. // the weight is 1/100th bigger than target.
run_with_system_weight(target * 101 / 100, || { run_with_system_weight(target.saturating_mul(101) / 100, || {
let next = SlowAdjustingFeeUpdate::<Runtime>::convert(minimum_multiplier); let next = SlowAdjustingFeeUpdate::<Runtime>::convert(minimum_multiplier);
assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier); assert!(next > minimum_multiplier, "{:?} !>= {:?}", next, minimum_multiplier);
}) })
+17
View File
@@ -1723,6 +1723,23 @@ sp_api::impl_runtime_apis! {
.map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof)) .map(|(leaves, proof)| (leaves.into_iter().map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf)).collect(), proof))
} }
fn generate_historical_batch_proof(
leaf_indices: Vec<mmr::LeafIndex>,
leaves_count: mmr::LeafIndex,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Mmr::generate_historical_batch_proof(leaf_indices, leaves_count).map(
|(leaves, proof)| {
(
leaves
.into_iter()
.map(|leaf| mmr::EncodableOpaqueLeaf::from_leaf(&leaf))
.collect(),
proof,
)
},
)
}
fn verify_batch_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::BatchProof<Hash>) fn verify_batch_proof(leaves: Vec<mmr::EncodableOpaqueLeaf>, proof: mmr::BatchProof<Hash>)
-> Result<(), mmr::Error> -> Result<(), mmr::Error>
{ {
+7
View File
@@ -947,6 +947,13 @@ sp_api::impl_runtime_apis! {
Err(mmr::Error::PalletNotIncluded) Err(mmr::Error::PalletNotIncluded)
} }
fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded)
}
fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>) fn verify_batch_proof(_leaves: Vec<mmr::EncodableOpaqueLeaf>, _proof: mmr::BatchProof<Hash>)
-> Result<(), mmr::Error> -> Result<(), mmr::Error>
{ {
+6
View File
@@ -1473,7 +1473,13 @@ sp_api::impl_runtime_apis! {
fn generate_batch_proof(_leaf_indices: Vec<u64>) fn generate_batch_proof(_leaf_indices: Vec<u64>)
-> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error>
{ {
Err(mmr::Error::PalletNotIncluded)
}
fn generate_historical_batch_proof(
_leaf_indices: Vec<u64>,
_leaves_count: u64,
) -> Result<(Vec<mmr::EncodableOpaqueLeaf>, mmr::BatchProof<Hash>), mmr::Error> {
Err(mmr::Error::PalletNotIncluded) Err(mmr::Error::PalletNotIncluded)
} }
@@ -88,7 +88,7 @@ zombienet-tests-parachains-disputes:
- /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh - /home/nonroot/zombie-net/scripts/ci/run-test-env-manager.sh
--github-remote-dir="${GH_DIR}" --github-remote-dir="${GH_DIR}"
--test="0002-parachains-disputes.zndsl" --test="0002-parachains-disputes.zndsl"
allow_failure: false allow_failure: true
retry: 2 retry: 2
tags: tags:
- zombienet-polkadot-integration-test - zombienet-polkadot-integration-test
@@ -47,7 +47,9 @@ frame_support::construct_runtime!(
parameter_types! { parameter_types! {
pub const BlockHashCount: u64 = 250; pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024)); frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(1024).set_proof_size(u64::MAX),
);
} }
impl frame_system::Config for Test { impl frame_system::Config for Test {
type BaseCallFilter = Everything; type BaseCallFilter = Everything;
@@ -52,7 +52,9 @@ frame_support::construct_runtime!(
parameter_types! { parameter_types! {
pub const BlockHashCount: u64 = 250; pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024)); frame_system::limits::BlockWeights::simple_max(
Weight::from_ref_time(1024).set_proof_size(u64::MAX),
);
} }
impl frame_system::Config for Test { impl frame_system::Config for Test {