mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
Add new Runtime API messages and make runtime API request fallible (#1485)
* polkadot-subsystem: update runtime API message types * update all networking subsystems to use fallible runtime APIs * fix bitfield-signing and make it use new runtime APIs * port candidate-backing to handle runtime API errors and new types * remove old runtime API messages * remove unused imports * fix grumbles * fix backing tests
This commit is contained in:
committed by
GitHub
parent
d234ba38bb
commit
c8cdfbfd17
@@ -161,17 +161,23 @@ impl BitfieldDistribution {
|
||||
for relay_parent in activated {
|
||||
trace!(target: "bitd", "Start {:?}", relay_parent);
|
||||
// query basic system parameters once
|
||||
let (validator_set, signing_context) =
|
||||
query_basics(&mut ctx, relay_parent).await?;
|
||||
|
||||
let _ = state.per_relay_parent.insert(
|
||||
relay_parent,
|
||||
PerRelayParentData {
|
||||
signing_context,
|
||||
validator_set,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
if let Some((validator_set, signing_context)) =
|
||||
query_basics(&mut ctx, relay_parent).await?
|
||||
{
|
||||
// If our runtime API fails, we don't take down the node,
|
||||
// but we might alter peers' reputations erroneously as a result
|
||||
// of not having the correct bookkeeping. If we have lost a race
|
||||
// with state pruning, it is unlikely that peers will be sending
|
||||
// us anything to do with this relay-parent anyway.
|
||||
let _ = state.per_relay_parent.insert(
|
||||
relay_parent,
|
||||
PerRelayParentData {
|
||||
signing_context,
|
||||
validator_set,
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for relay_parent in deactivated {
|
||||
@@ -562,12 +568,12 @@ where
|
||||
async fn query_basics<Context>(
|
||||
ctx: &mut Context,
|
||||
relay_parent: Hash,
|
||||
) -> SubsystemResult<(Vec<ValidatorId>, SigningContext)>
|
||||
) -> SubsystemResult<Option<(Vec<ValidatorId>, SigningContext)>>
|
||||
where
|
||||
Context: SubsystemContext<Message = BitfieldDistributionMessage>,
|
||||
{
|
||||
let (validators_tx, validators_rx) = oneshot::channel();
|
||||
let (signing_tx, signing_rx) = oneshot::channel();
|
||||
let (session_tx, session_rx) = oneshot::channel();
|
||||
|
||||
let query_validators = AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
relay_parent.clone(),
|
||||
@@ -576,13 +582,22 @@ where
|
||||
|
||||
let query_signing = AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
relay_parent.clone(),
|
||||
RuntimeApiRequest::SigningContext(signing_tx),
|
||||
RuntimeApiRequest::SessionIndexForChild(session_tx),
|
||||
));
|
||||
|
||||
ctx.send_messages(std::iter::once(query_validators).chain(std::iter::once(query_signing)))
|
||||
.await?;
|
||||
|
||||
Ok((validators_rx.await?, signing_rx.await?))
|
||||
match (validators_rx.await?, session_rx.await?) {
|
||||
(Ok(v), Ok(s)) => Ok(Some((
|
||||
v,
|
||||
SigningContext { parent_hash: relay_parent, session_index: s },
|
||||
))),
|
||||
(Err(e), _) | (_, Err(e)) => {
|
||||
warn!(target: "bitd", "Failed to fetch basics from runtime API: {:?}", e);
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user