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

Use a dependency graph for light.js #64

Open
amaury1093 opened this issue Dec 6, 2018 · 0 comments
Open

Use a dependency graph for light.js #64

amaury1093 opened this issue Dec 6, 2018 · 0 comments

Comments

@amaury1093
Copy link
Collaborator

light.js is used when pubsub on state is not available (e.g. on a light client). In that case, we need to find the minimal viable calls to track the relevant portion of the state we're interested in. (track == be notified when it changes).

Some examples:

  • To track the balance of an ETH account, we subscribe to new heads, and on each new head, we make a JSONRPC call api.eth.getBalance(...)
  • To track the balance of an account in a ERC20 contract, we subscribe to the events, and make a balanceOf call on events that are relevant to the tracked account.

An immediate remark that comes up is that there's a lot of "on each ..., do ...". And the best data structure to express "on each ..., do ..." is a dependency graph. Luckily, it also fits perfectly well with reactive programming, see for example reactive-graph.

We could refactor light.js into a graph structure for RxJS, similar to reactive-graph, where:

  • nodes are Observables
  • edges are pipes

So:

  • We start by manually defining some source nodes (STARTUP, NEW_HEAD, EVERY_SECOND), they don't have incoming edges.
  • Define all other nodes (balanceOf$, syncing$...) by combing source nodes (or other nodes), with the correct pipes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant