Skip to content

Commit

Permalink
feat(runtime): add metadata signed-extension
Browse files Browse the repository at this point in the history
Add a new signed extension that enables the metadata hash verification feature approved under [RFC 0078](https://polkadot-fellows.github.io/RFCs/approved/0078-merkleized-metadata.html#rfc-0078-merkleized-metadata). This enhancement will support the new generic ledger hardware wallet app and future hardware wallets within the Polkadot ecosystem.

[Reference implementation](paritytech/polkadot-sdk#4580)
  • Loading branch information
enddynayn committed Jul 29, 2024
1 parent 11297e0 commit 5cf3517
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 18 deletions.
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "r
frame-system-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
frame-metadata-hash-extension = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
Expand All @@ -44,6 +45,7 @@ scale-info = { version = "2.10.0", default-features = false, features = [
sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
chrono = { version = "0.4.24" }
pretty_assertions = { version = "1.3.0" }
smallvec = "1.11.0"
Expand Down Expand Up @@ -149,13 +151,11 @@ sp-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
sp-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-wasm-interface = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
sp-metadata-ir = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
substrate-test-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }

substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0"}
try-runtime-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }

[profile.release]
Expand Down
4 changes: 2 additions & 2 deletions common/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ std = [
'frame-support/std',
'frame-system/std',
'sp-std/std',
'sp-runtime/std',
'sp-api/std',
'scale-info/std',
'sp-core/std',
'sp-runtime/std'
'sp-runtime/std',
'sp-io/std',
]
1 change: 1 addition & 0 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ frame-benchmarking-cli = { workspace = true, optional = true }
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
pallet-balances = { workspace = true }
pallet-transaction-payment = { workspace = true }
sc-cli = { workspace = true, optional = true }
Expand Down
2 changes: 2 additions & 0 deletions node/cli/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub fn create_benchmark_extrinsic(
pallet_frequency_tx_payment::ChargeFrqTransactionPayment::<runtime::Runtime>::from(0),
pallet_msa::CheckFreeExtrinsicUse::<runtime::Runtime>::new(),
pallet_handles::handles_signed_extension::HandlesSignedExtension::<runtime::Runtime>::new(),
frame_metadata_hash_extension::CheckMetadataHash::<runtime::Runtime>::new(false),
);

let raw_payload = sp_runtime::generic::SignedPayload::from_raw(
Expand All @@ -146,6 +147,7 @@ pub fn create_benchmark_extrinsic(
(),
(),
(),
None,
),
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));
Expand Down
2 changes: 1 addition & 1 deletion node/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use frequency_runtime::RuntimeApi;
// RPC
use common_primitives::node::{AccountId, Balance, Block, Hash, Index as Nonce};
use jsonrpsee::RpcModule;
use substrate_prometheus_endpoint::Registry;

// Cumulus Imports
use cumulus_client_collator::service::CollatorService;
Expand Down Expand Up @@ -48,7 +49,6 @@ use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerH
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_blockchain::HeaderBackend;
use sp_keystore::KeystorePtr;
use substrate_prometheus_endpoint::Registry;

type FullBackend = TFullBackend<Block>;

Expand Down
16 changes: 14 additions & 2 deletions runtime/frequency/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version = "0.0.0"
targets = ["x86_64-unknown-linux-gnu"]

[build-dependencies]
substrate-wasm-builder = { workspace = true }
substrate-wasm-builder = { workspace = true, optional = true }

[dependencies]
parity-scale-codec = { workspace = true, features = ["derive"] }
Expand All @@ -30,6 +30,7 @@ frame-system = { workspace = true }
frame-system-benchmarking = { workspace = true, optional = true }
frame-system-rpc-runtime-api = { workspace = true }
frame-try-runtime = { workspace = true, optional = true }
frame-metadata-hash-extension = { workspace = true }

pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
Expand Down Expand Up @@ -162,6 +163,8 @@ std = [
"common-runtime/std",
"sp-version/std",
"system-runtime-api/std",
"substrate-wasm-builder",
"frame-metadata-hash-extension/std",
]
runtime-benchmarks = [
"cumulus-pallet-parachain-system/runtime-benchmarks",
Expand Down Expand Up @@ -238,4 +241,13 @@ frequency-local = ["common-runtime/frequency-local"]
frequency-no-relay = ["common-runtime/frequency-no-relay"]
# Following features are used in generating lean wasms
no-metadata-docs = ["frame-support/no-metadata-docs"]
on-chain-release-build = ["sp-api/disable-logging"]
on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"]

# Enable the metadata hash generation.
#
# This is hidden behind a feature because it increases the compile time.
# The wasm binary needs to be compiled twice, once to fetch the metadata,
# generate the metadata hash and then a second time with the
# `RUNTIME_METADATA_HASH` environment variable set for the `CheckMetadataHash`
# extension.
metadata-hash = ["substrate-wasm-builder/metadata-hash"]
20 changes: 12 additions & 8 deletions runtime/frequency/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use substrate_wasm_builder::WasmBuilder;
#[cfg(all(feature = "std", not(feature = "metadata-hash")))]
fn main() {
substrate_wasm_builder::WasmBuilder::build_using_defaults()
}

#[cfg(all(feature = "std", feature = "metadata-hash"))]
fn main() {
// VSCode Users: Uncomment the following line to disable the ANSI color codes.
// The OUTPUT pane does not understand ANSI color codes and will show garbage without this.
// std::env::set_var("WASM_BUILD_NO_COLOR", "1");
WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
substrate_wasm_builder::WasmBuilder::init_with_defaults()
.enable_metadata_hash("FRQCY", 8)
.build()
}

/// The wasm builder is deactivated when compiling
/// this crate for wasm to speed up the compilation.
#[cfg(not(feature = "std"))]
fn main() {}
5 changes: 3 additions & 2 deletions runtime/frequency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ pub type SignedExtra = (
pallet_frequency_tx_payment::ChargeFrqTransactionPayment<Runtime>,
pallet_msa::CheckFreeExtrinsicUse<Runtime>,
pallet_handles::handles_signed_extension::HandlesSignedExtension<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
/// A Block signed with a Justification
pub type SignedBlock = generic::SignedBlock<Block>;
Expand Down Expand Up @@ -364,7 +365,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("frequency"),
impl_name: create_runtime_str!("frequency"),
authoring_version: 1,
spec_version: 100,
spec_version: 101,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand All @@ -378,7 +379,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("frequency-testnet"),
impl_name: create_runtime_str!("frequency"),
authoring_version: 1,
spec_version: 100,
spec_version: 101,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
9 changes: 8 additions & 1 deletion runtime/system-runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ common-primitives = { default-features = false, path = "../../common/primitives"

[features]
default = ["std"]
std = ["sp-api/std", "frame-system/std", "frame-support/std", "common-primitives/std", "sp-std/std", "sp-runtime/std"]
std = [
"sp-api/std",
"frame-system/std",
"frame-support/std",
"common-primitives/std",
"sp-std/std",
"sp-runtime/std",
]

0 comments on commit 5cf3517

Please sign in to comment.