mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 21:51:06 +00:00
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:
committed by
GitHub
parent
0956357b60
commit
49874882cf
@@ -20,14 +20,16 @@ use cumulus_relay_chain_interface::{RelayChainError, RelayChainResult};
|
||||
use cumulus_relay_chain_rpc_interface::RelayChainRpcClient;
|
||||
use futures::{Stream, StreamExt};
|
||||
use polkadot_core_primitives::{Block, BlockNumber, Hash, Header};
|
||||
use polkadot_overseer::RuntimeApiSubsystemClient;
|
||||
use polkadot_overseer::{ChainApiBackend, RuntimeApiSubsystemClient};
|
||||
use polkadot_primitives::{
|
||||
async_backing::{AsyncBackingParams, BackingState},
|
||||
slashing,
|
||||
vstaging::NodeFeatures,
|
||||
};
|
||||
use sc_authority_discovery::{AuthorityDiscovery, Error as AuthorityDiscoveryError};
|
||||
use sp_api::{ApiError, RuntimeApiInfo};
|
||||
use sc_client_api::AuxStore;
|
||||
use sp_api::{ApiError, BlockT, HeaderT, NumberFor, RuntimeApiInfo};
|
||||
use sp_blockchain::Info;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct BlockChainRpcClient {
|
||||
@@ -54,6 +56,64 @@ impl BlockChainRpcClient {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl ChainApiBackend for BlockChainRpcClient {
|
||||
async fn header(
|
||||
&self,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
) -> sp_blockchain::Result<Option<<Block as BlockT>::Header>> {
|
||||
Ok(self.rpc_client.chain_get_header(Some(hash)).await?)
|
||||
}
|
||||
|
||||
async fn info(&self) -> sp_blockchain::Result<Info<Block>> {
|
||||
let (best_header_opt, genesis_hash, finalized_head) = futures::try_join!(
|
||||
self.rpc_client.chain_get_header(None),
|
||||
self.rpc_client.chain_get_head(Some(0)),
|
||||
self.rpc_client.chain_get_finalized_head()
|
||||
)?;
|
||||
let best_header = best_header_opt.ok_or_else(|| {
|
||||
RelayChainError::GenericError(
|
||||
"Unable to retrieve best header from relay chain.".to_string(),
|
||||
)
|
||||
})?;
|
||||
|
||||
let finalized_header =
|
||||
self.rpc_client.chain_get_header(Some(finalized_head)).await?.ok_or_else(|| {
|
||||
RelayChainError::GenericError(
|
||||
"Unable to retrieve finalized header from relay chain.".to_string(),
|
||||
)
|
||||
})?;
|
||||
Ok(Info {
|
||||
best_hash: best_header.hash(),
|
||||
best_number: best_header.number,
|
||||
genesis_hash,
|
||||
finalized_hash: finalized_head,
|
||||
finalized_number: finalized_header.number,
|
||||
finalized_state: Some((finalized_header.hash(), finalized_header.number)),
|
||||
number_leaves: 1,
|
||||
block_gap: None,
|
||||
})
|
||||
}
|
||||
|
||||
async fn number(
|
||||
&self,
|
||||
hash: <Block as BlockT>::Hash,
|
||||
) -> sp_blockchain::Result<Option<<<Block as BlockT>::Header as HeaderT>::Number>> {
|
||||
Ok(self
|
||||
.rpc_client
|
||||
.chain_get_header(Some(hash))
|
||||
.await?
|
||||
.map(|maybe_header| maybe_header.number))
|
||||
}
|
||||
|
||||
async fn hash(
|
||||
&self,
|
||||
number: NumberFor<Block>,
|
||||
) -> sp_blockchain::Result<Option<<Block as BlockT>::Hash>> {
|
||||
Ok(self.rpc_client.chain_get_block_hash(number.into()).await?)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl RuntimeApiSubsystemClient for BlockChainRpcClient {
|
||||
async fn validators(
|
||||
@@ -403,3 +463,25 @@ impl BlockChainRpcClient {
|
||||
Ok(self.rpc_client.get_finalized_heads_stream()?.boxed())
|
||||
}
|
||||
}
|
||||
|
||||
// Implementation required by ChainApiSubsystem
|
||||
// but never called in our case.
|
||||
impl AuxStore for BlockChainRpcClient {
|
||||
fn insert_aux<
|
||||
'a,
|
||||
'b: 'a,
|
||||
'c: 'a,
|
||||
I: IntoIterator<Item = &'a (&'c [u8], &'c [u8])>,
|
||||
D: IntoIterator<Item = &'a &'b [u8]>,
|
||||
>(
|
||||
&self,
|
||||
_insert: I,
|
||||
_delete: D,
|
||||
) -> sp_blockchain::Result<()> {
|
||||
unimplemented!("Not supported on the RPC collator")
|
||||
}
|
||||
|
||||
fn get_aux(&self, _key: &[u8]) -> sp_blockchain::Result<Option<Vec<u8>>> {
|
||||
unimplemented!("Not supported on the RPC collator")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ use polkadot_network_bridge::{
|
||||
NetworkBridgeTx as NetworkBridgeTxSubsystem,
|
||||
};
|
||||
use polkadot_node_collation_generation::CollationGenerationSubsystem;
|
||||
use polkadot_node_core_chain_api::ChainApiSubsystem;
|
||||
use polkadot_node_core_prospective_parachains::ProspectiveParachainsSubsystem;
|
||||
use polkadot_node_core_runtime_api::RuntimeApiSubsystem;
|
||||
use polkadot_node_network_protocol::{
|
||||
@@ -112,7 +113,7 @@ fn build_overseer(
|
||||
.candidate_backing(DummySubsystem)
|
||||
.candidate_validation(DummySubsystem)
|
||||
.pvf_checker(DummySubsystem)
|
||||
.chain_api(DummySubsystem)
|
||||
.chain_api(ChainApiSubsystem::new(runtime_client.clone(), Metrics::register(registry)?))
|
||||
.collation_generation(CollationGenerationSubsystem::new(Metrics::register(registry)?))
|
||||
.collator_protocol({
|
||||
let side = ProtocolSide::Collator {
|
||||
|
||||
Reference in New Issue
Block a user