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 2.7k
Add Subscription RPC for Grandpa Finality #5732
Merged
75 commits merged into
paritytech:master
from
HCastano:hc-add-subscription-rpc-for-finality
Aug 10, 2020
Merged
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
2f5367f
Rough skeleton for what I think the RPC should look like
HCastano 9d369ac
Create channel for sending justifications
HCastano 0095b78
WIP: Add subscribers for justifications to Grandpa
HCastano 7719292
WIP: Add a struct for managing subscriptions
HCastano 8c35b1e
Make naming more clear and lock data in Arc
HCastano 07ef5fa
Rough idea of what RPC would look like
HCastano c9aa9e2
Remove code from previous approach
HCastano 78250b7
Missed some things
HCastano fe31500
Update client/rpc-api/src/chain/mod.rs
HCastano ba13ee6
Update client/rpc-api/src/chain/mod.rs
HCastano fe360b9
Split justification subscription into sender and receiver halves
HCastano 254bebe
Replace RwLock with a Mutex
HCastano 9c996ea
Add sample usage from the Service's point of view
HCastano 8090161
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano 1150e5d
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano 130a871
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano f42b6c3
Remove code that referred to "chain_" RPC
HCastano d61d7ec
Use the Justification sender/receivers from Grandpa LinkHalf
HCastano 56e716b
Add some PubSub boilerplate
HCastano c0c6508
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano 1bc9103
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano 30e3831
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano 8b0850a
Add guiding comments
HCastano cf07f2f
TMP: comment out to fix compilation
octol ab64ecb
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol b1c04ba
Return MetaIoHandler from PubSubHandler in create_full
octol ebad4d7
Uncomment pubsub methods in rpc handler (fails to build)
octol caaaa61
node/rpc: make Metadata concrete in create_full to fix compilation
octol f3cc272
node: pass in SubscriptionManger to grandpa rpc handler
octol 3c4505a
grandpa-rpc: use SubscriptionManger to add subscriber
octol 9a225ac
grandpa-rpc: attempt at setting up the justification stream (fails to…
octol a85dd53
grandpa-rpc: fix compilation of connecting stream to sink
octol 1b0344f
grandpa-rpc: implement unsubscribe
octol 12dd5df
grandpa-rpc: update older tests
octol bca6a13
grandpa-rpc: add full prefix to avoid confusing rust-analyzer
octol efaa0d1
grandpa-rpc: add test for pubsub not available
octol 9632988
grandpa-rpc: tidy up leftover code
octol 964f1e3
grandpa-rpc: add test for sub and unsub of justifications
octol 82004cb
grandpa-rpc: minor stylistic changes
octol e526f95
grandpa-rpc: split unit test
octol 6c71b8f
grandpa-rpc: minor stylistic changes in test
octol 8bfb560
grandpa-rpc: skip returning future when cancelling
octol be7cb78
grandpa-rpc: reuse testing executor from sc-rpc
octol ac81cdf
grandpa-rpc: don't need to use PubSubHandler in tests
octol 3f8630d
node-rpc: use MetaIoHandler rather than PubSubHandler
octol 3b387e6
grandpa: log if getting header failed
octol bf4b19a
grandpa: move justification channel creation into factory function
octol 4c96b73
grandpa: make the justification sender optional
octol 12158a2
grandpa: fix compilation warnings
octol e2584e5
grandpa: move justification notification types to new file
octol dc3c888
grandpa-rpc: move JustificationNotification to grandpa-rpc
octol 410af1f
grandpa-rpc: move JustificationNotification to its own file
octol fb3ad63
grandpa: rename justification channel pairs
octol 5d80399
grandpa: rename notifier types
octol 3f33fd2
grandpa: pass justification as GrandpaJustification to the rpc module
octol 57f1963
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol 90ae56e
Move Metadata to sc-rpc-api
tomusdrw be1df4f
grandpa-rpc: remove unsed error code
octol d4cddf3
grandpa: fix bug for checking if channel is closed before sendind
octol 8bd9e5c
grandpa-rpc: unit test for sending justifications
octol 127c19e
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol f43ee9b
grandpa-rpc: update comments for the pubsub test
octol 39640c1
grandpa-rpc: update pubsub tests with more steps
octol f3c6c54
grandpa-rpc: fix pubsub test
octol 44ba73e
grandpa-rpc: minor indendation
octol 01f7d73
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol 3f3b136
grandpa-rpc: decode instead of encode in test
octol 908cf15
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol bb9ad4b
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol 410ddea
grandpa: fix review comments
octol ca126fd
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol 452024f
grandpa: remove unused serde dependency
octol 8b0cf76
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol 7ddffef
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol 817b425
Merge remote-tracking branch 'upstream/master' into hc-add-subscripti…
octol 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
Split justification subscription into sender and receiver halves
- Loading branch information
commit fe360b9ac0f0fb428dba1bf8dbd23215365c4e5e
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 |
|---|---|---|
|
|
@@ -147,7 +147,6 @@ impl<Block: BlockT> AuthoritySetForFinalityChecker<Block> for Arc<dyn FetchCheck | |
| } | ||
| } | ||
|
|
||
|
|
||
| /// Justification for a finalized block. | ||
| #[derive(Clone)] | ||
| pub struct JustificationNotification<Block: BlockT> { | ||
|
|
@@ -158,46 +157,76 @@ pub struct JustificationNotification<Block: BlockT> { | |
| } | ||
|
|
||
| type JustificationStream<Block> = TracingUnboundedReceiver<JustificationNotification<Block>>; | ||
|
||
| pub type SharedFinalitySubscribers<T> = Arc<RwLock<Vec<JustificationStream<T>>>>; | ||
|
|
||
| type FinalityNotifier<T> = TracingUnboundedSender<JustificationNotification<T>>; | ||
| pub type SharedFinalityNotifiers<T> = Arc<RwLock<Vec<FinalityNotifier<T>>>>; | ||
| type SharedFinalityNotifiers<T> = Arc<RwLock<Vec<FinalityNotifier<T>>>>; | ||
|
|
||
| pub struct FinalityProofSubscription<Block: BlockT> { | ||
| notifiers: SharedFinalityNotifiers<Block>, | ||
| /// The sending half of the Grandpa justification channel. | ||
| /// | ||
| /// Used to send notifictions about justifications generated | ||
| /// at the end of a Grandpa round. | ||
| #[derive(Clone)] | ||
| pub struct GrandpaJustificationSender<Block: BlockT> { | ||
| notifiers: SharedFinalityNotifiers<Block> | ||
| } | ||
|
|
||
| impl<Block: BlockT> FinalityProofSubscription<Block> { | ||
| pub fn new() -> Self { | ||
| impl<Block: BlockT> GrandpaJustificationSender<Block> { | ||
| /// The `notifiers` should be shared with a corresponding | ||
| /// `GrandpaJustificationReceiver`. | ||
| pub fn new(notifiers: SharedFinalityNotifiers<Block>) -> Self { | ||
| Self { | ||
| notifiers: Arc::new(RwLock::new(vec![])), | ||
| notifiers, | ||
| } | ||
| } | ||
|
|
||
| pub fn notifiers(&self) -> SharedFinalityNotifiers<Block> { | ||
| self.notifiers.clone() | ||
| } | ||
| /// Send out a notification to all subscribers that a new justification | ||
| /// is available for a block. | ||
| pub fn notify(&self, notification: JustificationNotification<Block>) -> Result<(), ()> { | ||
| { | ||
| // Clean up any closed sinks | ||
| self.notifiers.write().retain(|n| !n.is_closed()); | ||
| } | ||
|
|
||
| // Will notify subsribers (receivers) | ||
| pub fn notify(&self, notification: JustificationNotification<Block>) { | ||
| // TODO: Look at `notify_justified()` in `client` | ||
| for s in self.notifiers.read().iter() { | ||
| s.unbounded_send(notification.clone()); | ||
| } | ||
|
|
||
| todo!() | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// The receiving half of the Grandpa justification channel. | ||
| /// | ||
| /// Used to recieve notifictions about justifications generated | ||
| /// at the end of a Grandpa round. | ||
| #[derive(Clone)] | ||
| pub struct GrandpaJustificationReceiver<Block: BlockT> { | ||
| notifiers: SharedFinalityNotifiers<Block> | ||
| } | ||
|
|
||
| impl<Block: BlockT> GrandpaJustificationReceiver<Block> { | ||
| /// Crate a new receiver of justification notifications. | ||
| /// | ||
| /// The `notifiers` should be shared with a corresponding | ||
| /// `GrandpaJustificationSender`. | ||
| pub fn new(notifiers: SharedFinalityNotifiers<Block>) -> Self { | ||
| Self { | ||
| notifiers, | ||
| } | ||
| } | ||
|
|
||
| pub fn stream(&self) -> JustificationStream<Block> { | ||
| // TODO: I only want one channel to be created per instance | ||
| let (sink, stream) = tracing_unbounded("mpsc_justification_notification_stream"); | ||
| self.notifiers.write().push(sink); | ||
| stream | ||
| /// Subscribe to a channel through which justifications are sent | ||
| /// at the end of each Grandpa voting round. | ||
| pub fn subscribe(&self) -> JustificationStream<Block> { | ||
| let (sender, receiver) = tracing_unbounded("mpsc_justification_notification_stream"); | ||
| self.notifiers.write().push(sender); | ||
| receiver | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /// Finality proof provider for serving network requests. | ||
| pub struct FinalityProofProvider<B, Block: BlockT> { | ||
| pub struct FinalityProofProvider<B, Block: BlockT> { | ||
| backend: Arc<B>, | ||
| authority_provider: Arc<dyn AuthoritySetForFinalityProver<Block>>, | ||
| } | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this type should be defined in the rpc module. We can just use
(Block::Header, Justification)in this crate. Also not sure if we need the header here or if just the block hash is enough. The fianlized block number and block hash is already defined in the justification (although for convenience I guess it might be useful to have it on a top-level like this).