mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 23:21:06 +00:00
Notify collators about seconded collation (#2430)
* Notify collators about seconded collation This pr adds functionality to inform a collator that its collation was seconded by a parachain validator. Before this signed statement was only gossiped over the validation substream. Now, we explicitly send the seconded statement to the collator after it was validated successfully. Besides that it changes the `CollatorFn` to return an optional result sender that is informed when the build collation was seconded by a parachain validator. * Add test * Make sure we only send `Seconded` statements * Make sure we only receive valid statements * Review feedback
This commit is contained in:
@@ -39,6 +39,7 @@ use polkadot_node_subsystem_util::{
|
||||
use polkadot_primitives::v1::{
|
||||
CandidateReceipt, CollatorId, CoreState, CoreIndex, Hash, Id as ParaId, PoV,
|
||||
};
|
||||
use polkadot_node_primitives::SignedFullStatement;
|
||||
use std::{pin::Pin, sync::Arc};
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -190,6 +191,10 @@ impl CandidateSelectionJob {
|
||||
let _span = span.child("handle-invalid");
|
||||
self.handle_invalid(candidate_receipt).await;
|
||||
}
|
||||
Some(CandidateSelectionMessage::Seconded(_, statement)) => {
|
||||
let _span = span.child("handle-seconded");
|
||||
self.handle_seconded(statement).await;
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
@@ -251,9 +256,7 @@ impl CandidateSelectionJob {
|
||||
pov,
|
||||
&mut self.sender,
|
||||
&self.metrics,
|
||||
)
|
||||
.await
|
||||
{
|
||||
).await {
|
||||
Err(err) => tracing::warn!(target: LOG_TARGET, err = ?err, "failed to second a candidate"),
|
||||
Ok(()) => self.seconded_candidate = Some(collator_id),
|
||||
}
|
||||
@@ -293,6 +296,46 @@ impl CandidateSelectionJob {
|
||||
};
|
||||
self.metrics.on_invalid_selection(result);
|
||||
}
|
||||
|
||||
async fn handle_seconded(&mut self, statement: SignedFullStatement) {
|
||||
let received_from = match &self.seconded_candidate {
|
||||
Some(peer) => peer,
|
||||
None => {
|
||||
tracing::warn!(
|
||||
target: LOG_TARGET,
|
||||
"received seconded notice for a candidate we don't remember seconding"
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
statement = ?statement,
|
||||
"received seconded note for candidate",
|
||||
);
|
||||
|
||||
if let Err(e) = self.sender
|
||||
.send(AllMessages::from(CollatorProtocolMessage::NoteGoodCollation(received_from.clone())).into()).await
|
||||
{
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
error = ?e,
|
||||
"failed to note good collator"
|
||||
);
|
||||
}
|
||||
|
||||
if let Err(e) = self.sender
|
||||
.send(AllMessages::from(
|
||||
CollatorProtocolMessage::NotifyCollationSeconded(received_from.clone(), statement)
|
||||
).into()).await
|
||||
{
|
||||
tracing::debug!(
|
||||
target: LOG_TARGET,
|
||||
error = ?e,
|
||||
"failed to notify collator about seconded collation"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get a collation from the Collator Protocol subsystem
|
||||
|
||||
Reference in New Issue
Block a user