Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Don't use Parity-specific JSONRPCs #56

Merged
merged 10 commits into from
Nov 29, 2018
Merged

Don't use Parity-specific JSONRPCs #56

merged 10 commits into from
Nov 29, 2018

Conversation

amaury1093
Copy link
Collaborator

@amaury1093 amaury1093 commented Nov 27, 2018

Use

  • eth_subscribe('syncing')
  • eth_subscribe('newHeads')

instead of

  • parity_subscribe('eth_syncing')
  • parity_subscribe('eth_blockNumber)

In any case, if pubsub doesn't work, default to polling.

Notes: on parity-ethereum nodes, eth_subscribe('syncing') is not implemented, so it will poll.

Fixes #51, fixes #3

@@ -15,213 +15,296 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
const PubsubBase = require('../pubsubBase');

const { inAddress, inBlockNumber, inHex, inNumber16, inOptions, inFilter } = require('../../format/input');
const { outAddress, outBlock, outNumber, outTransaction, outSyncing, outReceipt, outLog } = require('../../format/output');
const {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

file diff mostly due to prettier :(

'eth_getBlockByNumber',
options
).pipe(
withLatestFrom(onSyncingChanged$(options).pipe(startWith(false))),
Copy link
Contributor

Choose a reason for hiding this comment

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

I might be wrong but wouldn't this make onEveryBlockWithApi$ emit on initialization, even though the user is not synced? e.g.:

  • onEveryBlockWithApi$ is called
  • blockNumber RPC answers
  • onEveryBlockWithApi$ emits wit the blockNumber
  • isSyncing RPC answers true (which was always the case)
  • onEveryBlockWithApi$ doesn't emit until isSyncing RPC answers false

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I think you're right. The problem is: when you connect to Metamask or infura, eth_subscribe('syncing') doesn't return anything, I assume they're always considered sync. So onSyncingChanged$ actually never fires.

Between the 2, i still prefer to fire once at the beginning.

However I'm open to other ideas

Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine a fix could be to make onSyncingChanged$ fire eth_syncing (non-pubsub rpc call) first to get an initial value, and then switch to the pubsub. non-pubsub "eth_syncing" does get an answer.

obviously not very clean though

Copy link
Collaborator Author

@amaury1093 amaury1093 Nov 29, 2018

Choose a reason for hiding this comment

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

I actually think it's a good idea, I thought about it too.

Another reason why it's good: before, parity_subscribe('eth_getBlock') immediately gives you an answer, and then gives you subsequent pubsub answers on each pub. eth_subscribe('newHeads') however doesn't give you the initial one, so there might be a (up to 15s) delay between subscribe and first event fired.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, makes sense then!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#61

const [fallbackNamespace, fallbackMethod] = fallback.split('_');

return timer(0, pollInterval).pipe(
switchMap(() => api[fallbackNamespace][fallbackMethod]())
Copy link
Contributor

Choose a reason for hiding this comment

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

might not be a problem but for RPC calls taking >1 second to answer, the observable would never fire

Copy link
Collaborator Author

@amaury1093 amaury1093 Nov 28, 2018

Choose a reason for hiding this comment

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

Ah yeah, it's a problem. I'll change it to mergeMap.

Is there something between mergeMap and switchMap? I.e. to make this work: https://codesandbox.io/s/9153w6n7r. but not in the mergeMap way (hope it's clear...)

Copy link
Contributor

@axelchalon axelchalon Nov 29, 2018

Choose a reason for hiding this comment

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

I think exhaustMap should do the trick https://repl.it/repls/BewitchedSubtleCookies

We have a timer (source observable) ; we make the RPC query each time the timer fires, unless the previous RPC hasn't resolved yet

Copy link
Contributor

@axelchalon axelchalon left a comment

Choose a reason for hiding this comment

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

👍

@amaury1093 amaury1093 merged commit e5d602e into master Nov 29, 2018
@amaury1093 amaury1093 deleted the am-fix-infura branch November 29, 2018 16:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Light.js not working with Infura Make it work with MetaMask
2 participants