waku-org / js-waku

JavaScript implementation of Waku v2
https://js.waku.org
Apache License 2.0
169 stars 42 forks source link

Static Sharding #1310

Closed fryorcraken closed 8 months ago

fryorcraken commented 1 year ago

Planned start date: Due date: 15 Oct 2023

Summary

Implement Static Sharding as specified in https://rfc.vac.dev/spec/51/#static-sharding

Acceptance Criteria

As an app dev, I can...

Tasks

Taking into account https://github.com/waku-org/js-waku/issues/1430#issuecomment-1655066881, where we assume that shards will not change mid-run; we can update the sequence diagram as:

sequenceDiagram
    participant Alice
    participant js-waku
    participant connection manager

    Alice->>js-waku: start (pass [`shard1`, `shard2`])
    js-waku->>connection manager: discovers & attempts connections to relevant peers
    Alice->>js-waku: send a subscription request that includes a pubsubtopic based on IDecoder
    js-waku->>js-waku: if the new pubsubtopic is different from initialisation, throw error
    js-waku->>js-waku: if the new pubsubtopic is one of the ones from initialisation, proceed
    js-waku->>connection manager: open a stream with one of the connected peers from the relevant shard
    js-waku->>Alice: return the subscription object 

this definitely narrows our scope of work (v1) but we can design our system as above discussed where we think of it being potentially scaled up to being used for run-time changes as well (v2?)


Tasks (v1)

Create

Discovery

ConnectionManager

Protocols

RAID (Risks, Assumptions, Issues and Dependencies)

danisharora099 commented 1 year ago

some learnings: js-waku being a client and not actually participating in discv5 discovery process, the implementation would be mostly limited to filtering out the right nodes from discovery protocols; in terms of peer exchange, the goal is to connect only with peers from the PX response that share the same pubsub topic or shard that the relay protocol is subscribed to, while discarding other peers received in the response

cc @fryorcraken keen to know your perspective on the above

danisharora099 commented 1 year ago

note: is currently blocked on nwaku and go-waku as while they have the functionality implemented, they are not exposed to the user yet through a flag

danisharora099 commented 1 year ago

Child issue: https://github.com/waku-org/js-waku/issues/1430

fryorcraken commented 1 year ago

some learnings: js-waku being a client and not actually participating in discv5 discovery process, the implementation would be mostly limited to filtering out the right nodes from discovery protocols; in terms of peer exchange, the goal is to connect only with peers from the PX response that share the same pubsub topic or shard that the relay protocol is subscribed to, while discarding other peers received in the response

cc @fryorcraken keen to know your perspective on the above

that and we also need to implement the API to enable static and naming sharding on filter, light push, store and relay. Which is the discussion I saw on Discord.

fryorcraken commented 1 year ago

Note this is needed for the "community preview" web portal of Status. Cc @danisharora099 @chair28980 @john-44 @prichodko @felicio

John-44 commented 1 year ago

Note this is needed for the "community preview" web portal of Status. Cc @danisharora099 @chair28980 @John-44 @prichodko @felicio

and Community Channel Preview web pages

danisharora099 commented 1 year ago

some notes for design:

danisharora099 commented 1 year ago

@weboko and I discussed how the user flow might look like for subscription & unsubscription from the user's end where we assume Alice will pass the shard during the initialisation of the node:

sequenceDiagram
    participant Alice
    participant js-waku
    participant connection manager

    Alice->>js-waku: start (pass [`shard1`, `shard2`])
    js-waku->>connection manager: discovers & attempts connections to relevant peers
    connection manager->>connection manager: cache peers for irrelevant static shards
    Alice->>js-waku: subscribe to a new pubsubtopic (`shard3`) based on IDecoder (that includes pubsubTopic)
    js-waku->>js-waku: if the new IDecoder is for static sharding (following topic name convention)
    js-waku->>connection manager: attempt dial
    connection manager->>connection manager: check if we already have a connected peer for this shard & use this peer
    connection manager->>connection manager: else, loop over discovered peers and attempt a dial to new peer
    js-waku->>Alice: if no peers are found for that shard -- throw error
    js-waku->>Alice: else, return the subscription object 
    Alice->>js-waku: unsubscribe (shard1)
    js-waku->>connection manager: drop connection with peers that exclusively support that shard
weboko commented 1 year ago

My view here is that there are the following sub-tasks:

danisharora099 commented 1 year ago

Taking into account https://github.com/waku-org/js-waku/issues/1430#issuecomment-1655066881, where we assume that shards will not change mid-run; we can update the sequence diagram as:

sequenceDiagram
    participant Alice
    participant js-waku
    participant connection manager

    Alice->>js-waku: start (pass [`shard1`, `shard2`])
    js-waku->>connection manager: discovers & attempts connections to relevant peers
    Alice->>js-waku: send a subscription request that includes a pubsubtopic based on IDecoder
    js-waku->>js-waku: if the new pubsubtopic is different from initialisation, throw error
    js-waku->>js-waku: if the new pubsubtopic is one of the ones from initialisation, proceed
    js-waku->>connection manager: open a stream with one of the connected peers from the relevant shard
    js-waku->>Alice: return the subscription object 

this definitely narrows our scope of work (v1) but we can design our system as above discussed where we think of it being potentially scaled up to being used for run-time changes as well (v2?)


Tasks (v1)

Create

Discovery

ConnectionManager

Protocols


let me know what you think @weboko @fryorcraken

fryorcraken commented 1 year ago

Looks good. Would be good to have a review from @waku-org/go-waku-developers and @waku-org/nwaku-developers if they see any issue from their experience/implementaiton.

Agreed that for static sharding, we can assume that the static shard does not change after a start to support the Community Preview portal and Community Channel web pages for Status. Cc @felicio @prichodko

Do note that with auto-sharding, shards can change mid run (but out of scope for this issue).

danisharora099 commented 1 year ago

Weekly Update

danisharora099 commented 1 year ago

Weekly Update

danisharora099 commented 1 year ago

Weekly Update

danisharora099 commented 1 year ago

reopening this in reference to https://github.com/waku-org/js-waku/issues/1684 to be done

danisharora099 commented 8 months ago

Closing considering #1684 is done