-
Notifications
You must be signed in to change notification settings - Fork 1.7k
RPC: Implements eth_subscribe("syncing") #10311
Conversation
It looks like @seunlanlege signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
1 similar comment
It looks like @seunlanlege signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
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.
Initial version looks good, a bunch of style grumbles though, but I think this is on a good track.
Would be good to have an RPC test for this as well.
fc2e948
to
4868692
Compare
@tomusdrw please could you take a look at this again? |
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.
Can we remove the is_major_importing
function from block_import
helpers?
Also what's the status of #10312 Can you coordinate with Axel about it? I like the fact that this PR uses subscription to actual syncing state instead of blocks, I guess if we want to provide sync details in the subscription events then combining the two approaches would be required.
@@ -699,6 +725,10 @@ pub trait SyncInfo { | |||
|
|||
/// Whether major sync is underway. | |||
fn is_major_importing(&self) -> bool; |
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.
IS this still used?
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.
yes for light clients
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.
Can't light clients use the same mechanism instead? it seems that it triggers notifications as well, no?
The eth_subscribe(syncing) pubsub isn't really "required" for Fether; currently we're polling the RPC eth_syncing and it does the job. We use the I imagine if we want to switch to using the pubsub eth_subscribe(syncing) in Fether, then the pubsub should also return those values (also for the sake of consistency with the RPC eth_syncing). However I'm not sure if we can switch to the eth_subscribe(syncing) in Fether because (at least on my PR, haven't tested on this one) the pubsub can emit values very many times / very fast; the granularity is a bit too small and I think this could bottleneck the receiving end |
@axelchalon indeed |
Having eth_subscribe("syncing") return true/false depending on is_major_importing sounds OK to me! |
actually in this PR, events are emitted only when |
5fecdc9
to
41cf48b
Compare
@tomusdrw could you look at this again? |
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.
Few more grumbles regarding the sync subscription. We should really think how to make it lightweight. The whole point of:
- Having notifications
- Storing an AtomicBool for sync status for easy access
was to prevent the need from calling into sync/client
status - cause that heavy and requires locks. If we still do that, then it's pretty wasteful. All the info that is required for the subscription should go with the event or should be accessed from lock-free structures.
Also if there is any additional data that we pass with the notification we need to be subscribed to as well. I.e. If we pass starting/current/highest block then people will expect that they are going to be notified about changes of those. This PR doesn't achieve that so it's a bit buggy behaviour. I'd be in favor of providing less data, but in a very reliable way.
ethcore/sync/src/api.rs
Outdated
/// Returns propagation count for pending transactions. | ||
fn transactions_stats(&self) -> BTreeMap<H256, TransactionStats>; | ||
|
||
/// gets |
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.
missing docs
@@ -699,6 +725,10 @@ pub trait SyncInfo { | |||
|
|||
/// Whether major sync is underway. | |||
fn is_major_importing(&self) -> bool; |
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.
Can't light clients use the same mechanism instead? it seems that it triggers notifications as well, no?
rpc/src/v1/types/pubsub.rs
Outdated
@@ -40,6 +55,7 @@ impl Serialize for Result { | |||
Result::Header(ref header) => header.serialize(serializer), | |||
Result::Log(ref log) => log.serialize(serializer), | |||
Result::TransactionHash(ref hash) => hash.serialize(serializer), | |||
Result::SyncState(ref sync) => sync.serialize(serializer) |
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.
missing comma
rpc/src/v1/types/pubsub.rs
Outdated
#[serde(rename_all="camelCase")] | ||
pub struct PubSubSyncStatus { | ||
/// starting block number | ||
pub starting_block: U64, |
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.
funky ident
rpc/src/v1/impls/eth_pubsub.rs
Outdated
C: 'static + LightSyncProvider + LightNetworkDispatcher + ManageNetwork | ||
{ | ||
/// adds a sync notification channel to the pubsub client | ||
pub fn add_light_sync_notifier(&mut self, receiver: Notification<SyncState>, sync: Arc<LightSyncInfo>) { |
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.
I thought that we extract QueueInfo
trait to unify the add_light_sync_notifier
and add_sync_notifier
, if we don't do that, then the other changes are just unnecessary.
Can we unify this completely the logic seems to be exactly the same?
If there is something that I'm missing we can also pass a closure that produces PubSubSyncStatus
and then the mode-specific logic can be there.
rpc/src/v1/impls/eth_pubsub.rs
Outdated
let sync_state = pubsub::PubSubSyncStatus { | ||
is_syncing: is_verifying || is_syncing_state, | ||
starting_block: status.start_block_number.into(), | ||
current_block: client.chain_info().best_block_number.into(), |
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.
So this is being triggered only when sync
changes status right? Then IMHO returning this additional data here doesn't make sense, cause it's just misleading for users - that stuff won't change at all, since we only notify about sync/notsync.
Either we need to trigger this notification more often (after every imported block for instance), but we discussed with @axelchalon that it might be overwhelming for subscribers.
I'd go for true/false
returned from subscription and then the clients can poll at their discretion for the proper sync status. Note that we also have subscription for newHeads
so the two subscriptions combined give you pretty good understanding what happens with the node.
Calling queue_info
an chain_info
from client seems pretty heavy, I'd prefer to not do it at all.
Regarding sync.status()
- why can't we just pass all the details in the state
already? It's just redundant call that requires some locks to be acquired while we can provide all necessary data with every event.
5eca317
to
53e0c4b
Compare
Please rebase |
53e0c4b
to
fb2a504
Compare
* master: fix(light cull): poll light cull instead of timer (#10559) Update Issue Template to direct security issue to email (#10562) RPC: Implements eth_subscribe("syncing") (#10311) Explicitly enable or disable Stratum in config file (Issue 9785) (#10521) version: bump master to 2.6 (#10560) tx-pool: check transaction readiness before replacing (#10526) fix(light account response): update `tx_queue` (#10545) Update light client harcoded headers (#10547) fix(light eth_gasPrice): ask network if not in cache (#10535) Implement caching for service transactions checker (#10088) build android with cache, win fixes (#10546) clique: make state backfill time measurement more accurate (#10551) updated lru-cache to 0.1.2 (#10542)
Hello! I'm using latest parity ethereum client 2.0.5-beta on ubuntu 18: Parity Ethereum Unfortunately, I still get the error "eth_subscribe(["syncing"]): -32000: This request is not implemented yet. Please create an issue on Github repo." My js code: provider.js:
index.js:
package.json:
Missing something? |
This PR was merged into master (currently 2.6) and wasn't backported to 2.5 (usually, we only backport bug fixes). |
closes #10080