Skip to content

Commit 2c8e521

Browse files
authored
Substrate 3.0 (paritytech#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
1 parent 51c48f2 commit 2c8e521

File tree

17 files changed

+218
-191
lines changed

17 files changed

+218
-191
lines changed

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn_single_line = false
1919
where_single_line = false
2020
imports_indent = "Block"
2121
imports_layout = "Vertical" # changed
22-
merge_imports = true # changed
22+
imports_granularity= "Crate" # changed
2323
reorder_imports = true
2424
reorder_modules = true
2525
reorder_impl_items = false

Cargo.toml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,32 @@ num-traits = { version = "0.2.14", default-features = false }
3232
serde = { version = "1.0.119", features = ["derive"] }
3333
serde_json = "1.0.61"
3434
url = "2.2.0"
35-
codec = { package = "parity-scale-codec", version = "1.3.6", default-features = false, features = ["derive", "full"] }
35+
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive", "full"] }
36+
# temporarily pinning funty via codec -> bitvec until https://github.com/myrrlyn/funty/issues/3
37+
# and https://github.com/bitvecto-rs/bitvec/issues/105 are resolved
38+
funty = "=1.1.0"
3639

37-
frame-metadata = "12.0.1"
38-
frame-support = "2.0.1"
39-
sp-runtime = "2.0.1"
40-
sp-version = "2.0.1"
41-
pallet-indices = "2.0.1"
40+
frame-metadata = "13.0.0"
41+
frame-support = "3.0.0"
42+
sp-runtime = "3.0.0"
43+
sp-version = "3.0.0"
44+
pallet-indices = "3.0.0"
4245
hex = "0.4.2"
43-
sp-std = "2.0.1"
44-
application-crypto = { version = "2.0.1", package = "sp-application-crypto" }
45-
pallet-staking = "2.0.1"
46+
sp-std = "3.0.0"
47+
application-crypto = { version = "3.0.0", package = "sp-application-crypto" }
48+
pallet-staking = "3.0.0"
4649

47-
sp-rpc = { version = "2.0.1", package = "sp-rpc" }
48-
sp-core = { version = "2.0.1", package = "sp-core" }
50+
sp-rpc = { version = "3.0.0", package = "sp-rpc" }
51+
sp-core = { version = "3.0.0", package = "sp-core" }
4952
substrate-subxt-client = { version = "0.6.0", path = "client", optional = true }
5053
substrate-subxt-proc-macro = { version = "0.14.0", path = "proc-macro" }
5154

5255
[dev-dependencies]
5356
async-std = { version = "1.8.0", features = ["attributes"] }
5457
env_logger = "0.8.2"
55-
frame-system = "2.0.1"
56-
pallet-balances = "2.0.1"
57-
sp-keyring = "2.0.1"
58+
frame-system = "3.0.0"
59+
pallet-balances = "3.0.0"
60+
sp-keyring = "3.0.0"
5861
substrate-subxt-client = { version = "0.6.0", path = "client" }
5962
tempdir = "0.3.7"
6063
test-node = { path = "test-node" }

client/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ futures = { version = "0.3.9", features = ["compat"], package = "futures" }
1717
futures01 = { package = "futures", version = "0.1.29" }
1818
jsonrpsee = "0.1.0"
1919
log = "0.4.13"
20-
sc-network = { version = "0.8.1", default-features = false }
21-
sc-service = { version = "0.8.1", default-features = false }
20+
sc-network = { version = "0.9.0", default-features = false }
21+
sc-client-db = "0.9.0"
22+
sc-service = { version = "0.9.0", default-features = false }
2223
serde_json = "1.0.61"
23-
sp-keyring = "2.0.1"
24+
sp-keyring = "3.0.0"
2425
thiserror = "1.0.23"
2526

2627
[dev-dependencies]

client/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ use sc_service::{
5757
},
5858
ChainSpec,
5959
Configuration,
60+
KeepBlocks,
6061
RpcHandlers,
6162
RpcSession,
6263
TaskManager,
@@ -232,7 +233,6 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
232233
enable_mdns: true,
233234
allow_private_ipv4: true,
234235
wasm_external_transport: None,
235-
use_yamux_flow_control: true,
236236
};
237237
let telemetry_endpoints = if let Some(port) = self.telemetry {
238238
let endpoints = TelemetryEndpoints::new(vec![(
@@ -265,13 +265,17 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
265265
telemetry_endpoints,
266266

267267
telemetry_external_transport: Default::default(),
268+
telemetry_handle: Default::default(),
269+
telemetry_span: Default::default(),
268270
default_heap_pages: Default::default(),
269271
disable_grandpa: Default::default(),
272+
disable_log_reloading: Default::default(),
270273
execution_strategies: Default::default(),
271274
force_authoring: Default::default(),
275+
keep_blocks: KeepBlocks::All,
276+
keystore_remote: Default::default(),
272277
offchain_worker: Default::default(),
273278
prometheus_config: Default::default(),
274-
pruning: Default::default(),
275279
rpc_cors: Default::default(),
276280
rpc_http: Default::default(),
277281
rpc_ipc: Default::default(),
@@ -286,6 +290,9 @@ impl<C: ChainSpec + 'static> SubxtClientConfig<C> {
286290
wasm_method: Default::default(),
287291
base_path: Default::default(),
288292
informant_output_format: Default::default(),
293+
state_pruning: Default::default(),
294+
transaction_storage: sc_client_db::TransactionStorageMode::BlockBody,
295+
wasm_runtime_overrides: Default::default(),
289296
};
290297

291298
log::info!("{}", service_config.impl_name);
@@ -310,7 +317,7 @@ mod tests {
310317
use substrate_subxt::{
311318
balances::TransferCallExt,
312319
ClientBuilder,
313-
KusamaRuntime as NodeTemplateRuntime,
320+
NodeTemplateRuntime,
314321
PairSigner,
315322
};
316323
use tempdir::TempDir;

proc-macro/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ synstructure = "0.12.4"
2525

2626
[dev-dependencies]
2727
async-std = { version = "1.8.0", features = ["attributes"] }
28-
codec = { package = "parity-scale-codec", version = "1.3.6", features = ["derive"] }
28+
codec = { package = "parity-scale-codec", version = "2.0.0", features = ["derive"] }
2929
env_logger = "0.8.2"
3030
pretty_assertions = "0.6.1"
31-
sp-keyring = "2.0.1"
31+
sp-keyring = "3.0.0"
3232
substrate-subxt = { path = ".." }
3333
trybuild = "1.0.38"
3434

src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ pub enum RuntimeError {
9898
/// Module error.
9999
#[error("Runtime module error: {0}")]
100100
Module(ModuleError),
101+
/// At least one consumer is remaining so the account cannot be destroyed.
102+
#[error("At least one consumer is remaining so the account cannot be destroyed.")]
103+
ConsumerRemaining,
104+
/// There are no providers so the account cannot be created.
105+
#[error("There are no providers so the account cannot be created.")]
106+
NoProviders,
101107
/// Bad origin.
102108
#[error("Bad origin: throw by ensure_signed, ensure_root or ensure_none.")]
103109
BadOrigin,
@@ -130,6 +136,8 @@ impl RuntimeError {
130136
}
131137
DispatchError::BadOrigin => Ok(Self::BadOrigin),
132138
DispatchError::CannotLookup => Ok(Self::CannotLookup),
139+
DispatchError::ConsumerRemaining => Ok(Self::ConsumerRemaining),
140+
DispatchError::NoProviders => Ok(Self::NoProviders),
133141
DispatchError::Other(msg) => Ok(Self::Other(msg.into())),
134142
}
135143
}

src/frame/balances.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ mod tests {
182182
env_logger::try_init().ok();
183183
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
184184
let bob = PairSigner::<TestRuntime, _>::new(AccountKeyring::Bob.pair());
185+
let bob_address = bob.account_id().clone().into();
185186
let (client, _) = test_client().await;
186187

187188
let alice_pre = client.account(alice.account_id(), None).await.unwrap();
188189
let bob_pre = client.account(bob.account_id(), None).await.unwrap();
189190

190191
let event = client
191-
.transfer_and_watch(&alice, &bob.account_id(), 10_000)
192+
.transfer_and_watch(&alice, &bob_address, 10_000)
192193
.await
193194
.expect("sending an xt works")
194195
.transfer()
@@ -269,15 +270,17 @@ mod tests {
269270
#[async_std::test]
270271
async fn test_transfer_error() {
271272
env_logger::try_init().ok();
272-
let alice = PairSigner::new(AccountKeyring::Alice.pair());
273-
let hans = PairSigner::new(Pair::generate().0);
273+
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
274+
let alice_addr = alice.account_id().clone().into();
275+
let hans = PairSigner::<TestRuntime, _>::new(Pair::generate().0);
276+
let hans_address = hans.account_id().clone().into();
274277
let (client, _) = test_client().await;
275278
client
276-
.transfer_and_watch(&alice, hans.account_id(), 100_000_000_000)
279+
.transfer_and_watch(&alice, &hans_address, 100_000_000_000)
277280
.await
278281
.unwrap();
279282
let res = client
280-
.transfer_and_watch(&hans, alice.account_id(), 100_000_000_000)
283+
.transfer_and_watch(&hans, &alice_addr, 100_000_000_000)
281284
.await;
282285
if let Err(Error::Runtime(RuntimeError::Module(error))) = res {
283286
let error2 = ModuleError {
@@ -293,15 +296,16 @@ mod tests {
293296
#[async_std::test]
294297
async fn test_transfer_subscription() {
295298
env_logger::try_init().ok();
296-
let alice = PairSigner::new(AccountKeyring::Alice.pair());
299+
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
297300
let bob = AccountKeyring::Bob.to_account_id();
301+
let bob_addr = bob.clone().into();
298302
let (client, _) = test_client().await;
299303
let sub = client.subscribe_events().await.unwrap();
300304
let mut decoder = EventsDecoder::<TestRuntime>::new(client.metadata().clone());
301305
decoder.with_balances();
302306
let mut sub = EventSubscription::<TestRuntime>::new(sub, decoder);
303307
sub.filter_event::<TransferEvent<_>>();
304-
client.transfer(&alice, &bob, 10_000).await.unwrap();
308+
client.transfer(&alice, &bob_addr, 10_000).await.unwrap();
305309
let raw = sub.next().await.unwrap().unwrap();
306310
let event = TransferEvent::<TestRuntime>::decode(&mut &raw.data[..]).unwrap();
307311
assert_eq!(

src/frame/sudo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ mod tests {
7575
async fn test_sudo() {
7676
env_logger::try_init().ok();
7777
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
78+
let bob = AccountKeyring::Bob.to_account_id().clone().into();
7879
let (client, _) = test_client().await;
7980

8081
let call = client
8182
.encode(TransferCall {
82-
to: &AccountKeyring::Bob.to_account_id(),
83+
to: &bob,
8384
amount: 10_000,
8485
})
8586
.unwrap();
@@ -98,11 +99,12 @@ mod tests {
9899
async fn test_sudo_unchecked_weight() {
99100
env_logger::try_init().ok();
100101
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
102+
let bob = AccountKeyring::Bob.to_account_id().into();
101103
let (client, _) = test_client().await;
102104

103105
let call = client
104106
.encode(TransferCall {
105-
to: &AccountKeyring::Bob.to_account_id(),
107+
to: &bob,
106108
amount: 10_000,
107109
})
108110
.unwrap();

src/frame/system.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ pub struct AccountInfo<T: System> {
127127
pub nonce: T::Index,
128128
/// The number of other modules that currently depend on this account's existence. The account
129129
/// cannot be reaped until this is zero.
130-
pub refcount: RefCount,
130+
pub consumers: RefCount,
131+
/// The number of other modules that allow this account to exist. The account may not be reaped
132+
/// until this is zero.
133+
pub providers: RefCount,
131134
/// The additional data that belongs to this account. Used to store the balance(s) in a lot of
132135
/// chains.
133136
pub data: T::AccountData,

src/runtimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl System for DefaultNodeRuntime {
186186
type Hash = sp_core::H256;
187187
type Hashing = BlakeTwo256;
188188
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
189-
type Address = pallet_indices::address::Address<Self::AccountId, u32>;
189+
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
190190
type Header = Header<Self::BlockNumber, BlakeTwo256>;
191191
type Extrinsic = OpaqueExtrinsic;
192192
type AccountData = AccountData<<Self as Balances>::Balance>;
@@ -225,7 +225,7 @@ impl System for NodeTemplateRuntime {
225225
type Hash = sp_core::H256;
226226
type Hashing = BlakeTwo256;
227227
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
228-
type Address = Self::AccountId;
228+
type Address = sp_runtime::MultiAddress<Self::AccountId, u32>;
229229
type Header = Header<Self::BlockNumber, BlakeTwo256>;
230230
type Extrinsic = OpaqueExtrinsic;
231231
type AccountData = AccountData<<Self as Balances>::Balance>;

0 commit comments

Comments
 (0)