Skip to content

Commit

Permalink
Substrate 3.0 (paritytech#232)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ascjones authored Feb 17, 2021
1 parent 51c48f2 commit 2c8e521
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
7 changes: 4 additions & 3 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 10 additions & 3 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use sc_service::{
},
ChainSpec,
Configuration,
KeepBlocks,
RpcHandlers,
RpcSession,
TaskManager,
Expand Down Expand Up @@ -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![(
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
Expand All @@ -310,7 +317,7 @@ mod tests {
use substrate_subxt::{
balances::TransferCallExt,
ClientBuilder,
KusamaRuntime as NodeTemplateRuntime,
NodeTemplateRuntime,
PairSigner,
};
use tempdir::TempDir;
Expand Down
4 changes: 2 additions & 2 deletions proc-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 8 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())),
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/frame/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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!(
Expand Down
6 changes: 4 additions & 2 deletions src/frame/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/frame/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/runtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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>;
Expand Down
36 changes: 18 additions & 18 deletions test-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
50 changes: 25 additions & 25 deletions test-node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 1 addition & 2 deletions test-node/runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading

0 comments on commit 2c8e521

Please sign in to comment.