-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add Subscription RPC for Grandpa Finality #5732
Changes from 8 commits
2f5367f
9d369ac
0095b78
7719292
8c35b1e
07ef5fa
c9aa9e2
78250b7
fe31500
ba13ee6
fe360b9
254bebe
9c996ea
8090161
1150e5d
130a871
f42b6c3
d61d7ec
56e716b
c0c6508
1bc9103
30e3831
8b0850a
cf07f2f
ab64ecb
b1c04ba
ebad4d7
caaaa61
f3cc272
3c4505a
9a225ac
a85dd53
1b0344f
12dd5df
bca6a13
efaa0d1
9632988
964f1e3
82004cb
e526f95
6c71b8f
8bfb560
be7cb78
ac81cdf
3f8630d
3b387e6
bf4b19a
4c96b73
12158a2
e2584e5
dc3c888
410af1f
fb3ad63
5d80399
3f33fd2
57f1963
90ae56e
be1df4f
d4cddf3
8bd9e5c
127c19e
f43ee9b
39640c1
f3c6c54
44ba73e
01f7d73
3f3b136
908cf15
bb9ad4b
410ddea
ca126fd
452024f
8b0cf76
7ddffef
817b425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ | |
|
|
||
| use std::sync::Arc; | ||
| use log::{trace, warn}; | ||
| use parking_lot::RwLock; | ||
|
|
||
| use sp_blockchain::{Backend as BlockchainBackend, Error as ClientError, Result as ClientResult}; | ||
| use sc_client_api::{ | ||
|
|
@@ -52,6 +53,7 @@ use sp_runtime::{ | |
| use sp_core::storage::StorageKey; | ||
| use sc_telemetry::{telemetry, CONSENSUS_INFO}; | ||
| use sp_finality_grandpa::{AuthorityId, AuthorityList, VersionedAuthorityList, GRANDPA_AUTHORITIES_KEY}; | ||
| use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedSender, TracingUnboundedReceiver}; | ||
|
|
||
| use crate::justification::GrandpaJustification; | ||
|
|
||
|
|
@@ -145,6 +147,55 @@ impl<Block: BlockT> AuthoritySetForFinalityChecker<Block> for Arc<dyn FetchCheck | |
| } | ||
| } | ||
|
|
||
|
|
||
| /// Justification for a finalized block. | ||
| #[derive(Clone)] | ||
| pub struct JustificationNotification<Block: BlockT> { | ||
|
||
| /// Highest finalized block header | ||
| pub header: Block::Header, | ||
| /// An encoded justification proving that the given header has been finalized | ||
| pub justification: Vec<u8>, | ||
|
||
| } | ||
|
|
||
| type JustificationStream<Block> = TracingUnboundedReceiver<JustificationNotification<Block>>; | ||
|
||
| pub type SharedFinalitySubscribers<T> = Arc<RwLock<Vec<JustificationStream<T>>>>; | ||
HCastano marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| type FinalityNotifier<T> = TracingUnboundedSender<JustificationNotification<T>>; | ||
| pub type SharedFinalityNotifiers<T> = Arc<RwLock<Vec<FinalityNotifier<T>>>>; | ||
HCastano marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| pub struct FinalityProofSubscription<Block: BlockT> { | ||
| notifiers: SharedFinalityNotifiers<Block>, | ||
| } | ||
|
|
||
| impl<Block: BlockT> FinalityProofSubscription<Block> { | ||
| pub fn new() -> Self { | ||
| Self { | ||
| notifiers: Arc::new(RwLock::new(vec![])), | ||
| } | ||
| } | ||
|
|
||
| pub fn notifiers(&self) -> SharedFinalityNotifiers<Block> { | ||
| self.notifiers.clone() | ||
| } | ||
|
|
||
| // 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!() | ||
| } | ||
|
|
||
| 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 | ||
| } | ||
| } | ||
|
|
||
| /// Finality proof provider for serving network requests. | ||
| pub struct FinalityProofProvider<B, Block: BlockT> { | ||
| backend: Arc<B>, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.