This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Collator protocol followup #1741
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,25 @@ 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; | ||
| type Metrics = (); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand why we expose the If on the other hand there's a reason to publish this type, then we really should be distributing it via an enum. |
||
|
|
||
| fn start(self, ctx: Context) -> SpawnedSubsystem { | ||
| SpawnedSubsystem { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.