From 38503aed8130baf452943499f810de871c024a3f Mon Sep 17 00:00:00 2001 From: bear Date: Wed, 9 Oct 2024 11:02:48 +0800 Subject: [PATCH] Fix pending runtime api --- Cargo.lock | 1 + Cargo.toml | 1 + node/Cargo.toml | 1 + node/src/service/mod.rs | 17 ++++++++++++++++- tests/ethereum/test-block.ts | 11 +++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 85fdffb0f..a7d4b90b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2639,6 +2639,7 @@ dependencies = [ "cumulus-primitives-core", "cumulus-primitives-parachain-inherent", "cumulus-relay-chain-interface", + "cumulus-test-relay-sproof-builder", "darwinia-runtime", "dc-primitives", "fc-api", diff --git a/Cargo.toml b/Cargo.toml index d597ed81f..83da3abdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,6 +107,7 @@ cumulus-primitives-core = { git = "https://github.com/darwini cumulus-primitives-parachain-inherent = { git = "https://github.com/darwinia-network/polkadot-sdk", branch = "release-polkadot-v1.7.2", default-features = false } cumulus-primitives-utility = { git = "https://github.com/darwinia-network/polkadot-sdk", branch = "release-polkadot-v1.7.2", default-features = false } cumulus-relay-chain-interface = { git = "https://github.com/darwinia-network/polkadot-sdk", branch = "release-polkadot-v1.7.2" } +cumulus-test-relay-sproof-builder = { git = "https://github.com/darwinia-network/polkadot-sdk", branch = "release-polkadot-v1.7.2" } frame-benchmarking = { git = "https://github.com/darwinia-network/polkadot-sdk", branch = "release-polkadot-v1.7.2", default-features = false } frame-benchmarking-cli = { git = "https://github.com/darwinia-network/polkadot-sdk", branch = "release-polkadot-v1.7.2" } frame-executive = { git = "https://github.com/darwinia-network/polkadot-sdk", branch = "release-polkadot-v1.7.2", default-features = false } diff --git a/node/Cargo.toml b/node/Cargo.toml index f25e5dbab..e10d698c0 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -56,6 +56,7 @@ cumulus-primitives-aura = { workspace = true, features = ["std"] } cumulus-primitives-core = { workspace = true, features = ["std"] } cumulus-primitives-parachain-inherent = { workspace = true, features = ["std"] } cumulus-relay-chain-interface = { workspace = true } +cumulus-test-relay-sproof-builder = { workspace = true } frame-benchmarking = { workspace = true, optional = true, features = ["std"] } frame-benchmarking-cli = { workspace = true } pallet-transaction-payment-rpc = { workspace = true } diff --git a/node/src/service/mod.rs b/node/src/service/mod.rs index dea6d1928..7efddf423 100644 --- a/node/src/service/mod.rs +++ b/node/src/service/mod.rs @@ -40,6 +40,9 @@ use futures::FutureExt; // darwinia use dc_primitives::*; // polkadot-sdk +use cumulus_primitives_core::PersistedValidationData; +use cumulus_primitives_parachain_inherent::ParachainInherentData; +use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; use sc_client_api::{Backend, HeaderBackend}; use sc_consensus::ImportQueue; use sc_network::NetworkBlock; @@ -905,7 +908,19 @@ where *timestamp, slot_duration, ); - Ok((slot, timestamp)) + let (relay_parent_storage_root, relay_chain_state) = + RelayStateSproofBuilder::default().into_state_root_and_proof(); + let parachain_inherent_data = ParachainInherentData { + validation_data: PersistedValidationData { + relay_parent_number: u32::MAX, + relay_parent_storage_root, + ..Default::default() + }, + relay_chain_state, + downward_messages: Default::default(), + horizontal_messages: Default::default(), + }; + Ok((slot, timestamp, parachain_inherent_data)) }; Box::new(move |deny_unsafe, subscription_task_executor| { diff --git a/tests/ethereum/test-block.ts b/tests/ethereum/test-block.ts index c9b5b364f..e36388ec4 100644 --- a/tests/ethereum/test-block.ts +++ b/tests/ethereum/test-block.ts @@ -9,6 +9,17 @@ describe("Test Block RPC", () => { expect(await web3.eth.getBlockNumber()).to.not.equal(0); }); + it("Get block by tags", async () => { + let earliest = await web3.eth.getBlock("earliest"); + expect(earliest.number).to.equal(0); + + let latest = await web3.eth.getBlock("latest"); + expect(latest.number).to.be.a("number"); + + let pending = await web3.eth.getBlock("pending"); + expect(pending.number).to.be.a("number"); + }); + it("Get block by hash", async () => { let latest_block = await web3.eth.getBlock("latest"); let block = await web3.eth.getBlock(latest_block.hash);