Skip to content

Commit

Permalink
feat: allow running rln with no credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Sep 15, 2023
1 parent 22b0978 commit 2060c8c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
5 changes: 2 additions & 3 deletions cmd/waku/flags_rln.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
},
Expand Down
3 changes: 1 addition & 2 deletions cmd/waku/rlngenerate/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion waku/v2/node/wakunode2.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,15 @@ 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 {
return nil, err
}
}

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)
Expand Down
9 changes: 6 additions & 3 deletions waku/v2/node/wakunode2_rln.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions waku/v2/protocol/rln/group_manager/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions waku/v2/protocol/rln/keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2060c8c

Please sign in to comment.