Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Moves Block, NodeBlock and UncheckedExtrinsic to frame_system, instead of construct_runtime #14193

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
e0f4cc7
Initial setup
gupnik May 15, 2023
5d688f8
Adds node block
gupnik May 15, 2023
1681e65
Uses UncheckedExtrinsic and removes Where section
gupnik May 15, 2023
3e461f1
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik May 23, 2023
a69a911
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 3, 2023
a5e7cb6
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 5, 2023
2590f43
Updates frame_system to use Block
gupnik Jun 5, 2023
f4e772a
Adds deprecation warning
gupnik Jun 5, 2023
989d2fc
Hopefully this fixes
gupnik Jun 10, 2023
ad7a25c
Fixes pallet-timestamp
gupnik Jun 11, 2023
c71aa74
Fixes node-template runtime
gupnik Jun 11, 2023
268e71f
Fixes node runtime
gupnik Jun 11, 2023
1616670
Fixes node-template
gupnik Jun 11, 2023
7bd6da7
Fixes cargo check
gupnik Jun 12, 2023
559e0e4
More fixes
gupnik Jun 12, 2023
c96d9bc
More fixes
gupnik Jun 13, 2023
0a19f0d
More fixes
gupnik Jun 13, 2023
6cb0ab9
".git/.scripts/commands/fmt/fmt.sh"
Jun 13, 2023
4ce055c
More fixes
gupnik Jun 13, 2023
9ab1b37
Removes unused import
gupnik Jun 13, 2023
54aebda
Fixes warnings
gupnik Jun 13, 2023
375bc0f
Fixes warnings
gupnik Jun 13, 2023
ee2eb17
Fixes warnings
gupnik Jun 13, 2023
9a9d41d
Fixes warnings
gupnik Jun 13, 2023
23bfc19
Fixes warnings
gupnik Jun 13, 2023
e63d231
Fixes warnings
gupnik Jun 13, 2023
3b50fe4
Fixes warnings
gupnik Jun 13, 2023
709d6a6
Fixes warnings
gupnik Jun 13, 2023
63decd8
Fixes tests
gupnik Jun 14, 2023
f66589a
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 14, 2023
b60fb81
".git/.scripts/commands/fmt/fmt.sh"
Jun 14, 2023
e5dafb9
Fixes tests
gupnik Jun 14, 2023
21abefc
Fixes doc link
gupnik Jun 14, 2023
8e2607a
Fixes warnings
gupnik Jun 14, 2023
2e4a3d2
Fixes warnings
gupnik Jun 14, 2023
b197dd0
Fixes warnings
gupnik Jun 14, 2023
dbf809e
Fixes warnings
gupnik Jun 14, 2023
922deb8
Fixes doc link and warnings
gupnik Jun 14, 2023
3377b38
Fixes tests
gupnik Jun 14, 2023
688922e
Minor update
gupnik Jun 14, 2023
dc3bf2c
Fixes tests
gupnik Jun 14, 2023
ccc76a2
Fixes impl_runtime_api
gupnik Jun 14, 2023
e0b1b14
Minor update
gupnik Jun 14, 2023
7eff183
Removes unused import
gupnik Jun 14, 2023
d39a6f2
Removes unused import
gupnik Jun 14, 2023
13db70d
Fixes tests
gupnik Jun 14, 2023
b8ded7f
Addresses review comments
gupnik Jun 18, 2023
f7a5450
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 18, 2023
7f82fe4
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 19, 2023
dbf3db3
Updates pallet-society
gupnik Jun 19, 2023
67a56fb
Updates pallet-society
gupnik Jun 19, 2023
6f40dda
Removes use_attr
gupnik Jun 19, 2023
701acd8
Fixes try-runtime-cli
gupnik Jun 19, 2023
f859b13
".git/.scripts/commands/fmt/fmt.sh"
Jun 19, 2023
204a1bc
Fixes unused import in ui tests
gupnik Jun 19, 2023
05b8873
Fixes sp-api tests
gupnik Jun 19, 2023
bf4b6aa
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 19, 2023
c9576f3
Fixes build
gupnik Jun 19, 2023
6f706bd
Uses u32 in mock block
gupnik Jun 20, 2023
60bd4c6
Uses u32 in mock block
gupnik Jun 20, 2023
dc946ad
Fixes type
gupnik Jun 20, 2023
f5f00d9
Revert "Fixes type"
gupnik Jun 20, 2023
cadd1e4
Revert "Uses u32 in mock block"
gupnik Jun 20, 2023
0040c20
Revert "Uses u32 in mock block"
gupnik Jun 20, 2023
88a92b6
Adds u32 block type
gupnik Jun 20, 2023
24e9580
Fixes doc tests
gupnik Jun 20, 2023
a2ecd52
".git/.scripts/commands/fmt/fmt.sh"
Jun 20, 2023
37d6cf4
Revert "Fixes doc tests"
gupnik Jun 20, 2023
6d18500
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 20, 2023
8461e97
Removes doc for decl_* to make CI happy
gupnik Jun 20, 2023
1c45275
Fixes sp-api doc
gupnik Jun 20, 2023
9296a79
Fixes rpc-support doc
gupnik Jun 20, 2023
86b6824
Merge branch 'master' of github.com:paritytech/substrate into gupnik/…
gupnik Jun 20, 2023
c537e8f
".git/.scripts/commands/fmt/fmt.sh"
Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 3 additions & 11 deletions bin/node-template/pallets/template/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
use crate as pallet_template;
use frame_support::traits::{ConstU16, ConstU64};
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
};
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system,
TemplateModule: pallet_template,
Expand All @@ -29,12 +22,11 @@ impl frame_system::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ConstU64<250>;
type Version = ();
Expand Down
26 changes: 10 additions & 16 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, NumberFor, One, Verify,
AccountIdLookup, BlakeTwo256, Block as BlockT, HeaderProvider, IdentifyAccount, NumberFor,
One, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
Expand Down Expand Up @@ -155,6 +156,8 @@ parameter_types! {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = frame_support::traits::Everything;
/// The block type for the runtime.
type Block = Block;
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
Expand All @@ -167,14 +170,10 @@ impl frame_system::Config for Runtime {
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
type BlockNumber = BlockNumber;
/// The type for hashing blocks and tries.
type Hash = Hash;
/// The hashing algorithm used.
type Hashing = BlakeTwo256;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
type RuntimeEvent = RuntimeEvent;
/// The ubiquitous origin type.
Expand Down Expand Up @@ -278,12 +277,7 @@ impl pallet_template::Config for Runtime {

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub struct Runtime
where
Block = Block,
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
pub struct Runtime {
System: frame_system,
Timestamp: pallet_timestamp,
Aura: pallet_aura,
Expand Down Expand Up @@ -354,7 +348,7 @@ impl_runtime_apis! {
Executive::execute_block(block);
}

fn initialize_block(header: &<Block as BlockT>::Header) {
fn initialize_block(header: &<Block as HeaderProvider>::Header) {
Executive::initialize_block(header)
}
}
Expand All @@ -378,7 +372,7 @@ impl_runtime_apis! {
Executive::apply_extrinsic(extrinsic)
}

fn finalize_block() -> <Block as BlockT>::Header {
fn finalize_block() -> <Block as HeaderProvider>::Header {
Executive::finalize_block()
}

Expand All @@ -398,14 +392,14 @@ impl_runtime_apis! {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
block_hash: <Block as HeaderProvider>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
}
}

impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
fn offchain_worker(header: &<Block as HeaderProvider>::Header) {
Executive::offchain_worker(header)
}
}
Expand Down Expand Up @@ -443,7 +437,7 @@ impl_runtime_apis! {

fn submit_report_equivocation_unsigned_extrinsic(
_equivocation_proof: sp_consensus_grandpa::EquivocationProof<
<Block as BlockT>::Hash,
<Block as HeaderProvider>::Hash,
NumberFor<Block>,
>,
_key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
Expand Down
4 changes: 2 additions & 2 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use sc_statement_store::Store as StatementStore;
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_api::ProvideRuntimeApi;
use sp_core::crypto::Pair;
use sp_runtime::{generic, traits::Block as BlockT, SaturatedConversion};
use sp_runtime::{generic, traits::HeaderProvider, SaturatedConversion};
use std::sync::Arc;

/// The full client type definition.
Expand Down Expand Up @@ -305,7 +305,7 @@ pub struct NewFullBase {
/// The client instance of the node.
pub client: Arc<FullClient>,
/// The networking service of the node.
pub network: Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
pub network: Arc<NetworkService<Block, <Block as HeaderProvider>::Hash>>,
/// The syncing service of the node.
pub sync: Arc<SyncingService<Block>>,
/// The transaction pool of the node.
Expand Down
6 changes: 5 additions & 1 deletion bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ where
+ Send
+ 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash, BlockNumber>,
C::Api: mmr_rpc::MmrRuntimeApi<
Block,
<Block as sp_runtime::traits::HeaderProvider>::Hash,
BlockNumber,
>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>,
C::Api: BlockBuilder<Block>,
Expand Down
24 changes: 10 additions & 14 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ use sp_runtime::{
curve::PiecewiseLinear,
generic, impl_opaque_keys,
traits::{
self, AccountIdConversion, BlakeTwo256, Block as BlockT, Bounded, ConvertInto, NumberFor,
OpaqueKeys, SaturatedConversion, StaticLookup,
self, AccountIdConversion, BlakeTwo256, Block as BlockT, Bounded, ConvertInto,
HeaderProvider, NumberFor, OpaqueKeys, SaturatedConversion, StaticLookup,
},
transaction_validity::{TransactionPriority, TransactionSource, TransactionValidity},
ApplyExtrinsicResult, FixedPointNumber, FixedU128, Perbill, Percent, Permill, Perquintill,
Expand Down Expand Up @@ -227,12 +227,11 @@ impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = Index;
type BlockNumber = BlockNumber;
type Hash = Hash;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = Indices;
type Header = generic::Header<BlockNumber, BlakeTwo256>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = Version;
Expand Down Expand Up @@ -1860,10 +1859,7 @@ impl pallet_statement::Config for Runtime {
}

construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = node_primitives::Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub struct Runtime
{
System: frame_system,
Utility: pallet_utility,
Expand Down Expand Up @@ -2076,7 +2072,7 @@ impl_runtime_apis! {
Executive::execute_block(block);
}

fn initialize_block(header: &<Block as BlockT>::Header) {
fn initialize_block(header: &<Block as HeaderProvider>::Header) {
Executive::initialize_block(header)
}
}
Expand All @@ -2100,7 +2096,7 @@ impl_runtime_apis! {
Executive::apply_extrinsic(extrinsic)
}

fn finalize_block() -> <Block as BlockT>::Header {
fn finalize_block() -> <Block as HeaderProvider>::Header {
Executive::finalize_block()
}

Expand All @@ -2117,7 +2113,7 @@ impl_runtime_apis! {
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: <Block as BlockT>::Hash,
block_hash: <Block as HeaderProvider>::Hash,
) -> TransactionValidity {
Executive::validate_transaction(source, tx, block_hash)
}
Expand All @@ -2133,7 +2129,7 @@ impl_runtime_apis! {
}

impl sp_offchain::OffchainWorkerApi<Block> for Runtime {
fn offchain_worker(header: &<Block as BlockT>::Header) {
fn offchain_worker(header: &<Block as HeaderProvider>::Header) {
Executive::offchain_worker(header)
}
}
Expand All @@ -2149,7 +2145,7 @@ impl_runtime_apis! {

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: sp_consensus_grandpa::EquivocationProof<
<Block as BlockT>::Hash,
<Block as HeaderProvider>::Hash,
NumberFor<Block>,
>,
key_owner_proof: sp_consensus_grandpa::OpaqueKeyOwnershipProof,
Expand Down Expand Up @@ -2231,7 +2227,7 @@ impl_runtime_apis! {
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: sp_consensus_babe::EquivocationProof<<Block as BlockT>::Header>,
equivocation_proof: sp_consensus_babe::EquivocationProof<<Block as HeaderProvider>::Header>,
key_owner_proof: sp_consensus_babe::OpaqueKeyOwnershipProof,
) -> Option<()> {
let key_owner_proof = key_owner_proof.decode()?;
Expand Down
4 changes: 2 additions & 2 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use parking_lot::RwLock;
use sp_consensus::BlockOrigin;
use sp_core::offchain::OffchainStorage;
use sp_runtime::{
traits::{Block as BlockT, HashFor, NumberFor},
traits::{Block as BlockT, HashFor, HeaderProvider, NumberFor},
Justification, Justifications, StateVersion, Storage,
};
use sp_state_machine::{
Expand Down Expand Up @@ -444,7 +444,7 @@ pub trait StorageProvider<Block: BlockT, B: Backend<Block>> {
/// values in that block.
fn storage_pairs(
&self,
hash: <Block as BlockT>::Hash,
hash: <Block as HeaderProvider>::Hash,
prefix: Option<&StorageKey>,
start_key: Option<&StorageKey>,
) -> sp_blockchain::Result<PairsIter<B::State, Block>>;
Expand Down
6 changes: 3 additions & 3 deletions client/api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_consensus::BlockOrigin;
use sp_core::storage::StorageKey;
use sp_runtime::{
generic::SignedBlock,
traits::{Block as BlockT, NumberFor},
traits::{Block as BlockT, HeaderProvider, NumberFor},
Justifications,
};
use std::{collections::HashSet, fmt, sync::Arc};
Expand All @@ -44,12 +44,12 @@ pub type FinalityNotifications<Block> = TracingUnboundedReceiver<FinalityNotific
/// This may be used as chain spec extension to set trusted checkpoints, i.e.
/// the client will refuse to import a block with a different hash at the given
/// height.
pub type ForkBlocks<Block> = Option<Vec<(NumberFor<Block>, <Block as BlockT>::Hash)>>;
pub type ForkBlocks<Block> = Option<Vec<(NumberFor<Block>, <Block as HeaderProvider>::Hash)>>;

/// Known bad block hashes.
///
/// This may be used as chain spec extension to filter out known, unwanted forks.
pub type BadBlocks<Block> = Option<HashSet<<Block as BlockT>::Hash>>;
pub type BadBlocks<Block> = Option<HashSet<<Block as HeaderProvider>::Hash>>;

/// Figure out the block type for a given type (for now, just a `Client`).
pub trait BlockOf {
Expand Down
18 changes: 9 additions & 9 deletions client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_core::{
};
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor, Zero},
traits::{Block as BlockT, HashFor, Header as HeaderT, HeaderProvider, NumberFor, Zero},
Justification, Justifications, StateVersion, Storage,
};
use sp_state_machine::{
Expand Down Expand Up @@ -155,7 +155,7 @@ impl<Block: BlockT> Blockchain<Block> {
pub fn insert(
&self,
hash: Block::Hash,
header: <Block as BlockT>::Header,
header: <Block as HeaderProvider>::Header,
justifications: Option<Justifications>,
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
new_state: NewBlockState,
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<Block: BlockT> Blockchain<Block> {
self.apply_head(&header)
}

fn apply_head(&self, header: &<Block as BlockT>::Header) -> sp_blockchain::Result<()> {
fn apply_head(&self, header: &<Block as HeaderProvider>::Header) -> sp_blockchain::Result<()> {
let hash = header.hash();
let number = header.number();

Expand Down Expand Up @@ -331,7 +331,7 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
fn header(
&self,
hash: Block::Hash,
) -> sp_blockchain::Result<Option<<Block as BlockT>::Header>> {
) -> sp_blockchain::Result<Option<<Block as HeaderProvider>::Header>> {
Ok(self.storage.read().blocks.get(&hash).map(|b| b.header().clone()))
}

Expand Down Expand Up @@ -366,7 +366,7 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {

fn hash(
&self,
number: <<Block as BlockT>::Header as HeaderT>::Number,
number: <<Block as HeaderProvider>::Header as HeaderT>::Number,
) -> sp_blockchain::Result<Option<Block::Hash>> {
Ok(self.id(BlockId::Number(number)))
}
Expand Down Expand Up @@ -525,7 +525,7 @@ impl<Block: BlockT> backend::BlockImportOperation<Block> for BlockImportOperatio

fn set_block_data(
&mut self,
header: <Block as BlockT>::Header,
header: <Block as HeaderProvider>::Header,
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
_indexed_body: Option<Vec<Vec<u8>>>,
justifications: Option<Justifications>,
Expand Down Expand Up @@ -632,7 +632,7 @@ impl<Block: BlockT> Backend<Block> {
/// # Warning
///
/// For testing purposes only!
pub fn pin_refs(&self, hash: &<Block as BlockT>::Hash) -> Option<i64> {
pub fn pin_refs(&self, hash: &<Block as HeaderProvider>::Hash) -> Option<i64> {
let blocks = self.pinned_blocks.read();
blocks.get(hash).map(|value| *value)
}
Expand Down Expand Up @@ -779,13 +779,13 @@ impl<Block: BlockT> backend::Backend<Block> for Backend<Block> {
false
}

fn pin_block(&self, hash: <Block as BlockT>::Hash) -> blockchain::Result<()> {
fn pin_block(&self, hash: <Block as HeaderProvider>::Hash) -> blockchain::Result<()> {
let mut blocks = self.pinned_blocks.write();
*blocks.entry(hash).or_default() += 1;
Ok(())
}

fn unpin_block(&self, hash: <Block as BlockT>::Hash) {
fn unpin_block(&self, hash: <Block as HeaderProvider>::Hash) {
let mut blocks = self.pinned_blocks.write();
blocks.entry(hash).and_modify(|counter| *counter -= 1).or_insert(-1);
}
Expand Down
Loading