Skip to content

Commit

Permalink
feat: 🎸 add metadata-hash-extension
Browse files Browse the repository at this point in the history
  • Loading branch information
yooml committed Jun 12, 2024
1 parent a62b6e0 commit 34fd760
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 18 deletions.
87 changes: 74 additions & 13 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ cumulus-primitives-utility = { version = "0.8.0", default-featur
cumulus-test-relay-sproof-builder = { version = "0.8.0", default-features = false }
frame-benchmarking = { version = "29.0.0", default-features = false }
frame-executive = { version = "29.0.0", default-features = false }
frame-metadata-hash-extension = { version = "0.1.0", default-features = false }
frame-support = { version = "29.0.0", default-features = false }
frame-system = { version = "29.0.0", default-features = false }
frame-system-benchmarking = { version = "29.0.0", default-features = false }
Expand Down Expand Up @@ -264,7 +265,7 @@ sp-rpc = { version = "27.0.0" }
substrate-build-script-utils = { version = "11.0.0" }
substrate-frame-rpc-system = { version = "29.0.0" }
substrate-prometheus-endpoint = { version = "0.17.0" }
substrate-wasm-builder = { version = "18.0.0" }
substrate-wasm-builder = { version = "18.0.1" }
try-runtime-cli = { version = "0.39.0" }
xcm-emulator = { version = "0.6.0" }
xcm-simulator = { version = "8.0.0" }
Expand Down
6 changes: 5 additions & 1 deletion runtime/bifrost-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde_json = { workspace = true }
# frame dependencies
frame-benchmarking = { workspace = true, optional = true }
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true, features = ["tuples-96"] }
frame-system = { workspace = true }
frame-system-benchmarking = { workspace = true, optional = true }
Expand Down Expand Up @@ -159,6 +160,7 @@ std = [

"frame-benchmarking?/std",
"frame-executive/std",
"frame-metadata-hash-extension/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
Expand Down Expand Up @@ -397,6 +399,8 @@ try-runtime = [
"bifrost-channel-commission/try-runtime",
]

# Enable the metadata hash generation in the wasm builder.
metadata-hash = ["substrate-wasm-builder/metadata-hash"]
# When enabled, the runtime API will not be build.
#
# This is required by Cumulus to access certain types of the
Expand All @@ -407,7 +411,7 @@ disable-runtime-api = []
# A feature that should be enabled when the runtime should be build for on-chain
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
# to make it smaller like logging for example.
on-chain-release-build = ["sp-api/disable-logging"]
on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"]

# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
12 changes: 11 additions & 1 deletion runtime/bifrost-kusama/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#[cfg(feature = "std")]
#[cfg(all(feature = "metadata-hash", feature = "std"))]
fn main() {
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.enable_metadata_hash("BNC", 12)
.build()
}

#[cfg(all(not(feature = "metadata-hash"), feature = "std"))]
fn main() {
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
Expand Down
2 changes: 2 additions & 0 deletions runtime/bifrost-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ where
frame_system::CheckNonce::<Runtime>::from(nonce),
frame_system::CheckWeight::<Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
frame_metadata_hash_extension::CheckMetadataHash::<Runtime>::new(true),
);
let raw_payload = SignedPayload::new(call, extra)
.map_err(|e| {
Expand Down Expand Up @@ -2030,6 +2031,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
Expand Down
6 changes: 5 additions & 1 deletion runtime/bifrost-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde_json = { workspace = true }
# frame dependencies
frame-benchmarking = { workspace = true, optional = true }
frame-executive = { workspace = true }
frame-metadata-hash-extension = { workspace = true }
frame-support = { workspace = true, features = ["tuples-96"] }
frame-system = { workspace = true }
frame-system-benchmarking = { workspace = true, optional = true }
Expand Down Expand Up @@ -156,6 +157,7 @@ std = [
"strum/std",

"frame-executive/std",
"frame-metadata-hash-extension/std",
"frame-support/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
Expand Down Expand Up @@ -372,6 +374,8 @@ try-runtime = [
"zenlink-protocol/try-runtime",
]

# Enable the metadata hash generation in the wasm builder.
metadata-hash = ["substrate-wasm-builder/metadata-hash"]
# When enabled, the runtime API will not be build.
#
# This is required by Cumulus to access certain types of the
Expand All @@ -382,7 +386,7 @@ disable-runtime-api = []
# A feature that should be enabled when the runtime should be build for on-chain
# deployment. This will disable stuff that shouldn't be part of the on-chain wasm
# to make it smaller like logging for example.
on-chain-release-build = ["sp-api/disable-logging"]
on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"]

# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
12 changes: 11 additions & 1 deletion runtime/bifrost-polkadot/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[cfg(feature = "std")]
#[cfg(all(feature = "metadata-hash", feature = "std"))]
fn main() {
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.import_memory()
.enable_metadata_hash("BNC", 12)
.build()
}

#[cfg(all(not(feature = "metadata-hash"), feature = "std"))]
fn main() {
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
Expand Down
1 change: 1 addition & 0 deletions runtime/bifrost-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,7 @@ pub type SignedExtra = (
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
);
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
Expand Down

0 comments on commit 34fd760

Please sign in to comment.