mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 20:01:08 +00:00
Scale trait and move to u32 blocknumbers (#3357)
* Scale trait and move to u32 blocknumbers. * Fixes * Cleanups * Update node/runtime/src/lib.rs Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com> * Fix up some of the factory stuff. * Update core/sr-primitives/src/traits.rs Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com> * Move Nonce/Index to u32 (#3361) * Force a non-borked version of upstream crate * Line lengths and runtime version bump
This commit is contained in:
@@ -49,7 +49,7 @@ keystore = { package = "substrate-keystore", path = "../../core/keystore" }
|
||||
babe = { package = "substrate-consensus-babe", path = "../../core/consensus/babe", features = ["test-helpers"] }
|
||||
consensus-common = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
|
||||
service-test = { package = "substrate-service-test", path = "../../core/service/test" }
|
||||
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17" }
|
||||
futures03 = { package = "futures-preview", version = "=0.3.0-alpha.17" }
|
||||
tempfile = "3.1"
|
||||
|
||||
[build-dependencies]
|
||||
|
||||
@@ -39,11 +39,11 @@ pub struct FactoryState<N> {
|
||||
block_no: N,
|
||||
|
||||
mode: Mode,
|
||||
start_number: u64,
|
||||
rounds: u64,
|
||||
round: u64,
|
||||
block_in_round: u64,
|
||||
num: u64,
|
||||
start_number: u32,
|
||||
rounds: u32,
|
||||
round: u32,
|
||||
block_in_round: u32,
|
||||
num: u32,
|
||||
}
|
||||
|
||||
type Number = <<node_primitives::Block as BlockT>::Header as HeaderT>::Number;
|
||||
@@ -77,9 +77,9 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
) -> FactoryState<Self::Number> {
|
||||
FactoryState {
|
||||
mode,
|
||||
num: num,
|
||||
num: num as u32,
|
||||
round: 0,
|
||||
rounds,
|
||||
rounds: rounds as u32,
|
||||
block_in_round: 0,
|
||||
block_no: 0,
|
||||
start_number: 0,
|
||||
@@ -150,7 +150,7 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
}
|
||||
|
||||
fn inherent_extrinsics(&self) -> InherentData {
|
||||
let timestamp = self.block_no * MINIMUM_PERIOD;
|
||||
let timestamp = self.block_no as u64 * MINIMUM_PERIOD;
|
||||
|
||||
let mut inherent = InherentData::new();
|
||||
inherent.put_data(timestamp::INHERENT_IDENTIFIER, ×tamp)
|
||||
@@ -194,12 +194,12 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
// This currently prevents the factory from being used
|
||||
// without a preceding purge of the database.
|
||||
if self.mode == Mode::MasterToN || self.mode == Mode::MasterTo1 {
|
||||
self.block_no()
|
||||
self.block_no() as Self::Index
|
||||
} else {
|
||||
match self.round() {
|
||||
0 =>
|
||||
// if round is 0 all transactions will be done with master as a sender
|
||||
self.block_no(),
|
||||
self.block_no() as Self::Index,
|
||||
_ =>
|
||||
// if round is e.g. 1 every sender account will be new and not yet have
|
||||
// any transactions done
|
||||
@@ -215,12 +215,12 @@ impl RuntimeAdapter for FactoryState<Number> {
|
||||
// TODO get correct phase via api. See #2587.
|
||||
// This currently prevents the factory from being used
|
||||
// without a preceding purge of the database.
|
||||
self.block_no
|
||||
self.block_no() as Self::Phase
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_seed_bytes(seed: u64) -> [u8; 32] {
|
||||
let mut rng: StdRng = SeedableRng::seed_from_u64(seed);
|
||||
fn gen_seed_bytes(seed: u32) -> [u8; 32] {
|
||||
let mut rng: StdRng = SeedableRng::seed_from_u64(seed as u64);
|
||||
|
||||
let mut seed_bytes = [0u8; 32];
|
||||
for i in 0..32 {
|
||||
|
||||
@@ -88,19 +88,32 @@ construct_service_factory! {
|
||||
RuntimeApi = RuntimeApi,
|
||||
NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) },
|
||||
RuntimeDispatch = node_executor::Executor,
|
||||
FullTransactionPoolApi = transaction_pool::ChainApi<client::Client<FullBackend<Self>, FullExecutor<Self>, Block, RuntimeApi>, Block>
|
||||
{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
|
||||
LightTransactionPoolApi = transaction_pool::ChainApi<client::Client<LightBackend<Self>, LightExecutor<Self>, Block, RuntimeApi>, Block>
|
||||
{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
|
||||
FullTransactionPoolApi =
|
||||
transaction_pool::ChainApi<
|
||||
client::Client<FullBackend<Self>, FullExecutor<Self>, Block, RuntimeApi>,
|
||||
Block
|
||||
> {
|
||||
|config, client|
|
||||
Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client)))
|
||||
},
|
||||
LightTransactionPoolApi =
|
||||
transaction_pool::ChainApi<
|
||||
client::Client<LightBackend<Self>, LightExecutor<Self>, Block, RuntimeApi>,
|
||||
Block
|
||||
> {
|
||||
|config, client|
|
||||
Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client)))
|
||||
},
|
||||
Genesis = GenesisConfig,
|
||||
Configuration = NodeConfig<Self>,
|
||||
FullService = FullComponents<Self>
|
||||
{ |config: FactoryFullConfiguration<Self>|
|
||||
FullComponents::<Factory>::new(config) },
|
||||
FullService = FullComponents<Self> {
|
||||
|config: FactoryFullConfiguration<Self>| FullComponents::<Factory>::new(config)
|
||||
},
|
||||
AuthoritySetup = {
|
||||
|mut service: Self::FullService| {
|
||||
let (block_import, link_half, babe_link) = service.config_mut().custom.import_setup.take()
|
||||
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
|
||||
let (block_import, link_half, babe_link) =
|
||||
service.config_mut().custom.import_setup.take()
|
||||
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
|
||||
|
||||
// spawn any futures that were created in the previous setup steps
|
||||
if let Some(tasks) = service.config_mut().custom.tasks_to_spawn.take() {
|
||||
@@ -120,7 +133,8 @@ construct_service_factory! {
|
||||
};
|
||||
|
||||
let client = service.client();
|
||||
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
|
||||
let select_chain = service.select_chain()
|
||||
.ok_or(ServiceError::SelectChainRequired)?;
|
||||
|
||||
let babe_config = babe::BabeParams {
|
||||
config: Config::get_or_compute(&*client)?,
|
||||
@@ -130,7 +144,8 @@ construct_service_factory! {
|
||||
block_import,
|
||||
env: proposer,
|
||||
sync_oracle: service.network(),
|
||||
inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
||||
inherent_data_providers: service.config()
|
||||
.custom.inherent_data_providers.clone(),
|
||||
force_authoring: service.config().force_authoring,
|
||||
time_source: babe_link,
|
||||
};
|
||||
@@ -167,7 +182,8 @@ construct_service_factory! {
|
||||
config: config,
|
||||
link: link_half,
|
||||
network: service.network(),
|
||||
inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
||||
inherent_data_providers:
|
||||
service.config().custom.inherent_data_providers.clone(),
|
||||
on_exit: service.on_exit(),
|
||||
telemetry_on_connect: Some(telemetry_on_connect),
|
||||
};
|
||||
@@ -187,8 +203,12 @@ construct_service_factory! {
|
||||
},
|
||||
LightService = LightComponents<Self>
|
||||
{ |config| <LightComponents<Factory>>::new(config) },
|
||||
FullImportQueue = BabeImportQueue<Self::Block>
|
||||
{ |config: &mut FactoryFullConfiguration<Self> , client: Arc<FullClient<Self>>, select_chain: Self::SelectChain| {
|
||||
FullImportQueue = BabeImportQueue<Self::Block> {
|
||||
|
|
||||
config: &mut FactoryFullConfiguration<Self>,
|
||||
client: Arc<FullClient<Self>>,
|
||||
select_chain: Self::SelectChain
|
||||
| {
|
||||
let (block_import, link_half) =
|
||||
grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>, _>(
|
||||
client.clone(), client.clone(), select_chain
|
||||
@@ -222,7 +242,8 @@ construct_service_factory! {
|
||||
)?;
|
||||
|
||||
let finality_proof_import = block_import.clone();
|
||||
let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder();
|
||||
let finality_proof_request_builder =
|
||||
finality_proof_import.create_finality_proof_request_builder();
|
||||
|
||||
// FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`.
|
||||
let (import_queue, ..) = import_queue(
|
||||
@@ -254,7 +275,9 @@ construct_service_factory! {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use babe::CompatibleDigestItem;
|
||||
use consensus_common::{Environment, Proposer, BlockImportParams, BlockOrigin, ForkChoiceStrategy};
|
||||
use consensus_common::{
|
||||
Environment, Proposer, BlockImportParams, BlockOrigin, ForkChoiceStrategy
|
||||
};
|
||||
use node_primitives::DigestItem;
|
||||
use node_runtime::{BalancesCall, Call, UncheckedExtrinsic};
|
||||
use node_runtime::constants::{currency::CENTS, time::SLOT_DURATION};
|
||||
@@ -306,7 +329,9 @@ mod tests {
|
||||
auxiliary: Vec::new(),
|
||||
}
|
||||
};
|
||||
let extrinsic_factory = |service: &SyncService<<Factory as service::ServiceFactory>::FullService>| {
|
||||
let extrinsic_factory =
|
||||
|service: &SyncService<<Factory as service::ServiceFactory>::FullService>|
|
||||
{
|
||||
let payload = (
|
||||
0,
|
||||
Call::Balances(BalancesCall::transfer(RawAddress::Id(bob.public().0.into()), 69.into())),
|
||||
@@ -333,7 +358,8 @@ mod tests {
|
||||
#[ignore]
|
||||
fn test_sync() {
|
||||
let keystore_path = tempfile::tempdir().expect("Creates keystore path");
|
||||
let keystore = keystore::Store::open(keystore_path.path(), None).expect("Creates keystore");
|
||||
let keystore = keystore::Store::open(keystore_path.path(), None)
|
||||
.expect("Creates keystore");
|
||||
let alice = keystore.write().insert_ephemeral_from_seed::<babe::AuthorityPair>("//Alice")
|
||||
.expect("Creates authority pair");
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ mod tests {
|
||||
})
|
||||
}
|
||||
|
||||
fn from_block_number(n: u64) -> Header {
|
||||
fn from_block_number(n: u32) -> Header {
|
||||
Header::new(n, Default::default(), Default::default(), [69; 32].into(), Default::default())
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ mod tests {
|
||||
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_initialize_block",
|
||||
&vec![].and(&from_block_number(1u64)),
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
@@ -228,7 +228,7 @@ mod tests {
|
||||
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_initialize_block",
|
||||
&vec![].and(&from_block_number(1u64)),
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
@@ -260,7 +260,7 @@ mod tests {
|
||||
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_initialize_block",
|
||||
&vec![].and(&from_block_number(1u64)),
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
@@ -296,7 +296,7 @@ mod tests {
|
||||
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_initialize_block",
|
||||
&vec![].and(&from_block_number(1u64)),
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
@@ -523,7 +523,7 @@ mod tests {
|
||||
(block1, block2)
|
||||
}
|
||||
|
||||
fn block_with_size(time: u64, nonce: u64, size: usize) -> (Vec<u8>, Hash) {
|
||||
fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
|
||||
construct_block(
|
||||
&mut new_test_ext(COMPACT_CODE, false),
|
||||
1,
|
||||
@@ -887,7 +887,7 @@ mod tests {
|
||||
], map![]));
|
||||
|
||||
let r = WasmExecutor::new()
|
||||
.call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u64)));
|
||||
.call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u32)));
|
||||
assert!(r.is_ok());
|
||||
let r = WasmExecutor::new()
|
||||
.call(&mut t, 8, COMPACT_CODE, "BlockBuilder_apply_extrinsic", &vec![].and(&xt())).unwrap();
|
||||
@@ -909,7 +909,7 @@ mod tests {
|
||||
], map![]));
|
||||
|
||||
let r = WasmExecutor::new()
|
||||
.call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u64)));
|
||||
.call(&mut t, 8, COMPACT_CODE, "Core_initialize_block", &vec![].and(&from_block_number(1u32)));
|
||||
assert!(r.is_ok());
|
||||
let r = WasmExecutor::new()
|
||||
.call(&mut t, 8, COMPACT_CODE, "BlockBuilder_apply_extrinsic", &vec![].and(&xt())).unwrap();
|
||||
@@ -1080,7 +1080,7 @@ mod tests {
|
||||
let r = executor().call::<_, NeverNativeValue, fn() -> _>(
|
||||
&mut t,
|
||||
"Core_initialize_block",
|
||||
&vec![].and(&from_block_number(1u64)),
|
||||
&vec![].and(&from_block_number(1u32)),
|
||||
true,
|
||||
None,
|
||||
).0;
|
||||
|
||||
@@ -25,7 +25,7 @@ use sr_primitives::{
|
||||
};
|
||||
|
||||
/// An index to a block.
|
||||
pub type BlockNumber = u64;
|
||||
pub type BlockNumber = u32;
|
||||
|
||||
/// Alias to 512-bit hash when used in the context of a transaction signature on the chain.
|
||||
pub type Signature = AnySignature;
|
||||
@@ -45,7 +45,7 @@ pub type Balance = u128;
|
||||
pub type Moment = u64;
|
||||
|
||||
/// Index of a transaction in the chain.
|
||||
pub type Index = u64;
|
||||
pub type Index = u32;
|
||||
|
||||
/// A hash of some data used by the chain.
|
||||
pub type Hash = primitives::H256;
|
||||
|
||||
@@ -27,7 +27,7 @@ pub mod currency {
|
||||
|
||||
/// Time.
|
||||
pub mod time {
|
||||
use node_primitives::Moment;
|
||||
use node_primitives::{Moment, BlockNumber};
|
||||
|
||||
/// Since BABE is probabilistic this is the average expected block time that
|
||||
/// we are targetting. Blocks will be produced at a minimum duration defined
|
||||
@@ -46,17 +46,17 @@ pub mod time {
|
||||
|
||||
pub const SLOT_DURATION: Moment = 1650;
|
||||
|
||||
pub const EPOCH_DURATION_IN_BLOCKS: Moment = 10 * MINUTES;
|
||||
pub const EPOCH_DURATION_IN_SLOTS: Moment = {
|
||||
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 10 * MINUTES;
|
||||
pub const EPOCH_DURATION_IN_SLOTS: u64 = {
|
||||
const SLOT_FILL_RATE: f64 = MILLISECS_PER_BLOCK as f64 / SLOT_DURATION as f64;
|
||||
|
||||
(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as Moment
|
||||
(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
|
||||
};
|
||||
|
||||
// These time units are defined in number of blocks.
|
||||
pub const MINUTES: Moment = 60 / SECS_PER_BLOCK;
|
||||
pub const HOURS: Moment = MINUTES * 60;
|
||||
pub const DAYS: Moment = HOURS * 24;
|
||||
pub const MINUTES: BlockNumber = 60 / (SECS_PER_BLOCK as BlockNumber);
|
||||
pub const HOURS: BlockNumber = MINUTES * 60;
|
||||
pub const DAYS: BlockNumber = HOURS * 24;
|
||||
}
|
||||
|
||||
// CRITICAL NOTE: The system module maintains two constants: a _maximum_ block weight and a
|
||||
|
||||
@@ -80,8 +80,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// and set impl_version to equal spec_version. If only runtime
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 137,
|
||||
impl_version: 137,
|
||||
spec_version: 138,
|
||||
impl_version: 138,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
|
||||
@@ -179,7 +179,7 @@ impl timestamp::Trait for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const UncleGenerations: u64 = 5;
|
||||
pub const UncleGenerations: BlockNumber = 5;
|
||||
}
|
||||
|
||||
impl authorship::Trait for Runtime {
|
||||
|
||||
Reference in New Issue
Block a user