Remove light client companion (#4191)

* Remove light client companion

* Update substrate

* cargo fmt

* Fixed benches

* fmt
This commit is contained in:
Arkadiy Paronyan
2021-11-12 15:07:33 +01:00
committed by GitHub
parent ea16b72e0b
commit 4354b6482e
10 changed files with 190 additions and 310 deletions
+167 -186
View File
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -600,7 +600,7 @@ pub fn initialize_for_benchmarks<T: Config<I>, I: 'static>(header: BridgedHeader
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::mock::{run_test, test_header, Origin, TestHash, TestHeader, TestNumber, TestRuntime}; use crate::mock::{run_test, test_header, Origin, TestHeader, TestNumber, TestRuntime};
use bp_test_utils::{ use bp_test_utils::{
authority_list, make_default_justification, make_justification_for_header, JustificationGeneratorParams, ALICE, authority_list, make_default_justification, make_justification_for_header, JustificationGeneratorParams, ALICE,
BOB, BOB,
@@ -644,18 +644,18 @@ mod tests {
let _ = Pallet::<TestRuntime>::on_initialize(current_number); let _ = Pallet::<TestRuntime>::on_initialize(current_number);
} }
fn change_log(delay: u64) -> Digest<TestHash> { fn change_log(delay: u64) -> Digest {
let consensus_log = ConsensusLog::<TestNumber>::ScheduledChange(sp_finality_grandpa::ScheduledChange { let consensus_log = ConsensusLog::<TestNumber>::ScheduledChange(sp_finality_grandpa::ScheduledChange {
next_authorities: vec![(ALICE.into(), 1), (BOB.into(), 1)], next_authorities: vec![(ALICE.into(), 1), (BOB.into(), 1)],
delay, delay,
}); });
Digest::<TestHash> { Digest {
logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())], logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())],
} }
} }
fn forced_change_log(delay: u64) -> Digest<TestHash> { fn forced_change_log(delay: u64) -> Digest {
let consensus_log = ConsensusLog::<TestNumber>::ForcedChange( let consensus_log = ConsensusLog::<TestNumber>::ForcedChange(
delay, delay,
sp_finality_grandpa::ScheduledChange { sp_finality_grandpa::ScheduledChange {
@@ -664,7 +664,7 @@ mod tests {
}, },
); );
Digest::<TestHash> { Digest {
logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())], logs: vec![DigestItem::Consensus(GRANDPA_ENGINE_ID, consensus_log.encode())],
} }
} }
@@ -28,7 +28,6 @@ use sp_runtime::{
pub type AccountId = u64; pub type AccountId = u64;
pub type TestHeader = crate::BridgedHeader<TestRuntime, ()>; pub type TestHeader = crate::BridgedHeader<TestRuntime, ()>;
pub type TestNumber = crate::BridgedBlockNumber<TestRuntime, ()>; pub type TestNumber = crate::BridgedBlockNumber<TestRuntime, ()>;
pub type TestHash = crate::BridgedBlockHash<TestRuntime, ()>;
type Block = frame_system::mocking::MockBlock<TestRuntime>; type Block = frame_system::mocking::MockBlock<TestRuntime>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRuntime>;
+1 -31
View File
@@ -32,7 +32,7 @@ use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT}, traits::{BlakeTwo256, Block as BlockT},
Justifications, Justifications,
}; };
use sp_storage::{ChildInfo, PrefixedStorageKey, StorageData, StorageKey}; use sp_storage::{ChildInfo, StorageData, StorageKey};
use std::sync::Arc; use std::sync::Arc;
pub type FullBackend = sc_service::TFullBackend<Block>; pub type FullBackend = sc_service::TFullBackend<Block>;
@@ -514,36 +514,6 @@ impl sc_client_api::StorageProvider<Block, crate::FullBackend> for Client {
} }
} }
} }
fn max_key_changes_range(
&self,
first: NumberFor<Block>,
last: BlockId<Block>,
) -> sp_blockchain::Result<Option<(NumberFor<Block>, BlockId<Block>)>> {
with_client! {
self,
client,
{
client.max_key_changes_range(first, last)
}
}
}
fn key_changes(
&self,
first: NumberFor<Block>,
last: BlockId<Block>,
storage_key: Option<&PrefixedStorageKey>,
key: &StorageKey,
) -> sp_blockchain::Result<Vec<(NumberFor<Block>, u32)>> {
with_client! {
self,
client,
{
client.key_changes(first, last, storage_key, key)
}
}
}
} }
impl sp_blockchain::HeaderBackend<Block> for Client { impl sp_blockchain::HeaderBackend<Block> for Client {
@@ -174,10 +174,6 @@ impl sp_externalities::Externalities for ValidationExternalities {
panic!("child_storage_root: unsupported feature for parachain validation") panic!("child_storage_root: unsupported feature for parachain validation")
} }
fn storage_changes_root(&mut self, _: &[u8]) -> Result<Option<Vec<u8>>, ()> {
panic!("storage_changes_root: unsupported feature for parachain validation")
}
fn next_child_storage_key(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> { fn next_child_storage_key(&self, _: &ChildInfo, _: &[u8]) -> Option<Vec<u8>> {
panic!("next_child_storage_key: unsupported feature for parachain validation") panic!("next_child_storage_key: unsupported feature for parachain validation")
} }
+8 -32
View File
@@ -303,10 +303,7 @@ fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::Gene
const STASH: u128 = 100 * DOT; const STASH: u128 = 100 * DOT;
polkadot::GenesisConfig { polkadot::GenesisConfig {
system: polkadot::SystemConfig { system: polkadot::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: polkadot::BalancesConfig { balances: polkadot::BalancesConfig {
balances: endowed_accounts balances: endowed_accounts
.iter() .iter()
@@ -494,10 +491,7 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Genesi
const STASH: u128 = 100 * WND; const STASH: u128 = 100 * WND;
westend::GenesisConfig { westend::GenesisConfig {
system: westend::SystemConfig { system: westend::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: westend::BalancesConfig { balances: westend::BalancesConfig {
balances: endowed_accounts balances: endowed_accounts
.iter() .iter()
@@ -685,10 +679,7 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::GenesisC
const STASH: u128 = 100 * KSM; const STASH: u128 = 100 * KSM;
kusama::GenesisConfig { kusama::GenesisConfig {
system: kusama::SystemConfig { system: kusama::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: kusama::BalancesConfig { balances: kusama::BalancesConfig {
balances: endowed_accounts balances: endowed_accounts
.iter() .iter()
@@ -1000,10 +991,7 @@ fn rococo_staging_testnet_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::
const STASH: u128 = 100 * ROC; const STASH: u128 = 100 * ROC;
rococo_runtime::GenesisConfig { rococo_runtime::GenesisConfig {
system: rococo_runtime::SystemConfig { system: rococo_runtime::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: rococo_runtime::BalancesConfig { balances: rococo_runtime::BalancesConfig {
balances: endowed_accounts balances: endowed_accounts
.iter() .iter()
@@ -1260,10 +1248,7 @@ pub fn polkadot_testnet_genesis(
const STASH: u128 = 100 * DOT; const STASH: u128 = 100 * DOT;
polkadot::GenesisConfig { polkadot::GenesisConfig {
system: polkadot::SystemConfig { system: polkadot::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
indices: polkadot::IndicesConfig { indices: vec![] }, indices: polkadot::IndicesConfig { indices: vec![] },
balances: polkadot::BalancesConfig { balances: polkadot::BalancesConfig {
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(),
@@ -1347,10 +1332,7 @@ pub fn kusama_testnet_genesis(
const STASH: u128 = 100 * KSM; const STASH: u128 = 100 * KSM;
kusama::GenesisConfig { kusama::GenesisConfig {
system: kusama::SystemConfig { system: kusama::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
indices: kusama::IndicesConfig { indices: vec![] }, indices: kusama::IndicesConfig { indices: vec![] },
balances: kusama::BalancesConfig { balances: kusama::BalancesConfig {
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(),
@@ -1436,10 +1418,7 @@ pub fn westend_testnet_genesis(
const STASH: u128 = 100 * DOT; const STASH: u128 = 100 * DOT;
westend::GenesisConfig { westend::GenesisConfig {
system: westend::SystemConfig { system: westend::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
indices: westend::IndicesConfig { indices: vec![] }, indices: westend::IndicesConfig { indices: vec![] },
balances: westend::BalancesConfig { balances: westend::BalancesConfig {
balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(),
@@ -1518,10 +1497,7 @@ pub fn rococo_testnet_genesis(
const ENDOWMENT: u128 = 1_000_000 * DOT; const ENDOWMENT: u128 = 1_000_000 * DOT;
rococo_runtime::GenesisConfig { rococo_runtime::GenesisConfig {
system: rococo_runtime::SystemConfig { system: rococo_runtime::SystemConfig { code: wasm_binary.to_vec() },
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
beefy: Default::default(), beefy: Default::default(),
indices: rococo_runtime::IndicesConfig { indices: vec![] }, indices: rococo_runtime::IndicesConfig { indices: vec![] },
balances: rococo_runtime::BalancesConfig { balances: rococo_runtime::BalancesConfig {
+1 -5
View File
@@ -107,8 +107,7 @@ pub use sp_api::{ApiRef, ConstructRuntimeApi, Core as CoreApi, ProvideRuntimeApi
pub use sp_runtime::{ pub use sp_runtime::{
generic, generic,
traits::{ traits::{
self as runtime_traits, BlakeTwo256, Block as BlockT, DigestFor, HashFor, self as runtime_traits, BlakeTwo256, Block as BlockT, HashFor, Header as HeaderT, NumberFor,
Header as HeaderT, NumberFor,
}, },
}; };
@@ -795,7 +794,6 @@ where
transaction_pool: transaction_pool.clone(), transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(), spawn_handle: task_manager.spawn_handle(),
import_queue, import_queue,
on_demand: None,
block_announce_validator_builder: None, block_announce_validator_builder: None,
warp_sync: Some(warp_sync), warp_sync: Some(warp_sync),
})?; })?;
@@ -865,8 +863,6 @@ where
rpc_extensions_builder: Box::new(rpc_extensions_builder), rpc_extensions_builder: Box::new(rpc_extensions_builder),
transaction_pool: transaction_pool.clone(), transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager, task_manager: &mut task_manager,
on_demand: None,
remote_blockchain: None,
system_rpc_tx, system_rpc_tx,
telemetry: telemetry.as_mut(), telemetry: telemetry.as_mut(),
})?; })?;
+4 -4
View File
@@ -1188,8 +1188,8 @@ pub enum ConsensusLog {
impl ConsensusLog { impl ConsensusLog {
/// Attempt to convert a reference to a generic digest item into a consensus log. /// Attempt to convert a reference to a generic digest item into a consensus log.
pub fn from_digest_item<H>( pub fn from_digest_item(
digest_item: &runtime_primitives::DigestItem<H>, digest_item: &runtime_primitives::DigestItem,
) -> Result<Option<Self>, parity_scale_codec::Error> { ) -> Result<Option<Self>, parity_scale_codec::Error> {
match digest_item { match digest_item {
runtime_primitives::DigestItem::Consensus(id, encoded) if id == &POLKADOT_ENGINE_ID => runtime_primitives::DigestItem::Consensus(id, encoded) if id == &POLKADOT_ENGINE_ID =>
@@ -1199,8 +1199,8 @@ impl ConsensusLog {
} }
} }
impl<H> From<ConsensusLog> for runtime_primitives::DigestItem<H> { impl From<ConsensusLog> for runtime_primitives::DigestItem {
fn from(c: ConsensusLog) -> runtime_primitives::DigestItem<H> { fn from(c: ConsensusLog) -> runtime_primitives::DigestItem {
Self::Consensus(POLKADOT_ENGINE_ID, c.encode()) Self::Consensus(POLKADOT_ENGINE_ID, c.encode())
} }
} }
+1 -40
View File
@@ -21,10 +21,7 @@
use std::sync::Arc; use std::sync::Arc;
use polkadot_primitives::v0::{AccountId, Balance, Block, BlockNumber, Hash, Nonce}; use polkadot_primitives::v0::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
use sc_client_api::{ use sc_client_api::AuxStore;
light::{Fetcher, RemoteBlockchain},
AuxStore,
};
use sc_consensus_babe::Epoch; use sc_consensus_babe::Epoch;
use sc_finality_grandpa::FinalityProofProvider; use sc_finality_grandpa::FinalityProofProvider;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
@@ -40,18 +37,6 @@ use txpool_api::TransactionPool;
/// A type representing all RPC extensions. /// A type representing all RPC extensions.
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>; pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
/// Light client extra dependencies.
pub struct LightDeps<C, F, P> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Remote access to the blockchain (async).
pub remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
/// Fetcher instance.
pub fetcher: Arc<F>,
}
/// Extra dependencies for BABE. /// Extra dependencies for BABE.
pub struct BabeDeps { pub struct BabeDeps {
/// BABE protocol config. /// BABE protocol config.
@@ -179,27 +164,3 @@ where
Ok(io) Ok(io)
} }
/// Instantiate all RPC extensions for light node.
pub fn create_light<C, P, F>(deps: LightDeps<C, F, P>) -> RpcExtension
where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block>,
C: Send + Sync + 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
P: TransactionPool + Sync + Send + 'static,
F: Fetcher<Block> + 'static,
{
use frame_rpc_system::{LightSystem, SystemApi};
let LightDeps { client, pool, remote_blockchain, fetcher } = deps;
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(SystemApi::<Hash, AccountId, Nonce>::to_delegate(LightSystem::new(
client,
remote_blockchain,
fetcher,
pool,
)));
io
}
@@ -16,8 +16,9 @@
use super::*; use super::*;
use frame_benchmarking::benchmarks; use frame_benchmarking::benchmarks;
use frame_system::{DigestItemOf, RawOrigin}; use frame_system::RawOrigin;
use primitives::v1::ConsensusLog; use primitives::v1::ConsensusLog;
use sp_runtime::DigestItem;
// Random large number for the digest // Random large number for the digest
const DIGEST_MAX_LEN: u32 = 65536; const DIGEST_MAX_LEN: u32 = 65536;
@@ -32,7 +33,7 @@ benchmarks! {
verify { verify {
assert_eq!( assert_eq!(
<frame_system::Pallet<T>>::digest().logs.last().unwrap(), <frame_system::Pallet<T>>::digest().logs.last().unwrap(),
&<DigestItemOf<T>>::from(ConsensusLog::ForceApprove(d + 1)), &DigestItem::from(ConsensusLog::ForceApprove(d + 1)),
); );
} }