Substrate 3.0 (#232)

* Update substrate deps to 3.0.0 and 0.9.0

* Update substrate wasm tools

* Fixing errors for 3.0.0 compat

* Fixing more errors for 3.0.0 compat

* Use MultiAddress for test runtime

* Fmt

* Fix node test

* Pin Funty

* Update AccountInfo struct

* Add comment about funty pin
This commit is contained in:
Andrew Jones
2021-02-17 16:45:05 +00:00
committed by GitHub
parent 51c48f223a
commit 2c8e5211aa
17 changed files with 218 additions and 191 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ fn_single_line = false
where_single_line = false
imports_indent = "Block"
imports_layout = "Vertical" # changed
merge_imports = true # changed
imports_granularity= "Crate" # changed
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
+17 -14
View File
@@ -32,29 +32,32 @@ num-traits = { version = "0.2.14", default-features = false }
serde = { version = "1.0.119", features = ["derive"] }
serde_json = "1.0.61"
url = "2.2.0"
codec = { package = "parity-scale-codec", version = "1.3.6", default-features = false, features = ["derive", "full"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "full"] }
# temporarily pinning funty via codec -> bitvec until https://github.com/myrrlyn/funty/issues/3
# and https://github.com/bitvecto-rs/bitvec/issues/105 are resolved
funty = "=1.1.0"
frame-metadata = "12.0.1"
frame-support = "2.0.1"
sp-runtime = "2.0.1"
sp-version = "2.0.1"
pallet-indices = "2.0.1"
frame-metadata = "13.0.0"
frame-support = "3.0.0"
sp-runtime = "3.0.0"
sp-version = "3.0.0"
pallet-indices = "3.0.0"
hex = "0.4.2"
sp-std = "2.0.1"
application-crypto = { version = "2.0.1", package = "sp-application-crypto" }
pallet-staking = "2.0.1"
sp-std = "3.0.0"
application-crypto = { version = "3.0.0", package = "sp-application-crypto" }
pallet-staking = "3.0.0"
sp-rpc = { version = "2.0.1", package = "sp-rpc" }
sp-core = { version = "2.0.1", package = "sp-core" }
sp-rpc = { version = "3.0.0", package = "sp-rpc" }
sp-core = { version = "3.0.0", package = "sp-core" }
substrate-subxt-client = { version = "0.6.0", path = "client", optional = true }
substrate-subxt-proc-macro = { version = "0.14.0", path = "proc-macro" }
[dev-dependencies]
async-std = { version = "1.8.0", features = ["attributes"] }
env_logger = "0.8.2"
frame-system = "2.0.1"
pallet-balances = "2.0.1"
sp-keyring = "2.0.1"
frame-system = "3.0.0"
pallet-balances = "3.0.0"
sp-keyring = "3.0.0"
substrate-subxt-client = { version = "0.6.0", path = "client" }
tempdir = "0.3.7"
test-node = { path = "test-node" }
+4 -3
View File
@@ -17,10 +17,11 @@ futures = { version = "0.3.9", features = ["compat"], package = "futures" }
futures01 = { package = "futures", version = "0.1.29" }
jsonrpsee = "0.1.0"
log = "0.4.13"
sc-network = { version = "0.8.1", default-features = false }
sc-service = { version = "0.8.1", default-features = false }
sc-network = { version = "0.9.0", default-features = false }
sc-client-db = "0.9.0"
sc-service = { version = "0.9.0", default-features = false }
serde_json = "1.0.61"
sp-keyring = "2.0.1"
sp-keyring = "3.0.0"
thiserror = "1.0.23"
[dev-dependencies]
+10 -3
View File
@@ -57,6 +57,7 @@ use sc_service::{
},
ChainSpec,
Configuration,
KeepBlocks,
RpcHandlers,
RpcSession,
TaskManager,
@@ -232,7 +233,6 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
enable_mdns: true,
allow_private_ipv4: true,
wasm_external_transport: None,
use_yamux_flow_control: true,
};
let telemetry_endpoints = if let Some(port) = self.telemetry {
let endpoints = TelemetryEndpoints::new(vec![(
@@ -265,13 +265,17 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
telemetry_endpoints,
telemetry_external_transport: Default::default(),
telemetry_handle: Default::default(),
telemetry_span: Default::default(),
default_heap_pages: Default::default(),
disable_grandpa: Default::default(),
disable_log_reloading: Default::default(),
execution_strategies: Default::default(),
force_authoring: Default::default(),
keep_blocks: KeepBlocks::All,
keystore_remote: Default::default(),
offchain_worker: Default::default(),
prometheus_config: Default::default(),
pruning: Default::default(),
rpc_cors: Default::default(),
rpc_http: Default::default(),
rpc_ipc: Default::default(),
@@ -286,6 +290,9 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
wasm_method: Default::default(),
base_path: Default::default(),
informant_output_format: Default::default(),
state_pruning: Default::default(),
transaction_storage: sc_client_db::TransactionStorageMode::BlockBody,
wasm_runtime_overrides: Default::default(),
};
log::info!("{}", service_config.impl_name);
@@ -310,7 +317,7 @@ mod tests {
use substrate_subxt::{
balances::TransferCallExt,
ClientBuilder,
KusamaRuntime as NodeTemplateRuntime,
NodeTemplateRuntime,
PairSigner,
};
use tempdir::TempDir;
+2 -2
View File
@@ -25,10 +25,10 @@ synstructure = "0.12.4"
[dev-dependencies]
async-std = { version = "1.8.0", features = ["attributes"] }
codec = { package = "parity-scale-codec", version = "1.3.6", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] }
env_logger = "0.8.2"
pretty_assertions = "0.6.1"
sp-keyring = "2.0.1"
sp-keyring = "3.0.0"
substrate-subxt = { path = ".." }
trybuild = "1.0.38"
+8
View File
@@ -98,6 +98,12 @@ pub enum RuntimeError {
/// Module error.
#[error("Runtime module error: {0}")]
Module(ModuleError),
/// At least one consumer is remaining so the account cannot be destroyed.
#[error("At least one consumer is remaining so the account cannot be destroyed.")]
ConsumerRemaining,
/// There are no providers so the account cannot be created.
#[error("There are no providers so the account cannot be created.")]
NoProviders,
/// Bad origin.
#[error("Bad origin: throw by ensure_signed, ensure_root or ensure_none.")]
BadOrigin,
@@ -130,6 +136,8 @@ impl RuntimeError {
}
DispatchError::BadOrigin => Ok(Self::BadOrigin),
DispatchError::CannotLookup => Ok(Self::CannotLookup),
DispatchError::ConsumerRemaining => Ok(Self::ConsumerRemaining),
DispatchError::NoProviders => Ok(Self::NoProviders),
DispatchError::Other(msg) => Ok(Self::Other(msg.into())),
}
}
+11 -7
View File
@@ -182,13 +182,14 @@ mod tests {
env_logger::try_init().ok();
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = PairSigner::<TestRuntime, _>::new(AccountKeyring::Bob.pair());
let bob_address = bob.account_id().clone().into();
let (client, _) = test_client().await;
let alice_pre = client.account(alice.account_id(), None).await.unwrap();
let bob_pre = client.account(bob.account_id(), None).await.unwrap();
let event = client
.transfer_and_watch(&alice, &bob.account_id(), 10_000)
.transfer_and_watch(&alice, &bob_address, 10_000)
.await
.expect("sending an xt works")
.transfer()
@@ -269,15 +270,17 @@ mod tests {
#[async_std::test]
async fn test_transfer_error() {
env_logger::try_init().ok();
let alice = PairSigner::new(AccountKeyring::Alice.pair());
let hans = PairSigner::new(Pair::generate().0);
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let alice_addr = alice.account_id().clone().into();
let hans = PairSigner::<TestRuntime, _>::new(Pair::generate().0);
let hans_address = hans.account_id().clone().into();
let (client, _) = test_client().await;
client
.transfer_and_watch(&alice, hans.account_id(), 100_000_000_000)
.transfer_and_watch(&alice, &hans_address, 100_000_000_000)
.await
.unwrap();
let res = client
.transfer_and_watch(&hans, alice.account_id(), 100_000_000_000)
.transfer_and_watch(&hans, &alice_addr, 100_000_000_000)
.await;
if let Err(Error::Runtime(RuntimeError::Module(error))) = res {
let error2 = ModuleError {
@@ -293,15 +296,16 @@ mod tests {
#[async_std::test]
async fn test_transfer_subscription() {
env_logger::try_init().ok();
let alice = PairSigner::new(AccountKeyring::Alice.pair());
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = AccountKeyring::Bob.to_account_id();
let bob_addr = bob.clone().into();
let (client, _) = test_client().await;
let sub = client.subscribe_events().await.unwrap();
let mut decoder = EventsDecoder::<TestRuntime>::new(client.metadata().clone());
decoder.with_balances();
let mut sub = EventSubscription::<TestRuntime>::new(sub, decoder);
sub.filter_event::<TransferEvent<_>>();
client.transfer(&alice, &bob, 10_000).await.unwrap();
client.transfer(&alice, &bob_addr, 10_000).await.unwrap();
let raw = sub.next().await.unwrap().unwrap();
let event = TransferEvent::<TestRuntime>::decode(&mut &raw.data[..]).unwrap();
assert_eq!(
+4 -2
View File
@@ -75,11 +75,12 @@ mod tests {
async fn test_sudo() {
env_logger::try_init().ok();
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = AccountKeyring::Bob.to_account_id().clone().into();
let (client, _) = test_client().await;
let call = client
.encode(TransferCall {
to: &AccountKeyring::Bob.to_account_id(),
to: &bob,
amount: 10_000,
})
.unwrap();
@@ -98,11 +99,12 @@ mod tests {
async fn test_sudo_unchecked_weight() {
env_logger::try_init().ok();
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let bob = AccountKeyring::Bob.to_account_id().into();
let (client, _) = test_client().await;
let call = client
.encode(TransferCall {
to: &AccountKeyring::Bob.to_account_id(),
to: &bob,
amount: 10_000,
})
.unwrap();
+4 -1
View File
@@ -127,7 +127,10 @@ pub struct AccountInfo<T: System> {
pub nonce: T::Index,
/// The number of other modules that currently depend on this account's existence. The account
/// cannot be reaped until this is zero.
pub refcount: RefCount,
pub consumers: RefCount,
/// The number of other modules that allow this account to exist. The account may not be reaped
/// until this is zero.
pub providers: RefCount,
/// The additional data that belongs to this account. Used to store the balance(s) in a lot of
/// chains.
pub data: T::AccountData,
+2 -2
View File
@@ -186,7 +186,7 @@ impl System for DefaultNodeRuntime {
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
type Address = pallet_indices::address::Address<Self::AccountId, u32>;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Extrinsic = OpaqueExtrinsic;
type AccountData = AccountData<<Self as Balances>::Balance>;
@@ -225,7 +225,7 @@ impl System for NodeTemplateRuntime {
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
type Address = Self::AccountId;
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Extrinsic = OpaqueExtrinsic;
type AccountData = AccountData<<Self as Balances>::Balance>;
+18 -18
View File
@@ -18,25 +18,25 @@ log = "0.4.13"
structopt = "0.3.21"
parking_lot = "0.11.1"
sc-cli = { version = "0.8.1", features = ["wasmtime"] }
sp-core = "2.0.1"
sc-executor = { version = "0.8.1", features = ["wasmtime"] }
sc-service = { version = "0.8.1", features = ["wasmtime"] }
sp-inherents = "2.0.1"
sc-transaction-pool = "2.0.1"
sp-transaction-pool = "2.0.1"
sc-network = "0.8.1"
sc-consensus-aura = "0.8.1"
sp-consensus-aura = "0.8.1"
sp-consensus = "0.8.1"
sc-consensus = "0.8.1"
sc-finality-grandpa = "0.8.1"
sp-finality-grandpa = "2.0.1"
sc-client-api = "2.0.1"
sp-runtime = "2.0.1"
sc-basic-authorship = "0.8.1"
sc-cli = { version = "0.9.0", features = ["wasmtime"] }
sp-core = "3.0.0"
sc-executor = { version = "0.9.0", features = ["wasmtime"] }
sc-service = { version = "0.9.0", features = ["wasmtime"] }
sp-inherents = "3.0.0"
sc-transaction-pool = "3.0.0"
sp-transaction-pool = "3.0.0"
sc-network = "0.9.0"
sc-consensus-aura = "0.9.0"
sp-consensus-aura = "0.9.0"
sp-consensus = "0.9.0"
sc-consensus = "0.9.0"
sc-finality-grandpa = "0.9.0"
sp-finality-grandpa = "3.0.0"
sc-client-api = "3.0.0"
sp-runtime = "3.0.0"
sc-basic-authorship = "0.9.0"
test-node-runtime = { path = "runtime" }
[build-dependencies]
substrate-build-script-utils = "2.0.1"
substrate-build-script-utils = "3.0.0"
+25 -25
View File
@@ -11,35 +11,35 @@ repository = "https://github.com/paritytech/substrate/"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
frame-executive = { version = "2.0.0", default-features = false }
frame-support = { version = "2.0.0", default-features = false }
frame-system = { version = "2.0.0", default-features = false }
pallet-aura = { version = "2.0.0", default-features = false }
pallet-balances = { version = "2.0.0", default-features = false }
pallet-grandpa = { version = "2.0.0", default-features = false }
pallet-randomness-collective-flip = { version = "2.0.0", default-features = false }
pallet-staking = { version = "2.0.0", default-features = false }
pallet-sudo = { version = "2.0.0", default-features = false }
pallet-timestamp = { version = "2.0.0", default-features = false }
pallet-transaction-payment = { version = "2.0.0", default-features = false }
frame-executive = { version = "3.0.0", default-features = false }
frame-support = { version = "3.0.0", default-features = false }
frame-system = { version = "3.0.0", default-features = false }
pallet-aura = { version = "3.0.0", default-features = false }
pallet-balances = { version = "3.0.0", default-features = false }
pallet-grandpa = { version = "3.0.0", default-features = false }
pallet-randomness-collective-flip = { version = "3.0.0", default-features = false }
pallet-staking = { version = "3.0.0", default-features = false }
pallet-sudo = { version = "3.0.0", default-features = false }
pallet-timestamp = { version = "3.0.0", default-features = false }
pallet-transaction-payment = { version = "3.0.0", default-features = false }
serde = { version = "1.0.116", optional = true, features = ["derive"] }
sp-api = { version = "2.0.0", default-features = false }
sp-block-builder = { version = "2.0.0", default-features = false }
sp-consensus-aura = { version = "0.8.0", default-features = false }
sp-core = { version = "2.0.0", default-features = false }
sp-inherents = { version = "2.0.0", default-features = false }
sp-io = { version = "2.0.0", default-features = false }
sp-offchain = { version = "2.0.0", default-features = false }
sp-runtime = { version = "2.0.0", default-features = false }
sp-session = { version = "2.0.0", default-features = false }
sp-std = { version = "2.0.0", default-features = false }
sp-transaction-pool = { version = "2.0.0", default-features = false }
sp-version = { version = "2.0.0", default-features = false }
sp-api = { version = "3.0.0", default-features = false }
sp-block-builder = { version = "3.0.0", default-features = false }
sp-consensus-aura = { version = "0.9.0", default-features = false }
sp-core = { version = "3.0.0", default-features = false }
sp-inherents = { version = "3.0.0", default-features = false }
sp-io = { version = "3.0.0", default-features = false }
sp-offchain = { version = "3.0.0", default-features = false }
sp-runtime = { version = "3.0.0", default-features = false }
sp-session = { version = "3.0.0", default-features = false }
sp-std = { version = "3.0.0", default-features = false }
sp-transaction-pool = { version = "3.0.0", default-features = false }
sp-version = { version = "3.0.0", default-features = false }
[build-dependencies]
substrate-wasm-builder-runner = "1.0.6"
substrate-wasm-builder = "3.0.0"
[features]
default = ["std"]
+1 -2
View File
@@ -14,12 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
use substrate_wasm_builder_runner::WasmBuilder;
use substrate_wasm_builder::WasmBuilder;
fn main() {
WasmBuilder::new()
.with_current_project()
.with_wasm_builder_from_crates("1.0.11")
.export_heap_base()
.import_memory()
.build()
+30 -41
View File
@@ -41,12 +41,11 @@ use sp_runtime::{
generic,
impl_opaque_keys,
traits::{
AccountIdLookup,
BlakeTwo256,
Block as BlockT,
IdentifyAccount,
IdentityLookup,
NumberFor,
Saturating,
Verify,
},
transaction_validity::{
@@ -169,29 +168,32 @@ pub fn native_version() -> NativeVersion {
}
}
const AVERAGE_ON_INITIALIZE_WEIGHT: Perbill = Perbill::from_percent(10);
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
parameter_types! {
pub const Version: RuntimeVersion = VERSION;
pub const BlockHashCount: BlockNumber = 2400;
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MaximumBlockWeight: Weight = 2 * WEIGHT_PER_SECOND;
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
/// Assume 10% of weight for average on_initialize calls.
pub MaximumExtrinsicWeight: Weight =
AvailableBlockRatio::get().saturating_sub(AVERAGE_ON_INITIALIZE_WEIGHT)
* MaximumBlockWeight::get();
pub const MaximumBlockLength: u32 = 5 * 1024 * 1024;
pub const Version: RuntimeVersion = VERSION;
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
}
impl frame_system::Trait for Runtime {
impl frame_system::Config for Runtime {
/// The basic call filter to use in dispatchable.
type BaseCallFilter = ();
/// Block & extrinsics weights: base values and limits.
type BlockWeights = BlockWeights;
/// The maximum length of a block (in bytes).
type BlockLength = BlockLength;
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The aggregated dispatch type that is available for extrinsics.
type Call = Call;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = IdentityLookup<AccountId>;
type Lookup = AccountIdLookup<AccountId, ()>;
/// The index type for storing how many extrinsics an account has signed.
type Index = Index;
/// The index type for blocks.
@@ -208,26 +210,14 @@ impl frame_system::Trait for Runtime {
type Origin = Origin;
/// Maximum number of block number to block hash mappings to keep (oldest pruned first).
type BlockHashCount = BlockHashCount;
/// Maximum weight of each block.
type MaximumBlockWeight = MaximumBlockWeight;
/// The weight of database operations that the runtime can invoke.
type DbWeight = RocksDbWeight;
/// The weight of the overhead invoked on the block import process, independent of the
/// extrinsics included in that block.
type BlockExecutionWeight = BlockExecutionWeight;
/// The base weight of any extrinsic processed by the runtime, independent of the
/// logic of that extrinsic. (Signature verification, nonce increment, fee, etc...)
type ExtrinsicBaseWeight = ExtrinsicBaseWeight;
/// The maximum weight that a single extrinsic of `Normal` dispatch class can have,
/// idependent of the logic of that extrinsics. (Roughly max block weight - average on
/// initialize cost).
type MaximumExtrinsicWeight = MaximumExtrinsicWeight;
/// Maximum size of all encoded transactions (in bytes) that are allowed in one block.
type MaximumBlockLength = MaximumBlockLength;
/// Portion of the block weight that is available to all normal transactions.
type AvailableBlockRatio = AvailableBlockRatio;
/// Version of the runtime.
type Version = Version;
/// Converts a module to the index of the module in `construct_runtime!`.
///
/// This type is being generated by `construct_runtime!`.
type PalletInfo = PalletInfo;
/// What to do if a new account is created.
type OnNewAccount = ();
/// What to do if an account is fully reaped from the system.
@@ -236,15 +226,15 @@ impl frame_system::Trait for Runtime {
type AccountData = pallet_balances::AccountData<Balance>;
/// Weight information for the extrinsics of this pallet.
type SystemWeightInfo = ();
/// Provides information about the pallet setup in the runtime.
type PalletInfo = PalletInfo;
/// This is used as an identifier of the chain. 42 is the generic substrate prefix.
type SS58Prefix = SS58Prefix;
}
impl pallet_aura::Trait for Runtime {
impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
}
impl pallet_grandpa::Trait for Runtime {
impl pallet_grandpa::Config for Runtime {
type Event = Event;
type Call = Call;
@@ -266,7 +256,7 @@ parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
}
impl pallet_timestamp::Trait for Runtime {
impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = u64;
type OnTimestampSet = Aura;
@@ -278,7 +268,7 @@ parameter_types! {
pub const ExistentialDeposit: u128 = 500;
}
impl pallet_balances::Trait for Runtime {
impl pallet_balances::Config for Runtime {
/// The type for recording an account's balance.
type Balance = Balance;
/// The ubiquitous event type.
@@ -294,15 +284,14 @@ parameter_types! {
pub const TransactionByteFee: Balance = 1;
}
impl pallet_transaction_payment::Trait for Runtime {
type Currency = pallet_balances::Module<Runtime>;
type OnTransactionPayment = ();
impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
}
impl pallet_sudo::Trait for Runtime {
impl pallet_sudo::Config for Runtime {
type Event = Event;
type Call = Call;
}
@@ -316,7 +305,7 @@ construct_runtime!(
System: frame_system::{Module, Call, Config, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Aura: pallet_aura::{Module, Config<T>, Inherent},
Aura: pallet_aura::{Module, Config<T>},
Grandpa: pallet_grandpa::{Module, Call, Storage, Config, Event},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Module, Storage},
@@ -325,7 +314,7 @@ construct_runtime!(
);
/// The address format for describing accounts.
pub type Address = AccountId;
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
+4 -2
View File
@@ -67,7 +67,8 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
}
pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY;
let wasm_binary =
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
Ok(ChainSpec::from_genesis(
// Name
@@ -106,7 +107,8 @@ pub fn development_config() -> Result<ChainSpec, String> {
}
pub fn local_testnet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY;
let wasm_binary =
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;
Ok(ChainSpec::from_genesis(
// Name
+7 -4
View File
@@ -87,11 +87,14 @@ pub fn run() -> sc_cli::Result<()> {
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| {
match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
async move {
match config.role {
Role::Light => service::new_light(config),
_ => service::new_full(config),
}
.map(|service| service.0)
.map_err(sc_cli::Error::Service)
}
.map(|service| service.0)
})
}
}
+70 -64
View File
@@ -23,10 +23,7 @@ use sc_client_api::{
};
use sc_executor::native_executor_instance;
pub use sc_executor::NativeExecutor;
use sc_finality_grandpa::{
FinalityProofProvider as GrandpaFinalityProofProvider,
SharedVoterState,
};
use sc_finality_grandpa::SharedVoterState;
use sc_service::{
error::Error as ServiceError,
Configuration,
@@ -67,20 +64,30 @@ pub fn new_partial(
sp_consensus::DefaultImportQueue<Block, FullClient>,
sc_transaction_pool::FullPool<Block, FullClient>,
(
sc_finality_grandpa::GrandpaBlockImport<
FullBackend,
sc_consensus_aura::AuraBlockImport<
Block,
FullClient,
FullSelectChain,
sc_finality_grandpa::GrandpaBlockImport<
FullBackend,
Block,
FullClient,
FullSelectChain,
>,
AuraPair,
>,
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
),
>,
ServiceError,
> {
if config.keystore_remote.is_some() {
return Err(ServiceError::Other(format!(
"Remote Keystores are not supported."
)))
}
let inherent_data_providers = sp_inherents::InherentDataProviders::new();
let (client, backend, keystore, task_manager) =
let (client, backend, keystore_container, task_manager) =
sc_service::new_full_parts::<Block, RuntimeApi, Executor>(&config)?;
let client = Arc::new(client);
@@ -88,6 +95,7 @@ pub fn new_partial(
let transaction_pool = sc_transaction_pool::BasicPool::new_full(
config.transaction_pool.clone(),
config.role.is_authority().into(),
config.prometheus_registry(),
task_manager.spawn_handle(),
client.clone(),
@@ -106,9 +114,8 @@ pub fn new_partial(
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>(
sc_consensus_aura::slot_duration(&*client)?,
aura_block_import,
aura_block_import.clone(),
Some(Box::new(grandpa_block_import.clone())),
None,
client.clone(),
inherent_data_providers.clone(),
&task_manager.spawn_handle(),
@@ -121,32 +128,34 @@ pub fn new_partial(
backend,
task_manager,
import_queue,
keystore,
keystore_container,
select_chain,
transaction_pool,
inherent_data_providers,
other: (grandpa_block_import, grandpa_link),
other: (aura_block_import, grandpa_link),
})
}
/// Builds a new service for a full client.
pub fn new_full(
config: Configuration,
mut config: Configuration,
) -> Result<(TaskManager, RpcHandlers), ServiceError> {
let PartialComponents {
client,
backend,
mut task_manager,
import_queue,
keystore,
keystore_container,
select_chain,
transaction_pool,
inherent_data_providers,
other: (block_import, grandpa_link),
} = new_partial(&config)?;
let finality_proof_provider =
GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone());
config
.network
.extra_sets
.push(sc_finality_grandpa::grandpa_peers_set_config());
let (network, network_status_sinks, system_rpc_tx, network_starter) =
sc_service::build_network(sc_service::BuildNetworkParams {
@@ -157,8 +166,6 @@ pub fn new_full(
import_queue,
on_demand: None,
block_announce_validator_builder: None,
finality_proof_request_builder: None,
finality_proof_provider: Some(finality_proof_provider),
})?;
if config.offchain_worker.enabled {
@@ -173,29 +180,32 @@ pub fn new_full(
let role = config.role.clone();
let force_authoring = config.force_authoring;
let backoff_authoring_blocks: Option<()> = None;
let name = config.network.node_name.clone();
let enable_grandpa = !config.disable_grandpa;
let prometheus_registry = config.prometheus_registry().cloned();
let telemetry_connection_sinks = sc_service::TelemetryConnectionSinks::default();
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
keystore: keystore.clone(),
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
telemetry_connection_sinks: telemetry_connection_sinks.clone(),
rpc_extensions_builder: Box::new(|_, _| ()),
on_demand: None,
remote_blockchain: None,
backend,
network_status_sinks,
system_rpc_tx,
config,
})?;
let rpc_extensions_builder = Box::new(|_, _| ());
let (rpc_handlers, telemetry_connection_notifier) =
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
keystore: keystore_container.sync_keystore(),
task_manager: &mut task_manager,
transaction_pool: transaction_pool.clone(),
rpc_extensions_builder,
on_demand: None,
remote_blockchain: None,
backend,
network_status_sinks,
system_rpc_tx,
config,
})?;
if role.is_authority() {
let proposer = sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
prometheus_registry.as_ref(),
@@ -204,7 +214,7 @@ pub fn new_full(
let can_author_with =
sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _>(
let aura = sc_consensus_aura::start_aura::<_, _, _, _, _, AuraPair, _, _, _, _>(
sc_consensus_aura::slot_duration(&*client)?,
client.clone(),
select_chain,
@@ -213,7 +223,8 @@ pub fn new_full(
network.clone(),
inherent_data_providers.clone(),
force_authoring,
keystore.clone(),
backoff_authoring_blocks,
keystore_container.sync_keystore(),
can_author_with,
)?;
@@ -227,7 +238,7 @@ pub fn new_full(
// if the node isn't actively participating in consensus then it doesn't
// need a keystore, regardless of which protocol we use below.
let keystore = if role.is_authority() {
Some(keystore as sp_core::traits::BareCryptoStorePtr)
Some(keystore_container.sync_keystore())
} else {
None
};
@@ -252,8 +263,8 @@ pub fn new_full(
config: grandpa_config,
link: grandpa_link,
network,
inherent_data_providers,
telemetry_on_connect: Some(telemetry_connection_sinks.on_connect_stream()),
telemetry_on_connect: telemetry_connection_notifier
.map(|x| x.on_connect_stream()),
voting_rule: sc_finality_grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
shared_voter_state: SharedVoterState::empty(),
@@ -265,12 +276,6 @@ pub fn new_full(
"grandpa-voter",
sc_finality_grandpa::run_grandpa_voter(grandpa_config)?,
);
} else {
sc_finality_grandpa::setup_disabled_grandpa(
client,
&inherent_data_providers,
network,
)?;
}
network_starter.start_network();
@@ -279,11 +284,18 @@ pub fn new_full(
/// Builds a new service for a light client.
pub fn new_light(
config: Configuration,
mut config: Configuration,
) -> Result<(TaskManager, RpcHandlers), ServiceError> {
let (client, backend, keystore, mut task_manager, on_demand) =
let (client, backend, keystore_container, mut task_manager, on_demand) =
sc_service::new_light_parts::<Block, RuntimeApi, Executor>(&config)?;
config
.network
.extra_sets
.push(sc_finality_grandpa::grandpa_peers_set_config());
let select_chain = sc_consensus::LongestChain::new(backend.clone());
let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light(
config.transaction_pool.clone(),
config.prometheus_registry(),
@@ -292,21 +304,21 @@ pub fn new_light(
on_demand.clone(),
));
let grandpa_block_import = sc_finality_grandpa::light_block_import(
let (grandpa_block_import, _) = sc_finality_grandpa::block_import(
client.clone(),
backend.clone(),
&(client.clone() as Arc<_>),
Arc::new(on_demand.checker().clone()) as Arc<_>,
select_chain.clone(),
)?;
let finality_proof_import = grandpa_block_import.clone();
let finality_proof_request_builder =
finality_proof_import.create_finality_proof_request_builder();
let aura_block_import = sc_consensus_aura::AuraBlockImport::<_, _, _, AuraPair>::new(
grandpa_block_import.clone(),
client.clone(),
);
let import_queue = sc_consensus_aura::import_queue::<_, _, _, AuraPair, _, _>(
sc_consensus_aura::slot_duration(&*client)?,
grandpa_block_import,
None,
Some(Box::new(finality_proof_import)),
aura_block_import,
Some(Box::new(grandpa_block_import)),
client.clone(),
InherentDataProviders::new(),
&task_manager.spawn_handle(),
@@ -314,9 +326,6 @@ pub fn new_light(
sp_consensus::NeverCanAuthor,
)?;
let finality_proof_provider =
GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone());
let (network, network_status_sinks, system_rpc_tx, network_starter) =
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
@@ -326,8 +335,6 @@ pub fn new_light(
import_queue,
on_demand: Some(on_demand.clone()),
block_announce_validator_builder: None,
finality_proof_request_builder: Some(finality_proof_request_builder),
finality_proof_provider: Some(finality_proof_provider),
})?;
if config.offchain_worker.enabled {
@@ -346,10 +353,9 @@ pub fn new_light(
task_manager: &mut task_manager,
on_demand: Some(on_demand),
rpc_extensions_builder: Box::new(|_, _| ()),
telemetry_connection_sinks: sc_service::TelemetryConnectionSinks::default(),
config,
client,
keystore,
keystore: keystore_container.sync_keystore(),
backend,
network,
network_status_sinks,
@@ -358,5 +364,5 @@ pub fn new_light(
network_starter.start_network();
Ok((task_manager, rpc_handlers))
Ok((task_manager, rpc_handlers.0))
}