mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 08:47:57 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user