polkadot-node-subsystems: ChainApiBackend added + polkadot-debug image version fixed (#2411)

The out-dated version (bad tag) of [polkadot
image](https://github.com/paritytech/polkadot-sdk/blob/ede4a362622dfa69eb167eaa876246b1289f4b41/.gitlab/pipeline/zombienet/cumulus.yml#L31)
([docker
info](https://hub.docker.com/layers/paritypr/polkadot-debug/master/images/sha256:adb1658052cf671b50c90d5cece5c7a131efa1a95978249bd5cb85a5ad654f7a?context=explore))
was used. This PR fixes this.

See also:
https://github.com/paritytech/polkadot-sdk/pull/2411#issuecomment-1822632724

Also adds an abstraction that allows asynchronous backends to be passed to `ChainApiSubsystem`
---------

Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
This commit is contained in:
Michal Kucharczyk
2023-11-22 19:24:11 +01:00
committed by GitHub
parent 0956357b60
commit 49874882cf
12 changed files with 213 additions and 55 deletions
+1
View File
@@ -17,6 +17,7 @@ polkadot-node-jaeger = { path = "../jaeger" }
orchestra = { version = "0.3.3", default-features = false, features=["futures_channel"] }
sc-network = { path = "../../../substrate/client/network" }
sp-api = { path = "../../../substrate/primitives/api" }
sp-blockchain = { path = "../../../substrate/primitives/blockchain" }
sp-consensus-babe = { path = "../../../substrate/primitives/consensus/babe" }
sp-authority-discovery = { path = "../../../substrate/primitives/authority-discovery" }
sc-client-api = { path = "../../../substrate/client/api" }
+1 -1
View File
@@ -40,7 +40,7 @@ pub mod errors;
pub mod messages;
mod runtime_client;
pub use runtime_client::{DefaultSubsystemClient, RuntimeApiSubsystemClient};
pub use runtime_client::{ChainApiBackend, DefaultSubsystemClient, RuntimeApiSubsystemClient};
pub use jaeger::*;
pub use polkadot_node_jaeger as jaeger;
@@ -18,17 +18,70 @@ use async_trait::async_trait;
use polkadot_primitives::{
async_backing, runtime_api::ParachainHost, slashing, vstaging, Block, BlockNumber,
CandidateCommitments, CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState,
DisputeState, ExecutorParams, GroupRotationInfo, Hash, Id, InboundDownwardMessage,
DisputeState, ExecutorParams, GroupRotationInfo, Hash, Header, Id, InboundDownwardMessage,
InboundHrmpMessage, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement,
ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash,
ValidatorId, ValidatorIndex, ValidatorSignature,
};
use sc_client_api::HeaderBackend;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_api::{ApiError, ApiExt, ProvideRuntimeApi};
use sp_api::{ApiError, ApiExt, HeaderT, NumberFor, ProvideRuntimeApi};
use sp_authority_discovery::AuthorityDiscoveryApi;
use sp_blockchain::Info;
use sp_consensus_babe::{BabeApi, Epoch};
use std::{collections::BTreeMap, sync::Arc};
/// Offers header utilities.
///
/// This is a async wrapper trait for ['HeaderBackend'] to be used with the
/// `ChainApiSubsystem`.
// This trait was introduced to suit the needs of collators. Depending on their operating mode, they
// might not have a client of the relay chain that can supply a synchronous HeaderBackend
// implementation.
#[async_trait]
pub trait ChainApiBackend: Send + Sync {
/// Get block header. Returns `None` if block is not found.
async fn header(&self, hash: Hash) -> sp_blockchain::Result<Option<Header>>;
/// Get blockchain info.
async fn info(&self) -> sp_blockchain::Result<Info<Block>>;
/// Get block number by hash. Returns `None` if the header is not in the chain.
async fn number(
&self,
hash: Hash,
) -> sp_blockchain::Result<Option<<Header as HeaderT>::Number>>;
/// Get block hash by number. Returns `None` if the header is not in the chain.
async fn hash(&self, number: NumberFor<Block>) -> sp_blockchain::Result<Option<Hash>>;
}
#[async_trait]
impl<T> ChainApiBackend for T
where
T: HeaderBackend<Block>,
{
/// Get block header. Returns `None` if block is not found.
async fn header(&self, hash: Hash) -> sp_blockchain::Result<Option<Header>> {
HeaderBackend::header(self, hash)
}
/// Get blockchain info.
async fn info(&self) -> sp_blockchain::Result<Info<Block>> {
Ok(HeaderBackend::info(self))
}
/// Get block number by hash. Returns `None` if the header is not in the chain.
async fn number(
&self,
hash: Hash,
) -> sp_blockchain::Result<Option<<Header as HeaderT>::Number>> {
HeaderBackend::number(self, hash)
}
/// Get block hash by number. Returns `None` if the header is not in the chain.
async fn hash(&self, number: NumberFor<Block>) -> sp_blockchain::Result<Option<Hash>> {
HeaderBackend::hash(self, number)
}
}
/// Exposes all runtime calls that are used by the runtime API subsystem.
#[async_trait]
pub trait RuntimeApiSubsystemClient {