Revert "BlockId removal: refactor: HeaderBackend::header (#1977)"

This reverts commit b7dff85939.
This commit is contained in:
EgorPopelyaev
2022-12-21 12:15:09 +01:00
parent fa953ab35a
commit 0f59d20a1e
5 changed files with 150 additions and 25 deletions
Generated
+120 -2
View File
@@ -443,13 +443,16 @@ dependencies = [
"fnv",
"futures",
"futures-timer",
"futures-timer",
"log",
"parity-scale-codec",
"parking_lot 0.12.1",
"sc-chain-spec",
"sc-chain-spec",
"sc-client-api",
"sc-consensus",
"sc-finality-grandpa",
"sc-finality-grandpa",
"sc-keystore",
"sc-network",
"sc-network-common",
@@ -483,6 +486,7 @@ dependencies = [
"parking_lot 0.12.1",
"sc-rpc",
"sc-utils",
"sc-utils",
"serde",
"sp-beefy",
"sp-core",
@@ -2586,9 +2590,9 @@ dependencies = [
[[package]]
name = "ed25519"
version = "1.5.2"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369"
checksum = "74e1069e39f1454367eb2de793ed062fac4c35c2934b76a81d90dd9abcd28816"
dependencies = [
"signature",
]
@@ -2993,15 +2997,19 @@ dependencies = [
"gethostname",
"handlebars",
"hash-db",
"hash-db",
"itertools",
"kvdb",
"kvdb",
"lazy_static",
"linked-hash-map",
"log",
"memory-db",
"memory-db",
"parity-scale-codec",
"rand 0.8.5",
"rand_pcg 0.3.1",
"rand_pcg 0.3.1",
"sc-block-builder",
"sc-cli",
"sc-client-api",
@@ -3012,6 +3020,7 @@ dependencies = [
"serde",
"serde_json",
"serde_nanos",
"serde_nanos",
"sp-api",
"sp-blockchain",
"sp-core",
@@ -3025,6 +3034,7 @@ dependencies = [
"sp-storage",
"sp-trie",
"tempfile",
"tempfile",
"thiserror",
"thousands",
]
@@ -3091,16 +3101,19 @@ name = "frame-remote-externalities"
version = "0.10.0-dev"
source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51"
dependencies = [
"env_logger 0.9.0",
"env_logger 0.9.0",
"futures",
"log",
"parity-scale-codec",
"serde",
"serde_json",
"serde_json",
"sp-core",
"sp-io",
"sp-runtime",
"sp-version",
"sp-version",
"substrate-rpc-client",
"tokio",
]
@@ -3423,9 +3436,11 @@ checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
dependencies = [
"cfg-if",
"js-sys",
"js-sys",
"libc",
"wasi 0.9.0+wasi-snapshot-preview1",
"wasm-bindgen",
"wasm-bindgen",
]
[[package]]
@@ -4956,6 +4971,7 @@ dependencies = [
"sp-consensus",
"sp-core",
"sp-io",
"sp-io",
"sp-mmr-primitives",
"sp-runtime",
]
@@ -5367,8 +5383,10 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"
[[package]]
name = "orchestra"
version = "0.0.2"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0aab54694ddaa8a9b703724c6ef04272b2d27bc32d2c855aae5cdd1857216b43"
checksum = "0aab54694ddaa8a9b703724c6ef04272b2d27bc32d2c855aae5cdd1857216b43"
dependencies = [
"async-trait",
"dyn-clonable",
@@ -5384,8 +5402,10 @@ dependencies = [
[[package]]
name = "orchestra-proc-macro"
version = "0.0.2"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a702b2f6bf592b3eb06c00d80d05afaf7a8eff6b41bb361e397d799acc21b45a"
checksum = "a702b2f6bf592b3eb06c00d80d05afaf7a8eff6b41bb361e397d799acc21b45a"
dependencies = [
"expander 0.0.6",
"itertools",
@@ -5705,6 +5725,7 @@ dependencies = [
"parity-scale-codec",
"rand 0.8.5",
"rand_pcg 0.3.1",
"rand_pcg 0.3.1",
"scale-info",
"serde",
"smallvec",
@@ -5788,6 +5809,7 @@ dependencies = [
"pallet-election-provider-support-benchmarking",
"parity-scale-codec",
"rand 0.7.3",
"rand 0.7.3",
"scale-info",
"sp-arithmetic",
"sp-core",
@@ -5796,6 +5818,7 @@ dependencies = [
"sp-runtime",
"sp-std",
"static_assertions",
"static_assertions",
"strum",
]
@@ -6224,6 +6247,7 @@ dependencies = [
"pallet-session",
"pallet-staking",
"rand 0.7.3",
"rand 0.7.3",
"sp-runtime",
"sp-session",
"sp-std",
@@ -6797,19 +6821,25 @@ checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5"
[[package]]
name = "pbkdf2"
version = "0.4.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216eaa586a190f0a738f2f918511eecfa90f13295abec0e457cdebcceda80cbd"
checksum = "216eaa586a190f0a738f2f918511eecfa90f13295abec0e457cdebcceda80cbd"
dependencies = [
"crypto-mac 0.8.0",
"crypto-mac 0.8.0",
]
[[package]]
name = "pbkdf2"
version = "0.8.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d95f5254224e617595d2cc3cc73ff0a5eaf2637519e25f03388154e9378b6ffa"
checksum = "d95f5254224e617595d2cc3cc73ff0a5eaf2637519e25f03388154e9378b6ffa"
dependencies = [
"crypto-mac 0.11.1",
"crypto-mac 0.11.1",
]
[[package]]
@@ -7469,6 +7499,7 @@ dependencies = [
"sp-blockchain",
"sp-inherents",
"sp-runtime",
"sp-runtime",
"thiserror",
"tracing-gum",
]
@@ -8713,6 +8744,7 @@ dependencies = [
"rand_core 0.5.1",
"rand_hc",
"rand_pcg 0.2.1",
"rand_pcg 0.2.1",
]
[[package]]
@@ -8792,6 +8824,15 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_pcg"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429"
dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_pcg"
version = "0.3.1"
@@ -9313,6 +9354,7 @@ dependencies = [
"prost",
"prost-build",
"rand 0.7.3",
"rand 0.7.3",
"sc-client-api",
"sc-network-common",
"sp-api",
@@ -9369,9 +9411,11 @@ name = "sc-chain-spec"
version = "4.0.0-dev"
source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51"
dependencies = [
"impl-trait-for-tuples",
"impl-trait-for-tuples",
"memmap2",
"parity-scale-codec",
"parity-scale-codec",
"sc-chain-spec-derive",
"sc-network-common",
"sc-telemetry",
@@ -9407,6 +9451,7 @@ dependencies = [
"names",
"parity-scale-codec",
"rand 0.7.3",
"rand 0.7.3",
"regex",
"rpassword",
"sc-client-api",
@@ -9440,6 +9485,7 @@ dependencies = [
"fnv",
"futures",
"hash-db",
"hash-db",
"log",
"parity-scale-codec",
"parking_lot 0.12.1",
@@ -9457,6 +9503,7 @@ dependencies = [
"sp-state-machine",
"sp-storage",
"sp-trie",
"sp-trie",
"substrate-prometheus-endpoint",
]
@@ -9562,6 +9609,7 @@ dependencies = [
"sc-telemetry",
"schnorrkel",
"serde",
"serde",
"sp-api",
"sp-application-crypto",
"sp-block-builder",
@@ -9573,9 +9621,11 @@ dependencies = [
"sp-core",
"sp-inherents",
"sp-io",
"sp-io",
"sp-keystore",
"sp-runtime",
"sp-version",
"sp-version",
"substrate-prometheus-endpoint",
"thiserror",
]
@@ -9637,6 +9687,7 @@ dependencies = [
"sp-runtime",
"sp-state-machine",
"thiserror",
"thiserror",
]
[[package]]
@@ -9728,6 +9779,7 @@ dependencies = [
"sc-client-api",
"sc-consensus",
"sc-keystore",
"sc-keystore",
"sc-network",
"sc-network-common",
"sc-network-gossip",
@@ -9762,6 +9814,7 @@ dependencies = [
"sc-rpc",
"serde",
"serde_json",
"serde_json",
"sp-blockchain",
"sp-core",
"sp-runtime",
@@ -9780,6 +9833,7 @@ dependencies = [
"sc-client-api",
"sc-network-common",
"sc-transaction-pool-api",
"sc-transaction-pool-api",
"sp-blockchain",
"sp-runtime",
]
@@ -9808,17 +9862,22 @@ dependencies = [
"async-trait",
"asynchronous-codec",
"bitflags",
"bitflags",
"bytes",
"cid",
"cid",
"either",
"fnv",
"fork-tree",
"fork-tree",
"futures",
"futures-timer",
"ip_network",
"libp2p",
"linked-hash-map",
"linked_hash_set",
"linked-hash-map",
"linked_hash_set",
"log",
"lru",
"parity-scale-codec",
@@ -9826,6 +9885,8 @@ dependencies = [
"pin-project",
"prost",
"rand 0.7.3",
"prost",
"rand 0.7.3",
"sc-block-builder",
"sc-client-api",
"sc-consensus",
@@ -9864,6 +9925,7 @@ dependencies = [
"thiserror",
"unsigned-varint",
"void",
"void",
]
[[package]]
@@ -9971,6 +10033,7 @@ dependencies = [
"array-bytes 4.2.0",
"futures",
"hex",
"hex",
"libp2p",
"log",
"parity-scale-codec",
@@ -10000,6 +10063,7 @@ dependencies = [
"parity-scale-codec",
"parking_lot 0.12.1",
"rand 0.7.3",
"rand 0.7.3",
"sc-client-api",
"sc-network-common",
"sc-peerset",
@@ -10041,6 +10105,7 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb
dependencies = [
"futures",
"hash-db",
"hash-db",
"jsonrpsee",
"log",
"parity-scale-codec",
@@ -10069,11 +10134,14 @@ name = "sc-rpc-api"
version = "0.10.0-dev"
source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51"
dependencies = [
"futures",
"futures",
"jsonrpsee",
"log",
"log",
"parity-scale-codec",
"parking_lot 0.12.1",
"parking_lot 0.12.1",
"sc-chain-spec",
"sc-transaction-pool-api",
"scale-info",
@@ -10083,6 +10151,7 @@ dependencies = [
"sp-rpc",
"sp-runtime",
"sp-tracing",
"sp-tracing",
"sp-version",
"thiserror",
]
@@ -10092,6 +10161,7 @@ name = "sc-rpc-server"
version = "4.0.0-dev"
source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51"
dependencies = [
"futures",
"futures",
"http",
"jsonrpsee",
@@ -10133,12 +10203,14 @@ dependencies = [
"futures",
"futures-timer",
"hash-db",
"hash-db",
"jsonrpsee",
"log",
"parity-scale-codec",
"parking_lot 0.12.1",
"pin-project",
"rand 0.7.3",
"rand 0.7.3",
"sc-block-builder",
"sc-chain-spec",
"sc-client-api",
@@ -10168,17 +10240,21 @@ dependencies = [
"sp-api",
"sp-application-crypto",
"sp-block-builder",
"sp-application-crypto",
"sp-block-builder",
"sp-blockchain",
"sp-consensus",
"sp-core",
"sp-externalities",
"sp-inherents",
"sp-inherents",
"sp-keystore",
"sp-runtime",
"sp-session",
"sp-state-machine",
"sp-storage",
"sp-tracing",
"sp-tracing",
"sp-transaction-pool",
"sp-transaction-storage-proof",
"sp-trie",
@@ -10201,6 +10277,7 @@ dependencies = [
"parity-scale-codec",
"parking_lot 0.12.1",
"sc-client-api",
"sc-client-api",
"sp-core",
]
@@ -10233,6 +10310,8 @@ dependencies = [
"log",
"rand 0.7.3",
"rand_pcg 0.2.1",
"rand 0.7.3",
"rand_pcg 0.2.1",
"regex",
"sc-telemetry",
"serde",
@@ -10254,6 +10333,7 @@ dependencies = [
"parking_lot 0.12.1",
"pin-project",
"rand 0.7.3",
"rand 0.7.3",
"serde",
"serde_json",
"thiserror",
@@ -10597,6 +10677,15 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_nanos"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e44969a61f5d316be20a42ff97816efb3b407a924d06824c3d8a49fa8450de0e"
dependencies = [
"serde",
]
[[package]]
name = "sha-1"
version = "0.8.2"
@@ -10898,6 +10987,7 @@ dependencies = [
"scale-info",
"serde",
"sp-debug-derive",
"sp-debug-derive",
"sp-std",
"static_assertions",
]
@@ -10982,6 +11072,7 @@ dependencies = [
"async-trait",
"futures",
"futures-timer",
"futures-timer",
"log",
"parity-scale-codec",
"sp-core",
@@ -11044,6 +11135,8 @@ dependencies = [
"serde",
"sp-arithmetic",
"sp-runtime",
"sp-arithmetic",
"sp-runtime",
"sp-std",
"sp-timestamp",
]
@@ -11071,6 +11164,7 @@ dependencies = [
"bitflags",
"blake2",
"byteorder",
"byteorder",
"dyn-clonable",
"ed25519-zebra",
"futures",
@@ -11082,10 +11176,12 @@ dependencies = [
"log",
"merlin",
"num-traits",
"num-traits",
"parity-scale-codec",
"parking_lot 0.12.1",
"primitive-types",
"rand 0.7.3",
"rand 0.7.3",
"regex",
"scale-info",
"schnorrkel",
@@ -11103,6 +11199,7 @@ dependencies = [
"thiserror",
"tiny-bip39",
"wasmi 0.13.0",
"wasmi 0.13.0",
"zeroize",
]
@@ -11202,10 +11299,12 @@ dependencies = [
"ed25519-dalek",
"futures",
"hash-db",
"hash-db",
"libsecp256k1",
"log",
"parity-scale-codec",
"parking_lot 0.12.1",
"parking_lot 0.12.1",
"secp256k1",
"sp-core",
"sp-externalities",
@@ -11216,6 +11315,7 @@ dependencies = [
"sp-tracing",
"sp-trie",
"sp-wasm-interface",
"sp-wasm-interface",
"tracing",
"tracing-core",
]
@@ -11331,6 +11431,7 @@ dependencies = [
"parity-scale-codec",
"paste",
"rand 0.7.3",
"rand 0.7.3",
"scale-info",
"serde",
"sp-application-crypto",
@@ -11414,9 +11515,11 @@ dependencies = [
"hash-db",
"log",
"num-traits",
"num-traits",
"parity-scale-codec",
"parking_lot 0.12.1",
"rand 0.7.3",
"rand 0.7.3",
"smallvec",
"sp-core",
"sp-externalities",
@@ -11426,6 +11529,7 @@ dependencies = [
"thiserror",
"tracing",
"trie-root",
"trie-root",
]
[[package]]
@@ -11456,6 +11560,7 @@ dependencies = [
"log",
"parity-scale-codec",
"sp-api",
"sp-api",
"sp-inherents",
"sp-runtime",
"sp-std",
@@ -11568,6 +11673,7 @@ name = "sp-weights"
version = "4.0.0"
source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51"
dependencies = [
"impl-trait-for-tuples",
"impl-trait-for-tuples",
"parity-scale-codec",
"scale-info",
@@ -11885,9 +11991,11 @@ dependencies = [
"log",
"parity-scale-codec",
"sc-client-api",
"sc-client-api",
"sc-rpc-api",
"sc-transaction-pool-api",
"serde_json",
"serde_json",
"sp-api",
"sp-block-builder",
"sp-blockchain",
@@ -11900,6 +12008,7 @@ name = "substrate-prometheus-endpoint"
version = "0.10.0-dev"
source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.36#cb4f2491b00af7d7817f3a54209c26b20faa1f51"
dependencies = [
"futures-util",
"futures-util",
"hyper",
"log",
@@ -11935,9 +12044,11 @@ dependencies = [
"serde",
"sp-core",
"sp-io",
"sp-io",
"sp-runtime",
"sp-state-machine",
"sp-std",
"sp-std",
"sp-trie",
"trie-db",
]
@@ -12210,16 +12321,22 @@ dependencies = [
[[package]]
name = "tiny-bip39"
version = "0.8.2"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc59cb9dfc85bb312c3a78fd6aa8a8582e310b0fa885d5bb877f6dcc601839d"
checksum = "ffc59cb9dfc85bb312c3a78fd6aa8a8582e310b0fa885d5bb877f6dcc601839d"
dependencies = [
"anyhow",
"hmac 0.8.1",
"hmac 0.8.1",
"once_cell",
"pbkdf2 0.4.0",
"rand 0.7.3",
"pbkdf2 0.4.0",
"rand 0.7.3",
"rustc-hash",
"sha2 0.9.8",
"sha2 0.9.8",
"thiserror",
"unicode-normalization",
"wasm-bindgen",
@@ -12578,6 +12695,7 @@ dependencies = [
"log",
"parity-scale-codec",
"sc-chain-spec",
"sc-chain-spec",
"sc-cli",
"sc-executor",
"sc-service",
+1 -1
View File
@@ -422,7 +422,7 @@ mod tests {
let para_id = ParaId::from(100);
let announce_block = |_, _| ();
let client = Arc::new(TestClientBuilder::new().build());
let header = client.header(client.chain_info().genesis_hash).unwrap().unwrap();
let header = client.header(&BlockId::Number(0)).unwrap().unwrap();
let (sub_tx, sub_rx) = mpsc::channel(64);
@@ -381,9 +381,20 @@ fn block_local<T>(fut: impl Future<Output = T>) -> T {
impl HeaderBackend<Block> for BlockChainRpcClient {
fn header(
&self,
hash: <Block as polkadot_service::BlockT>::Hash,
id: BlockId,
) -> sp_blockchain::Result<Option<<Block as polkadot_service::BlockT>::Header>> {
Ok(block_local(self.rpc_client.chain_get_header(Some(hash)))?)
let fetch_header = |hash| block_local(self.rpc_client.chain_get_header(Some(hash)));
match id {
BlockId::Hash(hash) => Ok(fetch_header(hash)?),
BlockId::Number(number) => {
if let Some(hash) = HeaderBackend::<Block>::hash(self, number)? {
Ok(fetch_header(hash)?)
} else {
Ok(None)
}
},
}
}
fn info(&self) -> Info<Block> {
@@ -414,7 +425,7 @@ impl HeaderBackend<Block> for BlockChainRpcClient {
id: sp_api::BlockId<Block>,
) -> sp_blockchain::Result<sp_blockchain::BlockStatus> {
let exists = match id {
BlockId::Hash(hash) => self.header(hash)?.is_some(),
BlockId::Hash(_) => self.header(id)?.is_some(),
BlockId::Number(n) => {
let best_header = block_local(self.rpc_client.chain_get_header(None))?;
if let Some(best) = best_header {
@@ -24,7 +24,7 @@ use cumulus_test_client::{
};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use sp_keyring::AccountKeyring::*;
use sp_runtime::traits::Header as HeaderT;
use sp_runtime::{generic::BlockId, traits::Header as HeaderT};
use std::{env, process::Command};
fn call_validate_block_encoded_header(
@@ -60,7 +60,7 @@ fn create_test_client() -> (Client, Header) {
.build();
let genesis_header = client
.header(client.chain_info().genesis_hash)
.header(&BlockId::number(0))
.ok()
.flatten()
.expect("Genesis header exists; qed");
+13 -17
View File
@@ -82,10 +82,7 @@ mod tests {
ValidationParams,
};
use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use sp_runtime::{generic::BlockId, traits::Header as HeaderT};
use std::{env, process::Command, str::FromStr};
const SLOT_DURATION: u64 = 6000;
@@ -109,14 +106,14 @@ mod tests {
fn build_block(
client: &Client,
hash: <Block as BlockT>::Hash,
at: BlockId<Block>,
timestamp: u64,
relay_chain_slot: Slot,
) -> (ParachainBlockData, PHash) {
let sproof_builder =
RelayStateSproofBuilder { current_slot: relay_chain_slot, ..Default::default() };
let parent_header = client.header(hash).ok().flatten().expect("Genesis header exists");
let parent_header = client.header(&at).ok().flatten().expect("Genesis header exists");
let relay_parent_storage_root = sproof_builder.clone().into_state_root_and_proof().0;
@@ -128,7 +125,7 @@ mod tests {
let block = client
.init_block_builder_with_timestamp(
&BlockId::Hash(hash),
&at,
Some(validation_data),
sproof_builder,
timestamp,
@@ -149,20 +146,19 @@ mod tests {
.expect("TIMESTAMP is a valid `u64`");
let block =
build_block(&client, client.chain_info().genesis_hash, SLOT_DURATION, 1.into())
.0
.into_block();
futures::executor::block_on(
client.import(sp_consensus::BlockOrigin::Own, block.clone()),
)
.unwrap();
build_block(&client, BlockId::number(0), SLOT_DURATION, 1.into()).0.into_block();
futures::executor::block_on(client.import(sp_consensus::BlockOrigin::Own, block))
.unwrap();
let hashof1 = block.hash();
let (block, relay_chain_root) =
build_block(&client, hashof1, timestamp, relay_chain_slot.into());
build_block(&client, BlockId::number(1), timestamp, relay_chain_slot.into());
let header = call_validate_block(
client.header(hashof1).ok().flatten().expect("Genesis header exists"),
client
.header(&BlockId::number(1))
.ok()
.flatten()
.expect("Genesis header exists"),
block.clone(),
relay_chain_root,
)