Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polkadot v1.1.0 upgrade #1

Merged
merged 8 commits into from
Sep 25, 2023
6 changes: 5 additions & 1 deletion cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,12 @@ pub mod pallet {
"ValidationData must be updated only once in a block",
);

let data_len = data.encoded_size() as u64;

// TODO: This is more than zero, but will need benchmarking to figure out what.
let mut total_weight = Weight::zero();
// MOONBEAM TODO: custom weight to account for validation data size is the PoV
// until https://github.com/paritytech/substrate/issues/13810 it's properly fix.
let mut total_weight = Weight::from_parts(0, data_len);

// NOTE: the inherent data is expected to be unique, even if this block is built
// in the context of the same relay parent as the previous one. In particular,
Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn init_block_builder(

inherents
.into_iter()
.for_each(|ext| block_builder.push(ext).expect("Pushes inherent"));
.for_each(|ext| block_builder.push(ext, None).expect("Pushes inherent"));

block_builder
}
Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/service/benches/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn benchmark_block_import(c: &mut Criterion) {
let mut block_builder =
client.new_block_at(parent_hash, Default::default(), RecordProof::No).unwrap();
for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
block_builder.push(extrinsic, None).unwrap();
}
let benchmark_block = block_builder.build().unwrap();

Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/service/benches/block_import_glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn benchmark_block_import(c: &mut Criterion) {
block_builder
.push(utils::extrinsic_set_validation_data(parent_header.clone()).clone())
.unwrap();
block_builder.push(utils::extrinsic_set_time(&client)).unwrap();
block_builder.push(utils::extrinsic_set_time(&client), None).unwrap();
let benchmark_block = block_builder.build().unwrap();

group.bench_function(
Expand Down
8 changes: 4 additions & 4 deletions cumulus/test/service/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ fn benchmark_block_production(c: &mut Criterion) {
let set_validation_data_extrinsic = utils::extrinsic_set_validation_data(parent_header);

let mut block_builder = client.new_block(Default::default()).unwrap();
block_builder.push(utils::extrinsic_set_time(&client)).unwrap();
block_builder.push(set_validation_data_extrinsic).unwrap();
block_builder.push(utils::extrinsic_set_time(&client), None).unwrap();
block_builder.push(set_validation_data_extrinsic, None).unwrap();
let built_block = block_builder.build().unwrap();

runtime.block_on(utils::import_block(&client, &built_block.block, false));
Expand All @@ -78,7 +78,7 @@ fn benchmark_block_production(c: &mut Criterion) {
.new_block_at(best_hash, Default::default(), RecordProof::Yes)
.unwrap();
for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
block_builder.push(extrinsic, None).unwrap();
}
block_builder.build().unwrap()
},
Expand All @@ -97,7 +97,7 @@ fn benchmark_block_production(c: &mut Criterion) {
.new_block_at(best_hash, Default::default(), RecordProof::No)
.unwrap();
for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
block_builder.push(extrinsic, None).unwrap();
}
block_builder.build().unwrap()
},
Expand Down
8 changes: 4 additions & 4 deletions cumulus/test/service/benches/block_production_glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
let mut block_builder = client
.new_block_at(best_hash, Default::default(), RecordProof::Yes)
.unwrap();
block_builder.push(validation_data).unwrap();
block_builder.push(time).unwrap();
block_builder.push(validation_data, None).unwrap();
block_builder.push(time, None).unwrap();
block_builder.build().unwrap()
},
BatchSize::SmallInput,
Expand All @@ -101,8 +101,8 @@ fn benchmark_block_production_compute(c: &mut Criterion) {
let mut block_builder = client
.new_block_at(best_hash, Default::default(), RecordProof::No)
.unwrap();
block_builder.push(validation_data).unwrap();
block_builder.push(time).unwrap();
block_builder.push(validation_data, None).unwrap();
block_builder.push(time, None).unwrap();
block_builder.build().unwrap()
},
BatchSize::SmallInput,
Expand Down
4 changes: 2 additions & 2 deletions cumulus/test/service/benches/validate_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn create_extrinsics(
None,
);

match block_builder.push(extrinsic.clone()) {
match block_builder.push(extrinsic.clone(), None) {
Ok(_) => {},
Err(ApplyExtrinsicFailed(Validity(TransactionValidityError::Invalid(
InvalidTransaction::ExhaustsResources,
Expand Down Expand Up @@ -96,7 +96,7 @@ fn benchmark_block_validation(c: &mut Criterion) {

let mut block_builder = client.init_block_builder(Some(validation_data), Default::default());
for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
block_builder.push(extrinsic, None).unwrap();
}

let parachain_block = block_builder.build_parachain_block(*parent_header.state_root());
Expand Down
2 changes: 1 addition & 1 deletion cumulus/test/service/benches/validate_block_glutton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn set_glutton_parameters(
let mut block_builder = client.init_block_builder(Some(validation_data), Default::default());

for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
block_builder.push(extrinsic, None).unwrap();
}

block_builder.build_parachain_block(*parent_header.state_root())
Expand Down
8 changes: 4 additions & 4 deletions cumulus/test/service/src/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub fn create_benchmarking_transfer_extrinsics(
Some(0),
);

match block_builder.push(extrinsic.clone().into()) {
match block_builder.push(extrinsic.clone().into(), None) {
Ok(_) => {},
Err(ApplyExtrinsicFailed(Validity(TransactionValidityError::Invalid(
InvalidTransaction::ExhaustsResources,
Expand Down Expand Up @@ -250,10 +250,10 @@ pub fn set_glutton_parameters(
extrinsics.push(set_storage);

let mut block_builder = client.new_block(Default::default()).unwrap();
block_builder.push(extrinsic_set_time(client)).unwrap();
block_builder.push(extrinsic_set_validation_data(parent_header)).unwrap();
block_builder.push(extrinsic_set_time(client), None).unwrap();
block_builder.push(extrinsic_set_validation_data(parent_header), None).unwrap();
for extrinsic in extrinsics {
block_builder.push(extrinsic.into()).unwrap();
block_builder.push(extrinsic.into(), None).unwrap();
}

let built_block = block_builder.build().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion polkadot/node/test/client/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl InitPolkadotBlockBuilder for Client {

inherents
.into_iter()
.for_each(|ext| block_builder.push(ext).expect("Pushes inherent"));
.for_each(|ext| block_builder.push(ext, None).expect("Pushes inherent"));

block_builder
}
Expand Down Expand Up @@ -154,6 +154,7 @@ impl BlockBuilderExt for BlockBuilder<'_, Block, Client, FullBackend> {
Decode::decode(&mut &encoded[..]).expect(
"The runtime specific extrinsic always decodes to an opaque extrinsic; qed",
),
None,
)
}
}
3 changes: 2 additions & 1 deletion polkadot/xcm/src/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ impl TryFrom<OldWeightLimit> for WeightLimit {
fn try_from(x: OldWeightLimit) -> result::Result<Self, ()> {
use OldWeightLimit::*;
match x {
Limited(w) => Ok(Self::Limited(Weight::from_parts(w, DEFAULT_PROOF_SIZE))),
// To support xcm v2 messages with limited weight, we need to buy a lot of PoV
Limited(w) => Ok(Self::Limited(Weight::from_parts(w, 5 * DEFAULT_PROOF_SIZE))),
Unlimited => Ok(Self::Unlimited),
}
}
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub use location_conversion::{
ChildParachainConvertsVia, DescribeAccountId32Terminal, DescribeAccountIdTerminal,
DescribeAccountKey20Terminal, DescribeAllTerminal, DescribeFamily, DescribeLocation,
DescribePalletTerminal, DescribeTerminus, GlobalConsensusConvertsFor,
GlobalConsensusParachainConvertsFor, HashedDescription, ParentIsPreset,
SiblingParachainConvertsVia,
GlobalConsensusParachainConvertsFor, HashedDescription,
HashedDescriptionDescribeFamilyAllTerminal, ParentIsPreset, SiblingParachainConvertsVia,
};

mod origin_conversion;
Expand Down
111 changes: 111 additions & 0 deletions polkadot/xcm/xcm-builder/src/location_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,48 @@ impl DescribeLocation for LegacyDescribeForeignChainAccount {
}
}

/// temporary struct that mimin the behavior of the upstream type:
/// HashedDescription<AccountId, DescribeFamily<DescribeAllTerminal>>
pub struct HashedDescriptionDescribeFamilyAllTerminal<AccountId>(PhantomData<AccountId>);
impl<AccountId: From<[u8; 32]> + Clone> HashedDescriptionDescribeFamilyAllTerminal<AccountId> {
fn describe_location_suffix(l: &MultiLocation) -> Option<Vec<u8>> {
match (l.parents, &l.interior) {
(0, Here) => Some(Vec::new()),
(0, X1(PalletInstance(i))) =>
Some((b"Pallet", Compact::<u32>::from(*i as u32)).encode()),
(0, X1(AccountId32 { id, .. })) => Some((b"AccountId32", id).encode()),
(0, X1(AccountKey20 { key, .. })) => Some((b"AccountKey20", key).encode()),
_ => return None,
}
}
}

impl<AccountId: From<[u8; 32]> + Clone> ConvertLocation<AccountId>
for HashedDescriptionDescribeFamilyAllTerminal<AccountId>
{
fn convert_location(location: &MultiLocation) -> Option<AccountId> {
let to_hash = match (location.parents, location.interior.first()) {
(0, Some(Parachain(index))) => {
let tail = location.interior.split_first().0;
let interior = Self::describe_location_suffix(&tail.into())?;
(b"ChildChain", Compact::<u32>::from(*index), interior).encode()
},
(1, Some(Parachain(index))) => {
let tail = location.interior.split_first().0;
let interior = Self::describe_location_suffix(&tail.into())?;
(b"SiblingChain", Compact::<u32>::from(*index), interior).encode()
},
(1, _) => {
let tail = location.interior.into();
let interior = Self::describe_location_suffix(&tail)?;
(b"ParentChain", interior).encode()
},
_ => return None,
};
Some(blake2_256(&to_hash).into())
}
}

/// Prefix for generating alias account for accounts coming
/// from chains that use 32 byte long representations.
pub const FOREIGN_CHAIN_PREFIX_PARA_32: [u8; 37] = *b"ForeignChainAliasAccountPrefix_Para32";
Expand Down Expand Up @@ -925,4 +967,73 @@ mod tests {
};
assert!(ForeignChainAliasAccount::<[u8; 32]>::convert_location(&mul).is_none());
}

#[test]
fn test_hashed_family_all_terminal_converter() {
type Converter<AccountId> = HashedDescriptionDescribeFamilyAllTerminal<AccountId>;

assert_eq!(
[
129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42,
215, 236, 154, 199, 191, 208, 110, 148, 223, 55, 92, 216, 250, 34
],
Converter::<[u8; 32]>::convert_location(&MultiLocation {
parents: 0,
interior: X2(Parachain(1), AccountId32 { network: None, id: [0u8; 32] }),
})
.unwrap()
);
assert_eq!(
[
17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181,
93, 252, 124, 60, 250, 195, 229, 86, 31, 220, 121, 111, 254, 252
],
Converter::<[u8; 32]>::convert_location(&MultiLocation {
parents: 1,
interior: X2(Parachain(1), AccountId32 { network: None, id: [0u8; 32] }),
})
.unwrap()
);
assert_eq!(
[
237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67,
52, 122, 195, 192, 10, 58, 253, 49, 0, 112, 175, 224, 125, 66
],
Converter::<[u8; 32]>::convert_location(&MultiLocation {
parents: 0,
interior: X2(Parachain(1), AccountKey20 { network: None, key: [0u8; 20] }),
})
.unwrap()
);
assert_eq!(
[
226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144,
19, 8, 204, 228, 112, 164, 189, 179, 124, 249, 1, 168, 110, 151, 50
],
Converter::<[u8; 32]>::convert_location(&MultiLocation {
parents: 1,
interior: X2(Parachain(1), AccountKey20 { network: None, key: [0u8; 20] }),
})
.unwrap()
);
assert_eq!(
[
254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215,
104, 121, 114, 53, 6, 124, 46, 42, 245, 121, 197, 12, 208
],
Converter::<[u8; 32]>::convert_location(&MultiLocation {
parents: 1,
interior: X2(Parachain(2), PalletInstance(3)),
})
.unwrap()
);
assert_eq!(
[
217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27,
16, 218, 254, 250, 184, 6, 27, 216, 138, 194, 93, 23, 165
],
Converter::<[u8; 32]>::convert_location(&MultiLocation { parents: 1, interior: Here })
.unwrap()
);
}
}
10 changes: 5 additions & 5 deletions substrate/bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn prepare_benchmark(client: &FullClient) -> (usize, Vec<OpaqueExtrinsic>) {

// Every block needs one timestamp extrinsic.
let extrinsic_set_time = extrinsic_set_time(1 + MINIMUM_PERIOD_FOR_BLOCKS);
block_builder.push(extrinsic_set_time.clone()).unwrap();
block_builder.push(extrinsic_set_time.clone(), None).unwrap();
extrinsics.push(extrinsic_set_time);

// Creating those is surprisingly costly, so let's only do it once and later just `clone` them.
Expand All @@ -147,7 +147,7 @@ fn prepare_benchmark(client: &FullClient) -> (usize, Vec<OpaqueExtrinsic>) {
)
.into();

match block_builder.push(extrinsic.clone()) {
match block_builder.push(extrinsic.clone(), None) {
Ok(_) => {},
Err(ApplyExtrinsicFailed(Validity(TransactionValidityError::Invalid(
InvalidTransaction::ExhaustsResources,
Expand All @@ -174,7 +174,7 @@ fn block_production(c: &mut Criterion) {
// Buliding the very first block is around ~30x slower than any subsequent one,
// so let's make sure it's built and imported before we benchmark anything.
let mut block_builder = client.new_block(Default::default()).unwrap();
block_builder.push(extrinsic_set_time(1)).unwrap();
block_builder.push(extrinsic_set_time(1), None).unwrap();
import_block(client, block_builder.build().unwrap());

let (max_transfer_count, extrinsics) = prepare_benchmark(&client);
Expand All @@ -194,7 +194,7 @@ fn block_production(c: &mut Criterion) {
let mut block_builder =
client.new_block_at(best_hash, Default::default(), RecordProof::No).unwrap();
for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
block_builder.push(extrinsic, None).unwrap();
}
block_builder.build().unwrap()
},
Expand All @@ -209,7 +209,7 @@ fn block_production(c: &mut Criterion) {
let mut block_builder =
client.new_block_at(best_hash, Default::default(), RecordProof::Yes).unwrap();
for extrinsic in extrinsics {
block_builder.push(extrinsic).unwrap();
block_builder.push(extrinsic, None).unwrap();
}
block_builder.build().unwrap()
},
Expand Down
4 changes: 2 additions & 2 deletions substrate/bin/node/testing/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ impl BenchDb {
let mut block = client.new_block(Default::default()).expect("Block creation failed");

for extrinsic in self.generate_inherents(&client) {
block.push(extrinsic).expect("Push inherent failed");
block.push(extrinsic, None).expect("Push inherent failed");
}

let start = std::time::Instant::now();
for opaque in self.block_content(content, &client) {
match block.push(opaque) {
match block.push(opaque, None) {
Err(sp_blockchain::Error::ApplyExtrinsicFailed(
sp_blockchain::ApplyExtrinsicFailed::Validity(e),
)) if e.exhausted_resources() => break,
Expand Down
Loading
Loading