Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
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 Apr 8, 2020
9d369ac
Create channel for sending justifications
HCastano Apr 10, 2020
0095b78
WIP: Add subscribers for justifications to Grandpa
HCastano Apr 18, 2020
7719292
WIP: Add a struct for managing subscriptions
HCastano Apr 21, 2020
8c35b1e
Make naming more clear and lock data in Arc
HCastano Apr 21, 2020
07ef5fa
Rough idea of what RPC would look like
HCastano Apr 21, 2020
c9aa9e2
Remove code from previous approach
HCastano Apr 22, 2020
78250b7
Missed some things
HCastano Apr 22, 2020
fe31500
Update client/rpc-api/src/chain/mod.rs
HCastano Apr 22, 2020
ba13ee6
Update client/rpc-api/src/chain/mod.rs
HCastano Apr 22, 2020
fe360b9
Split justification subscription into sender and receiver halves
HCastano Apr 26, 2020
254bebe
Replace RwLock with a Mutex
HCastano Apr 26, 2020
9c996ea
Add sample usage from the Service's point of view
HCastano Apr 26, 2020
8090161
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano Apr 29, 2020
1150e5d
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano May 7, 2020
130a871
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano May 15, 2020
f42b6c3
Remove code that referred to "chain_" RPC
HCastano May 15, 2020
d61d7ec
Use the Justification sender/receivers from Grandpa LinkHalf
HCastano May 17, 2020
56e716b
Add some PubSub boilerplate
HCastano May 18, 2020
c0c6508
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano May 18, 2020
1bc9103
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano Jun 1, 2020
30e3831
Merge branch 'master' into hc-add-subscription-rpc-for-finality
HCastano Jun 3, 2020
8b0850a
Add guiding comments
HCastano Jun 3, 2020
cf07f2f
TMP: comment out to fix compilation
octol Jun 8, 2020
ab64ecb
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Jun 9, 2020
b1c04ba
Return MetaIoHandler from PubSubHandler in create_full
octol Jun 10, 2020
ebad4d7
Uncomment pubsub methods in rpc handler (fails to build)
octol Jun 10, 2020
caaaa61
node/rpc: make Metadata concrete in create_full to fix compilation
octol Jun 11, 2020
f3cc272
node: pass in SubscriptionManger to grandpa rpc handler
octol Jun 11, 2020
3c4505a
grandpa-rpc: use SubscriptionManger to add subscriber
octol Jun 12, 2020
9a225ac
grandpa-rpc: attempt at setting up the justification stream (fails to…
octol Jun 16, 2020
a85dd53
grandpa-rpc: fix compilation of connecting stream to sink
octol Jun 16, 2020
1b0344f
grandpa-rpc: implement unsubscribe
octol Jun 16, 2020
12dd5df
grandpa-rpc: update older tests
octol Jun 18, 2020
bca6a13
grandpa-rpc: add full prefix to avoid confusing rust-analyzer
octol Jun 22, 2020
efaa0d1
grandpa-rpc: add test for pubsub not available
octol Jun 22, 2020
9632988
grandpa-rpc: tidy up leftover code
octol Jun 22, 2020
964f1e3
grandpa-rpc: add test for sub and unsub of justifications
octol Jun 22, 2020
82004cb
grandpa-rpc: minor stylistic changes
octol Jun 23, 2020
e526f95
grandpa-rpc: split unit test
octol Jun 23, 2020
6c71b8f
grandpa-rpc: minor stylistic changes in test
octol Jun 23, 2020
8bfb560
grandpa-rpc: skip returning future when cancelling
octol Jun 25, 2020
be7cb78
grandpa-rpc: reuse testing executor from sc-rpc
octol Jun 25, 2020
ac81cdf
grandpa-rpc: don't need to use PubSubHandler in tests
octol Jun 25, 2020
3f8630d
node-rpc: use MetaIoHandler rather than PubSubHandler
octol Jun 26, 2020
3b387e6
grandpa: log if getting header failed
octol Jun 26, 2020
bf4b19a
grandpa: move justification channel creation into factory function
octol Jun 26, 2020
4c96b73
grandpa: make the justification sender optional
octol Jun 26, 2020
12158a2
grandpa: fix compilation warnings
octol Jun 27, 2020
e2584e5
grandpa: move justification notification types to new file
octol Jun 27, 2020
dc3c888
grandpa-rpc: move JustificationNotification to grandpa-rpc
octol Jun 27, 2020
410af1f
grandpa-rpc: move JustificationNotification to its own file
octol Jun 27, 2020
fb3ad63
grandpa: rename justification channel pairs
octol Jun 27, 2020
5d80399
grandpa: rename notifier types
octol Jun 27, 2020
3f33fd2
grandpa: pass justification as GrandpaJustification to the rpc module
octol Jun 29, 2020
57f1963
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Jun 29, 2020
90ae56e
Move Metadata to sc-rpc-api
tomusdrw Jun 30, 2020
be1df4f
grandpa-rpc: remove unsed error code
octol Jun 29, 2020
d4cddf3
grandpa: fix bug for checking if channel is closed before sendind
octol Jul 1, 2020
8bd9e5c
grandpa-rpc: unit test for sending justifications
octol Jun 30, 2020
127c19e
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Jul 2, 2020
f43ee9b
grandpa-rpc: update comments for the pubsub test
octol Jul 2, 2020
39640c1
grandpa-rpc: update pubsub tests with more steps
octol Jul 2, 2020
f3c6c54
grandpa-rpc: fix pubsub test
octol Jul 2, 2020
44ba73e
grandpa-rpc: minor indendation
octol Jul 3, 2020
01f7d73
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Jul 22, 2020
3f3b136
grandpa-rpc: decode instead of encode in test
octol Jul 23, 2020
908cf15
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Jul 27, 2020
bb9ad4b
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Jul 27, 2020
410ddea
grandpa: fix review comments
octol Jul 31, 2020
ca126fd
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Aug 4, 2020
452024f
grandpa: remove unused serde dependency
octol Aug 4, 2020
8b0cf76
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Aug 5, 2020
7ddffef
Merge branch 'master' into hc-add-subscription-rpc-for-finality
octol Aug 6, 2020
817b425
Merge remote-tracking branch 'upstream/master' into hc-add-subscripti…
octol Aug 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove code from previous approach
  • Loading branch information
HCastano committed Apr 22, 2020
commit c9aa9e242d0ca36b846338266e47023e011ba89e
13 changes: 0 additions & 13 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@ pub struct ImportSummary<Block: BlockT> {
pub retracted: Vec<Block::Hash>,
}

/// Summary of a Justification event.
///
/// Contains the most recently finalized block as well
/// as a justification for its finalization.
pub struct JustificationSummary<Block: BlockT> {
/// Most recently finalized header.
pub header: Block::Header,
/// A justification proving that the given block was finalized.
pub justification: Justification,
}

/// Import operation wrapper
pub struct ClientImportOperation<Block: BlockT, B: Backend<Block>> {
/// DB Operation.
Expand All @@ -88,8 +77,6 @@ pub struct ClientImportOperation<Block: BlockT, B: Backend<Block>> {
pub notify_imported: Option<ImportSummary<Block>>,
/// A list of hashes of blocks that got finalized.
pub notify_finalized: Vec<Block::Hash>,
/// Best finalized block and accompanying justification.
pub notify_justified: Option<JustificationSummary<Block>>,
}

/// State of a new block.
Expand Down
18 changes: 0 additions & 18 deletions client/api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ pub type ImportNotifications<Block> = TracingUnboundedReceiver<BlockImportNotifi
/// A stream of block finality notifications.
pub type FinalityNotifications<Block> = TracingUnboundedReceiver<FinalityNotification<Block>>;

/// A stream of Grandpa Justification notifications.
pub type JustificationNotifications<Block> = TracingUnboundedReceiver<JustificationNotification<Block>>;

/// Expected hashes of blocks at given heights.
///
/// This may be used as chain spec extension to set trusted checkpoints, i.e.
Expand Down Expand Up @@ -67,12 +64,6 @@ pub trait BlockchainEvents<Block: BlockT> {
/// finalized block.
fn finality_notification_stream(&self) -> FinalityNotifications<Block>;

/// Get a stream of Grandpa justifications alongside the best block that's
/// been finalized with that justification.
///
/// Idk about the guarantees around the frequency of this yet
fn justification_notification_stream(&self) -> JustificationNotifications<Block>;

/// Get storage changes event stream.
///
/// Passing `None` as `filter_keys` subscribes to all storage changes.
Expand Down Expand Up @@ -255,12 +246,3 @@ pub struct FinalityNotification<Block: BlockT> {
/// Imported block header.
pub header: Block::Header,
}

/// Justification for a finalized block.
#[derive(Clone, Debug)]
pub struct JustificationNotification<Block: BlockT> {
/// Highest finalized block header
pub header: Block::Header,
/// A justification that the given header has been finalized
pub justification: Justification,
}
58 changes: 2 additions & 56 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
pub use sc_client_api::{
backend::{
self, BlockImportOperation, PrunableStateChangesTrieStorage,
ClientImportOperation, Finalizer, ImportSummary, JustificationSummary, NewBlockState,
ClientImportOperation, Finalizer, ImportSummary, NewBlockState,
changes_tries_state_at_block, StorageProvider,
LockImportRun,
},
client::{
ImportNotifications, FinalityNotification, FinalityNotifications, BlockImportNotification,
JustificationNotification, JustificationNotifications,
ClientInfo, BlockchainEvents, BlockBackend, ProvideUncles, BadBlocks, ForkBlocks,
BlockOf,
},
Expand All @@ -96,7 +95,6 @@ pub struct Client<B, E, Block, RA> where Block: BlockT {
storage_notifications: Mutex<StorageNotifications<Block>>,
import_notification_sinks: Mutex<Vec<TracingUnboundedSender<BlockImportNotification<Block>>>>,
finality_notification_sinks: Mutex<Vec<TracingUnboundedSender<FinalityNotification<Block>>>>,
justification_notification_sinks: Mutex<Vec<TracingUnboundedSender<JustificationNotification<Block>>>>,
// holds the block hash currently being imported. TODO: replace this with block queue
importing_block: RwLock<Option<Block::Hash>>,
block_rules: BlockRules<Block>,
Expand Down Expand Up @@ -206,7 +204,6 @@ impl<B, E, Block, RA> LockImportRun<Block, B> for Client<B, E, Block, RA>
op: self.backend.begin_operation()?,
notify_imported: None,
notify_finalized: Vec::new(),
notify_justified: None,
};

let r = f(&mut op)?;
Expand All @@ -215,14 +212,11 @@ impl<B, E, Block, RA> LockImportRun<Block, B> for Client<B, E, Block, RA>
op,
notify_imported,
notify_finalized,
notify_justified,
} = op;
self.backend.commit_operation(op)?;

// Q: Does the order of these matter?
self.notify_finalized(notify_finalized)?;
self.notify_imported(notify_imported)?;
self.notify_justified(notify_justified)?;

Ok(r)
};
Expand Down Expand Up @@ -289,7 +283,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
storage_notifications: Default::default(),
import_notification_sinks: Default::default(),
finality_notification_sinks: Default::default(),
justification_notification_sinks: Default::default(),
importing_block: Default::default(),
block_rules: BlockRules::new(fork_blocks, bad_blocks),
execution_extensions,
Expand Down Expand Up @@ -625,7 +618,7 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
if let Ok(ImportResult::Imported(ref aux)) = result {
if aux.is_new_best {
use rand::Rng;

// don't send telemetry block import events during initial sync for every
// block to avoid spamming the telemetry server, these events will be randomly
// sent at a rate of 1/10.
Expand Down Expand Up @@ -906,19 +899,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
for finalized in &enacted[start..] {
operation.notify_finalized.push(finalized.hash);
}

// Only want to notify if a block was "explicitly" finalized
// instead of one that was implicitly finlized
if let Some(justification) = justification {
// TODO: Check that this expect() holds true
let header = self.header(&BlockId::Hash(block))?
.expect("header already known to exist in DB because it is indicated in the tree route; qed");
operation.notify_justified = Some(JustificationSummary {
header,
justification,
});
}

}

Ok(())
Expand Down Expand Up @@ -1004,34 +984,6 @@ impl<B, E, Block, RA> Client<B, E, Block, RA> where
Ok(())
}

fn notify_justified(
&self,
notify_justified: Option<JustificationSummary<Block>>,
) -> sp_blockchain::Result<()> {
let notify_justified = match notify_justified {
Some(notify_justified) => notify_justified,
None => {
// Clean up unused justification notification
// Is this neccesary though?
self.justification_notification_sinks
.lock()
.retain(|sink| !sink.is_closed());

return Ok(());
}
};

let notification = JustificationNotification::<Block> {
header: notify_justified.header,
justification: notify_justified.justification,
};

self.justification_notification_sinks.lock()
.retain(|sink| sink.unbounded_send(notification.clone()).is_ok());

Ok(())
}

/// Attempts to revert the chain by `n` blocks guaranteeing that no block is
/// reverted past the last finalized block. Returns the number of blocks
/// that were successfully reverted.
Expand Down Expand Up @@ -1829,12 +1781,6 @@ where
stream
}

fn justification_notification_stream(&self) -> JustificationNotifications<Block> {
let (sink, stream) = tracing_unbounded("mpsc_justification_notification_stream");
self.justification_notification_sinks.lock().push(sink);
stream
}

/// Get storage changes event stream.
fn storage_changes_notification_stream(
&self,
Expand Down