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

Use a dependency graph for light.js #64

Open
@amaury1093

Description

@amaury1093

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions