diff --git a/cmd/waku/flags.go b/cmd/waku/flags.go index 053d6d9b1..b0d541578 100644 --- a/cmd/waku/flags.go +++ b/cmd/waku/flags.go @@ -227,7 +227,7 @@ var ( }) Topics = altsrc.NewStringSliceFlag(&cli.StringSliceFlag{ Name: "topic", - Usage: "Default topic to subscribe to. Argument may be repeated", + Usage: "Pubsub topic to subscribe to. Argument may be repeated", Destination: &options.Relay.Topics, EnvVars: []string{"WAKUNODE2_TOPICS"}, }) diff --git a/cmd/waku/flags_rln.go b/cmd/waku/flags_rln.go index 7cd88d89f..4765a4cfd 100644 --- a/cmd/waku/flags_rln.go +++ b/cmd/waku/flags_rln.go @@ -6,6 +6,7 @@ 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" ) func rlnFlags() []cli.Flag { @@ -30,7 +31,7 @@ func rlnFlags() []cli.Flag { }, &cli.StringFlag{ Name: "rln-relay-content-topic", - Value: "/toy-chat/2/luzhou/proto", + Value: protocol.NewContentTopic("toy-chat", 3, "mingde", "proto").String(), Usage: "the content topic for which rln-relay gets enabled", Destination: &options.RLNRelay.ContentTopic, }, diff --git a/examples/basic2/go.mod b/examples/basic2/go.mod index d1984077e..e478fc670 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.13 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 // indirect + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/examples/basic2/go.sum b/examples/basic2/go.sum index 9031c7438..bffd7944b 100644 --- a/examples/basic2/go.sum +++ b/examples/basic2/go.sum @@ -658,14 +658,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.13 h1:9Ti/my7dmpJGNxNpL1MvVurzAjSd6xwBOm2WUZi33Mo= -github.com/waku-org/go-zerokit-rln v0.1.13/go.mod h1:1S6g1KXC45HkDXhIWD9+mdAs9fdyzQy8gtmw4RLjVcM= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e h1:Ad0rJod5F1FuYCJ8SUB/bQZsQwirNHQRE0IcaVloxZo= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a h1:10cre+P76QvnLeyeCVAM8WDbUCri/y5xY3LtwI9Y5DE= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 h1:GseAHwGMixJ2zlY1kFYr3z1Ts0dREIYbgW4yIji9Ksw= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 h1:391fHwCB9ehuSmBim6Vjr9txaEFdM2LWBcfRinyhkFU= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d h1:7Ot7vJAniJWQkarZBFxmjRo39gGksKcqs4kZ10l+szs= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 h1:33LEcvkC5eRdCIKt0bTG6G6DYZRNQGcpdoScA1ZFgRI= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 h1:kJfvDpiZZGNTpHB7Mp4BBNj/hsG6UzMg84E+bl+n7Eo= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005/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/chat.go b/examples/chat2/chat.go index b1de662d9..527077613 100644 --- a/examples/chat2/chat.go +++ b/examples/chat2/chat.go @@ -57,6 +57,11 @@ func NewChat(ctx context.Context, node *node.WakuNode, connNotifier <-chan node. chat.ui = NewUIModel(chat.uiReady, chat.inputChan) + topics := options.Relay.Topics.Value() + if len(topics) == 0 { + topics = append(topics, relay.DefaultWakuTopic) + } + if options.Filter.Enable { cf := filter.ContentFilter{ Topic: relay.DefaultWakuTopic, @@ -77,16 +82,19 @@ func NewChat(ctx context.Context, node *node.WakuNode, connNotifier <-chan node. chat.C = theFilter.C } } else { - sub, err := node.Relay().Subscribe(ctx) - if err != nil { - chat.ui.ErrorMessage(err) - } else { - chat.C = make(chan *protocol.Envelope) - go func() { - for e := range sub.Ch { - chat.C <- e - } - }() + + for _, topic := range topics { + sub, err := node.Relay().SubscribeToTopic(ctx, topic) + if err != nil { + chat.ui.ErrorMessage(err) + } else { + chat.C = make(chan *protocol.Envelope) + go func() { + for e := range sub.Ch { + chat.C <- e + } + }() + } } } diff --git a/examples/chat2/flags.go b/examples/chat2/flags.go index e55d49f2a..e269d5567 100644 --- a/examples/chat2/flags.go +++ b/examples/chat2/flags.go @@ -6,6 +6,7 @@ import ( "github.com/waku-org/go-waku/waku/cliutils" wcli "github.com/waku-org/go-waku/waku/cliutils" "github.com/waku-org/go-waku/waku/v2/protocol" + "github.com/waku-org/go-waku/waku/v2/protocol/relay" "github.com/urfave/cli/v2" ) @@ -34,6 +35,8 @@ func getFlags() []cli.Flag { // Defaults options.Fleet = fleetProd + testnetContentTopic := protocol.NewContentTopic("toy-chat", 3, "mingde", "proto").String() + return []cli.Flag{ &cli.GenericFlag{ Name: "nodekey", @@ -74,7 +77,7 @@ func getFlags() []cli.Flag { &cli.StringFlag{ Name: "content-topic", Usage: "content topic to use for the chat", - Value: protocol.NewContentTopic("toy-chat", 2, "luzhou", "proto").String(), + Value: testnetContentTopic, Destination: &options.ContentTopic, }, &cli.GenericFlag{ @@ -105,8 +108,8 @@ func getFlags() []cli.Flag { Destination: &options.Relay.Enable, }, &cli.StringSliceFlag{ - Name: "topics", - Usage: "List of topics to listen", + Name: "topic", + Usage: "Pubsub topics to subscribe to. Option can be repeated", Destination: &options.Relay.Topics, }, &cli.BoolFlag{ @@ -197,13 +200,13 @@ func getFlags() []cli.Flag { }, &cli.StringFlag{ Name: "rln-relay-pubsub-topic", - Value: "/waku/2/default-waku/proto", + Value: relay.DefaultWakuTopic, Usage: "the pubsub topic for which rln-relay gets enabled", Destination: &options.RLNRelay.PubsubTopic, }, &cli.StringFlag{ Name: "rln-relay-content-topic", - Value: "/toy-chat/2/luzhou/proto", + Value: testnetContentTopic, Usage: "the content topic for which rln-relay gets enabled", Destination: &options.RLNRelay.ContentTopic, }, diff --git a/examples/chat2/go.mod b/examples/chat2/go.mod index 5590953b3..b720a4d59 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.20230807195439-655973b24310 + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 golang.org/x/crypto v0.9.0 golang.org/x/term v0.8.0 google.golang.org/protobuf v1.31.0 diff --git a/examples/chat2/go.sum b/examples/chat2/go.sum index f9e274ae9..e61abd35f 100644 --- a/examples/chat2/go.sum +++ b/examples/chat2/go.sum @@ -693,8 +693,8 @@ 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.20230807195439-655973b24310 h1:/PqVk1fy61o4Wd/ud2qdd8Q9zI3+tpW+GFy/bJ9YTyc= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230807195439-655973b24310/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 h1:391fHwCB9ehuSmBim6Vjr9txaEFdM2LWBcfRinyhkFU= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d h1:7Ot7vJAniJWQkarZBFxmjRo39gGksKcqs4kZ10l+szs= github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 h1:33LEcvkC5eRdCIKt0bTG6G6DYZRNQGcpdoScA1ZFgRI= diff --git a/examples/filter2/go.mod b/examples/filter2/go.mod index 80ea13859..5cc2f1574 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.13 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 // indirect + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/examples/filter2/go.sum b/examples/filter2/go.sum index 9031c7438..bffd7944b 100644 --- a/examples/filter2/go.sum +++ b/examples/filter2/go.sum @@ -658,14 +658,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.13 h1:9Ti/my7dmpJGNxNpL1MvVurzAjSd6xwBOm2WUZi33Mo= -github.com/waku-org/go-zerokit-rln v0.1.13/go.mod h1:1S6g1KXC45HkDXhIWD9+mdAs9fdyzQy8gtmw4RLjVcM= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e h1:Ad0rJod5F1FuYCJ8SUB/bQZsQwirNHQRE0IcaVloxZo= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a h1:10cre+P76QvnLeyeCVAM8WDbUCri/y5xY3LtwI9Y5DE= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 h1:GseAHwGMixJ2zlY1kFYr3z1Ts0dREIYbgW4yIji9Ksw= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 h1:391fHwCB9ehuSmBim6Vjr9txaEFdM2LWBcfRinyhkFU= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d h1:7Ot7vJAniJWQkarZBFxmjRo39gGksKcqs4kZ10l+szs= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 h1:33LEcvkC5eRdCIKt0bTG6G6DYZRNQGcpdoScA1ZFgRI= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 h1:kJfvDpiZZGNTpHB7Mp4BBNj/hsG6UzMg84E+bl+n7Eo= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005/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/noise/go.mod b/examples/noise/go.mod index daaecdf5e..16eb5d44c 100644 --- a/examples/noise/go.mod +++ b/examples/noise/go.mod @@ -109,10 +109,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.13 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 // indirect + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/examples/noise/go.sum b/examples/noise/go.sum index 7e813aa16..b01a8878b 100644 --- a/examples/noise/go.sum +++ b/examples/noise/go.sum @@ -660,14 +660,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.13 h1:9Ti/my7dmpJGNxNpL1MvVurzAjSd6xwBOm2WUZi33Mo= -github.com/waku-org/go-zerokit-rln v0.1.13/go.mod h1:1S6g1KXC45HkDXhIWD9+mdAs9fdyzQy8gtmw4RLjVcM= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e h1:Ad0rJod5F1FuYCJ8SUB/bQZsQwirNHQRE0IcaVloxZo= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a h1:10cre+P76QvnLeyeCVAM8WDbUCri/y5xY3LtwI9Y5DE= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 h1:GseAHwGMixJ2zlY1kFYr3z1Ts0dREIYbgW4yIji9Ksw= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 h1:391fHwCB9ehuSmBim6Vjr9txaEFdM2LWBcfRinyhkFU= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d h1:7Ot7vJAniJWQkarZBFxmjRo39gGksKcqs4kZ10l+szs= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 h1:33LEcvkC5eRdCIKt0bTG6G6DYZRNQGcpdoScA1ZFgRI= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 h1:kJfvDpiZZGNTpHB7Mp4BBNj/hsG6UzMg84E+bl+n7Eo= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005/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 b16aa4fc6..cb90e9bb5 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.13 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 // indirect + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/examples/rln/go.sum b/examples/rln/go.sum index 9031c7438..bffd7944b 100644 --- a/examples/rln/go.sum +++ b/examples/rln/go.sum @@ -658,14 +658,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.13 h1:9Ti/my7dmpJGNxNpL1MvVurzAjSd6xwBOm2WUZi33Mo= -github.com/waku-org/go-zerokit-rln v0.1.13/go.mod h1:1S6g1KXC45HkDXhIWD9+mdAs9fdyzQy8gtmw4RLjVcM= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e h1:Ad0rJod5F1FuYCJ8SUB/bQZsQwirNHQRE0IcaVloxZo= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a h1:10cre+P76QvnLeyeCVAM8WDbUCri/y5xY3LtwI9Y5DE= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 h1:GseAHwGMixJ2zlY1kFYr3z1Ts0dREIYbgW4yIji9Ksw= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 h1:391fHwCB9ehuSmBim6Vjr9txaEFdM2LWBcfRinyhkFU= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d h1:7Ot7vJAniJWQkarZBFxmjRo39gGksKcqs4kZ10l+szs= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 h1:33LEcvkC5eRdCIKt0bTG6G6DYZRNQGcpdoScA1ZFgRI= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005 h1:kJfvDpiZZGNTpHB7Mp4BBNj/hsG6UzMg84E+bl+n7Eo= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230807124913-ea636e5b4005/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 ef043ab1f..e5e28a2e0 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,7 @@ ]; doCheck = false; # FIXME: This needs to be manually changed when updating modules. - vendorSha256 = "sha256-AeCfDWWPeOir0IyfH+/057YBRKv6oHxC+g84YycySJU="; + vendorSha256 = "sha256-yh9ZgQpz1oDkmT65gbad+rb4pOBo8YD/pRv53pDWr2c="; # Fix for 'nix run' trying to execute 'go-waku'. meta = { mainProgram = "waku"; }; }; diff --git a/go.mod b/go.mod index 13998910f..233a1a1d6 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,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.20230807195439-655973b24310 + github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 github.com/wk8/go-ordered-map v1.0.0 ) diff --git a/go.sum b/go.sum index b8808942e..95a96815c 100644 --- a/go.sum +++ b/go.sum @@ -1554,8 +1554,8 @@ 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.20230807195439-655973b24310 h1:/PqVk1fy61o4Wd/ud2qdd8Q9zI3+tpW+GFy/bJ9YTyc= -github.com/waku-org/go-zerokit-rln v0.1.14-0.20230807195439-655973b24310/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585 h1:391fHwCB9ehuSmBim6Vjr9txaEFdM2LWBcfRinyhkFU= +github.com/waku-org/go-zerokit-rln v0.1.14-0.20230817221953-1ccba817b585/go.mod h1:4KuePn2B86JtUH5U6VYd432A/KI8gHSqoX98Gh4EBbI= github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d h1:7Ot7vJAniJWQkarZBFxmjRo39gGksKcqs4kZ10l+szs= github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230807124901-05ef8aca570d/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230807124929-ea702b1b4305 h1:33LEcvkC5eRdCIKt0bTG6G6DYZRNQGcpdoScA1ZFgRI= diff --git a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go index de3b18fcc..7926add08 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/dynamic.go @@ -303,7 +303,7 @@ func (gm *DynamicGroupManager) InsertMembers(toInsert *om.OrderedMap) error { if oldestIndexInBlock == nil { oldestIndexInBlock = evt.Index } - idCommitments = append(idCommitments, rln.Bytes32(evt.Pubkey.Bytes())) + idCommitments = append(idCommitments, rln.BigIntToBytes32(evt.Pubkey)) } if len(idCommitments) == 0 { @@ -361,6 +361,7 @@ func (gm *DynamicGroupManager) MembershipIndex() (rln.MembershipIndex, error) { return *gm.membershipIndex, nil } +// Stop stops all go-routines, eth client and closes the rln database func (gm *DynamicGroupManager) Stop() error { if gm.cancel == nil { return nil diff --git a/waku/v2/protocol/rln/group_manager/dynamic/handler_test.go b/waku/v2/protocol/rln/group_manager/dynamic/handler_test.go index 94df42a48..b20e542ed 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/handler_test.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/handler_test.go @@ -60,7 +60,7 @@ func TestHandler(t *testing.T) { require.Len(t, roots, 2) require.Equal(t, root0, roots[0]) - require.Equal(t, [32]byte{0x96, 0x65, 0xdb, 0xbc, 0x28, 0x6b, 0x1f, 0xc6, 0xab, 0x2d, 0x82, 0xe, 0x30, 0xe0, 0xc1, 0x92, 0x32, 0x73, 0xd2, 0xd6, 0xe1, 0x21, 0xef, 0xa1, 0xc8, 0xa6, 0xa6, 0xd, 0x9, 0x7c, 0x85, 0x19}, roots[1]) + require.Equal(t, [32]byte{0x1c, 0xe4, 0x6b, 0x9a, 0xb2, 0x54, 0xa1, 0xb0, 0x2, 0x77, 0xbf, 0xc0, 0xf6, 0x27, 0x38, 0x38, 0x8f, 0xc8, 0x6a, 0x3d, 0x18, 0xe3, 0x1a, 0xd, 0xdd, 0xb8, 0xe5, 0x38, 0xf5, 0x9e, 0xc3, 0x16}, roots[1]) events = []*contracts.RLNMemberRegistered{ eventBuilder(1, false, 0xbbbb, 2), @@ -75,7 +75,7 @@ func TestHandler(t *testing.T) { // Root[1] should become [0] roots = gm.rootTracker.Roots() require.Len(t, roots, 5) - require.Equal(t, [32]byte{0x96, 0x65, 0xdb, 0xbc, 0x28, 0x6b, 0x1f, 0xc6, 0xab, 0x2d, 0x82, 0xe, 0x30, 0xe0, 0xc1, 0x92, 0x32, 0x73, 0xd2, 0xd6, 0xe1, 0x21, 0xef, 0xa1, 0xc8, 0xa6, 0xa6, 0xd, 0x9, 0x7c, 0x85, 0x19}, roots[0]) + require.Equal(t, [32]byte{0x1c, 0xe4, 0x6b, 0x9a, 0xb2, 0x54, 0xa1, 0xb0, 0x2, 0x77, 0xbf, 0xc0, 0xf6, 0x27, 0x38, 0x38, 0x8f, 0xc8, 0x6a, 0x3d, 0x18, 0xe3, 0x1a, 0xd, 0xdd, 0xb8, 0xe5, 0x38, 0xf5, 0x9e, 0xc3, 0x16}, roots[0]) require.Len(t, rootTracker.Buffer(), 1) require.Equal(t, root0, rootTracker.Buffer()[0]) diff --git a/waku/v2/protocol/rln/group_manager/dynamic/metadata.go b/waku/v2/protocol/rln/group_manager/dynamic/metadata.go index 255b1dabc..e709b87db 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/metadata.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/metadata.go @@ -5,16 +5,19 @@ import ( "errors" ) +// RLNMetadata persists attributes in the RLN database type RLNMetadata struct { LastProcessedBlock uint64 } +// Serialize converts a RLNMetadata into a binary format expected by zerokit's RLN func (r RLNMetadata) Serialize() []byte { result := make([]byte, 8) binary.LittleEndian.PutUint64(result, r.LastProcessedBlock) return result } +// DeserializeMetadata converts a byte slice into a RLNMetadata instance func DeserializeMetadata(b []byte) (RLNMetadata, error) { if len(b) != 8 { return RLNMetadata{}, errors.New("wrong size") @@ -24,11 +27,13 @@ func DeserializeMetadata(b []byte) (RLNMetadata, error) { }, nil } +// SetMetadata stores some metadata into the zerokit's RLN database func (gm *DynamicGroupManager) SetMetadata(meta RLNMetadata) error { b := meta.Serialize() return gm.rln.SetMetadata(b) } +// GetMetadata retrieves metadata from the zerokit's RLN database func (gm *DynamicGroupManager) GetMetadata() (RLNMetadata, error) { b, err := gm.rln.GetMetadata() if err != nil { diff --git a/waku/v2/protocol/rln/group_manager/dynamic/web3.go b/waku/v2/protocol/rln/group_manager/dynamic/web3.go index 83a1681b8..92f8f2b37 100644 --- a/waku/v2/protocol/rln/group_manager/dynamic/web3.go +++ b/waku/v2/protocol/rln/group_manager/dynamic/web3.go @@ -13,17 +13,11 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/rpc" "github.com/waku-org/go-waku/waku/v2/protocol/rln/contracts" - r "github.com/waku-org/go-zerokit-rln/rln" + "github.com/waku-org/go-zerokit-rln/rln" "go.uber.org/zap" ) -func ToBigInt(i []byte) *big.Int { - result := new(big.Int) - result.SetBytes(i[:]) - return result -} - -func register(ctx context.Context, backend *ethclient.Client, membershipFee *big.Int, idComm r.IDCommitment, ethAccountPrivateKey *ecdsa.PrivateKey, rlnContract *contracts.RLN, chainID *big.Int, registrationHandler RegistrationHandler, log *zap.Logger) (*r.MembershipIndex, error) { +func register(ctx context.Context, backend *ethclient.Client, membershipFee *big.Int, idComm rln.IDCommitment, ethAccountPrivateKey *ecdsa.PrivateKey, rlnContract *contracts.RLN, chainID *big.Int, registrationHandler RegistrationHandler, log *zap.Logger) (*rln.MembershipIndex, error) { auth, err := bind.NewKeyedTransactorWithChainID(ethAccountPrivateKey, chainID) if err != nil { return nil, err @@ -34,7 +28,7 @@ func register(ctx context.Context, backend *ethclient.Client, membershipFee *big log.Debug("registering an id commitment", zap.Binary("idComm", idComm[:])) // registers the idComm into the membership contract whose address is in rlnPeer.membershipContractAddress - tx, err := rlnContract.Register(auth, ToBigInt(idComm[:])) + tx, err := rlnContract.Register(auth, rln.Bytes32ToBigInt(idComm)) if err != nil { return nil, err } @@ -60,16 +54,16 @@ func register(ctx context.Context, backend *ethclient.Client, membershipFee *big return nil, err } - var eventIdComm r.IDCommitment = r.Bytes32(evt.Pubkey.Bytes()) + var eventIDComm rln.IDCommitment = rln.BigIntToBytes32(evt.Pubkey) - log.Debug("the identity commitment key extracted from tx log", zap.Binary("eventIdComm", eventIdComm[:])) + log.Debug("the identity commitment key extracted from tx log", zap.Binary("eventIDComm", eventIDComm[:])) - if eventIdComm != idComm { + if eventIDComm != idComm { return nil, errors.New("invalid id commitment key") } - result := new(r.MembershipIndex) - *result = r.MembershipIndex(uint(evt.Index.Int64())) + result := new(rln.MembershipIndex) + *result = rln.MembershipIndex(uint(evt.Index.Int64())) // debug "the index of registered identity commitment key", eventIndex=eventIndex @@ -80,7 +74,7 @@ func register(ctx context.Context, backend *ethclient.Client, membershipFee *big // Register registers the public key of the rlnPeer which is rlnPeer.membershipKeyPair.publicKey // into the membership contract whose address is in rlnPeer.membershipContractAddress -func (gm *DynamicGroupManager) Register(ctx context.Context) (*r.MembershipIndex, error) { +func (gm *DynamicGroupManager) Register(ctx context.Context) (*rln.MembershipIndex, error) { return register(ctx, gm.ethClient, gm.membershipFee, @@ -112,9 +106,8 @@ func (gm *DynamicGroupManager) HandleGroupUpdates(ctx context.Context, handler R } func (gm *DynamicGroupManager) loadOldEvents(ctx context.Context, rlnContract *contracts.RLN, handler RegistrationEventHandler) error { - - metadata, err := gm.GetMetadata() fromBlock := uint64(0) + metadata, err := gm.GetMetadata() if err == nil { fromBlock = metadata.LastProcessedBlock gm.log.Info("resuming onchain sync", zap.Uint64("fromBlock", fromBlock)) @@ -161,7 +154,6 @@ func (gm *DynamicGroupManager) watchNewEvents(ctx context.Context, rlnContract * events, err := gm.getEvents(ctx, blk, &blk) if err != nil { gm.log.Error("obtaining rln events", zap.Error(err)) - } err = handler(gm, events) @@ -204,6 +196,11 @@ func (gm *DynamicGroupManager) getEvents(ctx context.Context, from uint64, to *u toBlock = &blockNumber } + if from == *toBlock { // Only loading a single block + return gm.fetchEvents(ctx, from, toBlock) + } + + // Fetching blocks in batches batchSize := maxBatchSize additiveFactor := uint64(float64(batchSize) * additiveFactorMultiplier) diff --git a/waku/v2/protocol/rln/group_manager/static/static.go b/waku/v2/protocol/rln/group_manager/static/static.go index d8ff89bea..fb2c44552 100644 --- a/waku/v2/protocol/rln/group_manager/static/static.go +++ b/waku/v2/protocol/rln/group_manager/static/static.go @@ -93,6 +93,7 @@ func (gm *StaticGroupManager) MembershipIndex() (rln.MembershipIndex, error) { return *gm.membershipIndex, nil } +// Stop is a function created just to comply with the GroupManager interface (it does nothing) func (gm *StaticGroupManager) Stop() error { // Do nothing return nil diff --git a/waku/v2/protocol/rln/onchain_test.go b/waku/v2/protocol/rln/onchain_test.go index a431a4dce..40e48f41c 100644 --- a/waku/v2/protocol/rln/onchain_test.go +++ b/waku/v2/protocol/rln/onchain_test.go @@ -15,7 +15,6 @@ import ( "time" "github.com/waku-org/go-zerokit-rln/rln" - r "github.com/waku-org/go-zerokit-rln/rln" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -120,7 +119,7 @@ func (s *WakuRLNRelayDynamicSuite) register(privKey *ecdsa.PrivateKey, commitmen func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() { // Create a RLN instance - rlnInstance, err := r.NewRLN() + rlnInstance, err := rln.NewRLN() s.Require().NoError(err) port, err := tests.FindFreePort(s.T(), "", 5) @@ -148,7 +147,7 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() { relay: relay, RLN: rlnInstance, log: utils.Logger(), - nullifierLog: make(map[r.MerkleNode][]r.ProofMetadata), + nullifierLog: make(map[rln.MerkleNode][]rln.ProofMetadata), } // generate another membership key pair @@ -162,7 +161,7 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() { gm.Register(context.TODO()) handler := func(evt *contracts.RLNMemberRegistered) error { - pubkey := rln.Bytes32(evt.Pubkey.Bytes()) + pubkey := rln.BigIntToBytes32(evt.Pubkey) if !bytes.Equal(pubkey[:], keyPair2.IDCommitment[:]) { return errors.New("not found") } @@ -171,7 +170,7 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() { } // register member with contract - s.register(s.u2PrivKey, dynamic.ToBigInt(keyPair2.IDCommitment[:]), handler) + s.register(s.u2PrivKey, rln.Bytes32ToBigInt(keyPair2.IDCommitment), handler) time.Sleep(2 * time.Second) } @@ -196,7 +195,7 @@ func (s *WakuRLNRelayDynamicSuite) TestInsertKeyMembershipContract() { func (s *WakuRLNRelayDynamicSuite) TestMerkleTreeConstruction() { // Create a RLN instance - rlnInstance, err := r.NewRLN() + rlnInstance, err := rln.NewRLN() s.Require().NoError(err) keyPair1, err := rlnInstance.MembershipKeyGen() @@ -216,8 +215,8 @@ func (s *WakuRLNRelayDynamicSuite) TestMerkleTreeConstruction() { s.Require().NoError(err) // register the members to the contract - s.register(s.u1PrivKey, dynamic.ToBigInt(keyPair1.IDCommitment[:]), nil) - s.register(s.u1PrivKey, dynamic.ToBigInt(keyPair2.IDCommitment[:]), nil) + s.register(s.u1PrivKey, rln.Bytes32ToBigInt(keyPair1.IDCommitment), nil) + s.register(s.u1PrivKey, rln.Bytes32ToBigInt(keyPair2.IDCommitment), nil) // Creating relay port, err := tests.FindFreePort(s.T(), "", 5) @@ -326,6 +325,6 @@ func (s *WakuRLNRelayDynamicSuite) TestCorrectRegistrationOfPeers() { idx2, err := rlnRelay2.groupManager.MembershipIndex() s.Require().NoError(err) - s.Require().Equal(r.MembershipIndex(0), idx1) - s.Require().Equal(r.MembershipIndex(1), idx2) + s.Require().Equal(rln.MembershipIndex(0), idx1) + s.Require().Equal(rln.MembershipIndex(1), idx2) } diff --git a/waku/v2/protocol/rln/waku_rln_relay.go b/waku/v2/protocol/rln/waku_rln_relay.go index 096062b94..9a01367f5 100644 --- a/waku/v2/protocol/rln/waku_rln_relay.go +++ b/waku/v2/protocol/rln/waku_rln_relay.go @@ -49,8 +49,7 @@ type WakuRLNRelay struct { log *zap.Logger } -const rlnDefaultDepth = 20 -const rlnDefaultTreePath = "rln_tree.db" +const rlnDefaultTreePath = "./rln_tree.db" func New( relay *relay.WakuRelay, @@ -66,16 +65,12 @@ func New( treePath = rlnDefaultTreePath } - // TODO: add a constant in go-zerokit-rln with 20 instead of having the constant in go-waku - rlnInstance, err := rln.NewWithConfig(rlnDefaultDepth, &rln.Config{ - ResourcesFolder: "tree_height_20", - TreeConfig: &rln.TreeConfig{ - CacheCapacity: 15000, - Mode: "high_throughput", // TODO: find out in zerokit the possible values - Compression: false, - FlushInterval: 12000, - Path: treePath, - }, + rlnInstance, err := rln.NewWithConfig(rln.DefaultTreeDepth, &rln.TreeConfig{ + CacheCapacity: 15000, + Mode: rln.HighThroughput, + Compression: false, + FlushInterval: 500, + Path: treePath, }) if err != nil { return nil, err @@ -122,6 +117,7 @@ func (rlnRelay *WakuRLNRelay) Start(ctx context.Context) error { return nil } +// Stop will stop any operation or goroutine started while using WakuRLNRelay func (rlnRelay *WakuRLNRelay) Stop() error { return rlnRelay.groupManager.Stop() }