From 8df69279eefc53583f7b3298877e42519030648d Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Thu, 14 Sep 2023 14:06:08 +0530 Subject: [PATCH 1/9] chore:remove duplicate declaration of relay protocol const (#736) --- waku/v2/peermanager/peer_manager.go | 11 ++++------- waku/v2/peermanager/peer_manager_test.go | 7 ++++--- waku/v2/peermanager/service_slot.go | 3 ++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/waku/v2/peermanager/peer_manager.go b/waku/v2/peermanager/peer_manager.go index 72d2d293d..69f665df7 100644 --- a/waku/v2/peermanager/peer_manager.go +++ b/waku/v2/peermanager/peer_manager.go @@ -12,15 +12,12 @@ import ( ma "github.com/multiformats/go-multiaddr" "github.com/waku-org/go-waku/logging" wps "github.com/waku-org/go-waku/waku/v2/peerstore" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/utils" "go.uber.org/zap" ) -// WakuRelayIDv200 is protocol ID for Waku v2 relay protocol -// TODO: Move all the protocol IDs to a common location. -const WakuRelayIDv200 = protocol.ID("/vac/waku/relay/2.0.0") - // PeerManager applies various controls and manage connections towards peers. type PeerManager struct { peerConnector *PeerConnectionStrategy @@ -133,10 +130,10 @@ func (pm *PeerManager) getRelayPeers() (inRelayPeers peer.IDSlice, outRelayPeers //Need to filter peers to check if they support relay if inPeers.Len() != 0 { - inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, WakuRelayIDv200) + inRelayPeers, _ = utils.FilterPeersByProto(pm.host, inPeers, relay.WakuRelayID_v200) } if outPeers.Len() != 0 { - outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, WakuRelayIDv200) + outRelayPeers, _ = utils.FilterPeersByProto(pm.host, outPeers, relay.WakuRelayID_v200) } return } @@ -283,7 +280,7 @@ func (pm *PeerManager) RemovePeer(peerID peer.ID) { // Adding to peerStore is expected to be already done by caller. // If relay proto is passed, it is not added to serviceSlot. func (pm *PeerManager) addPeerToServiceSlot(proto protocol.ID, peerID peer.ID) { - if proto == WakuRelayIDv200 { + if proto == relay.WakuRelayID_v200 { pm.logger.Warn("Cannot add Relay peer to service peer slots") return } diff --git a/waku/v2/peermanager/peer_manager_test.go b/waku/v2/peermanager/peer_manager_test.go index a64bce9f0..ac7c2b1c9 100644 --- a/waku/v2/peermanager/peer_manager_test.go +++ b/waku/v2/peermanager/peer_manager_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/waku-org/go-waku/tests" wps "github.com/waku-org/go-waku/waku/v2/peerstore" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/utils" ) @@ -110,7 +111,7 @@ func TestDefaultProtocol(t *testing.T) { // check peer for default protocol /////////////// //Test empty peer selection for relay protocol - _, err := pm.SelectPeer(WakuRelayIDv200, nil) + _, err := pm.SelectPeer(relay.WakuRelayID_v200, nil) require.Error(t, err, utils.ErrNoPeersAvailable) /////////////// @@ -121,11 +122,11 @@ func TestDefaultProtocol(t *testing.T) { defer h5.Close() //Test peer selection for relay protocol from peer store - _, err = pm.AddPeer(getAddr(h5), wps.Static, WakuRelayIDv200) + _, err = pm.AddPeer(getAddr(h5), wps.Static, relay.WakuRelayID_v200) require.NoError(t, err) // since we are not passing peerList, selectPeer fn using filterByProto checks in PeerStore for peers with same protocol. - peerID, err := pm.SelectPeer(WakuRelayIDv200, nil) + peerID, err := pm.SelectPeer(relay.WakuRelayID_v200, nil) require.NoError(t, err) require.Equal(t, peerID, h5.ID()) } diff --git a/waku/v2/peermanager/service_slot.go b/waku/v2/peermanager/service_slot.go index aff2d856b..c88711e76 100644 --- a/waku/v2/peermanager/service_slot.go +++ b/waku/v2/peermanager/service_slot.go @@ -5,6 +5,7 @@ import ( "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/protocol" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/utils" ) @@ -57,7 +58,7 @@ func NewServiceSlot() *ServiceSlots { // getPeers for getting all the peers for a given protocol // since peerMap is only used in peerManager that's why it is unexported func (slots *ServiceSlots) getPeers(proto protocol.ID) *peerMap { - if proto == WakuRelayIDv200 { + if proto == relay.WakuRelayID_v200 { return nil } slots.mu.Lock() From ab7e45c735772db1d8422f0413f00cbdcb3c7e37 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 12 Sep 2023 15:14:08 -0400 Subject: [PATCH 2/9] feat: make RLN available by default --- .golangci.full.yaml | 4 ---- .golangci.yaml | 3 --- Makefile | 14 +++++++------- cmd/waku/flags_no_rln.go | 4 ++-- cmd/waku/flags_rln.go | 4 ++-- cmd/waku/node_no_rln.go | 4 ++-- cmd/waku/node_rln.go | 4 ++-- cmd/waku/rlngenerate/command_no_rln.go | 4 ++-- cmd/waku/rlngenerate/command_rln.go | 4 ++-- cmd/waku/rlngenerate/flags.go | 4 ++-- cmd/waku/rlngenerate/web3.go | 4 ++-- cmd/waku/server/no_rln.go | 4 ++-- cmd/waku/server/rln.go | 4 ++-- examples/chat2/Makefile | 2 +- examples/rln/Makefile | 2 +- flake.nix | 1 + waku/v2/node/wakunode2_no_rln.go | 4 ++-- waku/v2/node/wakunode2_rln.go | 4 ++-- waku/v2/node/wakuoptions_rln.go | 6 ++---- 19 files changed, 36 insertions(+), 44 deletions(-) delete mode 100644 .golangci.yaml diff --git a/.golangci.full.yaml b/.golangci.full.yaml index 0e6afaf9b..ece7d58ec 100644 --- a/.golangci.full.yaml +++ b/.golangci.full.yaml @@ -1,7 +1,3 @@ -run: - build-tags: - - gowaku_rln - issues: include: - EXC0012 diff --git a/.golangci.yaml b/.golangci.yaml deleted file mode 100644 index 0b27243b3..000000000 --- a/.golangci.yaml +++ /dev/null @@ -1,3 +0,0 @@ -run: - build-tags: - - gowaku_rln diff --git a/Makefile b/Makefile index bce0115bd..98632e6f5 100644 --- a/Makefile +++ b/Makefile @@ -42,8 +42,8 @@ BUILD_FLAGS ?= $(shell echo "-ldflags='\ ANDROID_TARGET ?= 23 # control rln code compilation -ifeq ($(RLN), true) -BUILD_TAGS := gowaku_rln +ifeq ($(NO_RLN), true) +BUILD_TAGS := gowaku_no_rln endif all: build @@ -58,7 +58,7 @@ build: chat2: pushd ./examples/chat2 && \ - ${GOBIN} build -tags="gowaku_rln" -o ../../build/chat2 . && \ + ${GOBIN} build -o ../../build/chat2 . && \ popd vendor: @@ -130,7 +130,7 @@ static-library: @echo "Building static library..." ${GOBIN} build \ -buildmode=c-archive \ - -tags="${BUILD_TAGS}" \ + -tags="${BUILD_TAGS} gowaku_no_rln" \ -o ./build/lib/libgowaku.a \ ./library/c/ @echo "Static library built:" @@ -146,7 +146,7 @@ dynamic-library: rm -f ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT)* $(GOBIN_SHARED_LIB_CFLAGS) $(GOBIN_SHARED_LIB_CGO_LDFLAGS) ${GOBIN} build \ -buildmode=c-shared \ - -tags="${BUILD_TAGS}" \ + -tags="${BUILD_TAGS} gowaku_no_rln" \ -o ./build/lib/libgowaku.$(GOBIN_SHARED_LIB_EXT) \ ./library/c/ ifeq ($(detected_OS),Darwin) @@ -166,14 +166,14 @@ mobile-android: @echo "Android target: ${ANDROID_TARGET} (override with ANDROID_TARGET var)" gomobile init && \ ${GOBIN} get -d golang.org/x/mobile/cmd/gomobile && \ - gomobile bind -v -target=android -androidapi=${ANDROID_TARGET} -ldflags="-s -w" -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o ./build/lib/gowaku.aar ./library/mobile + CGO=1 gomobile bind -v -target=android -androidapi=${ANDROID_TARGET} -ldflags="-s -w" -tags="${BUILD_TAGS} gowaku_no_rln" $(BUILD_FLAGS) -o ./build/lib/gowaku.aar ./library/mobile @echo "Android library built:" @ls -la ./build/lib/*.aar ./build/lib/*.jar mobile-ios: gomobile init && \ ${GOBIN} get -d golang.org/x/mobile/cmd/gomobile && \ - gomobile bind -target=ios -ldflags="-s -w" -tags="nowatchdog ${BUILD_TAGS}" $(BUILD_FLAGS) -o ./build/lib/Gowaku.xcframework ./library/mobile + gomobile bind -target=ios -ldflags="-s -w" -tags="nowatchdog ${BUILD_TAGS} gowaku_no_rln" $(BUILD_FLAGS) -o ./build/lib/Gowaku.xcframework ./library/mobile @echo "IOS library built:" @ls -la ./build/lib/*.xcframework diff --git a/cmd/waku/flags_no_rln.go b/cmd/waku/flags_no_rln.go index 7bbb48a82..e1e0e034f 100644 --- a/cmd/waku/flags_no_rln.go +++ b/cmd/waku/flags_no_rln.go @@ -1,5 +1,5 @@ -//go:build !gowaku_rln -// +build !gowaku_rln +//go:build gowaku_no_rln +// +build gowaku_no_rln package main diff --git a/cmd/waku/flags_rln.go b/cmd/waku/flags_rln.go index 3d73d6e1b..be76c35ae 100644 --- a/cmd/waku/flags_rln.go +++ b/cmd/waku/flags_rln.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package main diff --git a/cmd/waku/node_no_rln.go b/cmd/waku/node_no_rln.go index 92d64ff9d..de285e5a7 100644 --- a/cmd/waku/node_no_rln.go +++ b/cmd/waku/node_no_rln.go @@ -1,5 +1,5 @@ -//go:build !gowaku_rln -// +build !gowaku_rln +//go:build gowaku_no_rln +// +build gowaku_no_rln package main diff --git a/cmd/waku/node_rln.go b/cmd/waku/node_rln.go index 72192258c..703660f27 100644 --- a/cmd/waku/node_rln.go +++ b/cmd/waku/node_rln.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package main diff --git a/cmd/waku/rlngenerate/command_no_rln.go b/cmd/waku/rlngenerate/command_no_rln.go index edd287f67..38d86c8a2 100644 --- a/cmd/waku/rlngenerate/command_no_rln.go +++ b/cmd/waku/rlngenerate/command_no_rln.go @@ -1,5 +1,5 @@ -//go:build !gowaku_rln -// +build !gowaku_rln +//go:build gowaku_no_rln +// +build gowaku_no_rln package rlngenerate diff --git a/cmd/waku/rlngenerate/command_rln.go b/cmd/waku/rlngenerate/command_rln.go index 7e580d8f5..8a05cea91 100644 --- a/cmd/waku/rlngenerate/command_rln.go +++ b/cmd/waku/rlngenerate/command_rln.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package rlngenerate diff --git a/cmd/waku/rlngenerate/flags.go b/cmd/waku/rlngenerate/flags.go index 2f5f06801..447fb62c2 100644 --- a/cmd/waku/rlngenerate/flags.go +++ b/cmd/waku/rlngenerate/flags.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package rlngenerate diff --git a/cmd/waku/rlngenerate/web3.go b/cmd/waku/rlngenerate/web3.go index 535311fec..5990c9613 100644 --- a/cmd/waku/rlngenerate/web3.go +++ b/cmd/waku/rlngenerate/web3.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package rlngenerate diff --git a/cmd/waku/server/no_rln.go b/cmd/waku/server/no_rln.go index ab094e60b..78aac3178 100644 --- a/cmd/waku/server/no_rln.go +++ b/cmd/waku/server/no_rln.go @@ -1,5 +1,5 @@ -//go:build !gowaku_rln -// +build !gowaku_rln +//go:build gowaku_no_rln +// +build gowaku_no_rln package server diff --git a/cmd/waku/server/rln.go b/cmd/waku/server/rln.go index d0c247705..b203f91e5 100644 --- a/cmd/waku/server/rln.go +++ b/cmd/waku/server/rln.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package server diff --git a/examples/chat2/Makefile b/examples/chat2/Makefile index bacb34998..9d47d514a 100644 --- a/examples/chat2/Makefile +++ b/examples/chat2/Makefile @@ -3,7 +3,7 @@ all: build build: - go build -tags="gowaku_rln" -o build/chat2 . + go build -o build/chat2 . run: ./build/chat2 \ No newline at end of file diff --git a/examples/rln/Makefile b/examples/rln/Makefile index 73207b72e..296020556 100644 --- a/examples/rln/Makefile +++ b/examples/rln/Makefile @@ -1,6 +1,6 @@ .PHONY: all build build: - go build -tags="gowaku_rln" -o build/rln . + go build -o build/rln . all: build \ No newline at end of file diff --git a/flake.nix b/flake.nix index f0249d26a..fde4446b3 100644 --- a/flake.nix +++ b/flake.nix @@ -22,6 +22,7 @@ name = "go-waku"; src = self; inherit subPackages; + tags = [ "gowaku_no_rln" ]; ldflags = [ "-X github.com/waku-org/go-waku/waku/v2/node.GitCommit=${commit}" "-X github.com/waku-org/go-waku/waku/v2/node.Version=${version}" diff --git a/waku/v2/node/wakunode2_no_rln.go b/waku/v2/node/wakunode2_no_rln.go index d6da3e988..c74e13605 100644 --- a/waku/v2/node/wakunode2_no_rln.go +++ b/waku/v2/node/wakunode2_no_rln.go @@ -1,5 +1,5 @@ -//go:build !gowaku_rln -// +build !gowaku_rln +//go:build gowaku_no_rln +// +build gowaku_no_rln package node diff --git a/waku/v2/node/wakunode2_rln.go b/waku/v2/node/wakunode2_rln.go index 5b637478d..695cb214e 100644 --- a/waku/v2/node/wakunode2_rln.go +++ b/waku/v2/node/wakunode2_rln.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package node diff --git a/waku/v2/node/wakuoptions_rln.go b/waku/v2/node/wakuoptions_rln.go index 0f2df3e60..70f94a6dc 100644 --- a/waku/v2/node/wakuoptions_rln.go +++ b/waku/v2/node/wakuoptions_rln.go @@ -1,5 +1,5 @@ -//go:build gowaku_rln -// +build gowaku_rln +//go:build !gowaku_no_rln +// +build !gowaku_no_rln package node @@ -10,7 +10,6 @@ import ( ) // WithStaticRLNRelay enables the Waku V2 RLN protocol in offchain mode -// Requires the `gowaku_rln` build constrain (or the env variable RLN=true if building go-waku) func WithStaticRLNRelay(memberIndex *r.MembershipIndex, spamHandler rln.SpamHandler) WakuNodeOption { return func(params *WakuNodeParameters) error { params.enableRLN = true @@ -22,7 +21,6 @@ func WithStaticRLNRelay(memberIndex *r.MembershipIndex, spamHandler rln.SpamHand } // WithDynamicRLNRelay enables the Waku V2 RLN protocol in onchain mode. -// Requires the `gowaku_rln` build constrain (or the env variable RLN=true if building go-waku) func WithDynamicRLNRelay(keystorePath string, keystorePassword string, treePath string, membershipContract common.Address, membershipIndex *uint, spamHandler rln.SpamHandler, ethClientAddress string) WakuNodeOption { return func(params *WakuNodeParameters) error { params.enableRLN = true From 7beaa3f02939069027a0435d0859c25e7d443068 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 7 Sep 2023 17:39:10 -0400 Subject: [PATCH 3/9] feat(rln-relay): ensure execution order for pubsub validators --- examples/chat2/exec.go | 2 +- waku/v2/node/wakunode2.go | 5 +- waku/v2/node/wakunode2_rln.go | 8 +- waku/v2/node/wakuoptions.go | 2 +- waku/v2/protocol/envelope.go | 4 +- waku/v2/protocol/relay/validators.go | 89 ++++++++++++++++------- waku/v2/protocol/relay/validators_test.go | 31 ++------ waku/v2/protocol/relay/waku_relay.go | 18 +++-- waku/v2/protocol/relay/waku_relay_test.go | 9 ++- waku/v2/protocol/rln/common.go | 2 +- waku/v2/protocol/rln/waku_rln_relay.go | 49 ++++++------- 11 files changed, 117 insertions(+), 102 deletions(-) diff --git a/examples/chat2/exec.go b/examples/chat2/exec.go index 08e04eddd..45caa49b8 100644 --- a/examples/chat2/exec.go +++ b/examples/chat2/exec.go @@ -43,7 +43,7 @@ func execute(options Options) { } if options.RLNRelay.Enable { - spamHandler := func(message *pb.WakuMessage) error { + spamHandler := func(message *pb.WakuMessage, topic string) error { return nil } diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 311e436ec..d49043c5c 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -10,7 +10,6 @@ import ( backoffv4 "github.com/cenkalti/backoff/v4" golog "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p" - pubsub "github.com/libp2p/go-libp2p-pubsub" "go.uber.org/zap" "github.com/ethereum/go-ethereum/crypto" @@ -66,13 +65,13 @@ type IdentityCredential = struct { IDCommitment byte32 `json:"idCommitment"` } -type SpamHandler = func(message *pb.WakuMessage) error +type SpamHandler = func(message *pb.WakuMessage, topic string) error type RLNRelay interface { IdentityCredential() (IdentityCredential, error) MembershipIndex() uint AppendRLNProof(msg *pb.WakuMessage, senderEpochTime time.Time) error - Validator(spamHandler SpamHandler) func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool + Validator(spamHandler SpamHandler) func(ctx context.Context, message *pb.WakuMessage, topic string) bool Start(ctx context.Context) error Stop() error } diff --git a/waku/v2/node/wakunode2_rln.go b/waku/v2/node/wakunode2_rln.go index 695cb214e..4d93c04b9 100644 --- a/waku/v2/node/wakunode2_rln.go +++ b/waku/v2/node/wakunode2_rln.go @@ -8,7 +8,6 @@ import ( "context" "errors" - pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/waku-org/go-waku/waku/v2/protocol/rln" "github.com/waku-org/go-waku/waku/v2/protocol/rln/group_manager" "github.com/waku-org/go-waku/waku/v2/protocol/rln/group_manager/dynamic" @@ -29,6 +28,10 @@ func (w *WakuNode) setupRLNRelay() error { return nil } + if !w.opts.enableRelay { + return errors.New("rln requires relay") + } + var groupManager group_manager.GroupManager rlnInstance, rootTracker, err := rln.GetRLNInstanceAndRootTracker(w.opts.rlnTreePath) @@ -85,8 +88,7 @@ func (w *WakuNode) setupRLNRelay() error { w.rlnRelay = rlnRelay - // Adding RLN as a default validator - w.opts.pubsubOpts = append(w.opts.pubsubOpts, pubsub.WithDefaultValidator(rlnRelay.Validator(w.opts.rlnSpamHandler))) + w.Relay().RegisterDefaultValidator(w.rlnRelay.Validator(w.opts.rlnSpamHandler)) return nil } diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index e02610f43..9b3342240 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -96,7 +96,7 @@ type WakuNodeParameters struct { enableRLN bool rlnRelayMemIndex *uint rlnRelayDynamic bool - rlnSpamHandler func(message *pb.WakuMessage) error + rlnSpamHandler func(message *pb.WakuMessage, topic string) error rlnETHClientAddress string keystorePath string keystorePassword string diff --git a/waku/v2/protocol/envelope.go b/waku/v2/protocol/envelope.go index c87ee1430..6b0a0f7b5 100644 --- a/waku/v2/protocol/envelope.go +++ b/waku/v2/protocol/envelope.go @@ -20,12 +20,12 @@ type Envelope struct { // as well as generating a hash based on the bytes that compose the message func NewEnvelope(msg *wpb.WakuMessage, receiverTime int64, pubSubTopic string) *Envelope { messageHash := msg.Hash(pubSubTopic) - hash := hash.SHA256([]byte(msg.ContentTopic), msg.Payload) + digest := hash.SHA256([]byte(msg.ContentTopic), msg.Payload) return &Envelope{ msg: msg, hash: messageHash, index: &pb.Index{ - Digest: hash[:], + Digest: digest[:], ReceiverTime: receiverTime, SenderTime: msg.Timestamp, PubsubTopic: pubSubTopic, diff --git a/waku/v2/protocol/relay/validators.go b/waku/v2/protocol/relay/validators.go index 144908702..1405179a4 100644 --- a/waku/v2/protocol/relay/validators.go +++ b/waku/v2/protocol/relay/validators.go @@ -10,14 +10,14 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto/secp256k1" - pubsub "github.com/libp2p/go-libp2p-pubsub" "github.com/libp2p/go-libp2p/core/peer" + proto "google.golang.org/protobuf/proto" + "github.com/waku-org/go-waku/waku/v2/hash" "github.com/waku-org/go-waku/waku/v2/protocol/pb" "github.com/waku-org/go-waku/waku/v2/timesource" "go.uber.org/zap" - proto "google.golang.org/protobuf/proto" ) func msgHash(pubSubTopic string, msg *pb.WakuMessage) []byte { @@ -38,23 +38,29 @@ func msgHash(pubSubTopic string, msg *pb.WakuMessage) []byte { ) } -const messageWindowDuration = time.Minute * 5 +type validatorFn = func(ctx context.Context, msg *pb.WakuMessage, topic string) bool -func withinTimeWindow(t timesource.Timesource, msg *pb.WakuMessage) bool { - if msg.Timestamp == 0 { - return false - } +func (w *WakuRelay) RegisterDefaultValidator(fn validatorFn) { + w.topicValidatorMutex.Lock() + defer w.topicValidatorMutex.Unlock() + w.defaultTopicValidators = append(w.defaultTopicValidators, fn) +} - now := t.Now() - msgTime := time.Unix(0, msg.Timestamp) +func (w *WakuRelay) RegisterTopicValidator(topic string, fn validatorFn) { + w.topicValidatorMutex.Lock() + defer w.topicValidatorMutex.Unlock() - return now.Sub(msgTime).Abs() <= messageWindowDuration + w.topicValidators[topic] = append(w.topicValidators[topic], fn) } -type validatorFn = func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool +func (w *WakuRelay) RemoveTopicValidator(topic string) { + w.topicValidatorMutex.Lock() + defer w.topicValidatorMutex.Unlock() -func validatorFnBuilder(t timesource.Timesource, topic string, publicKey *ecdsa.PublicKey) (validatorFn, error) { - publicKeyBytes := crypto.FromECDSAPub(publicKey) + delete(w.topicValidators, topic) +} + +func (w *WakuRelay) topicValidator(topic string) func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool { return func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool { msg := new(pb.WakuMessage) err := proto.Unmarshal(message.Data, msg) @@ -62,30 +68,30 @@ func validatorFnBuilder(t timesource.Timesource, topic string, publicKey *ecdsa. return false } - if !withinTimeWindow(t, msg) { - return false + w.topicValidatorMutex.RLock() + validators, exists := w.topicValidators[topic] + validators = append(validators, w.defaultTopicValidators...) + w.topicValidatorMutex.RUnlock() + + if exists { + for _, v := range validators { + if !v(ctx, msg, topic) { + return false + } + } } - msgHash := msgHash(topic, msg) - signature := msg.Meta - - return secp256k1.VerifySignature(publicKeyBytes, msgHash, signature) - }, nil + return true + } } // AddSignedTopicValidator registers a gossipsub validator for a topic which will check that messages Meta field contains a valid ECDSA signature for the specified pubsub topic. This is used as a DoS prevention mechanism func (w *WakuRelay) AddSignedTopicValidator(topic string, publicKey *ecdsa.PublicKey) error { w.log.Info("adding validator to signed topic", zap.String("topic", topic), zap.String("publicKey", hex.EncodeToString(elliptic.Marshal(publicKey.Curve, publicKey.X, publicKey.Y)))) - fn, err := validatorFnBuilder(w.timesource, topic, publicKey) - if err != nil { - return err - } + fn := signedTopicBuilder(w.timesource, publicKey) - err = w.pubsub.RegisterTopicValidator(topic, fn) - if err != nil { - return err - } + w.RegisterTopicValidator(topic, fn) if !w.IsSubscribed(topic) { w.log.Warn("relay is not subscribed to signed topic", zap.String("topic", topic)) @@ -94,6 +100,33 @@ func (w *WakuRelay) AddSignedTopicValidator(topic string, publicKey *ecdsa.Publi return nil } +const messageWindowDuration = time.Minute * 5 + +func withinTimeWindow(t timesource.Timesource, msg *pb.WakuMessage) bool { + if msg.Timestamp == 0 { + return false + } + + now := t.Now() + msgTime := time.Unix(0, msg.Timestamp) + + return now.Sub(msgTime).Abs() <= messageWindowDuration +} + +func signedTopicBuilder(t timesource.Timesource, publicKey *ecdsa.PublicKey) validatorFn { + publicKeyBytes := crypto.FromECDSAPub(publicKey) + return func(ctx context.Context, msg *pb.WakuMessage, topic string) bool { + if !withinTimeWindow(t, msg) { + return false + } + + msgHash := msgHash(topic, msg) + signature := msg.Meta + + return secp256k1.VerifySignature(publicKeyBytes, msgHash, signature) + } +} + // SignMessage adds an ECDSA signature to a WakuMessage as an opt-in mechanism for DoS prevention func SignMessage(privKey *ecdsa.PrivateKey, msg *pb.WakuMessage, pubsubTopic string) error { msgHash := msgHash(pubsubTopic, msg) diff --git a/waku/v2/protocol/relay/validators_test.go b/waku/v2/protocol/relay/validators_test.go index 383c1fcb4..9f03590c6 100644 --- a/waku/v2/protocol/relay/validators_test.go +++ b/waku/v2/protocol/relay/validators_test.go @@ -7,11 +7,8 @@ import ( "time" "github.com/ethereum/go-ethereum/crypto" - pubsub "github.com/libp2p/go-libp2p-pubsub" - pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" "github.com/stretchr/testify/require" "github.com/waku-org/go-waku/waku/v2/protocol/pb" - "google.golang.org/protobuf/proto" ) type FakeTimesource struct { @@ -59,39 +56,23 @@ func TestMsgHash(t *testing.T) { // expectedSignature, _ := hex.DecodeString("127FA211B2514F0E974A055392946DC1A14052182A6ABEFB8A6CD7C51DA1BF2E40595D28EF1A9488797C297EED3AAC45430005FB3A7F037BDD9FC4BD99F59E63") // require.True(t, bytes.Equal(expectedSignature, msg.Meta)) - msgData, _ := proto.Marshal(msg) - //expectedMessageHash, _ := hex.DecodeString("662F8C20A335F170BD60ABC1F02AD66F0C6A6EE285DA2A53C95259E7937C0AE9") //messageHash := MsgHash(pubsubTopic, msg) //require.True(t, bytes.Equal(expectedMessageHash, messageHash)) - myValidator, err := validatorFnBuilder(NewFakeTimesource(timestamp), protectedPubSubTopic, &prvKey.PublicKey) - require.NoError(t, err) - result := myValidator(context.Background(), "", &pubsub.Message{ - Message: &pubsub_pb.Message{ - Data: msgData, - }, - }) + myValidator := signedTopicBuilder(NewFakeTimesource(timestamp), &prvKey.PublicKey) + result := myValidator(context.Background(), msg, protectedPubSubTopic) require.True(t, result) // Exceed 5m window in both directions now5m1sInPast := timestamp.Add(-5 * time.Minute).Add(-1 * time.Second) - myValidator, err = validatorFnBuilder(NewFakeTimesource(now5m1sInPast), protectedPubSubTopic, &prvKey.PublicKey) + myValidator = signedTopicBuilder(NewFakeTimesource(now5m1sInPast), &prvKey.PublicKey) require.NoError(t, err) - result = myValidator(context.Background(), "", &pubsub.Message{ - Message: &pubsub_pb.Message{ - Data: msgData, - }, - }) + result = myValidator(context.Background(), msg, protectedPubSubTopic) require.False(t, result) now5m1sInFuture := timestamp.Add(5 * time.Minute).Add(1 * time.Second) - myValidator, err = validatorFnBuilder(NewFakeTimesource(now5m1sInFuture), protectedPubSubTopic, &prvKey.PublicKey) - require.NoError(t, err) - result = myValidator(context.Background(), "", &pubsub.Message{ - Message: &pubsub_pb.Message{ - Data: msgData, - }, - }) + myValidator = signedTopicBuilder(NewFakeTimesource(now5m1sInFuture), &prvKey.PublicKey) + result = myValidator(context.Background(), msg, protectedPubSubTopic) require.False(t, result) } diff --git a/waku/v2/protocol/relay/waku_relay.go b/waku/v2/protocol/relay/waku_relay.go index 51efae513..672732ace 100644 --- a/waku/v2/protocol/relay/waku_relay.go +++ b/waku/v2/protocol/relay/waku_relay.go @@ -49,6 +49,10 @@ type WakuRelay struct { minPeersToPublish int + topicValidatorMutex sync.RWMutex + topicValidators map[string][]validatorFn + defaultTopicValidators []validatorFn + // TODO: convert to concurrent maps topicsMutex sync.Mutex wakuRelayTopics map[string]*pubsub.Topic @@ -83,6 +87,7 @@ func NewWakuRelay(bcaster Broadcaster, minPeersToPublish int, timesource timesou w.timesource = timesource w.wakuRelayTopics = make(map[string]*pubsub.Topic) w.relaySubs = make(map[string]*pubsub.Subscription) + w.topicValidators = make(map[string][]validatorFn) w.bcaster = bcaster w.minPeersToPublish = minPeersToPublish w.CommonService = waku_proto.NewCommonService() @@ -177,12 +182,6 @@ func NewWakuRelay(bcaster Broadcaster, minPeersToPublish int, timesource timesou pubsub.WithSeenMessagesTTL(2 * time.Minute), pubsub.WithPeerScore(w.peerScoreParams, w.peerScoreThresholds), pubsub.WithPeerScoreInspect(w.peerScoreInspector, 6*time.Second), - // TODO: to improve - setup default validator only if no default validator has been set. - pubsub.WithDefaultValidator(func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool { - msg := new(pb.WakuMessage) - err := proto.Unmarshal(message.Data, msg) - return err == nil - }), }, opts...) return w @@ -270,6 +269,11 @@ func (w *WakuRelay) upsertTopic(topic string) (*pubsub.Topic, error) { pubSubTopic, ok := w.wakuRelayTopics[topic] if !ok { // Joins topic if node hasn't joined yet + err := w.pubsub.RegisterTopicValidator(topic, w.topicValidator(topic)) + if err != nil { + return nil, err + } + newTopic, err := w.pubsub.Join(string(topic)) if err != nil { return nil, err @@ -419,6 +423,8 @@ func (w *WakuRelay) Unsubscribe(ctx context.Context, topic string) error { } delete(w.wakuRelayTopics, topic) + w.RemoveTopicValidator(topic) + err = w.emitters.EvtRelayUnsubscribed.Emit(EvtRelayUnsubscribed{topic}) if err != nil { return err diff --git a/waku/v2/protocol/relay/waku_relay_test.go b/waku/v2/protocol/relay/waku_relay_test.go index aeb7eb9a6..c7b335d81 100644 --- a/waku/v2/protocol/relay/waku_relay_test.go +++ b/waku/v2/protocol/relay/waku_relay_test.go @@ -79,10 +79,6 @@ func TestGossipsubScore(t *testing.T) { relay := make([]*WakuRelay, 5) for i := 0; i < 5; i++ { hosts[i], relay[i] = createRelayNode(t) - if i == 0 { - // This is a hack to remove the default validator from the list of default options - relay[i].opts = relay[i].opts[:len(relay[i].opts)-1] - } err := relay[i].Start(context.Background()) require.NoError(t, err) } @@ -119,6 +115,11 @@ func TestGossipsubScore(t *testing.T) { // We obtain the go-libp2p topic directly because we normally can't publish anything other than WakuMessages pubsubTopic, err := relay[0].upsertTopic(testTopic) require.NoError(t, err) + + // Removing validator from relayer0 to allow it to send invalid messages + err = relay[0].pubsub.UnregisterTopicValidator(testTopic) + require.NoError(t, err) + for i := 0; i < 50; i++ { buf := make([]byte, 1000) _, err := rand.Read(buf) diff --git a/waku/v2/protocol/rln/common.go b/waku/v2/protocol/rln/common.go index 69412d4c7..1f3afd711 100644 --- a/waku/v2/protocol/rln/common.go +++ b/waku/v2/protocol/rln/common.go @@ -26,7 +26,7 @@ const acceptableRootWindowSize = 5 type RegistrationHandler = func(tx *types.Transaction) -type SpamHandler = func(message *pb.WakuMessage) error +type SpamHandler = func(msg *pb.WakuMessage, topic string) error func toRLNSignal(wakuMessage *pb.WakuMessage) []byte { if wakuMessage == nil { diff --git a/waku/v2/protocol/rln/waku_rln_relay.go b/waku/v2/protocol/rln/waku_rln_relay.go index 4e489a7d2..d3c00eb46 100644 --- a/waku/v2/protocol/rln/waku_rln_relay.go +++ b/waku/v2/protocol/rln/waku_rln_relay.go @@ -2,14 +2,11 @@ package rln import ( "context" - "encoding/hex" "errors" "math" "time" "github.com/ethereum/go-ethereum/log" - pubsub "github.com/libp2p/go-libp2p-pubsub" - "github.com/libp2p/go-libp2p/core/peer" "github.com/prometheus/client_golang/prometheus" "github.com/waku-org/go-waku/logging" "github.com/waku-org/go-waku/waku/v2/protocol/pb" @@ -17,7 +14,6 @@ import ( "github.com/waku-org/go-waku/waku/v2/timesource" "github.com/waku-org/go-zerokit-rln/rln" "go.uber.org/zap" - proto "google.golang.org/protobuf/proto" ) type WakuRLNRelay struct { @@ -218,52 +214,49 @@ func (rlnRelay *WakuRLNRelay) AppendRLNProof(msg *pb.WakuMessage, senderEpochTim // Validator returns a validator for the waku messages. // The message validation logic is according to https://rfc.vac.dev/spec/17/ func (rlnRelay *WakuRLNRelay) Validator( - spamHandler SpamHandler) func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool { - return func(ctx context.Context, peerID peer.ID, message *pubsub.Message) bool { - rlnRelay.log.Debug("rln-relay topic validator called") + spamHandler SpamHandler) func(ctx context.Context, msg *pb.WakuMessage, topic string) bool { + return func(ctx context.Context, msg *pb.WakuMessage, topic string) bool { - rlnRelay.metrics.RecordMessage() + hash := msg.Hash(topic) - wakuMessage := &pb.WakuMessage{} - if err := proto.Unmarshal(message.Data, wakuMessage); err != nil { - rlnRelay.log.Debug("could not unmarshal message") - return true - } + log := rlnRelay.log.With( + logging.HexBytes("hash", hash), + zap.String("pubsubTopic", topic), + zap.String("contentTopic", msg.ContentTopic), + ) + + log.Debug("rln-relay topic validator called") + + rlnRelay.metrics.RecordMessage() // validate the message - validationRes, err := rlnRelay.ValidateMessage(wakuMessage, nil) + validationRes, err := rlnRelay.ValidateMessage(msg, nil) if err != nil { - rlnRelay.log.Debug("validating message", zap.Error(err)) + log.Debug("validating message", zap.Error(err)) return false } switch validationRes { case validMessage: - rlnRelay.log.Debug("message verified", - zap.String("id", hex.EncodeToString([]byte(message.ID))), - ) + log.Debug("message verified") return true case invalidMessage: - rlnRelay.log.Debug("message could not be verified", - zap.String("id", hex.EncodeToString([]byte(message.ID))), - ) + log.Debug("message could not be verified") return false case spamMessage: - rlnRelay.log.Debug("spam message found", - zap.String("id", hex.EncodeToString([]byte(message.ID))), - ) + log.Debug("spam message found") - rlnRelay.metrics.RecordSpam(wakuMessage.ContentTopic) + rlnRelay.metrics.RecordSpam(msg.ContentTopic) if spamHandler != nil { - if err := spamHandler(wakuMessage); err != nil { - rlnRelay.log.Error("executing spam handler", zap.Error(err)) + if err := spamHandler(msg, topic); err != nil { + log.Error("executing spam handler", zap.Error(err)) } } return false default: - rlnRelay.log.Debug("unhandled validation result", zap.Int("validationResult", int(validationRes))) + log.Debug("unhandled validation result", zap.Int("validationResult", int(validationRes))) return false } } From 55bc21c604b08a7a83458fa29b87361347ca3559 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 11 Sep 2023 17:34:56 -0400 Subject: [PATCH 4/9] feat(rln-relay): isReady --- cmd/waku/server/rest/health.go | 48 +++++++++++++++++++ cmd/waku/server/rest/health_api.yaml | 41 ++++++++++++++++ cmd/waku/server/rest/waku_rest.go | 2 +- waku/v2/node/wakunode2.go | 1 + .../rln/group_manager/dynamic/dynamic.go | 35 ++++++++++++-- .../rln/group_manager/dynamic/metrics.go | 14 ++---- .../rln/group_manager/group_manager.go | 1 + .../rln/group_manager/static/static.go | 4 ++ waku/v2/protocol/rln/waku_rln_relay.go | 5 ++ waku/v2/protocol/rln/web3/web3.go | 1 + 10 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 cmd/waku/server/rest/health.go create mode 100644 cmd/waku/server/rest/health_api.yaml diff --git a/cmd/waku/server/rest/health.go b/cmd/waku/server/rest/health.go new file mode 100644 index 000000000..6fb186851 --- /dev/null +++ b/cmd/waku/server/rest/health.go @@ -0,0 +1,48 @@ +package rest + +import ( + "context" + "errors" + "net/http" + + "github.com/go-chi/chi/v5" + "github.com/waku-org/go-waku/waku/v2/node" +) + +type HealthService struct { + node *node.WakuNode + mux *chi.Mux +} + +const routeHealth = "/health" + +func NewHealthService(node *node.WakuNode, m *chi.Mux) *HealthService { + h := &HealthService{ + node: node, + mux: m, + } + + m.Get(routeHealth, h.getHealth) + + return h +} + +type HealthResponse string + +func (d *HealthService) getHealth(w http.ResponseWriter, r *http.Request) { + isReady, err := d.node.RLNRelay().IsReady(r.Context()) + if err != nil { + if errors.Is(err, context.DeadlineExceeded) { + writeResponse(w, HealthResponse("Health check timed out"), http.StatusInternalServerError) + } else { + writeResponse(w, HealthResponse(err.Error()), http.StatusInternalServerError) + } + return + } + + if isReady { + writeResponse(w, HealthResponse("Node is healthy"), http.StatusOK) + } else { + writeResponse(w, HealthResponse("Node is not ready"), http.StatusInternalServerError) + } +} diff --git a/cmd/waku/server/rest/health_api.yaml b/cmd/waku/server/rest/health_api.yaml new file mode 100644 index 000000000..d1528c77a --- /dev/null +++ b/cmd/waku/server/rest/health_api.yaml @@ -0,0 +1,41 @@ +openapi: 3.0.3 +info: + title: Waku V2 node REST API + version: 1.0.0 + contact: + name: VAC Team + url: https://forum.vac.dev/ + +tags: + - name: health + description: Healt check REST API for WakuV2 node + +paths: + /health: + get: + summary: Get node health status + description: Retrieve readiness of a Waku v2 node. + operationId: healthcheck + tags: + - health + responses: + '200': + description: Waku v2 node is up and running. + content: + text/plain: + schema: + type: string + example: Node is healty + '500': + description: Internal server error + content: + text/plain: + schema: + type: string + '503': + description: Node not initialized or having issues + content: + text/plain: + schema: + type: string + example: Node is not initialized \ No newline at end of file diff --git a/cmd/waku/server/rest/waku_rest.go b/cmd/waku/server/rest/waku_rest.go index 19f02cd0a..ec0325905 100644 --- a/cmd/waku/server/rest/waku_rest.go +++ b/cmd/waku/server/rest/waku_rest.go @@ -34,7 +34,7 @@ func NewWakuRest(node *node.WakuNode, address string, port int, enablePProf bool } _ = NewDebugService(node, mux) - + _ = NewHealthService(node, mux) _ = NewStoreService(node, mux) listenAddr := fmt.Sprintf("%s:%d", address, port) diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index d49043c5c..afe9d1d9c 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -74,6 +74,7 @@ type RLNRelay interface { Validator(spamHandler SpamHandler) func(ctx context.Context, message *pb.WakuMessage, topic string) bool Start(ctx context.Context) error Stop() error + IsReady(ctx context.Context) (bool, error) } type WakuNode struct { diff --git a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go index a9ff27455..fdecd309f 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math/big" + "sync" "time" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -36,7 +37,8 @@ type DynamicGroupManager struct { identityCredential *rln.IdentityCredential membershipIndex rln.MembershipIndex - lastBlockProcessed uint64 + lastBlockProcessedMutex sync.RWMutex + lastBlockProcessed uint64 appKeystore *keystore.AppKeystore keystorePassword string @@ -44,6 +46,9 @@ type DynamicGroupManager struct { } func (gm *DynamicGroupManager) handler(events []*contracts.RLNMemberRegistered) error { + gm.lastBlockProcessedMutex.Lock() + defer gm.lastBlockProcessedMutex.Unlock() + toRemoveTable := om.New() toInsertTable := om.New() @@ -82,8 +87,6 @@ func (gm *DynamicGroupManager) handler(events []*contracts.RLNMemberRegistered) return err } - gm.metrics.RecordRegisteredMembership(toInsertTable.Len() - toRemoveTable.Len()) - gm.lastBlockProcessed = lastBlockProcessed err = gm.SetMetadata(RLNMetadata{ LastProcessedBlock: gm.lastBlockProcessed, @@ -95,7 +98,7 @@ func (gm *DynamicGroupManager) handler(events []*contracts.RLNMemberRegistered) // this is not a fatal error, hence we don't raise an exception gm.log.Warn("failed to persist rln metadata", zap.Error(err)) } else { - gm.log.Debug("rln metadata persisted", zap.Uint64("lastProcessedBlock", gm.lastBlockProcessed), zap.Uint64("chainID", gm.web3Config.ChainID.Uint64()), logging.HexBytes("contractAddress", gm.web3Config.RegistryContract.Address.Bytes())) + gm.log.Debug("rln metadata persisted", zap.Uint64("lastBlockProcessed", gm.lastBlockProcessed), zap.Uint64("chainID", gm.web3Config.ChainID.Uint64()), logging.HexBytes("contractAddress", gm.web3Config.RegistryContract.Address.Bytes())) } return nil @@ -228,6 +231,8 @@ func (gm *DynamicGroupManager) InsertMembers(toInsert *om.OrderedMap) error { } gm.metrics.RecordMembershipInsertionDuration(time.Since(start)) + gm.metrics.RecordRegisteredMembership(startIndex + uint(len(idCommitments))) + _, err = gm.rootTracker.UpdateLatestRoot(pair.Key.(uint64)) if err != nil { return err @@ -279,3 +284,25 @@ func (gm *DynamicGroupManager) Stop() error { return nil } + +func (gm *DynamicGroupManager) IsReady(ctx context.Context) (bool, error) { + latestBlockNumber, err := gm.latestBlockNumber(ctx) + if err != nil { + return false, fmt.Errorf("could not retrieve latest block: %w", err) + } + + gm.lastBlockProcessedMutex.RLock() + allBlocksProcessed := gm.lastBlockProcessed >= latestBlockNumber + gm.lastBlockProcessedMutex.RUnlock() + + if !allBlocksProcessed { + return false, nil + } + + syncProgress, err := gm.web3Config.ETHClient.SyncProgress(ctx) + if err != nil { + return false, fmt.Errorf("could not retrieve sync state: %w", err) + } + + return syncProgress == nil, nil // syncProgress only has a value while node is syncing +} diff --git a/waku/v2/protocol/rln/group_manager/dynamic/metrics.go b/waku/v2/protocol/rln/group_manager/dynamic/metrics.go index a11fc201d..a345dc0bc 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/metrics.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/metrics.go @@ -7,8 +7,8 @@ import ( "github.com/prometheus/client_golang/prometheus" ) -var numberRegisteredMemberships = prometheus.NewCounter( - prometheus.CounterOpts{ +var numberRegisteredMemberships = prometheus.NewGauge( + prometheus.GaugeOpts{ Name: "waku_rln_number_registered_memberships", Help: "number of registered and active rln memberships", }) @@ -33,7 +33,7 @@ var collectors = []prometheus.Collector{ // Metrics exposes the functions required to update prometheus metrics for lightpush protocol type Metrics interface { - RecordRegisteredMembership(num int) + RecordRegisteredMembership(num uint) RecordMembershipInsertionDuration(duration time.Duration) RecordMembershipCredentialsImportDuration(duration time.Duration) } @@ -60,10 +60,6 @@ func (m *metricsImpl) RecordMembershipCredentialsImportDuration(duration time.Du } // RecordRegisteredMembership records the number of registered memberships -func (m *metricsImpl) RecordRegisteredMembership(num int) { - if num < 0 { - return - } - - numberRegisteredMemberships.Add(float64(num)) +func (m *metricsImpl) RecordRegisteredMembership(num uint) { + numberRegisteredMemberships.Set(float64(num)) } diff --git a/waku/v2/protocol/rln/group_manager/group_manager.go b/waku/v2/protocol/rln/group_manager/group_manager.go index 3dbec8865..32792482e 100644 --- a/waku/v2/protocol/rln/group_manager/group_manager.go +++ b/waku/v2/protocol/rln/group_manager/group_manager.go @@ -11,6 +11,7 @@ type GroupManager interface { IdentityCredentials() (rln.IdentityCredential, error) MembershipIndex() rln.MembershipIndex Stop() error + IsReady(ctx context.Context) (bool, error) } type Details struct { diff --git a/waku/v2/protocol/rln/group_manager/static/static.go b/waku/v2/protocol/rln/group_manager/static/static.go index 251bf1b49..e4c5889a5 100644 --- a/waku/v2/protocol/rln/group_manager/static/static.go +++ b/waku/v2/protocol/rln/group_manager/static/static.go @@ -95,3 +95,7 @@ func (gm *StaticGroupManager) Stop() error { // Do nothing return nil } + +func (gm *StaticGroupManager) IsReady(ctx context.Context) (bool, error) { + return true, nil +} diff --git a/waku/v2/protocol/rln/waku_rln_relay.go b/waku/v2/protocol/rln/waku_rln_relay.go index d3c00eb46..3e0248ef3 100644 --- a/waku/v2/protocol/rln/waku_rln_relay.go +++ b/waku/v2/protocol/rln/waku_rln_relay.go @@ -293,3 +293,8 @@ func (rlnRelay *WakuRLNRelay) IdentityCredential() (rln.IdentityCredential, erro func (rlnRelay *WakuRLNRelay) MembershipIndex() uint { return rlnRelay.GroupManager.MembershipIndex() } + +// IsReady returns true if the RLN Relay protocol is ready to relay messages +func (rlnRelay *WakuRLNRelay) IsReady(ctx context.Context) (bool, error) { + return rlnRelay.GroupManager.IsReady(ctx) +} diff --git a/waku/v2/protocol/rln/web3/web3.go b/waku/v2/protocol/rln/web3/web3.go index cdd162a0a..59c2234b6 100644 --- a/waku/v2/protocol/rln/web3/web3.go +++ b/waku/v2/protocol/rln/web3/web3.go @@ -31,6 +31,7 @@ type RLNContract struct { // EthClient is an interface for the ethclient.Client, so that we can pass mock client for testing type EthClient interface { bind.ContractBackend + SyncProgress(ctx context.Context) (*ethereum.SyncProgress, error) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) From bfc3083fb1e16bf9e7f7065db13ead930d6d8b41 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Thu, 14 Sep 2023 20:30:06 +0530 Subject: [PATCH 5/9] feat: update WakuPeerStore to store pubSubTopics for a peer (#734) * feat: update peerStore to store pubSubTopics a peer is linked to * derive pubSubTopics from ENR * New API to retrieve peers by shard information --- cmd/waku/node.go | 29 ++++++++------- cmd/waku/server/rest/store.go | 2 +- cmd/waku/server/rpc/filter_test.go | 2 +- examples/chat2/exec.go | 10 +++--- examples/filter2/main.go | 3 +- library/node.go | 2 +- waku/v2/node/wakunode2.go | 14 ++++++-- waku/v2/peermanager/peer_connector.go | 7 ++-- waku/v2/peermanager/peer_manager.go | 39 +++++++++++++++++--- waku/v2/peermanager/peer_manager_test.go | 10 +++--- waku/v2/peerstore/waku_peer_store.go | 46 ++++++++++++++++++++++++ waku/v2/rendezvous/rendezvous.go | 5 +-- 12 files changed, 131 insertions(+), 38 deletions(-) diff --git a/cmd/waku/node.go b/cmd/waku/node.go index c1e8dff71..73c21675f 100644 --- a/cmd/waku/node.go +++ b/cmd/waku/node.go @@ -300,26 +300,30 @@ func Execute(options NodeOptions) { utils.Logger().Info("Version details ", zap.String("version", node.Version), zap.String("commit", node.GitCommit)) failOnErr(err, "Wakunode") + //Process pubSub and contentTopics specified and arrive at all corresponding pubSubTopics + pubSubTopicMap := processTopics(options) + pubSubTopicMapKeys := make([]string, 0, len(pubSubTopicMap)) + for k := range pubSubTopicMap { + pubSubTopicMapKeys = append(pubSubTopicMapKeys, k) + } if options.Filter.UseV1 { - addStaticPeers(wakuNode, options.Filter.NodesV1, legacy_filter.FilterID_v20beta1) + addStaticPeers(wakuNode, options.Filter.NodesV1, pubSubTopicMapKeys, legacy_filter.FilterID_v20beta1) } - //Process pubSub and contentTopics specified and arrive at all corresponding pubSubTopics - pubSubTopicMap := processTopics(options) - if err = wakuNode.Start(ctx); err != nil { logger.Fatal("starting waku node", zap.Error(err)) } for _, d := range discoveredNodes { - wakuNode.AddDiscoveredPeer(d.PeerID, d.PeerInfo.Addrs, wakupeerstore.DNSDiscovery) + wakuNode.AddDiscoveredPeer(d.PeerID, d.PeerInfo.Addrs, wakupeerstore.DNSDiscovery, nil) } - addStaticPeers(wakuNode, options.Store.Nodes, store.StoreID_v20beta4) - addStaticPeers(wakuNode, options.LightPush.Nodes, lightpush.LightPushID_v20beta1) - addStaticPeers(wakuNode, options.Rendezvous.Nodes, rendezvous.RendezvousID) - addStaticPeers(wakuNode, options.Filter.Nodes, filter.FilterSubscribeID_v20beta1) + //For now assuming that static peers added support/listen on all topics specified via commandLine. + addStaticPeers(wakuNode, options.Store.Nodes, pubSubTopicMapKeys, store.StoreID_v20beta4) + addStaticPeers(wakuNode, options.LightPush.Nodes, pubSubTopicMapKeys, lightpush.LightPushID_v20beta1) + addStaticPeers(wakuNode, options.Rendezvous.Nodes, pubSubTopicMapKeys, rendezvous.RendezvousID) + addStaticPeers(wakuNode, options.Filter.Nodes, pubSubTopicMapKeys, filter.FilterSubscribeID_v20beta1) var wg sync.WaitGroup @@ -409,7 +413,8 @@ func Execute(options NodeOptions) { if options.PeerExchange.Enable && options.PeerExchange.Node != nil { logger.Info("retrieving peer info via peer exchange protocol") - peerID, err := wakuNode.AddPeer(*options.PeerExchange.Node, wakupeerstore.Static, peer_exchange.PeerExchangeID_v20alpha1) + peerID, err := wakuNode.AddPeer(*options.PeerExchange.Node, wakupeerstore.Static, + pubSubTopicMapKeys, peer_exchange.PeerExchangeID_v20alpha1) if err != nil { logger.Error("adding peer exchange peer", logging.MultiAddrs("node", *options.PeerExchange.Node), zap.Error(err)) } else { @@ -510,9 +515,9 @@ func processTopics(options NodeOptions) map[string]struct{} { return pubSubTopicMap } -func addStaticPeers(wakuNode *node.WakuNode, addresses []multiaddr.Multiaddr, protocols ...protocol.ID) { +func addStaticPeers(wakuNode *node.WakuNode, addresses []multiaddr.Multiaddr, pubSubTopics []string, protocols ...protocol.ID) { for _, addr := range addresses { - _, err := wakuNode.AddPeer(addr, wakupeerstore.Static, protocols...) + _, err := wakuNode.AddPeer(addr, wakupeerstore.Static, pubSubTopics, protocols...) failOnErr(err, "error adding peer") } } diff --git a/cmd/waku/server/rest/store.go b/cmd/waku/server/rest/store.go index e457af58f..280669e23 100644 --- a/cmd/waku/server/rest/store.go +++ b/cmd/waku/server/rest/store.go @@ -197,7 +197,7 @@ func (d *StoreService) getV1Messages(w http.ResponseWriter, r *http.Request) { ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second) defer cancel() - _, err = d.node.AddPeer(peerAddr, peerstore.Static) + _, err = d.node.AddPeer(peerAddr, peerstore.Static, d.node.Relay().Topics()) if err != nil { writeStoreError(w, http.StatusInternalServerError, err) return diff --git a/cmd/waku/server/rpc/filter_test.go b/cmd/waku/server/rpc/filter_test.go index 202cc113d..4d2b7c11e 100644 --- a/cmd/waku/server/rpc/filter_test.go +++ b/cmd/waku/server/rpc/filter_test.go @@ -84,7 +84,7 @@ func TestFilterSubscription(t *testing.T) { break } - _, err = d.node.AddPeer(addr, peerstore.Static, legacy_filter.FilterID_v20beta1) + _, err = d.node.AddPeer(addr, peerstore.Static, []string{testTopic}, legacy_filter.FilterID_v20beta1) require.NoError(t, err) args := &FilterContentArgs{Topic: testTopic, ContentFilters: []*pb.FilterRequest_ContentFilter{{ContentTopic: "ct"}}} diff --git a/examples/chat2/exec.go b/examples/chat2/exec.go index 45caa49b8..266b03151 100644 --- a/examples/chat2/exec.go +++ b/examples/chat2/exec.go @@ -77,19 +77,19 @@ func execute(options Options) { return } - err = addPeer(wakuNode, options.Store.Node, store.StoreID_v20beta4) + err = addPeer(wakuNode, options.Store.Node, options.Relay.Topics.Value(), store.StoreID_v20beta4) if err != nil { fmt.Println(err.Error()) return } - err = addPeer(wakuNode, options.LightPush.Node, lightpush.LightPushID_v20beta1) + err = addPeer(wakuNode, options.LightPush.Node, options.Relay.Topics.Value(), lightpush.LightPushID_v20beta1) if err != nil { fmt.Println(err.Error()) return } - err = addPeer(wakuNode, options.Filter.Node, filter.FilterSubscribeID_v20beta1) + err = addPeer(wakuNode, options.Filter.Node, options.Relay.Topics.Value(), filter.FilterSubscribeID_v20beta1) if err != nil { fmt.Println(err.Error()) @@ -113,10 +113,10 @@ func execute(options Options) { chat.Stop() } -func addPeer(wakuNode *node.WakuNode, addr *multiaddr.Multiaddr, protocols ...protocol.ID) error { +func addPeer(wakuNode *node.WakuNode, addr *multiaddr.Multiaddr, topics []string, protocols ...protocol.ID) error { if addr == nil { return nil } - _, err := wakuNode.AddPeer(*addr, peerstore.Static, protocols...) + _, err := wakuNode.AddPeer(*addr, peerstore.Static, topics, protocols...) return err } diff --git a/examples/filter2/main.go b/examples/filter2/main.go index 8e1ae9577..fbcb51004 100644 --- a/examples/filter2/main.go +++ b/examples/filter2/main.go @@ -90,7 +90,8 @@ func main() { // Setup filter // - _, err = lightNode.AddPeer(fullNode.ListenAddresses()[0], wps.Static, filter.FilterSubscribeID_v20beta1) + _, err = lightNode.AddPeer(fullNode.ListenAddresses()[0], wps.Static, + []string{pubSubTopic.String()}, filter.FilterSubscribeID_v20beta1) if err != nil { log.Info("Error adding filter peer on light node ", err) } diff --git a/library/node.go b/library/node.go index 72a2c6328..a3da4f03d 100644 --- a/library/node.go +++ b/library/node.go @@ -260,7 +260,7 @@ func AddPeer(address string, protocolID string) (string, error) { return "", err } - peerID, err := wakuState.node.AddPeer(ma, peerstore.Static, libp2pProtocol.ID(protocolID)) + peerID, err := wakuState.node.AddPeer(ma, peerstore.Static, wakuState.relayTopics, libp2pProtocol.ID(protocolID)) if err != nil { return "", err } diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index afe9d1d9c..540679b42 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -31,6 +31,7 @@ import ( "github.com/waku-org/go-waku/waku/v2/discv5" "github.com/waku-org/go-waku/waku/v2/peermanager" wps "github.com/waku-org/go-waku/waku/v2/peerstore" + wakuprotocol "github.com/waku-org/go-waku/waku/v2/protocol" "github.com/waku-org/go-waku/waku/v2/protocol/enr" "github.com/waku-org/go-waku/waku/v2/protocol/filter" "github.com/waku-org/go-waku/waku/v2/protocol/legacy_filter" @@ -688,18 +689,20 @@ func (w *WakuNode) startStore(ctx context.Context, sub relay.Subscription) error } // AddPeer is used to add a peer and the protocols it support to the node peerstore -func (w *WakuNode) AddPeer(address ma.Multiaddr, origin wps.Origin, protocols ...protocol.ID) (peer.ID, error) { - return w.peermanager.AddPeer(address, origin, protocols...) +// TODO: Need to update this for autosharding, to only take contentTopics and optional pubSubTopics or provide an alternate API only for contentTopics. +func (w *WakuNode) AddPeer(address ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) (peer.ID, error) { + return w.peermanager.AddPeer(address, origin, pubSubTopics, protocols...) } // AddDiscoveredPeer to add a discovered peer to the node peerStore -func (w *WakuNode) AddDiscoveredPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin) { +func (w *WakuNode) AddDiscoveredPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubsubTopics []string) { p := peermanager.PeerData{ Origin: origin, AddrInfo: peer.AddrInfo{ ID: ID, Addrs: addrs, }, + PubSubTopics: pubsubTopics, } w.peermanager.AddDiscoveredPeer(p) } @@ -838,6 +841,11 @@ func (w *WakuNode) Peers() ([]*Peer, error) { return peers, nil } +func (w *WakuNode) PeersByShard(cluster uint16, shard uint16) peer.IDSlice { + pTopic := wakuprotocol.NewStaticShardingPubsubTopic(cluster, shard).String() + return w.peerstore.(wps.WakuPeerstore).PeersByPubSubTopic(pTopic) +} + func (w *WakuNode) findRelayNodes(ctx context.Context) { defer w.wg.Done() diff --git a/waku/v2/peermanager/peer_connector.go b/waku/v2/peermanager/peer_connector.go index 7468418e7..e8c0c31e6 100644 --- a/waku/v2/peermanager/peer_connector.go +++ b/waku/v2/peermanager/peer_connector.go @@ -27,9 +27,10 @@ import ( // PeerData contains information about a peer useful in establishing connections with it. type PeerData struct { - Origin wps.Origin - AddrInfo peer.AddrInfo - ENR *enode.Node + Origin wps.Origin + AddrInfo peer.AddrInfo + PubSubTopics []string + ENR *enode.Node } // PeerConnectionStrategy is a utility to connect to peers, diff --git a/waku/v2/peermanager/peer_manager.go b/waku/v2/peermanager/peer_manager.go index 69f665df7..87ddeae98 100644 --- a/waku/v2/peermanager/peer_manager.go +++ b/waku/v2/peermanager/peer_manager.go @@ -12,6 +12,7 @@ import ( ma "github.com/multiformats/go-multiaddr" "github.com/waku-org/go-waku/logging" wps "github.com/waku-org/go-waku/waku/v2/peerstore" + wenr "github.com/waku-org/go-waku/waku/v2/protocol/enr" "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/waku-org/go-waku/waku/v2/utils" @@ -213,8 +214,27 @@ func (pm *PeerManager) pruneInRelayConns(inRelayPeers peer.IDSlice) { // Note that these peers will not be set in service-slots. // TODO: It maybe good to set in service-slots based on services supported in the ENR func (pm *PeerManager) AddDiscoveredPeer(p PeerData) { + // Try to fetch shard info from ENR to arrive at pubSub topics. + if len(p.PubSubTopics) == 0 && p.ENR != nil { + shards, err := wenr.RelaySharding(p.ENR.Record()) + if err != nil { + pm.logger.Error("Could not derive relayShards from ENR", zap.Error(err), + logging.HostID("peer", p.AddrInfo.ID), zap.String("enr", p.ENR.String())) + } else { + if shards != nil { + p.PubSubTopics = make([]string, 0) + topics := shards.Topics() + for _, topic := range topics { + topicStr := topic.String() + p.PubSubTopics = append(p.PubSubTopics, topicStr) + } + } else { + pm.logger.Info("ENR doesn't have relay shards", logging.HostID("peer", p.AddrInfo.ID)) + } + } + } - _ = pm.addPeer(p.AddrInfo.ID, p.AddrInfo.Addrs, p.Origin) + _ = pm.addPeer(p.AddrInfo.ID, p.AddrInfo.Addrs, p.Origin, p.PubSubTopics) if p.ENR != nil { err := pm.host.Peerstore().(wps.WakuPeerstore).SetENR(p.AddrInfo.ID, p.ENR) @@ -223,11 +243,12 @@ func (pm *PeerManager) AddDiscoveredPeer(p PeerData) { logging.HostID("peer", p.AddrInfo.ID), zap.String("enr", p.ENR.String())) } } + } // addPeer adds peer to only the peerStore. // It also sets additional metadata such as origin, ENR and supported protocols -func (pm *PeerManager) addPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, protocols ...protocol.ID) error { +func (pm *PeerManager) addPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) error { pm.logger.Info("adding peer to peerstore", logging.HostID("peer", ID)) pm.host.Peerstore().AddAddrs(ID, addrs, peerstore.AddressTTL) err := pm.host.Peerstore().(wps.WakuPeerstore).SetOrigin(ID, origin) @@ -242,11 +263,21 @@ func (pm *PeerManager) addPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Orig return err } } + if len(pubSubTopics) == 0 { + // Probably the peer is discovered via DNSDiscovery (for which we don't have pubSubTopic info) + //If pubSubTopic and enr is empty or no shard info in ENR,then set to defaultPubSubTopic + pubSubTopics = []string{relay.DefaultWakuTopic} + } + err = pm.host.Peerstore().(wps.WakuPeerstore).SetPubSubTopics(ID, pubSubTopics) + if err != nil { + pm.logger.Error("could not store pubSubTopic", zap.Error(err), + logging.HostID("peer", ID), zap.Strings("topics", pubSubTopics)) + } return nil } // AddPeer adds peer to the peerStore and also to service slots -func (pm *PeerManager) AddPeer(address ma.Multiaddr, origin wps.Origin, protocols ...protocol.ID) (peer.ID, error) { +func (pm *PeerManager) AddPeer(address ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) (peer.ID, error) { //Assuming all addresses have peerId info, err := peer.AddrInfoFromP2pAddr(address) if err != nil { @@ -259,7 +290,7 @@ func (pm *PeerManager) AddPeer(address ma.Multiaddr, origin wps.Origin, protocol } //Add to the peer-store - err = pm.addPeer(info.ID, info.Addrs, origin, protocols...) + err = pm.addPeer(info.ID, info.Addrs, origin, pubSubTopics, protocols...) if err != nil { return "", err } diff --git a/waku/v2/peermanager/peer_manager_test.go b/waku/v2/peermanager/peer_manager_test.go index ac7c2b1c9..cef6598fa 100644 --- a/waku/v2/peermanager/peer_manager_test.go +++ b/waku/v2/peermanager/peer_manager_test.go @@ -57,7 +57,7 @@ func TestServiceSlots(t *testing.T) { // add h2 peer to peer manager t.Log(h2.ID()) - _, err = pm.AddPeer(getAddr(h2), wps.Static, libp2pProtocol.ID(protocol)) + _, err = pm.AddPeer(getAddr(h2), wps.Static, []string{""}, libp2pProtocol.ID(protocol)) require.NoError(t, err) /////////////// @@ -70,7 +70,7 @@ func TestServiceSlots(t *testing.T) { require.Equal(t, peerID, h2.ID()) // add h3 peer to peer manager - _, err = pm.AddPeer(getAddr(h3), wps.Static, libp2pProtocol.ID(protocol)) + _, err = pm.AddPeer(getAddr(h3), wps.Static, []string{""}, libp2pProtocol.ID(protocol)) require.NoError(t, err) // check that returned peer is h2 or h3 peer @@ -94,7 +94,7 @@ func TestServiceSlots(t *testing.T) { require.Error(t, err, utils.ErrNoPeersAvailable) // add h4 peer for protocol1 - _, err = pm.AddPeer(getAddr(h4), wps.Static, libp2pProtocol.ID(protocol1)) + _, err = pm.AddPeer(getAddr(h4), wps.Static, []string{""}, libp2pProtocol.ID(protocol1)) require.NoError(t, err) //Test peer selection for protocol1 @@ -122,7 +122,7 @@ func TestDefaultProtocol(t *testing.T) { defer h5.Close() //Test peer selection for relay protocol from peer store - _, err = pm.AddPeer(getAddr(h5), wps.Static, relay.WakuRelayID_v200) + _, err = pm.AddPeer(getAddr(h5), wps.Static, []string{""}, relay.WakuRelayID_v200) require.NoError(t, err) // since we are not passing peerList, selectPeer fn using filterByProto checks in PeerStore for peers with same protocol. @@ -143,7 +143,7 @@ func TestAdditionAndRemovalOfPeer(t *testing.T) { require.NoError(t, err) defer h6.Close() - _, err = pm.AddPeer(getAddr(h6), wps.Static, protocol2) + _, err = pm.AddPeer(getAddr(h6), wps.Static, []string{""}, protocol2) require.NoError(t, err) peerID, err := pm.SelectPeer(protocol2, nil) diff --git a/waku/v2/peerstore/waku_peer_store.go b/waku/v2/peerstore/waku_peer_store.go index b1feb42d5..0d856001d 100644 --- a/waku/v2/peerstore/waku_peer_store.go +++ b/waku/v2/peerstore/waku_peer_store.go @@ -25,6 +25,7 @@ const ( const peerOrigin = "origin" const peerENR = "enr" const peerDirection = "direction" +const peerPubSubTopics = "pubSubTopics" // ConnectionFailures contains connection failure information towards all peers type ConnectionFailures struct { @@ -51,6 +52,11 @@ type WakuPeerstore interface { SetDirection(p peer.ID, direction network.Direction) error Direction(p peer.ID) (network.Direction, error) + + AddPubSubTopic(p peer.ID, topic string) error + PubSubTopics(p peer.ID) ([]string, error) + SetPubSubTopics(p peer.ID, topics []string) error + PeersByPubSubTopic(pubSubTopic string) peer.IDSlice } // NewWakuPeerstore creates a new WakuPeerStore object @@ -139,3 +145,43 @@ func (ps *WakuPeerstoreImpl) Direction(p peer.ID) (network.Direction, error) { return result.(network.Direction), nil } + +// AddPubSubTopic adds a new pubSubTopic for a peer +func (ps *WakuPeerstoreImpl) AddPubSubTopic(p peer.ID, topic string) error { + existingTopics, err := ps.PubSubTopics(p) + if err != nil { + return err + } + existingTopics = append(existingTopics, topic) + return ps.peerStore.Put(p, peerPubSubTopics, existingTopics) +} + +// SetPubSubTopics sets pubSubTopics for a peer, it also overrides existing ones that were set previously.. +func (ps *WakuPeerstoreImpl) SetPubSubTopics(p peer.ID, topics []string) error { + return ps.peerStore.Put(p, peerPubSubTopics, topics) +} + +// PubSubTopics fetches list of pubSubTopics for a peer +func (ps *WakuPeerstoreImpl) PubSubTopics(p peer.ID) ([]string, error) { + result, err := ps.peerStore.Get(p, peerPubSubTopics) + if err != nil { + return nil, err + } + return result.([]string), nil +} + +// PeersByPubSubTopic Returns list of peers by pubSubTopic +func (ps *WakuPeerstoreImpl) PeersByPubSubTopic(pubSubTopic string) peer.IDSlice { + var result peer.IDSlice + for _, p := range ps.Peers() { + topics, err := ps.PubSubTopics(p) + if err == nil { + for _, topic := range topics { + if topic == pubSubTopic { + result = append(result, p) + } + } + } //Note: skipping a peer in case of an error as there would be others available. + } + return result +} diff --git a/waku/v2/rendezvous/rendezvous.go b/waku/v2/rendezvous/rendezvous.go index eecab0d34..5b21ffaf3 100644 --- a/waku/v2/rendezvous/rendezvous.go +++ b/waku/v2/rendezvous/rendezvous.go @@ -103,8 +103,9 @@ func (r *Rendezvous) DiscoverWithNamespace(ctx context.Context, namespace string r.peerConnector.Subscribe(ctx, peerCh) for _, p := range addrInfo { peer := peermanager.PeerData{ - Origin: peerstore.Rendezvous, - AddrInfo: p, + Origin: peerstore.Rendezvous, + AddrInfo: p, + PubSubTopics: []string{namespace}, } select { case <-ctx.Done(): From e1a84aab0e4f29ef0f9cf62075f1784f89404512 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 13 Sep 2023 19:08:14 -0400 Subject: [PATCH 6/9] chore(rln-relay): docs and docker --- Dockerfile | 11 ++-- Makefile | 5 +- README.md | 8 +-- docs/operators/how-to/build.md | 8 +-- docs/operators/how-to/run-with-rln.md | 74 +++++++++++++++++++++++ docs/operators/how-to/run.md | 14 ++--- docs/operators/quickstart.md | 2 +- docs/tutorials/onchain-rln-relay-chat2.md | 18 +++--- examples/rln/README.md | 2 +- examples/rln/main.go | 21 +++---- scripts/linux/Dockerfile | 2 +- waku/v2/protocol/rln/keystore/keystore.go | 5 ++ 12 files changed, 124 insertions(+), 46 deletions(-) create mode 100644 docs/operators/how-to/run-with-rln.md diff --git a/Dockerfile b/Dockerfile index 700b8a78e..b8a6ab578 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,5 @@ # BUILD IMAGE -------------------------------------------------------- -FROM golang:1.19-alpine3.16 as builder - -# Get build tools and required header files -RUN apk add --no-cache build-base -RUN apk add --no-cache bash -RUN apk add --no-cache git +FROM golang:1.19 as builder WORKDIR /app COPY . . @@ -14,7 +9,7 @@ RUN make -j$(nproc) build # ACTUAL IMAGE ------------------------------------------------------- -FROM alpine:3.16 +FROM debian:12.1-slim ARG GIT_COMMIT=unknown @@ -26,6 +21,8 @@ LABEL commit=$GIT_COMMIT # color, nocolor, json ENV GOLOG_LOG_FMT=nocolor +RUN apt update && apt install -y ca-certificates + # go-waku default ports EXPOSE 9000 30303 60000 60001 8008 8009 diff --git a/Makefile b/Makefile index 98632e6f5..ca9007a00 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,10 @@ build-example-filter2: build-example-c-bindings: cd examples/c-bindings && $(MAKE) -build-example: build-example-basic2 build-example-chat-2 build-example-filter2 build-example-c-bindings +build-example-rln: + cd examples/rln && $(MAKE) + +build-example: build-example-basic2 build-example-chat-2 build-example-filter2 build-example-c-bindings build-example-rln static-library: @echo "Building static library..." diff --git a/README.md b/README.md index a619cc248..9ae67af7a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A Go implementation of the [Waku v2 protocol](https://rfc.vac.dev/spec/10).

- +

@@ -38,7 +38,7 @@ nix develop #### Docker ``` docker run -i -t -p 60000:60000 -p 9000:9000/udp \ - statusteam/go-waku:v0.5.2 \ # or, the image:tag of your choice + statusteam/go-waku:latest \ # or, the image:tag of your choice --dns-discovery:true \ --dns-discovery-url:enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.waku.nodes.status.im \ --discv5-discovery @@ -47,9 +47,9 @@ docker run -i -t -p 60000:60000 -p 9000:9000/udp \ or build and run the image with: ``` -docker build -t go-waku:latest . +docker build -t statusteam/go-waku:latest . -docker run go-waku:latest --help +docker run statusteam/go-waku:latest --help ``` #### Building on windows diff --git a/docs/operators/how-to/build.md b/docs/operators/how-to/build.md index fd8f875b8..0c08d662e 100644 --- a/docs/operators/how-to/build.md +++ b/docs/operators/how-to/build.md @@ -4,7 +4,7 @@ Go-waku can be built on Linux, macOS and Windows ## Installing dependencies -Cloning and building go-waku requires Go +1.17, a C compiler, Make, Bash and Git. +Cloning and building go-waku requires Go +1.19, a C compiler, Make, Bash and Git. Go can be installed by following [these instructions](https://go.dev/doc/install) @@ -31,13 +31,13 @@ Assuming you use [Homebrew](https://brew.sh/) to manage packages brew install cmake ``` -## Building nwaku +## Building go-waku -### 1. Clone the nwaku repository +### 1. Clone the go-waku repository ```sh git clone https://github.com/waku-org/go-waku -cd nwaku +cd go-waku ``` ### 2. Build waku diff --git a/docs/operators/how-to/run-with-rln.md b/docs/operators/how-to/run-with-rln.md new file mode 100644 index 000000000..c4e5969c1 --- /dev/null +++ b/docs/operators/how-to/run-with-rln.md @@ -0,0 +1,74 @@ +# How to run spam prevention on your go-waku node (RLN) + +This guide explains how to run a go-waku node with RLN (Rate Limiting Nullifier) enabled. + +[RLN](https://rfc.vac.dev/spec/32/) is a protocol integrated into waku v2, +which prevents spam-based attacks on the network. + +For further background on the research for RLN tailored to waku, refer +to [this](https://rfc.vac.dev/spec/17/) RFC. + +Registering to the membership group has been left out for brevity. +If you would like to register to the membership group and send messages with RLN, +refer to the [on-chain chat2 tutorial](../../tutorial/onchain-rln-relay-chat2.md). + +This guide specifically allows a node to participate in RLN testnet +You may alter the rln-specific arguments as required. + + +## 1. Update the runtime arguments + +Follow the steps from the [build](./build.md) and [run](./run.md) guides while replacing the run command with - + +```bash +export WAKU_FLEET= +export SEPOLIA_WS_NODE_ADDRESS= +export RLN_RELAY_CONTRACT_ADDRESS="0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4" # Replace this with any compatible implementation +$WAKUNODE_DIR/build/waku \ +--dns-discovery \ +--dns-discovery-url="$WAKU_FLEET" \ +--discv5-discovery=true \ +--rln-relay=true \ +--rln-relay-dynamic=true \ +--rln-relay-eth-contract-address="$RLN_RELAY_CONTRACT_ADDRESS" \ +--rln-relay-eth-client-address="$SEPOLIA_WS_NODE_ADDRESS" +``` + +OR + +If you installed go-waku using a `.dpkg` or `.rpm` package, you can use the `waku` command instead of building go-waku yourself + +OR + +If you have the go-waku node within docker, you can replace the run command with - + +```bash +export WAKU_FLEET= +export SEPOLIA_WS_NODE_ADDRESS= +export RLN_RELAY_CONTRACT_ADDRESS="0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4" # Replace this with any compatible implementation +docker run -i -t -p 60000:60000 -p 9000:9000/udp \ + -v /absolute/path/to/your/rlnKeystore.json:/rlnKeystore.json:ro \ + statusteam/go-waku:latest \ + --dns-discovery=true \ + --dns-discovery-url="$WAKU_FLEET" \ + --discv5-discovery \ + --rln-relay=true \ + --rln-relay-dynamic=true \ + --rln-relay-eth-contract-address="$RLN_RELAY_CONTRACT_ADDRESS" \ + --rln-relay-eth-client-address="$SEPOLIA_WS_NODE_ADDRESS" +``` + +Following is the list of additional fields that have been added to the +runtime arguments - + +1. `--rln-relay`: Allows waku-rln-relay to be mounted into the setup of the go-waku node. All messages sent and received in this node will require to contain a valid proof that will be verified, and nodes that relay messages with invalid proofs will have their peer scoring affected negatively and will be eventually disconnected. +2. `--rln-relay-dynamic`: Enables waku-rln-relay to connect to an ethereum node to fetch the membership group +3. `--rln-relay-eth-contract-address`: The contract address of an RLN membership group +4. `--rln-relay-eth-client-address`: The websocket url to a Sepolia ethereum node + +The `--dns-discovery-url` flag should contain a valid URL with nodes encoded according to EIP-1459. You can read more about DNS Discovery [here](https://github.com/waku-org/nwaku/blob/master/docs/tutorial/dns-disc.md) + +You should now have go-waku running, with RLN enabled! + + +> Note: This guide will be updated in the future to include features like slashing. \ No newline at end of file diff --git a/docs/operators/how-to/run.md b/docs/operators/how-to/run.md index aeb577bfa..98f8de108 100644 --- a/docs/operators/how-to/run.md +++ b/docs/operators/how-to/run.md @@ -17,13 +17,13 @@ See [this tutorial](./configure-key.md) if you want to generate and configure a - enable `relay` protocol - subscribe to the default pubsub topic, namely `/waku/2/default-waku/proto` - enable `store` protocol, but only as a client. -This implies that the nwaku node will not persist any historical messages itself, +This implies that the go-waku node will not persist any historical messages itself, but can query `store` service peers who do so. To configure `store` as a service node, see [this tutorial](./configure-store.md). > **Note:** The `filter` and `lightpush` protocols are _not_ enabled by default. -Consult the [configuration guide](./configure.md) on how to configure your nwaku node to run these protocols. +Consult the [configuration guide](./configure.md) on how to configure your go-waku node to run these protocols. Some typical non-default configurations are explained below. For more advanced configuration, see the [configuration guide](./configure.md). @@ -33,7 +33,7 @@ Different ways to connect to other nodes are expanded upon in our [connection gu Find the log entry beginning with `Listening on`. It should be printed at INFO level when you start your node -and contains a list of all publically announced listening addresses for the nwaku node. +and contains a list of all publically announced listening addresses for the go-waku node. For example @@ -80,7 +80,7 @@ returns a response similar to ## Finding your discoverable ENR address(es) -A nwaku node can encode its addressing information in an [Ethereum Node Record (ENR)](https://eips.ethereum.org/EIPS/eip-778) according to [`31/WAKU2-ENR`](https://rfc.vac.dev/spec/31/). +A go-waku node can encode its addressing information in an [Ethereum Node Record (ENR)](https://eips.ethereum.org/EIPS/eip-778) according to [`31/WAKU2-ENR`](https://rfc.vac.dev/spec/31/). These ENR are most often used for discovery purposes. ### ENR for DNS discovery and DiscV5 @@ -111,10 +111,10 @@ to continually discover and connect to random peers for a more robust mesh. A typical run configuration for a go-waku node is to connect to existing peers with known listening addresses using the `--staticnode` option. The `--staticnode` option can be repeated for each peer you want to connect to on startup. -This is also useful if you want to run several nwaku instances locally +This is also useful if you want to run several go-waku instances locally and therefore know the listening addresses of all peers. -As an example, consider a nwaku node that connects to two known peers +As an example, consider a go-waku node that connects to two known peers on the same local host (with IP `0.0.0.0`) with TCP ports `60002` and `60003`, and peer IDs `16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H` and `16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ` respectively. @@ -180,5 +180,5 @@ See our [store configuration tutorial](./configure-store.md) for more. A running go-waku node can be interacted with using the [Waku v2 JSON RPC API](https://rfc.vac.dev/spec/16/). > **Note:** Private and Admin API functionality are disabled by default. -To configure a nwaku node with these enabled, +To configure a go-waku node with these enabled, use the `--rpc-admin:true` and `--rpc-private:true` CLI options. \ No newline at end of file diff --git a/docs/operators/quickstart.md b/docs/operators/quickstart.md index 7d1177c3c..1c6ddf6b6 100644 --- a/docs/operators/quickstart.md +++ b/docs/operators/quickstart.md @@ -16,7 +16,7 @@ or download a precompiled binary from our [releases page](https://github.com/wak [Run the go-waku node](./how-to/run.md) using a default or common configuration or [configure](./how-to/configure.md) the node for more advanced use cases. -[Connect](./how-to/connect.md) the nwaku node to other peers to start communicating. +[Connect](./how-to/connect.md) the go-waku node to other peers to start communicating. ## 3. Interact diff --git a/docs/tutorials/onchain-rln-relay-chat2.md b/docs/tutorials/onchain-rln-relay-chat2.md index e82208083..90aaf9185 100644 --- a/docs/tutorials/onchain-rln-relay-chat2.md +++ b/docs/tutorials/onchain-rln-relay-chat2.md @@ -11,14 +11,14 @@ To complete this tutorial, you will need 1. An rln keystore file with credentials to the rln membership smart contract you wish to use. You may obtain this by registering to the smart contract and generating a keystore. It is possible to use go-waku to register into the smart contract: ``` make -./build/waku generate-rln-credentials --eth-account-private-key= --eth-contract-address=<0x000...> --eth-client-address= --cred-path=rlnKeystore.json +./build/waku generate-rln-credentials --eth-account-private-key= --eth-contract-address=<0x000...> --eth-client-address= --cred-path=./rlnKeystore.json ``` +Once this command is executed, A keystore file will be generated at the path defined in the `--cred-path` flag. You may now use this keystore with wakunode2 or chat2. + ## Overview Figure 1 provides an overview of the interaction of the chat2 clients with the test fleets and the membership contract. At a high level, when a chat2 client is run with Waku-RLN-Relay mounted in on-chain mode, the passed in credential will get displayed on the console of your chat2 client. -You may copy the displayed RLN credential and reuse them for the future execution of the chat2 application. -Proper instructions in this regard is provided in the following [section](#how-to-persist-and-reuse-rln-credential). Under the hood, the chat2 client constantly listens to the membership contract and keeps itself updated with the latest state of the group. In the following test setting, the chat2 clients are to be connected to the Waku test fleets as their first hop. @@ -56,7 +56,7 @@ Run the following command to set up your chat2 client. --content-topic=/toy-chat/3/mingde/proto \ --rln-relay=true \ --rln-relay-dynamic=true \ ---rln-relay-eth-contract-address=0x9C09146844C1326c2dBC41c451766C7138F88155 \ +--rln-relay-eth-contract-address=0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 \ --rln-relay-cred-path=xxx/xx/rlnKeystore.json \ --rln-relay-cred-password=xxxx \ --rln-relay-eth-client-address=xxxx @@ -68,8 +68,8 @@ In this command - the `--rln-relay` flag is set to `true` to enable the Waku-RLN-Relay protocol for spam protection. - the `--rln-relay-dynamic` flag is set to `true` to enable the on-chain mode of Waku-RLN-Relay protocol with dynamic group management. - the `--rln-relay-eth-contract-address` option gets the address of the membership contract. - The current address of the contract is `0x9C09146844C1326c2dBC41c451766C7138F88155`. - You may check the state of the contract on the [Sepolia testnet](https://sepolia.etherscan.io/address/0x9C09146844C1326c2dBC41c451766C7138F88155). + The current address of the contract is `0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4`. + You may check the state of the contract on the [Sepolia testnet](https://sepolia.etherscan.io/address/0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4). - the `--rln-relay-cred-path` option denotes the path to the keystore file described above - the `--rln-relay-cred-password` option denotes the password to the keystore - the `rln-relay-eth-client-address` is the WebSocket address of the hosted node on the Sepolia testnet. @@ -176,7 +176,7 @@ You may provide an index to the membership you wish to use (within the same memb --content-topic=/toy-chat/3/mingde/proto \ --rln-relay=true \ --rln-relay-dynamic=true \ ---rln-relay-eth-contract-address=0x9C09146844C1326c2dBC41c451766C7138F88155 \ +--rln-relay-eth-contract-address=0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 \ --rln-relay-eth-client-address=your_sepolia_node \ --rln-relay-cred-path=./rlnKeystore.json \ --rln-relay-cred-password=your_password \ @@ -197,7 +197,7 @@ You can check this fact by looking at `Bob`'s console, where `message3` is missi **Alice** ```bash -./build/chat2 --fleet=test --content-topic=/toy-chat/3/mingde/proto --rln-relay=true --rln-relay-dynamic=true --rln-relay-eth-contract-address=0x9C09146844C1326c2dBC41c451766C7138F88155 --rln-relay-cred-path=rlnKeystore.json --rln-relay-cred-password=password --rln-relay-eth-client-address=wss://sepolia.infura.io/ws/v3/12345678901234567890123456789012 --nickname=Alice +./build/chat2 --fleet=test --content-topic=/toy-chat/3/mingde/proto --rln-relay=true --rln-relay-dynamic=true --rln-relay-eth-contract-address=0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 --rln-relay-cred-path=rlnKeystore.json --rln-relay-cred-password=password --rln-relay-eth-client-address=wss://sepolia.infura.io/ws/v3/12345678901234567890123456789012 --nickname=Alice ``` ``` @@ -247,7 +247,7 @@ INFO RLN Epoch: 165886593 **Bob** ```bash -./build/chat2 --fleet=test --content-topic=/toy-chat/3/mingde/proto --rln-relay=true --rln-relay-dynamic=true --rln-relay-eth-contract-address=0x9C09146844C1326c2dBC41c451766C7138F88155 --rln-relay-cred-path=rlnKeystore.json --rln-relay-cred-index=1 --rln-relay-cred-password=password --rln-relay-eth-client-address=wss://sepolia.infura.io/ws/v3/12345678901234567890123456789012 --nickname=Bob +./build/chat2 --fleet=test --content-topic=/toy-chat/3/mingde/proto --rln-relay=true --rln-relay-dynamic=true --rln-relay-eth-contract-address=0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4 --rln-relay-cred-path=rlnKeystore.json --rln-relay-cred-index=1 --rln-relay-cred-password=password --rln-relay-eth-client-address=wss://sepolia.infura.io/ws/v3/12345678901234567890123456789012 --nickname=Bob ``` ``` diff --git a/examples/rln/README.md b/examples/rln/README.md index aad4461b8..da81f7c12 100644 --- a/examples/rln/README.md +++ b/examples/rln/README.md @@ -10,7 +10,7 @@ Edit `main.go` and set proper values to these constants and variables: ```go const ethClientAddress = "wss://sepolia.infura.io/ws/v3/API_KEY_GOES_HERE" const ethPrivateKey = "PRIVATE_KEY_GOES_HERE" -const contractAddress = "0x9C09146844C1326c2dBC41c451766C7138F88155" +const contractAddress = "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4" const credentialsPath = "" const credentialsPassword = "" diff --git a/examples/rln/main.go b/examples/rln/main.go index 6269ff49d..3c566d8df 100644 --- a/examples/rln/main.go +++ b/examples/rln/main.go @@ -25,13 +25,12 @@ var log = utils.Logger().Named("rln") // Update these values // ============================================================================ -const ethClientAddress = "wss://sepolia.infura.io/ws/v3/API_KEY_GOES_HERE" -const contractAddress = "0x9C09146844C1326c2dBC41c451766C7138F88155" -const keystorePath = "" // Empty to store in current folder -const keystorePassword = "" // Empty to use default -const membershipIndex = 0 - -var contentTopic = protocol.NewContentTopic("rln", 1, "test", "proto").String() +var ethClientAddress = "wss://sepolia.infura.io/ws/v3/API_KEY_GOES_HERE" +var contractAddress = "0xF471d71E9b1455bBF4b85d475afb9BB0954A29c4" +var keystorePath = "./rlnKeystore.json" +var keystorePassword = "password" +var membershipIndex = uint(0) +var contentTopic, _ = protocol.NewContentTopic("rln", 1, "test", "proto") var pubsubTopic = protocol.DefaultPubsubTopic() // ============================================================================ @@ -51,7 +50,7 @@ func main() { ctx := context.Background() - spamHandler := func(message *pb.WakuMessage) error { + spamHandler := func(message *pb.WakuMessage, topic string) error { fmt.Println("Spam message received") return nil } @@ -66,7 +65,7 @@ func main() { keystorePassword, "", // Will use default tree path common.HexToAddress(contractAddress), - membershipIndex, + &membershipIndex, spamHandler, ethClientAddress, ), @@ -120,7 +119,7 @@ func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) { msg := &pb.WakuMessage{ Payload: payload, Version: version, - ContentTopic: contentTopic, + ContentTopic: contentTopic.String(), Timestamp: timestamp, } @@ -150,7 +149,7 @@ func readLoop(ctx context.Context, wakuNode *node.WakuNode) { } for envelope := range sub.Ch { - if envelope.Message().ContentTopic != contentTopic { + if envelope.Message().ContentTopic != contentTopic.String() { continue } diff --git a/scripts/linux/Dockerfile b/scripts/linux/Dockerfile index dd95d2049..9c128b3b3 100644 --- a/scripts/linux/Dockerfile +++ b/scripts/linux/Dockerfile @@ -1,5 +1,5 @@ # BUILD IMAGE -------------------------------------------------------- -FROM ubuntu:18.04 +FROM ubuntu:22.04 ARG UNAME=jenkins ARG UID=1001 ARG GID=1001 diff --git a/waku/v2/protocol/rln/keystore/keystore.go b/waku/v2/protocol/rln/keystore/keystore.go index 0b1e24267..a5bbd46d4 100644 --- a/waku/v2/protocol/rln/keystore/keystore.go +++ b/waku/v2/protocol/rln/keystore/keystore.go @@ -87,6 +87,11 @@ func (k *AppKeystore) GetMembershipCredentials(keystorePassword string, index *r var key Key var err error + + if len(k.Credentials) == 0 { + return nil, nil + } + if len(k.Credentials) == 1 { // Only one credential, the tree index does not matter. k.logger.Warn("automatically loading the only credential found on the keystore") From 22b097817e7508609e586350d7f83965b1dbf4b6 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 14 Sep 2023 20:05:01 -0400 Subject: [PATCH 7/9] feat(rln-relay): use zerokit 0.3.4 to obtain number of leaves set in merkle tree --- examples/basic2/go.mod | 8 ++++---- examples/basic2/go.sum | 16 ++++++++-------- examples/chat2/go.mod | 8 ++++---- examples/chat2/go.sum | 16 ++++++++-------- examples/filter2/go.mod | 8 ++++---- examples/filter2/go.sum | 16 ++++++++-------- examples/rln/go.mod | 8 ++++---- examples/rln/go.sum | 16 ++++++++-------- flake.nix | 2 +- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- .../rln/group_manager/dynamic/dynamic.go | 11 +++++++++-- 12 files changed, 70 insertions(+), 63 deletions(-) diff --git a/examples/basic2/go.mod b/examples/basic2/go.mod index e1f0c53f5..056df94d2 100644 --- a/examples/basic2/go.mod +++ b/examples/basic2/go.mod @@ -107,10 +107,10 @@ require ( github.com/tklauser/numcpus v0.2.2 // indirect github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 // indirect github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 // indirect - github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 // indirect + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/dig v1.17.0 // indirect diff --git a/examples/basic2/go.sum b/examples/basic2/go.sum index 492917d3b..c0e1b90c2 100644 --- a/examples/basic2/go.sum +++ b/examples/basic2/go.sum @@ -644,14 +644,14 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 h1:M5skPFmapY5i5a9jSiGWft9PZMiQr2nCi8uzJc2IfBI= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816/go.mod h1:zc3FBSLP6vy2sOjAnqIju3yKLRq1WkcxsS1Lh9w0CuA= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c h1:aDn17iEMrdXeQ6dp+Cv3ywJYStkomkvKWv8I00iy79c= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 h1:yNRDUyWJu/wHEPLps5D/Zce24mu/5ax2u1pXsMwRPbg= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 h1:dURzhyGtPrpmBJcnY4hpY83dW81cZimkZ8U+S89ANd0= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb h1:jeoCt8oJCEW6qvCFZ+re2WQn/pdIt5Vd63P24bfC1QM= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb/go.mod h1:9QlOve5GEl53rWZQlOahA4kh+sugwYWIQKuexiS2WxI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 h1:bYnGf+NdSDOoxpGmGSiJsaiiDCPcZPMFYwcxMfONUE0= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac h1:50Us7F8/2V0qIpEenexZ7gNRHIPakyYG6GSlpb+MqkY= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 h1:JAQUiPcH26rgkNAPEhLPtRxvPaYiPoLbtbZnmz5ALeI= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8= github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= diff --git a/examples/chat2/go.mod b/examples/chat2/go.mod index 79cb78fb6..3db89917b 100644 --- a/examples/chat2/go.mod +++ b/examples/chat2/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiformats/go-multiaddr v0.10.1 github.com/urfave/cli/v2 v2.24.4 github.com/waku-org/go-waku v0.2.3-0.20221109195301-b2a5a68d28ba - github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb golang.org/x/crypto v0.12.0 golang.org/x/term v0.11.0 google.golang.org/protobuf v1.31.0 @@ -126,9 +126,9 @@ require ( github.com/tklauser/numcpus v0.2.2 // indirect github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 // indirect github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/examples/chat2/go.sum b/examples/chat2/go.sum index 6c6a13376..9f51b59b9 100644 --- a/examples/chat2/go.sum +++ b/examples/chat2/go.sum @@ -679,14 +679,14 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 h1:M5skPFmapY5i5a9jSiGWft9PZMiQr2nCi8uzJc2IfBI= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816/go.mod h1:zc3FBSLP6vy2sOjAnqIju3yKLRq1WkcxsS1Lh9w0CuA= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c h1:aDn17iEMrdXeQ6dp+Cv3ywJYStkomkvKWv8I00iy79c= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 h1:yNRDUyWJu/wHEPLps5D/Zce24mu/5ax2u1pXsMwRPbg= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 h1:dURzhyGtPrpmBJcnY4hpY83dW81cZimkZ8U+S89ANd0= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb h1:jeoCt8oJCEW6qvCFZ+re2WQn/pdIt5Vd63P24bfC1QM= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb/go.mod h1:9QlOve5GEl53rWZQlOahA4kh+sugwYWIQKuexiS2WxI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 h1:bYnGf+NdSDOoxpGmGSiJsaiiDCPcZPMFYwcxMfONUE0= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac h1:50Us7F8/2V0qIpEenexZ7gNRHIPakyYG6GSlpb+MqkY= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 h1:JAQUiPcH26rgkNAPEhLPtRxvPaYiPoLbtbZnmz5ALeI= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8= github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= diff --git a/examples/filter2/go.mod b/examples/filter2/go.mod index 626e01208..13d5346d0 100644 --- a/examples/filter2/go.mod +++ b/examples/filter2/go.mod @@ -106,10 +106,10 @@ require ( github.com/tklauser/numcpus v0.2.2 // indirect github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 // indirect github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 // indirect - github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 // indirect + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/dig v1.17.0 // indirect diff --git a/examples/filter2/go.sum b/examples/filter2/go.sum index 492917d3b..c0e1b90c2 100644 --- a/examples/filter2/go.sum +++ b/examples/filter2/go.sum @@ -644,14 +644,14 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 h1:M5skPFmapY5i5a9jSiGWft9PZMiQr2nCi8uzJc2IfBI= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816/go.mod h1:zc3FBSLP6vy2sOjAnqIju3yKLRq1WkcxsS1Lh9w0CuA= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c h1:aDn17iEMrdXeQ6dp+Cv3ywJYStkomkvKWv8I00iy79c= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 h1:yNRDUyWJu/wHEPLps5D/Zce24mu/5ax2u1pXsMwRPbg= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 h1:dURzhyGtPrpmBJcnY4hpY83dW81cZimkZ8U+S89ANd0= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb h1:jeoCt8oJCEW6qvCFZ+re2WQn/pdIt5Vd63P24bfC1QM= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb/go.mod h1:9QlOve5GEl53rWZQlOahA4kh+sugwYWIQKuexiS2WxI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 h1:bYnGf+NdSDOoxpGmGSiJsaiiDCPcZPMFYwcxMfONUE0= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac h1:50Us7F8/2V0qIpEenexZ7gNRHIPakyYG6GSlpb+MqkY= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 h1:JAQUiPcH26rgkNAPEhLPtRxvPaYiPoLbtbZnmz5ALeI= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8= github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= diff --git a/examples/rln/go.mod b/examples/rln/go.mod index a7a5ca1ba..c2afb22ae 100644 --- a/examples/rln/go.mod +++ b/examples/rln/go.mod @@ -107,10 +107,10 @@ require ( github.com/tklauser/numcpus v0.2.2 // indirect github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 // indirect github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 // indirect - github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 // indirect + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/dig v1.17.0 // indirect diff --git a/examples/rln/go.sum b/examples/rln/go.sum index 492917d3b..c0e1b90c2 100644 --- a/examples/rln/go.sum +++ b/examples/rln/go.sum @@ -644,14 +644,14 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 h1:M5skPFmapY5i5a9jSiGWft9PZMiQr2nCi8uzJc2IfBI= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816/go.mod h1:zc3FBSLP6vy2sOjAnqIju3yKLRq1WkcxsS1Lh9w0CuA= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c h1:aDn17iEMrdXeQ6dp+Cv3ywJYStkomkvKWv8I00iy79c= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 h1:yNRDUyWJu/wHEPLps5D/Zce24mu/5ax2u1pXsMwRPbg= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 h1:dURzhyGtPrpmBJcnY4hpY83dW81cZimkZ8U+S89ANd0= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb h1:jeoCt8oJCEW6qvCFZ+re2WQn/pdIt5Vd63P24bfC1QM= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb/go.mod h1:9QlOve5GEl53rWZQlOahA4kh+sugwYWIQKuexiS2WxI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 h1:bYnGf+NdSDOoxpGmGSiJsaiiDCPcZPMFYwcxMfONUE0= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac h1:50Us7F8/2V0qIpEenexZ7gNRHIPakyYG6GSlpb+MqkY= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 h1:JAQUiPcH26rgkNAPEhLPtRxvPaYiPoLbtbZnmz5ALeI= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8= github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= diff --git a/flake.nix b/flake.nix index fde4446b3..3a7894c6b 100644 --- a/flake.nix +++ b/flake.nix @@ -29,7 +29,7 @@ ]; doCheck = false; # FIXME: This needs to be manually changed when updating modules. - vendorSha256 = "sha256-p8DwZ/tQTHKo98/UUvBKqpWJMxUopbD92FbuWK8L5KA="; + vendorSha256 = "sha256-aF+E7w4HahbkZ2mLmYg38Dma63uSVc+9wy0KZ/b9xVA="; # Fix for 'nix run' trying to execute 'go-waku'. meta = { mainProgram = "waku"; }; }; diff --git a/go.mod b/go.mod index 2812419a5..0db9da6e8 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/jackc/pgx/v5 v5.4.1 github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 github.com/waku-org/go-noise v0.0.4 - github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb github.com/wk8/go-ordered-map v1.0.0 ) @@ -70,9 +70,9 @@ require ( github.com/rjeczalik/notify v0.9.3 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect github.com/status-im/status-go/extkeys v1.1.2 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 // indirect go.uber.org/dig v1.17.0 // indirect go.uber.org/fx v1.20.0 // indirect golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect diff --git a/go.sum b/go.sum index b4a2a5673..d89407925 100644 --- a/go.sum +++ b/go.sum @@ -1535,14 +1535,14 @@ github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0 github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= github.com/waku-org/go-noise v0.0.4 h1:ZfQDcCw8pazm89EBl5SXY7GGAnzDQb9AHFXlw3Ktbvk= github.com/waku-org/go-noise v0.0.4/go.mod h1:+PWRfs2eSOVwKrPcQlfhwDngSh3faL/1QoxvoqggEKc= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816 h1:M5skPFmapY5i5a9jSiGWft9PZMiQr2nCi8uzJc2IfBI= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230905214645-ca686a02e816/go.mod h1:zc3FBSLP6vy2sOjAnqIju3yKLRq1WkcxsS1Lh9w0CuA= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c h1:aDn17iEMrdXeQ6dp+Cv3ywJYStkomkvKWv8I00iy79c= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230905213302-1d6d18a03e7c/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468 h1:yNRDUyWJu/wHEPLps5D/Zce24mu/5ax2u1pXsMwRPbg= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230905183322-05f4cda61468/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866 h1:dURzhyGtPrpmBJcnY4hpY83dW81cZimkZ8U+S89ANd0= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230905182930-2b11e72ef866/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb h1:jeoCt8oJCEW6qvCFZ+re2WQn/pdIt5Vd63P24bfC1QM= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230914234036-e0ebce7c29eb/go.mod h1:9QlOve5GEl53rWZQlOahA4kh+sugwYWIQKuexiS2WxI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9 h1:bYnGf+NdSDOoxpGmGSiJsaiiDCPcZPMFYwcxMfONUE0= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230914230757-87caaeb9e6c9/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac h1:50Us7F8/2V0qIpEenexZ7gNRHIPakyYG6GSlpb+MqkY= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230914230828-f14923ed4dac/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32 h1:JAQUiPcH26rgkNAPEhLPtRxvPaYiPoLbtbZnmz5ALeI= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230914230901-6057b9728a32/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI= diff --git a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go index fdecd309f..13db0393e 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go @@ -171,7 +171,14 @@ func (gm *DynamicGroupManager) Start(ctx context.Context) error { return err } - return gm.MembershipFetcher.HandleGroupUpdates(ctx, gm.handler) + err = gm.MembershipFetcher.HandleGroupUpdates(ctx, gm.handler) + if err != nil { + return err + } + + gm.metrics.RecordRegisteredMembership(gm.rln.LeavesSet()) + + return nil } func (gm *DynamicGroupManager) loadCredential(ctx context.Context) error { @@ -231,7 +238,7 @@ func (gm *DynamicGroupManager) InsertMembers(toInsert *om.OrderedMap) error { } gm.metrics.RecordMembershipInsertionDuration(time.Since(start)) - gm.metrics.RecordRegisteredMembership(startIndex + uint(len(idCommitments))) + gm.metrics.RecordRegisteredMembership(gm.rln.LeavesSet()) _, err = gm.rootTracker.UpdateLatestRoot(pair.Key.(uint64)) if err != nil { From 2060c8c8373f012e7b00ecf0b50336b46d8b6d92 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 14 Sep 2023 17:24:34 -0400 Subject: [PATCH 8/9] feat: allow running rln with no credentials --- cmd/waku/flags_rln.go | 5 ++--- cmd/waku/rlngenerate/flags.go | 3 +-- waku/v2/node/wakunode2.go | 3 ++- waku/v2/node/wakunode2_rln.go | 9 ++++++--- waku/v2/protocol/rln/group_manager/dynamic/dynamic.go | 4 ++++ waku/v2/protocol/rln/keystore/keystore.go | 11 ----------- 6 files changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/waku/flags_rln.go b/cmd/waku/flags_rln.go index be76c35ae..fb5c5062b 100644 --- a/cmd/waku/flags_rln.go +++ b/cmd/waku/flags_rln.go @@ -6,7 +6,6 @@ package main import ( cli "github.com/urfave/cli/v2" wcli "github.com/waku-org/go-waku/waku/cliutils" - "github.com/waku-org/go-waku/waku/v2/protocol/rln/keystore" ) func rlnFlags() []cli.Flag { @@ -32,12 +31,12 @@ func rlnFlags() []cli.Flag { &cli.PathFlag{ Name: "rln-relay-cred-path", Usage: "RLN relay membership credentials file", - Value: keystore.DefaultCredentialsFilename, + Value: "", Destination: &options.RLNRelay.CredentialsPath, }, &cli.StringFlag{ Name: "rln-relay-cred-password", - Value: keystore.DefaultCredentialsPassword, + Value: "", Usage: "Password for encrypting RLN credentials", Destination: &options.RLNRelay.CredentialsPassword, }, diff --git a/cmd/waku/rlngenerate/flags.go b/cmd/waku/rlngenerate/flags.go index 447fb62c2..65fd72649 100644 --- a/cmd/waku/rlngenerate/flags.go +++ b/cmd/waku/rlngenerate/flags.go @@ -6,14 +6,13 @@ package rlngenerate import ( cli "github.com/urfave/cli/v2" wcli "github.com/waku-org/go-waku/waku/cliutils" - "github.com/waku-org/go-waku/waku/v2/protocol/rln/keystore" ) var flags = []cli.Flag{ &cli.PathFlag{ Name: "cred-path", Usage: "RLN relay membership credentials file", - Value: keystore.DefaultCredentialsFilename, + Value: "./rlnKeystore.json", Destination: &options.CredentialsPath, }, &cli.StringFlag{ diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index 540679b42..e074e681a 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -273,6 +273,8 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) { w.rendezvous = rendezvous.NewRendezvous(w.opts.rendezvousDB, w.peerConnector, w.log) + w.relay = relay.NewWakuRelay(w.bcaster, w.opts.minRelayPeersToPublish, w.timesource, w.opts.prometheusReg, w.log, w.opts.pubsubOpts...) + if w.opts.enableRelay { err = w.setupRLNRelay() if err != nil { @@ -280,7 +282,6 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) { } } - w.relay = relay.NewWakuRelay(w.bcaster, w.opts.minRelayPeersToPublish, w.timesource, w.opts.prometheusReg, w.log, w.opts.pubsubOpts...) w.legacyFilter = legacy_filter.NewWakuFilter(w.bcaster, w.opts.isLegacyFilterFullNode, w.timesource, w.opts.prometheusReg, w.log, w.opts.legacyFilterOpts...) w.filterFullNode = filter.NewWakuFilterFullNode(w.timesource, w.opts.prometheusReg, w.log, w.opts.filterOpts...) w.filterLightNode = filter.NewWakuFilterLightNode(w.bcaster, w.peermanager, w.timesource, w.opts.prometheusReg, w.log) diff --git a/waku/v2/node/wakunode2_rln.go b/waku/v2/node/wakunode2_rln.go index 4d93c04b9..5932a9ac4 100644 --- a/waku/v2/node/wakunode2_rln.go +++ b/waku/v2/node/wakunode2_rln.go @@ -59,9 +59,12 @@ func (w *WakuNode) setupRLNRelay() error { } else { w.log.Info("setting up waku-rln-relay in on-chain mode") - appKeystore, err := keystore.New(w.opts.keystorePath, dynamic.RLNAppInfo, w.log) - if err != nil { - return err + var appKeystore *keystore.AppKeystore + if w.opts.keystorePath != "" { + appKeystore, err = keystore.New(w.opts.keystorePath, dynamic.RLNAppInfo, w.log) + if err != nil { + return err + } } groupManager, err = dynamic.NewDynamicGroupManager( diff --git a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go index 13db0393e..4e688735c 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go @@ -182,6 +182,10 @@ func (gm *DynamicGroupManager) Start(ctx context.Context) error { } func (gm *DynamicGroupManager) loadCredential(ctx context.Context) error { + if gm.appKeystore == nil { + gm.log.Warn("no credentials were loaded. Node will only validate messages, but wont be able to generate proofs and attach them to messages") + return nil + } start := time.Now() credentials, err := gm.appKeystore.GetMembershipCredentials( diff --git a/waku/v2/protocol/rln/keystore/keystore.go b/waku/v2/protocol/rln/keystore/keystore.go index a5bbd46d4..32e8ad3ef 100644 --- a/waku/v2/protocol/rln/keystore/keystore.go +++ b/waku/v2/protocol/rln/keystore/keystore.go @@ -15,21 +15,10 @@ import ( "go.uber.org/zap" ) -// DefaultCredentialsFilename is the suggested default filename for the rln credentials keystore -const DefaultCredentialsFilename = "./rlnKeystore.json" - -// DefaultCredentialsPassword is the suggested default password for the rln credentials store -const DefaultCredentialsPassword = "password" - // New creates a new instance of a rln credentials keystore func New(path string, appInfo AppInfo, logger *zap.Logger) (*AppKeystore, error) { logger = logger.Named("rln-keystore") - if path == "" { - logger.Warn("keystore: no credentials path set, using default path", zap.String("path", DefaultCredentialsFilename)) - path = DefaultCredentialsFilename - } - _, err := os.Stat(path) if err != nil { if os.IsNotExist(err) { From fb2df14cb7d214bd89e7fe9f11bf8656efb24891 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sun, 17 Sep 2023 14:53:09 -0400 Subject: [PATCH 9/9] feat: 0.8.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index faef31a43..a3df0a695 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 +0.8.0