mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 05:11:09 +00:00
Companion for removal of execution strategies (#7443)
* Companion for removal of execution strategies https://github.com/paritytech/substrate/pull/14387 * Fix some tests * 🤦 * Adapt to latest changes * Start supporting the offchain transaction pool * Fix tests * FMT * Remove patches * Update Substrate * update lockfile for {"substrate"} * Fix parachain upgrade smoke test * Fix test * Rewrite all tests to use `MockSubstemClient` --------- Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -18,6 +18,7 @@ sc-network = { git = "https://github.com/paritytech/substrate", branch = "master
|
||||
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
smallvec = "1.8.0"
|
||||
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
thiserror = "1.0.31"
|
||||
|
||||
@@ -31,7 +31,7 @@ pub mod errors;
|
||||
pub mod messages;
|
||||
|
||||
mod runtime_client;
|
||||
pub use runtime_client::RuntimeApiSubsystemClient;
|
||||
pub use runtime_client::{DefaultSubsystemClient, RuntimeApiSubsystemClient};
|
||||
|
||||
pub use jaeger::*;
|
||||
pub use polkadot_node_jaeger as jaeger;
|
||||
|
||||
@@ -23,10 +23,11 @@ use polkadot_primitives::{
|
||||
SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
|
||||
ValidatorSignature,
|
||||
};
|
||||
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
|
||||
use sp_api::{ApiError, ApiExt, ProvideRuntimeApi};
|
||||
use sp_authority_discovery::AuthorityDiscoveryApi;
|
||||
use sp_consensus_babe::{BabeApi, Epoch};
|
||||
use std::collections::BTreeMap;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
/// Exposes all runtime calls that are used by the runtime API subsystem.
|
||||
#[async_trait]
|
||||
@@ -231,28 +232,44 @@ pub trait RuntimeApiSubsystemClient {
|
||||
) -> std::result::Result<Vec<sp_authority_discovery::AuthorityId>, ApiError>;
|
||||
}
|
||||
|
||||
/// Default implementation of [`RuntimeApiSubsystemClient`] using the client.
|
||||
pub struct DefaultSubsystemClient<Client> {
|
||||
client: Arc<Client>,
|
||||
offchain_transaction_pool_factory: OffchainTransactionPoolFactory<Block>,
|
||||
}
|
||||
|
||||
impl<Client> DefaultSubsystemClient<Client> {
|
||||
/// Create new instance.
|
||||
pub fn new(
|
||||
client: Arc<Client>,
|
||||
offchain_transaction_pool_factory: OffchainTransactionPoolFactory<Block>,
|
||||
) -> Self {
|
||||
Self { client, offchain_transaction_pool_factory }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<T> RuntimeApiSubsystemClient for T
|
||||
impl<Client> RuntimeApiSubsystemClient for DefaultSubsystemClient<Client>
|
||||
where
|
||||
T: ProvideRuntimeApi<Block> + Send + Sync,
|
||||
T::Api: ParachainHost<Block> + BabeApi<Block> + AuthorityDiscoveryApi<Block>,
|
||||
Client: ProvideRuntimeApi<Block> + Send + Sync,
|
||||
Client::Api: ParachainHost<Block> + BabeApi<Block> + AuthorityDiscoveryApi<Block>,
|
||||
{
|
||||
async fn validators(&self, at: Hash) -> Result<Vec<ValidatorId>, ApiError> {
|
||||
self.runtime_api().validators(at)
|
||||
self.client.runtime_api().validators(at)
|
||||
}
|
||||
|
||||
async fn validator_groups(
|
||||
&self,
|
||||
at: Hash,
|
||||
) -> Result<(Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumber>), ApiError> {
|
||||
self.runtime_api().validator_groups(at)
|
||||
self.client.runtime_api().validator_groups(at)
|
||||
}
|
||||
|
||||
async fn availability_cores(
|
||||
&self,
|
||||
at: Hash,
|
||||
) -> Result<Vec<CoreState<Hash, BlockNumber>>, ApiError> {
|
||||
self.runtime_api().availability_cores(at)
|
||||
self.client.runtime_api().availability_cores(at)
|
||||
}
|
||||
|
||||
async fn persisted_validation_data(
|
||||
@@ -261,7 +278,7 @@ where
|
||||
para_id: Id,
|
||||
assumption: OccupiedCoreAssumption,
|
||||
) -> Result<Option<PersistedValidationData<Hash, BlockNumber>>, ApiError> {
|
||||
self.runtime_api().persisted_validation_data(at, para_id, assumption)
|
||||
self.client.runtime_api().persisted_validation_data(at, para_id, assumption)
|
||||
}
|
||||
|
||||
async fn assumed_validation_data(
|
||||
@@ -271,7 +288,7 @@ where
|
||||
expected_persisted_validation_data_hash: Hash,
|
||||
) -> Result<Option<(PersistedValidationData<Hash, BlockNumber>, ValidationCodeHash)>, ApiError>
|
||||
{
|
||||
self.runtime_api().assumed_validation_data(
|
||||
self.client.runtime_api().assumed_validation_data(
|
||||
at,
|
||||
para_id,
|
||||
expected_persisted_validation_data_hash,
|
||||
@@ -284,11 +301,11 @@ where
|
||||
para_id: Id,
|
||||
outputs: CandidateCommitments,
|
||||
) -> Result<bool, ApiError> {
|
||||
self.runtime_api().check_validation_outputs(at, para_id, outputs)
|
||||
self.client.runtime_api().check_validation_outputs(at, para_id, outputs)
|
||||
}
|
||||
|
||||
async fn session_index_for_child(&self, at: Hash) -> Result<SessionIndex, ApiError> {
|
||||
self.runtime_api().session_index_for_child(at)
|
||||
self.client.runtime_api().session_index_for_child(at)
|
||||
}
|
||||
|
||||
async fn validation_code(
|
||||
@@ -297,7 +314,7 @@ where
|
||||
para_id: Id,
|
||||
assumption: OccupiedCoreAssumption,
|
||||
) -> Result<Option<ValidationCode>, ApiError> {
|
||||
self.runtime_api().validation_code(at, para_id, assumption)
|
||||
self.client.runtime_api().validation_code(at, para_id, assumption)
|
||||
}
|
||||
|
||||
async fn candidate_pending_availability(
|
||||
@@ -305,11 +322,11 @@ where
|
||||
at: Hash,
|
||||
para_id: Id,
|
||||
) -> Result<Option<CommittedCandidateReceipt<Hash>>, ApiError> {
|
||||
self.runtime_api().candidate_pending_availability(at, para_id)
|
||||
self.client.runtime_api().candidate_pending_availability(at, para_id)
|
||||
}
|
||||
|
||||
async fn candidate_events(&self, at: Hash) -> Result<Vec<CandidateEvent<Hash>>, ApiError> {
|
||||
self.runtime_api().candidate_events(at)
|
||||
self.client.runtime_api().candidate_events(at)
|
||||
}
|
||||
|
||||
async fn dmq_contents(
|
||||
@@ -317,7 +334,7 @@ where
|
||||
at: Hash,
|
||||
recipient: Id,
|
||||
) -> Result<Vec<InboundDownwardMessage<BlockNumber>>, ApiError> {
|
||||
self.runtime_api().dmq_contents(at, recipient)
|
||||
self.client.runtime_api().dmq_contents(at, recipient)
|
||||
}
|
||||
|
||||
async fn inbound_hrmp_channels_contents(
|
||||
@@ -325,7 +342,7 @@ where
|
||||
at: Hash,
|
||||
recipient: Id,
|
||||
) -> Result<BTreeMap<Id, Vec<InboundHrmpMessage<BlockNumber>>>, ApiError> {
|
||||
self.runtime_api().inbound_hrmp_channels_contents(at, recipient)
|
||||
self.client.runtime_api().inbound_hrmp_channels_contents(at, recipient)
|
||||
}
|
||||
|
||||
async fn validation_code_by_hash(
|
||||
@@ -333,14 +350,14 @@ where
|
||||
at: Hash,
|
||||
hash: ValidationCodeHash,
|
||||
) -> Result<Option<ValidationCode>, ApiError> {
|
||||
self.runtime_api().validation_code_by_hash(at, hash)
|
||||
self.client.runtime_api().validation_code_by_hash(at, hash)
|
||||
}
|
||||
|
||||
async fn on_chain_votes(
|
||||
&self,
|
||||
at: Hash,
|
||||
) -> Result<Option<ScrapedOnChainVotes<Hash>>, ApiError> {
|
||||
self.runtime_api().on_chain_votes(at)
|
||||
self.client.runtime_api().on_chain_votes(at)
|
||||
}
|
||||
|
||||
async fn session_executor_params(
|
||||
@@ -348,7 +365,7 @@ where
|
||||
at: Hash,
|
||||
session_index: SessionIndex,
|
||||
) -> Result<Option<ExecutorParams>, ApiError> {
|
||||
self.runtime_api().session_executor_params(at, session_index)
|
||||
self.client.runtime_api().session_executor_params(at, session_index)
|
||||
}
|
||||
|
||||
async fn session_info(
|
||||
@@ -356,7 +373,7 @@ where
|
||||
at: Hash,
|
||||
index: SessionIndex,
|
||||
) -> Result<Option<SessionInfo>, ApiError> {
|
||||
self.runtime_api().session_info(at, index)
|
||||
self.client.runtime_api().session_info(at, index)
|
||||
}
|
||||
|
||||
async fn submit_pvf_check_statement(
|
||||
@@ -365,11 +382,17 @@ where
|
||||
stmt: PvfCheckStatement,
|
||||
signature: ValidatorSignature,
|
||||
) -> Result<(), ApiError> {
|
||||
self.runtime_api().submit_pvf_check_statement(at, stmt, signature)
|
||||
let mut runtime_api = self.client.runtime_api();
|
||||
|
||||
runtime_api.register_extension(
|
||||
self.offchain_transaction_pool_factory.offchain_transaction_pool(at),
|
||||
);
|
||||
|
||||
runtime_api.submit_pvf_check_statement(at, stmt, signature)
|
||||
}
|
||||
|
||||
async fn pvfs_require_precheck(&self, at: Hash) -> Result<Vec<ValidationCodeHash>, ApiError> {
|
||||
self.runtime_api().pvfs_require_precheck(at)
|
||||
self.client.runtime_api().pvfs_require_precheck(at)
|
||||
}
|
||||
|
||||
async fn validation_code_hash(
|
||||
@@ -378,36 +401,36 @@ where
|
||||
para_id: Id,
|
||||
assumption: OccupiedCoreAssumption,
|
||||
) -> Result<Option<ValidationCodeHash>, ApiError> {
|
||||
self.runtime_api().validation_code_hash(at, para_id, assumption)
|
||||
self.client.runtime_api().validation_code_hash(at, para_id, assumption)
|
||||
}
|
||||
|
||||
async fn current_epoch(&self, at: Hash) -> Result<Epoch, ApiError> {
|
||||
self.runtime_api().current_epoch(at)
|
||||
self.client.runtime_api().current_epoch(at)
|
||||
}
|
||||
|
||||
async fn authorities(
|
||||
&self,
|
||||
at: Hash,
|
||||
) -> std::result::Result<Vec<sp_authority_discovery::AuthorityId>, ApiError> {
|
||||
self.runtime_api().authorities(at)
|
||||
self.client.runtime_api().authorities(at)
|
||||
}
|
||||
|
||||
async fn api_version_parachain_host(&self, at: Hash) -> Result<Option<u32>, ApiError> {
|
||||
self.runtime_api().api_version::<dyn ParachainHost<Block>>(at)
|
||||
self.client.runtime_api().api_version::<dyn ParachainHost<Block>>(at)
|
||||
}
|
||||
|
||||
async fn disputes(
|
||||
&self,
|
||||
at: Hash,
|
||||
) -> Result<Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>, ApiError> {
|
||||
self.runtime_api().disputes(at)
|
||||
self.client.runtime_api().disputes(at)
|
||||
}
|
||||
|
||||
async fn unapplied_slashes(
|
||||
&self,
|
||||
at: Hash,
|
||||
) -> Result<Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>, ApiError> {
|
||||
self.runtime_api().unapplied_slashes(at)
|
||||
self.client.runtime_api().unapplied_slashes(at)
|
||||
}
|
||||
|
||||
async fn key_ownership_proof(
|
||||
@@ -415,7 +438,7 @@ where
|
||||
at: Hash,
|
||||
validator_id: ValidatorId,
|
||||
) -> Result<Option<vstaging::slashing::OpaqueKeyOwnershipProof>, ApiError> {
|
||||
self.runtime_api().key_ownership_proof(at, validator_id)
|
||||
self.client.runtime_api().key_ownership_proof(at, validator_id)
|
||||
}
|
||||
|
||||
async fn submit_report_dispute_lost(
|
||||
@@ -424,7 +447,12 @@ where
|
||||
dispute_proof: vstaging::slashing::DisputeProof,
|
||||
key_ownership_proof: vstaging::slashing::OpaqueKeyOwnershipProof,
|
||||
) -> Result<Option<()>, ApiError> {
|
||||
self.runtime_api()
|
||||
.submit_report_dispute_lost(at, dispute_proof, key_ownership_proof)
|
||||
let mut runtime_api = self.client.runtime_api();
|
||||
|
||||
runtime_api.register_extension(
|
||||
self.offchain_transaction_pool_factory.offchain_transaction_pool(at),
|
||||
);
|
||||
|
||||
runtime_api.submit_report_dispute_lost(at, dispute_proof, key_ownership_proof)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user