Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

RPC: Implements eth_subscribe("syncing")#10311

Merged
soc1c merged 14 commits into
masterfrom
rpc-eth_subscribe-syncing
Apr 2, 2019
Merged

RPC: Implements eth_subscribe("syncing")#10311
soc1c merged 14 commits into
masterfrom
rpc-eth_subscribe-syncing

Conversation

@seunlanlege
Copy link
Copy Markdown
Member

@seunlanlege seunlanlege commented Feb 7, 2019

closes #10080

@parity-cla-bot
Copy link
Copy Markdown

It looks like @seunlanlege signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

1 similar comment
@parity-cla-bot
Copy link
Copy Markdown

It looks like @seunlanlege signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@seunlanlege seunlanlege added A0-pleasereview 🤓 Pull request needs code review. M6-rpcapi 📣 RPC API. labels Feb 7, 2019
@5chdn 5chdn added this to the 2.4 milestone Feb 7, 2019
@axelchalon
Copy link
Copy Markdown
Contributor

oops, looks like we've been working on the same thing #10312
thought I had communicated this with the assignment on the issue #10080 sorry

Copy link
Copy Markdown
Collaborator

@tomusdrw tomusdrw left a 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.

Comment thread ethcore/sync/src/api.rs
Comment thread ethcore/sync/src/chain/mod.rs
Comment thread ethcore/sync/src/chain/mod.rs Outdated
Comment thread ethcore/sync/src/chain/mod.rs Outdated
Comment thread parity/rpc_apis.rs Outdated
Comment thread rpc/src/v1/impls/eth_pubsub.rs Outdated
Comment thread ethcore/sync/Cargo.toml
Comment thread rpc/src/v1/impls/eth_pubsub.rs Outdated
Comment thread rpc/src/v1/types/pubsub.rs Outdated
Comment thread rpc/src/v1/impls/eth_pubsub.rs
Comment thread ethcore/sync/src/api.rs
Comment thread ethcore/sync/src/api.rs
@seunlanlege seunlanlege force-pushed the rpc-eth_subscribe-syncing branch 2 times, most recently from fc2e948 to 4868692 Compare February 12, 2019 11:27
@seunlanlege seunlanlege added the M4-core ⛓ Core client code / Rust. label Feb 14, 2019
@seunlanlege
Copy link
Copy Markdown
Member Author

@tomusdrw please could you take a look at this again?

Copy link
Copy Markdown
Collaborator

@tomusdrw tomusdrw left a 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.

Comment thread ethcore/sync/src/lib.rs Outdated
Comment thread ethcore/sync/src/light_sync/mod.rs
@@ -699,6 +725,10 @@ pub trait SyncInfo {

/// Whether major sync is underway.
fn is_major_importing(&self) -> bool;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IS this still used?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes for light clients

Copy link
Copy Markdown
Collaborator

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?

Comment thread rpc/src/v1/tests/helpers/sync_provider.rs Outdated
Comment thread rpc/src/v1/types/pubsub.rs Outdated
@tomusdrw tomusdrw added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Feb 18, 2019
@axelchalon
Copy link
Copy Markdown
Contributor

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 currentBlock, highestBlock, startingBlock returned by the RPC to display the syncing percentage to the user.

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

@tomusdrw
Copy link
Copy Markdown
Collaborator

@axelchalon indeed chain_new_blocks can be triggered quite often during initial sync, we should figure out how to throttle it.
Perhaps we could then have true/false flags in the pubsub subscriptions and let the client poll as often as need to update the status?

@axelchalon
Copy link
Copy Markdown
Contributor

Having eth_subscribe("syncing") return true/false depending on is_major_importing sounds OK to me!

@seunlanlege
Copy link
Copy Markdown
Member Author

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

actually in this PR, events are emitted only when SyncState changes, which doesn't occur very frequently during syncing, infact i think you'd still need to poll eth_syncing to consistently show sync progress.

@seunlanlege seunlanlege force-pushed the rpc-eth_subscribe-syncing branch 2 times, most recently from 5fecdc9 to 41cf48b Compare February 19, 2019 11:19
@seunlanlege
Copy link
Copy Markdown
Member Author

@tomusdrw could you look at this again?

Copy link
Copy Markdown
Collaborator

@tomusdrw tomusdrw left a 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:

  1. Having notifications
  2. 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.

Comment thread ethcore/sync/src/api.rs Outdated
/// Returns propagation count for pending transactions.
fn transactions_stats(&self) -> BTreeMap<H256, TransactionStats>;

/// gets
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing docs

Comment thread ethcore/sync/src/api.rs
Comment thread ethcore/sync/src/api.rs
@@ -699,6 +725,10 @@ pub trait SyncInfo {

/// Whether major sync is underway.
fn is_major_importing(&self) -> bool;
Copy link
Copy Markdown
Collaborator

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?

Comment thread rpc/src/v1/types/pubsub.rs Outdated
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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comma

Comment thread rpc/src/v1/types/pubsub.rs Outdated
#[serde(rename_all="camelCase")]
pub struct PubSubSyncStatus {
/// starting block number
pub starting_block: U64,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funky ident

Comment thread 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>) {
Copy link
Copy Markdown
Collaborator

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.

Comment thread 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(),
Copy link
Copy Markdown
Collaborator

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.

@5chdn 5chdn modified the milestones: 2.4, 2.5, 2.6 Feb 21, 2019
@niklasad1 niklasad1 added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts. and removed A0-pleasereview 🤓 Pull request needs code review. labels Mar 29, 2019
@soc1c soc1c added the B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. label Mar 29, 2019
@seunlanlege seunlanlege force-pushed the rpc-eth_subscribe-syncing branch from 5eca317 to 53e0c4b Compare March 30, 2019 08:16
@soc1c
Copy link
Copy Markdown
Contributor

soc1c commented Mar 31, 2019

Please rebase

@seunlanlege seunlanlege force-pushed the rpc-eth_subscribe-syncing branch from 53e0c4b to fb2a504 Compare April 1, 2019 06:56
@soc1c soc1c modified the milestones: 2.5, 2.6 Apr 2, 2019
@soc1c soc1c merged commit fba63de into master Apr 2, 2019
@soc1c soc1c deleted the rpc-eth_subscribe-syncing branch April 2, 2019 15:14
ordian added a commit that referenced this pull request Apr 5, 2019
* 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)
@aawaken
Copy link
Copy Markdown

aawaken commented May 2, 2019

Hello! I'm using latest parity ethereum client 2.0.5-beta on ubuntu 18:

Parity Ethereum
version Parity-Ethereum/v2.5.0-beta-b52ac20-20190408/x86_64-linux-gnu/rustc1.33.0

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:

import Api from "@parity/api";

const provider = new Api.Provider.Ws("ws://localhost:8450");

export default provider;

index.js:

import React from "react";
import ReactDOM from "react-dom";

import App from "./App";
import provider from "./provider";

import light, {accounts$, balanceOf$, blockNumber$, post$, transactionCountOf$} from "@parity/light.js";
import Api from '@parity/api';

light.setProvider(provider);

const api = new Api(provider);

accounts$().subscribe(accounts => {
    console.log(accounts);
});

package.json:

{
  "name": "new",
  "version": "1.0.0",
  "description": "",
  "keywords": [],
  "main": "src/index.js",
  "dependencies": {
    "@parity/api": "^5.1.3",
    "@parity/light.js": "5.1.3",
    "ajv": "^6.10.0",
    "react": "16.4.2",
    "react-dom": "16.4.2",
    "react-scripts": "^3.0.0",
    "rxjs": "^6.2.2",
    "typescript": "^3.4.5"
  },
  "devDependencies": {},
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Missing something?

@ordian
Copy link
Copy Markdown
Member

ordian commented May 3, 2019

@aawaken

Missing something?

This PR was merged into master (currently 2.6) and wasn't backported to 2.5 (usually, we only backport bug fixes).

@aawaken
Copy link
Copy Markdown

aawaken commented May 3, 2019

@aawaken

Missing something?

This PR was merged into master (currently 2.6) and wasn't backported to 2.5 (usually, we only backport bug fixes).

Thanks @ordian Any suggestions when 2.6 will be released?

Best

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. A7-looksgoodcantmerge 🙄 Pull request is reviewed well, but cannot be merged due to conflicts. B7-releasenotes 📜 Changes should be mentioned in the release notes of the next minor version release. M4-core ⛓ Core client code / Rust. M6-rpcapi 📣 RPC API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement eth_subscribe('syncing')

9 participants