mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
rpc-v2: Enable the archive class of methods (#3017)
The [archive](https://github.com/paritytech/json-rpc-interface-spec/blob/main/src/api/archive.md) API is unstable and subject to change. This PR enables the `archive` class of the RPC-V2 spec to substrate based chains. The `archive` API is enabled for archive nodes: - the state of the blocks is in archive mode - the block's bodies are in archive mode While at it, this PR extends the `BlocksPrunning` enum with an `is_archive` helper to check if the pruning mode keeps the block's bodies for long enough. Defaults used for the `archive` API: - a maximum of 5 responses are provided for descendants queries (this is similar to chainHead) - a maximum of 8 item queries are accepted at a time Before stabilizing the API we should look into these defaults and adjust after collecting some data. --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
@@ -63,7 +63,9 @@ use sc_rpc::{
|
||||
system::SystemApiServer,
|
||||
DenyUnsafe, SubscriptionTaskExecutor,
|
||||
};
|
||||
use sc_rpc_spec_v2::{chain_head::ChainHeadApiServer, transaction::TransactionApiServer};
|
||||
use sc_rpc_spec_v2::{
|
||||
archive::ArchiveApiServer, chain_head::ChainHeadApiServer, transaction::TransactionApiServer,
|
||||
};
|
||||
use sc_telemetry::{telemetry, ConnectionMessage, Telemetry, TelemetryHandle, SUBSTRATE_INFO};
|
||||
use sc_transaction_pool_api::{MaintainedTransactionPool, TransactionPool};
|
||||
use sc_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
|
||||
@@ -664,6 +666,26 @@ where
|
||||
)
|
||||
.into_rpc();
|
||||
|
||||
// Part of the RPC v2 spec.
|
||||
// An archive node that can respond to the `archive` RPC-v2 queries is a node with:
|
||||
// - state pruning in archive mode: The storage of blocks is kept around
|
||||
// - block pruning in archive mode: The block's body is kept around
|
||||
let is_archive_node = config.state_pruning.as_ref().map(|sp| sp.is_archive()).unwrap_or(false) &&
|
||||
config.blocks_pruning.is_archive();
|
||||
if is_archive_node {
|
||||
let genesis_hash =
|
||||
client.hash(Zero::zero()).ok().flatten().expect("Genesis block exists; qed");
|
||||
let archive_v2 = sc_rpc_spec_v2::archive::Archive::new(
|
||||
client.clone(),
|
||||
backend.clone(),
|
||||
genesis_hash,
|
||||
// Defaults to sensible limits for the `Archive`.
|
||||
sc_rpc_spec_v2::archive::ArchiveConfig::default(),
|
||||
)
|
||||
.into_rpc();
|
||||
rpc_api.merge(archive_v2).map_err(|e| Error::Application(e.into()))?;
|
||||
}
|
||||
|
||||
let author = sc_rpc::author::Author::new(
|
||||
client.clone(),
|
||||
transaction_pool,
|
||||
|
||||
Reference in New Issue
Block a user