Enrich metadata with type information (#8615)

* Cargo.lock after merge

* Restore scale-info feature

* Fully qualify TypeInfo derive

* Skip PendingSwap T

* Add missing skip_type_params attr

* metadata docs features

* Reduce pallet event attribute to struct

* Cargo.lock

* Update frame/balances/src/tests_composite.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Line widths check

* Cargo.lock

* Add scale-info/std

* Update frame/system/src/lib.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Use `skip_type_params` to remove `TypeInfo` requirements on checks

* Revert "Remove unused Call metadata stuff"

This reverts commit 41311f85

* Skip BalanceSwapAction type parameter

* Remove unused event metadata macro

* Update frame-metadata

* Update primitives/npos-elections/compact/src/codec.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Manual TypeInfo for Header

* Remove TypeInfo requirement for consts in BoundedVec etc.

* Another TypeInfo bound removed

* review: fix indentation

* TypeInfo impls for Identity types

* Add some todos to add custom TypeInfo impls

* Update frame/support/procedural/src/pallet/expand/pallet_struct.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Add some todos to add custom TypeInfo impls

* Add a test for manual Data TypeInfo impl

* Add custom TypeInfo impl for Vote

* Era custom TypeInfo crimes

* Revert finality-grandpa version to 0.14.z

* review: renamed module to pallet_constants_metadata

* New line at end of file

* Add missing scale-info/std

* Update frame/support/src/storage/types/mod.rs

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

* Remove StorageEntryType::Map unused flag

* Add missing scale-info dependency after merge

* SignedExtension::AdditionalSigned metadata

* Update frame-metadata, use abbreviated docs and args fields

* Update frame/example/Cargo.toml

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Add scale_info/std and remove unused scale-info dependency

* Remove scale-info dependency

* Remove treasury pallet::metadata

* Remove redundant Event test

* Add back scale-info as dev dependency

* fix error metadata when no error defined in decl_module

* Add Module3 to tests

* Fix metadata test

* Add docs feature to frame-support test

* WIP fixing pallet metadata test

* Remove redundant FunctionMetadata, FunctionArgumentMetadata as per https://github.com/paritytech/frame-metadata/pull/20

* Use main branch of frame-metadata

* Use patch of scale-info for latest changes

* Use latest patched scale-info

* Manual TypeInfo for DigestItem

* Manual TypeInfo for DigestItem

* Update scale-info

* Skip __Ignore variants for Error, depends on https://github.com/paritytech/scale-info/pull/117

* Named fields for FRAME v2 pallet Call variants

* Named fields for FRAME v1 pallet Call variants

* Add missing scale-info dependency

* WIP expand benchmark call variant

* fix benchmark with new function

create a new function for each variant of a pallet call.
This function is called by benchmarking macro in order not to break call
creation with unnamed argument

* fix tests

* more fix

* Fix staking tests

* Fix offchain workers calls

* Cherry pick rustfmt.toml from master

* cargo +nightly-2021-06-22 fmt --all

* Update to new call variant structs

* More call variant struct updates

* Remove unused import

* More call variant structs

* More call variant structs

* Even more call variant structs

* Mooar variant structs

* Evermore variant structs

* Call variant structs ad infinitum

* Fmt

* More call variants

* Last call variant

* Call variants all done?

* Fix SS58Prefix type

* Potential workaround for BitFlags<IdentityFields> TypeInfo

* Enable docs capturing for Call, Event, and Error types

* Fix IdentityFields TypeInfo

* Remove metadata-docs feature

* Add capture_docs = true for legacy Call, Event and Error types

* Fmt

* Fix metadata test type

* Update benchmarks with call struct variants

* Fmt

* More test fixes

* Fmt

* Fix benches

* Use latest capture_docs attr

* Latest scale_info

* Fmt

* review: change &Vec to &[]

* Remove pallet metadata attr

* review: remove commented out test code

* review: skip_type_params trailing comma suggestion

* Update to scale-info 0.10.0

* Update construct_runtime ui tests, different because of metadata TypeInfo impls

* Add some TypeInfo derives for UI tests

* Update storage ensure span ui stderrs

* Update call argument bound ui tests

Possibly changed because change from tuple to struct variants?

* Add scale-info dev dependency

* Update to latest finality-grandpa release

* review: missing newline

* review: missing scale-info/std

* review: remove duplicate scale-info/std

* review: remove fully qualified TypeInfo

* review: add missing scale-info/std

* review: remove unnecessary imports.

* Fmt

* Use crates.io RC version of frame-metadata

* Remove scale-info/std because it is a dev dependency

* Add missing scale_info dev-dependency for test

* Delete empty metadata folder

* Fix sp_std import

* review: improve manual UncheckedExtrinsic TypeInfo impl

* review: use full scale-info for dev-dependency

* Remove DefaultByteGetter impl

* review: derive TypeInfo for generic header

* Fmt

* Update primitives/runtime/src/generic/unchecked_extrinsic.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Update primitives/runtime/src/generic/unchecked_extrinsic.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Update bin/node/executor/Cargo.toml

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/identity/src/types.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/src/dispatch.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Remove redundant derive

* Simplify scale-info dependency

* Strip underscore prefix from call variant struct names

* Another underscore field

* More underscore fields

* Another underscore field

* Update to frame-metadata 14.0.0-rc.2 with combined StorageEntryType::Map

* Fmt

* Revert weights formatting

* Fix up some tests

* Fix up some tests for StorageEntryTypeMetadata

* scale-info dev dependency

* Fix test error

* Add missing TypeInfo derives

* Add back missing scale-info dependency

* Add back missing scale-info dependency

* Fix npos compact impls

* Cargo.lock

* Fmt

* Fix errors

* Fmt

* Fix renamed raw_solution field

* Fix error

* Fmt

* Fix some benchmarks

* Fmt

* Stray R

* Fix

* Add missing TypeInfos

* ui test fix

* Fix line widths

* Revert "ui test fix"

This reverts commit 2d15ec058a216e3f92d713f1174603a2bb1eac65.

* Upgrade to scale-info 0.11.0

* Revert "Upgrade to scale-info 0.11.0"

This reverts commit 047bb179085a0059c36cd20ab405f55cf0867e28.

* Add Runtime type

* Update to scale-info 0.12

* Update to scale-info 1.0

* Update frame-metadata to version 14.0.0

* Patch finality-grandpa until release available

* Fix metadata tests

* Fix metadata tests

* Fmt

* Remove patched finality-grandpa

* Fix tests, use scale_info imports

* Fix pallet tests

* Add BlockNumber TypeInfo bound

* ui test fix

* Cargo.lock

* Remove pallet metadata

* Cargo.lock

* Add missing scale-info dependency

* Remove pallet event metadata

* Fix error

* Fix collective errors

* Semicolol

* Fmt

* Remove another metadata attribute

* Add new variant to custom digest TypeInfo

* Fmt

* Cargo.lock from master

* Remove comma lol

* Fix example call error

* Fix example call error properly

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Andrew Jones
2021-09-15 12:40:41 +01:00
committed by GitHub
parent ebe78a4c1b
commit 49b6dfd2e5
305 changed files with 4015 additions and 3947 deletions
+2 -1
View File
@@ -810,7 +810,8 @@ mod tests {
};
let signer = charlie.clone();
let function = Call::Balances(BalancesCall::transfer(to.into(), amount));
let function =
Call::Balances(BalancesCall::transfer { dest: to.into(), value: amount });
let check_spec_version = frame_system::CheckSpecVersion::new();
let check_tx_version = frame_system::CheckTxVersion::new();
+1
View File
@@ -13,6 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0" }
scale-info = { version = "1.0", features = ["derive"] }
node-primitives = { version = "2.0.0", path = "../primitives" }
node-runtime = { version = "3.0.0-dev", path = "../runtime" }
sc-executor = { version = "0.10.0-dev", path = "../../../client/executor" }
+5 -2
View File
@@ -162,11 +162,14 @@ fn test_blocks(
let mut test_ext = new_test_ext(genesis_config);
let mut block1_extrinsics = vec![CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(0)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: 0 }),
}];
block1_extrinsics.extend((0..20).map(|i| CheckedExtrinsic {
signed: Some((alice(), signed_extra(i, 0))),
function: Call::Balances(pallet_balances::Call::transfer(bob().into(), 1 * DOLLARS)),
function: Call::Balances(pallet_balances::Call::transfer {
dest: bob().into(),
value: 1 * DOLLARS,
}),
}));
let block1 =
construct_block(executor, &mut test_ext.ext(), 1, GENESIS_HASH.into(), block1_extrinsics);
+36 -36
View File
@@ -84,14 +84,14 @@ fn changes_trie_block() -> (Vec<u8>, Hash) {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(time)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: time }),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(0, 0))),
function: Call::Balances(pallet_balances::Call::transfer(
bob().into(),
69 * DOLLARS,
)),
function: Call::Balances(pallet_balances::Call::transfer {
dest: bob().into(),
value: 69 * DOLLARS,
}),
},
],
(time / SLOT_DURATION).into(),
@@ -111,14 +111,14 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(time1)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: time1 }),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(0, 0))),
function: Call::Balances(pallet_balances::Call::transfer(
bob().into(),
69 * DOLLARS,
)),
function: Call::Balances(pallet_balances::Call::transfer {
dest: bob().into(),
value: 69 * DOLLARS,
}),
},
],
(time1 / SLOT_DURATION).into(),
@@ -131,21 +131,21 @@ fn blocks() -> ((Vec<u8>, Hash), (Vec<u8>, Hash)) {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(time2)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: time2 }),
},
CheckedExtrinsic {
signed: Some((bob(), signed_extra(0, 0))),
function: Call::Balances(pallet_balances::Call::transfer(
alice().into(),
5 * DOLLARS,
)),
function: Call::Balances(pallet_balances::Call::transfer {
dest: alice().into(),
value: 5 * DOLLARS,
}),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(1, 0))),
function: Call::Balances(pallet_balances::Call::transfer(
bob().into(),
15 * DOLLARS,
)),
function: Call::Balances(pallet_balances::Call::transfer {
dest: bob().into(),
value: 15 * DOLLARS,
}),
},
],
(time2 / SLOT_DURATION).into(),
@@ -166,11 +166,11 @@ fn block_with_size(time: u64, nonce: u32, size: usize) -> (Vec<u8>, Hash) {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(time * 1000)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: time * 1000 }),
},
CheckedExtrinsic {
signed: Some((alice(), signed_extra(nonce, 0))),
function: Call::System(frame_system::Call::remark(vec![0; size])),
function: Call::System(frame_system::Call::remark { remark: vec![0; size] }),
},
],
(time * 1000 / SLOT_DURATION).into(),
@@ -357,7 +357,7 @@ fn full_native_block_import_works() {
let mut fees = t.execute_with(|| transfer_fee(&xt()));
let transfer_weight = default_transfer_call().get_dispatch_info().weight;
let timestamp_weight = pallet_timestamp::Call::set::<Runtime>(Default::default())
let timestamp_weight = pallet_timestamp::Call::set::<Runtime> { now: Default::default() }
.get_dispatch_info()
.weight;
@@ -646,28 +646,28 @@ fn deploying_wasm_contract_should_work() {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(time)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: time }),
},
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(0, 0))),
function: Call::Contracts(
pallet_contracts::Call::instantiate_with_code::<Runtime>(
1000 * DOLLARS + subsistence,
500_000_000,
transfer_code,
Vec::new(),
Vec::new(),
),
pallet_contracts::Call::instantiate_with_code::<Runtime> {
endowment: 1000 * DOLLARS + subsistence,
gas_limit: 500_000_000,
code: transfer_code,
data: Vec::new(),
salt: Vec::new(),
},
),
},
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(1, 0))),
function: Call::Contracts(pallet_contracts::Call::call::<Runtime>(
sp_runtime::MultiAddress::Id(addr.clone()),
10,
500_000_000,
vec![0x00, 0x01, 0x02, 0x03],
)),
function: Call::Contracts(pallet_contracts::Call::call::<Runtime> {
dest: sp_runtime::MultiAddress::Id(addr.clone()),
value: 10,
gas_limit: 500_000_000,
data: vec![0x00, 0x01, 0x02, 0x03],
}),
},
],
(time / SLOT_DURATION).into(),
+1 -1
View File
@@ -88,7 +88,7 @@ pub fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
}
pub fn default_transfer_call() -> pallet_balances::Call<Runtime> {
pallet_balances::Call::transfer::<Runtime>(bob().into(), 69 * DOLLARS)
pallet_balances::Call::<Runtime>::transfer { dest: bob().into(), value: 69 * DOLLARS }
}
pub fn from_block_number(n: u32) -> Header {
+9 -9
View File
@@ -56,11 +56,13 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(time1)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: time1 }),
},
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(0, 0))),
function: Call::System(frame_system::Call::fill_block(Perbill::from_percent(60))),
function: Call::System(frame_system::Call::fill_block {
ratio: Perbill::from_percent(60),
}),
},
],
(time1 / SLOT_DURATION).into(),
@@ -75,11 +77,11 @@ fn fee_multiplier_increases_and_decreases_on_big_weight() {
vec![
CheckedExtrinsic {
signed: None,
function: Call::Timestamp(pallet_timestamp::Call::set(time2)),
function: Call::Timestamp(pallet_timestamp::Call::set { now: time2 }),
},
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(1, 0))),
function: Call::System(frame_system::Call::remark(vec![0; 1])),
function: Call::System(frame_system::Call::remark { remark: vec![0; 1] }),
},
],
(time2 / SLOT_DURATION).into(),
@@ -321,11 +323,9 @@ fn block_length_capacity_report() {
},
CheckedExtrinsic {
signed: Some((charlie(), signed_extra(nonce, 0))),
function: Call::System(frame_system::Call::remark(vec![
0u8;
(block_number * factor)
as usize
])),
function: Call::System(frame_system::Call::remark {
remark: vec![0u8; (block_number * factor) as usize],
}),
},
],
(time * 1000 / SLOT_DURATION).into(),
@@ -42,7 +42,7 @@ fn should_submit_unsigned_transaction() {
validators_len: 0,
};
let call = pallet_im_online::Call::heartbeat(heartbeat_data, signature);
let call = pallet_im_online::Call::heartbeat { heartbeat: heartbeat_data, signature };
SubmitTransaction::<Runtime, pallet_im_online::Call<Runtime>>::submit_unsigned_transaction(
call.into(),
)
@@ -84,7 +84,10 @@ fn should_submit_signed_transaction() {
t.execute_with(|| {
let results =
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
pallet_balances::Call::transfer(Default::default(), Default::default())
pallet_balances::Call::transfer {
dest: Default::default(),
value: Default::default(),
}
});
let len = results.len();
@@ -118,7 +121,10 @@ fn should_submit_signed_twice_from_the_same_account() {
t.execute_with(|| {
let result =
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
pallet_balances::Call::transfer(Default::default(), Default::default())
pallet_balances::Call::transfer {
dest: Default::default(),
value: Default::default(),
}
});
assert!(result.is_some());
@@ -127,7 +133,10 @@ fn should_submit_signed_twice_from_the_same_account() {
// submit another one from the same account. The nonce should be incremented.
let result =
Signer::<Runtime, TestAuthorityId>::any_account().send_signed_transaction(|_| {
pallet_balances::Call::transfer(Default::default(), Default::default())
pallet_balances::Call::transfer {
dest: Default::default(),
value: Default::default(),
}
});
assert!(result.is_some());
@@ -163,7 +172,7 @@ fn should_submit_signed_twice_from_all_accounts() {
t.execute_with(|| {
let results = Signer::<Runtime, TestAuthorityId>::all_accounts()
.send_signed_transaction(|_| {
pallet_balances::Call::transfer(Default::default(), Default::default())
pallet_balances::Call::transfer { dest: Default::default(), value: Default::default() }
});
let len = results.len();
@@ -174,7 +183,7 @@ fn should_submit_signed_twice_from_all_accounts() {
// submit another one from the same account. The nonce should be incremented.
let results = Signer::<Runtime, TestAuthorityId>::all_accounts()
.send_signed_transaction(|_| {
pallet_balances::Call::transfer(Default::default(), Default::default())
pallet_balances::Call::transfer { dest: Default::default(), value: Default::default() }
});
let len = results.len();
@@ -227,7 +236,10 @@ fn submitted_transaction_should_be_valid() {
t.execute_with(|| {
let results =
Signer::<Runtime, TestAuthorityId>::all_accounts().send_signed_transaction(|_| {
pallet_balances::Call::transfer(Default::default(), Default::default())
pallet_balances::Call::transfer {
dest: Default::default(),
value: Default::default(),
}
});
let len = results.len();
assert_eq!(len, 1);
+2
View File
@@ -14,6 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = [
"derive",
] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../../frame/system" }
sp-application-crypto = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/application-crypto" }
sp-core = { version = "4.0.0-dev", default-features = false, path = "../../../primitives/core" }
@@ -23,6 +24,7 @@ sp-runtime = { version = "4.0.0-dev", default-features = false, path = "../../..
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"frame-system/std",
"sp-application-crypto/std",
"sp-core/std",
+2
View File
@@ -18,6 +18,7 @@ codec = { package = "parity-scale-codec", version = "2.2.0", default-features =
"derive",
"max-encoded-len",
] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
static_assertions = "1.1.0"
hex-literal = { version = "0.3.1", optional = true }
log = { version = "0.4.14", default-features = false }
@@ -113,6 +114,7 @@ std = [
"pallet-bounties/std",
"sp-block-builder/std",
"codec/std",
"scale-info/std",
"pallet-collective/std",
"pallet-contracts/std",
"pallet-contracts-primitives/std",
+14 -4
View File
@@ -255,7 +255,17 @@ parameter_types! {
/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, MaxEncodedLen,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
)]
pub enum ProxyType {
Any,
@@ -276,8 +286,8 @@ impl InstanceFilter<Call> for ProxyType {
c,
Call::Balances(..) |
Call::Assets(..) | Call::Uniques(..) |
Call::Vesting(pallet_vesting::Call::vested_transfer(..)) |
Call::Indices(pallet_indices::Call::transfer(..))
Call::Vesting(pallet_vesting::Call::vested_transfer { .. }) |
Call::Indices(pallet_indices::Call::transfer { .. })
),
ProxyType::Governance => matches!(
c,
@@ -1314,7 +1324,7 @@ impl_runtime_apis! {
impl sp_api::Metadata<Block> for Runtime {
fn metadata() -> OpaqueMetadata {
Runtime::metadata().into()
OpaqueMetadata::new(Runtime::metadata().into())
}
}
@@ -115,7 +115,7 @@ mod tests {
let alice = MultiSigner::from(Alice.public()).into_account();
let _hash = node
.submit_extrinsic(
frame_system::Call::remark((b"hello world").to_vec()),
frame_system::Call::remark { remark: (b"hello world").to_vec() },
Some(alice),
)
.await
+9 -9
View File
@@ -299,19 +299,19 @@ impl<'a> Iterator for BlockContentIterator<'a> {
)),
function: match self.content.block_type {
BlockType::RandomTransfersKeepAlive =>
Call::Balances(BalancesCall::transfer_keep_alive(
sp_runtime::MultiAddress::Id(receiver),
node_runtime::ExistentialDeposit::get() + 1,
)),
Call::Balances(BalancesCall::transfer_keep_alive {
dest: sp_runtime::MultiAddress::Id(receiver),
value: node_runtime::ExistentialDeposit::get() + 1,
}),
BlockType::RandomTransfersReaping => {
Call::Balances(BalancesCall::transfer(
sp_runtime::MultiAddress::Id(receiver),
Call::Balances(BalancesCall::transfer {
dest: sp_runtime::MultiAddress::Id(receiver),
// Transfer so that ending balance would be 1 less than existential
// deposit so that we kill the sender account.
100 * DOLLARS - (node_runtime::ExistentialDeposit::get() - 1),
))
value: 100 * DOLLARS - (node_runtime::ExistentialDeposit::get() - 1),
})
},
BlockType::Noop => Call::System(SystemCall::remark(Vec::new())),
BlockType::Noop => Call::System(SystemCall::remark { remark: Vec::new() }),
},
},
self.runtime_version.spec_version,