mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
Collator protocol followup (#1741)
* Metrics * Dont punish late collations * Fix metrics * Update node/network/collator-protocol/src/lib.rs Co-authored-by: Andronik Ordian <write@reusable.software> * Change on_request arg to Result Co-authored-by: Andronik Ordian <write@reusable.software>
This commit is contained in:
@@ -53,13 +53,15 @@ enum Error {
|
||||
RuntimeApi(RuntimeApiError),
|
||||
#[from]
|
||||
UtilError(util::Error),
|
||||
#[from]
|
||||
Prometheus(prometheus::PrometheusError),
|
||||
}
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
enum ProtocolSide {
|
||||
Validator,
|
||||
Collator(CollatorId),
|
||||
Validator(validator_side::Metrics),
|
||||
Collator(CollatorId, collator_side::Metrics),
|
||||
}
|
||||
|
||||
/// The collator protocol subsystem.
|
||||
@@ -71,10 +73,12 @@ impl CollatorProtocolSubsystem {
|
||||
/// Start the collator protocol.
|
||||
/// If `id` is `Some` this is a collator side of the protocol.
|
||||
/// If `id` is `None` this is a validator side of the protocol.
|
||||
pub fn new(id: Option<CollatorId>) -> Self {
|
||||
/// Caller must provide a registry for prometheus metrics.
|
||||
pub fn new(id: Option<CollatorId>, registry: Option<&prometheus::Registry>) -> Self {
|
||||
use metrics::Metrics;
|
||||
let protocol_side = match id {
|
||||
Some(id) => ProtocolSide::Collator(id),
|
||||
None => ProtocolSide::Validator,
|
||||
Some(id) => ProtocolSide::Collator(id, collator_side::Metrics::register(registry)),
|
||||
None => ProtocolSide::Validator(validator_side::Metrics::register(registry)),
|
||||
};
|
||||
|
||||
Self {
|
||||
@@ -87,28 +91,26 @@ impl CollatorProtocolSubsystem {
|
||||
Context: SubsystemContext<Message = CollatorProtocolMessage>,
|
||||
{
|
||||
match self.protocol_side {
|
||||
ProtocolSide::Validator => validator_side::run(ctx, REQUEST_TIMEOUT).await,
|
||||
ProtocolSide::Collator(id) => collator_side::run(ctx, id).await,
|
||||
ProtocolSide::Validator(metrics) => validator_side::run(
|
||||
ctx,
|
||||
REQUEST_TIMEOUT,
|
||||
metrics,
|
||||
).await,
|
||||
ProtocolSide::Collator(id, metrics) => collator_side::run(
|
||||
ctx,
|
||||
id,
|
||||
metrics,
|
||||
).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Collator protocol metrics.
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Metrics;
|
||||
|
||||
impl metrics::Metrics for Metrics {
|
||||
fn try_register(_registry: &prometheus::Registry)
|
||||
-> std::result::Result<Self, prometheus::PrometheusError> {
|
||||
Ok(Metrics)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Context> Subsystem<Context> for CollatorProtocolSubsystem
|
||||
where
|
||||
Context: SubsystemContext<Message = CollatorProtocolMessage> + Sync + Send,
|
||||
{
|
||||
type Metrics = Metrics;
|
||||
// The actual `Metrics` type depends on whether we're on the collator or validator side.
|
||||
type Metrics = ();
|
||||
|
||||
fn start(self, ctx: Context) -> SpawnedSubsystem {
|
||||
SpawnedSubsystem {
|
||||
|
||||
Reference in New Issue
Block a user