mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Unify RelayChainInterface error handling and introduce async (#909)
This commit is contained in:
@@ -56,7 +56,7 @@ use polkadot_primitives::v1::{
|
||||
};
|
||||
|
||||
use cumulus_primitives_core::ParachainBlockData;
|
||||
use cumulus_relay_chain_interface::RelayChainInterface;
|
||||
use cumulus_relay_chain_interface::{RelayChainInterface, RelayChainResult};
|
||||
|
||||
use codec::Decode;
|
||||
use futures::{select, stream::FuturesUnordered, Future, FutureExt, Stream, StreamExt};
|
||||
@@ -381,7 +381,14 @@ where
|
||||
let mut imported_blocks = self.parachain_client.import_notification_stream().fuse();
|
||||
let mut finalized_blocks = self.parachain_client.finality_notification_stream().fuse();
|
||||
let pending_candidates =
|
||||
pending_candidates(self.relay_chain_interface.clone(), self.para_id).fuse();
|
||||
match pending_candidates(self.relay_chain_interface.clone(), self.para_id).await {
|
||||
Ok(pending_candidate_stream) => pending_candidate_stream.fuse(),
|
||||
Err(err) => {
|
||||
tracing::error!(target: LOG_TARGET, error = ?err, "Unable to retrieve pending candidate stream.");
|
||||
return
|
||||
},
|
||||
};
|
||||
|
||||
futures::pin_mut!(pending_candidates);
|
||||
|
||||
loop {
|
||||
@@ -435,28 +442,41 @@ where
|
||||
}
|
||||
|
||||
/// Returns a stream over pending candidates for the parachain corresponding to `para_id`.
|
||||
fn pending_candidates(
|
||||
relay_chain_client: impl RelayChainInterface,
|
||||
async fn pending_candidates(
|
||||
relay_chain_client: impl RelayChainInterface + Clone,
|
||||
para_id: ParaId,
|
||||
) -> impl Stream<Item = (CommittedCandidateReceipt, SessionIndex)> {
|
||||
relay_chain_client.import_notification_stream().filter_map(move |n| {
|
||||
let res = relay_chain_client
|
||||
.candidate_pending_availability(&BlockId::hash(n.hash), para_id)
|
||||
.and_then(|pa| {
|
||||
relay_chain_client
|
||||
.session_index_for_child(&BlockId::hash(n.hash))
|
||||
.map(|v| pa.map(|pa| (pa, v)))
|
||||
})
|
||||
.map_err(|e| {
|
||||
tracing::error!(
|
||||
target: LOG_TARGET,
|
||||
error = ?e,
|
||||
"Failed fetch pending candidates.",
|
||||
)
|
||||
})
|
||||
.ok()
|
||||
.flatten();
|
||||
) -> RelayChainResult<impl Stream<Item = (CommittedCandidateReceipt, SessionIndex)>> {
|
||||
let import_notification_stream = relay_chain_client.import_notification_stream().await?;
|
||||
|
||||
async move { res }
|
||||
})
|
||||
let filtered_stream = import_notification_stream.filter_map(move |n| {
|
||||
let client_for_closure = relay_chain_client.clone();
|
||||
async move {
|
||||
let block_id = BlockId::hash(n.hash());
|
||||
let pending_availability_result = client_for_closure
|
||||
.candidate_pending_availability(&block_id, para_id)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
tracing::error!(
|
||||
target: LOG_TARGET,
|
||||
error = ?e,
|
||||
"Failed to fetch pending candidates.",
|
||||
)
|
||||
});
|
||||
let session_index_result =
|
||||
client_for_closure.session_index_for_child(&block_id).await.map_err(|e| {
|
||||
tracing::error!(
|
||||
target: LOG_TARGET,
|
||||
error = ?e,
|
||||
"Failed to fetch session index.",
|
||||
)
|
||||
});
|
||||
|
||||
if let Ok(Some(candidate)) = pending_availability_result {
|
||||
session_index_result.map(|session_index| (candidate, session_index)).ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
});
|
||||
Ok(filtered_stream)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user