Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d1bce56
inherent overhaul
liamaharon May 7, 2024
20878ee
bump version
liamaharon May 7, 2024
d58941c
clean up custom idps
liamaharon May 8, 2024
ff30415
smart inherent provider
liamaharon May 8, 2024
5883f46
licence and basic docs
liamaharon May 9, 2024
b27fd10
clippy
liamaharon May 9, 2024
62d9696
remove node-executor node-primitive deps
liamaharon May 9, 2024
9c5fcbe
fmt
liamaharon May 9, 2024
ac898c2
update cargo.lock
liamaharon May 9, 2024
36a8cf1
move shared params to common
liamaharon May 10, 2024
4424f61
move misc logging to common
liamaharon May 10, 2024
a0a5485
move parse to common
liamaharon May 10, 2024
16c5b39
move state to common
liamaharon May 10, 2024
9632a14
move inherents to empty block production dir
liamaharon May 10, 2024
4f7e04e
move block creation out of fast forward
liamaharon May 10, 2024
b728086
improve log
liamaharon May 10, 2024
039cdaf
clippy
liamaharon May 10, 2024
bcdd083
cargo fmt
liamaharon May 13, 2024
4a406c6
update test runtimes and snapshots
liamaharon May 14, 2024
fd0092e
use stable for clippy
liamaharon May 14, 2024
4b4648b
fix typos
liamaharon May 14, 2024
527c857
Update core/src/common/empty_block/inherents/pre_apply.rs
liamaharon May 15, 2024
c7dbbfe
address comments
liamaharon May 16, 2024
8b465e2
doc comment
liamaharon May 16, 2024
828a357
doc
liamaharon May 16, 2024
5980993
use valueenum
liamaharon May 16, 2024
aee8086
rename execute_next_block to mine_block
liamaharon May 16, 2024
2254202
bump relay_offset +1
liamaharon May 17, 2024
00e2962
blocktime arg
liamaharon May 20, 2024
e80f524
make blocktime a required value
liamaharon May 20, 2024
47a76ca
hardcode relaychain blocktime
liamaharon May 20, 2024
c6a143b
clippy
liamaharon May 26, 2024
5fdd6d5
free disk space on test runner
liamaharon May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
licence and basic docs
  • Loading branch information
liamaharon committed May 9, 2024
commit 5883f4694123aae673637c2c57e7376703f25a0d
17 changes: 17 additions & 0 deletions core/src/inherents/custom_idps/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// This file is partmilliles of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod para_parachain;
pub mod relay_parachains;
pub mod timestamp;
28 changes: 20 additions & 8 deletions core/src/inherents/custom_idps/para_parachain.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// This file is partmilliles of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Inherent data provider for the [cumulus parachin inherents](https://github.com/paritytech/polkadot-sdk/blob/master/cumulus/primitives/parachain-inherent/src/lib.rs)
//! for empty block production on top of an existing externalities.

use parity_scale_codec::{Decode, Encode};
use polkadot_primitives::{BlockNumber, HeadData};
use sp_consensus_babe::SlotDuration;
Expand All @@ -6,14 +26,6 @@ use sp_inherents::InherentIdentifier;
use sp_runtime::traits::{Block as BlockT, HashingFor, NumberFor};
use sp_state_machine::TestExternalities;

pub fn is_parachain<B: BlockT>(ext: &mut TestExternalities<HashingFor<B>>) -> bool {
let para_id_key = [twox_128(b"ParachainInfo"), twox_128(b"ParachainId")].concat();

ext.execute_with(|| sp_io::storage::get(&para_id_key))
.map(|b| -> Option<u32> { Decode::decode(&mut &b[..]).ok() })
.is_some()
}

/// ext cannot be part of the InherentDataProvider (thread safety), so we need to make storage
/// queries seperately
pub fn get_para_id<B: BlockT>(ext: &mut TestExternalities<HashingFor<B>>) -> Option<u32> {
Expand Down
3 changes: 2 additions & 1 deletion core/src/inherents/custom_idps/relay_parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//! Relay chain parachains inherent.
//! Inherent data provider for the [polkadot parachins inherent](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/primitives/src/v7/mod.rs)
//! for empty block production on top of an existing externalities.

use sp_inherents::InherentIdentifier;
use sp_runtime::traits::Block as BlockT;
Expand Down
20 changes: 20 additions & 0 deletions core/src/inherents/custom_idps/timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Inherent data provider for the timestamp, for empty block production on top of an existing
//! externalities.

use sp_inherents::{InherentData, InherentIdentifier};
use sp_runtime::Digest;
use sp_timestamp::{Timestamp, TimestampInherentData};
Expand Down
17 changes: 17 additions & 0 deletions core/src/inherents/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// This file is partmilliles of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod custom_idps;
pub mod pre_apply;
pub mod providers;
27 changes: 21 additions & 6 deletions core/src/inherents/pre_apply.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
// This file is partmilliles of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use cumulus_primitives_parachain_inherent::MessageQueueChain;
use parity_scale_codec::Encode;
use sp_core::{twox_128, H256};
use sp_runtime::traits::{Block as BlockT, HashingFor};
use sp_state_machine::TestExternalities;

/// Some operations must be to performed prior to inherents being applied.
///
/// This fn sets the last dmq mcq head value to zero to pass [this check](https://github.com/paritytech/polkadot-sdk/blob/ef114a422291b44f8973739ab7858a29a523e6a2/cumulus/pallets/parachain-system/src/lib.rs#L1162)
///
/// It must be called prior to attempting to apply inherents.
pub fn pre_apply_inherents<B: BlockT>(ext: &mut TestExternalities<HashingFor<B>>) {
// set the last dmq mcq head value to zero to pass this check
// https://github.com/paritytech/polkadot-sdk/blob/ef114a422291b44f8973739ab7858a29a523e6a2/cumulus/pallets/parachain-system/src/lib.rs#L1162
//
// it would have been preferable to set it to the real value in the mock inherent
// provider for parachain system, but that would require the paraid which we cannot
// derive from the externalities.
let last_dmq_mqc_head_key =
[twox_128(b"ParachainSystem"), twox_128(b"LastDmqMqcHead")].concat();
ext.insert(
Expand Down
11 changes: 8 additions & 3 deletions core/src/inherents/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@

use std::{str::FromStr, time::Duration};

use cumulus_primitives_parachain_inherent::MessageQueueChain;
use itertools::Itertools;
use parity_scale_codec::Encode;
use sp_consensus_aura::{Slot, SlotDuration, AURA_ENGINE_ID};
use sp_consensus_babe::{
digests::{PreDigest, SecondaryPlainPreDigest},
BABE_ENGINE_ID,
};
use sp_core::{twox_128, H256};
use sp_inherents::InherentData;
use sp_runtime::{
traits::{Block as BlockT, HashingFor},
Digest, DigestItem,
};
use sp_state_machine::TestExternalities;
use sp_std::prelude::*;
use sp_timestamp::TimestampInherentData;
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter};

Expand Down Expand Up @@ -108,6 +105,14 @@ impl<B: BlockT> InherentProvider<B> for ProviderVariant {
}
}

/// Attempts to provide inherents in a fashion that works for as many chains as possible.
///
/// It is currently tested for
/// - Polkadot-based relay chains
/// - Polkadot-ecosystem system parachains
///
/// If it does not work for your Substrate-based chain, [please open an issue](https://github.com/paritytech/try-runtime-cli/issues)
/// and we will look into supporting it.
struct SmartInherentProvider {
blocktime: Duration,
}
Expand Down