Kill the light client, CHTs and change tries. (#10080)

* Remove light client, change tries and CHTs

* Update tests

* fmt

* Restore changes_root

* Fixed benches

* Cargo fmt

* fmt

* fmt
This commit is contained in:
Arkadiy Paronyan
2021-11-12 14:15:01 +01:00
committed by GitHub
parent 112b7dac47
commit 4cbbf0cf43
141 changed files with 532 additions and 17807 deletions
@@ -33,7 +33,7 @@ use sp_core::offchain::{
};
use sp_externalities::Extensions;
use sp_keystore::{testing::KeyStore, KeystoreExt, SyncCryptoStorePtr};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use sp_state_machine::StateMachine;
use std::{fmt::Debug, sync::Arc, time};
@@ -152,9 +152,8 @@ impl BenchmarkCmd {
// Get Benchmark List
let state = &state_without_tracking;
let result = StateMachine::<_, _, NumberFor<BB>, _>::new(
let result = StateMachine::new(
state,
None,
&mut changes,
&executor,
"Benchmark_benchmark_metadata",
@@ -243,9 +242,8 @@ impl BenchmarkCmd {
if !self.no_verify {
// Dont use these results since verification code will add overhead
let state = &state_without_tracking;
let _results = StateMachine::<_, _, NumberFor<BB>, _>::new(
let _results = StateMachine::new(
state,
None,
&mut changes,
&executor,
"Benchmark_dispatch_benchmark",
@@ -270,9 +268,8 @@ impl BenchmarkCmd {
// Do one loop of DB tracking.
{
let state = &state_with_tracking;
let result = StateMachine::<_, _, NumberFor<BB>, _>::new(
let result = StateMachine::new(
state, // todo remove tracking
None,
&mut changes,
&executor,
"Benchmark_dispatch_benchmark",
@@ -303,9 +300,8 @@ impl BenchmarkCmd {
// Finally run a bunch of loops to get extrinsic timing information.
for r in 0..self.external_repeat {
let state = &state_without_tracking;
let result = StateMachine::<_, _, NumberFor<BB>, _>::new(
let result = StateMachine::new(
state, // todo remove tracking
None,
&mut changes,
&executor,
"Benchmark_dispatch_benchmark",
+2 -87
View File
@@ -20,14 +20,13 @@
use std::sync::Arc;
use codec::{Codec, Decode, Encode};
use futures::{future::ready, FutureExt, TryFutureExt};
use futures::FutureExt;
use jsonrpc_core::{Error as RpcError, ErrorCode};
use jsonrpc_derive::rpc;
use sc_client_api::light::{future_header, Fetcher, RemoteBlockchain, RemoteCallRequest};
use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as ClientError, HeaderBackend};
use sp_blockchain::HeaderBackend;
use sp_core::{hexdisplay::HexDisplay, Bytes};
use sp_runtime::{generic::BlockId, traits};
@@ -154,90 +153,6 @@ where
}
}
/// An implementation of System-specific RPC methods on light client.
pub struct LightSystem<P: TransactionPool, C, F, Block> {
client: Arc<C>,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
pool: Arc<P>,
}
impl<P: TransactionPool, C, F, Block> LightSystem<P, C, F, Block> {
/// Create new `LightSystem`.
pub fn new(
client: Arc<C>,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
pool: Arc<P>,
) -> Self {
LightSystem { client, remote_blockchain, fetcher, pool }
}
}
impl<P, C, F, Block, AccountId, Index> SystemApi<<Block as traits::Block>::Hash, AccountId, Index>
for LightSystem<P, C, F, Block>
where
P: TransactionPool + 'static,
C: HeaderBackend<Block>,
C: Send + Sync + 'static,
F: Fetcher<Block> + 'static,
Block: traits::Block,
AccountId: Clone + std::fmt::Display + Codec + Send + 'static,
Index: Clone + std::fmt::Display + Codec + Send + traits::AtLeast32Bit + 'static,
{
fn nonce(&self, account: AccountId) -> FutureResult<Index> {
let best_hash = self.client.info().best_hash;
let best_id = BlockId::hash(best_hash);
let future_best_header = future_header(&*self.remote_blockchain, &*self.fetcher, best_id);
let fetcher = self.fetcher.clone();
let call_data = account.encode();
let future_best_header = future_best_header.and_then(move |maybe_best_header| {
ready(
maybe_best_header
.ok_or_else(|| ClientError::UnknownBlock(format!("{}", best_hash))),
)
});
let future_nonce = future_best_header.and_then(move |best_header| {
fetcher.remote_call(RemoteCallRequest {
block: best_hash,
header: best_header,
method: "AccountNonceApi_account_nonce".into(),
call_data,
retry_count: None,
})
});
let future_nonce = future_nonce.and_then(|nonce| async move {
Index::decode(&mut &nonce[..])
.map_err(|e| ClientError::CallResultDecode("Cannot decode account nonce", e))
});
let future_nonce = future_nonce.map_err(|e| RpcError {
code: ErrorCode::ServerError(Error::RuntimeError.into()),
message: "Unable to query nonce.".into(),
data: Some(format!("{:?}", e).into()),
});
let pool = self.pool.clone();
future_nonce.map_ok(move |nonce| adjust_nonce(&*pool, account, nonce)).boxed()
}
fn dry_run(
&self,
_extrinsic: Bytes,
_at: Option<<Block as traits::Block>::Hash>,
) -> FutureResult<Bytes> {
async {
Err(RpcError {
code: ErrorCode::MethodNotFound,
message: "Unable to dry run extrinsic.".into(),
data: None,
})
}
.boxed()
}
}
/// Adjust account nonce from state, so that tx with the nonce will be
/// placed after all ready txpool transactions.
fn adjust_nonce<P, AccountId, Index>(pool: &P, account: AccountId, nonce: Index) -> Index
@@ -152,12 +152,7 @@ where
.map_err(|e| format!("failed to decode output: {:?}", e))?;
let storage_changes = changes
.drain_storage_changes::<_, _, NumberFor<Block>>(
&state_ext.backend,
None,
Default::default(),
&mut Default::default(),
)
.drain_storage_changes(&state_ext.backend, Default::default(), &mut Default::default())
.unwrap();
state_ext.backend.apply_transaction(
storage_changes.transaction_storage_root,
@@ -680,9 +680,8 @@ pub(crate) fn state_machine_call<Block: BlockT, D: NativeExecutionDispatch + 'st
extensions: Extensions,
) -> sc_cli::Result<(OverlayedChanges, Vec<u8>)> {
let mut changes = Default::default();
let encoded_results = StateMachine::<_, _, NumberFor<Block>, _>::new(
let encoded_results = StateMachine::new(
&ext.backend,
None,
&mut changes,
executor,
method,