feat(rln-relay): pass in index to keystore credentials

This commit is contained in:
Richard Ramos 2023-07-27 15:51:31 -04:00 committed by richΛrd
parent 2b494a384e
commit a4b038730c
11 changed files with 45 additions and 16 deletions

View File

@ -17,10 +17,10 @@ func rlnFlags() []cli.Flag {
Destination: &options.RLNRelay.Enable, Destination: &options.RLNRelay.Enable,
}, },
&cli.IntFlag{ &cli.IntFlag{
Name: "rln-relay-membership-index", Name: "rln-relay-membership-group-index",
Value: 0, Value: 0,
Usage: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive", Usage: "the index of credentials to use, within a specific rln membership set",
Destination: &options.RLNRelay.MembershipIndex, Destination: &options.RLNRelay.MembershipGroupIndex,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "rln-relay-pubsub-topic", Name: "rln-relay-pubsub-topic",
@ -51,6 +51,12 @@ func rlnFlags() []cli.Flag {
Usage: "Password for encrypting RLN credentials", Usage: "Password for encrypting RLN credentials",
Destination: &options.RLNRelay.CredentialsPassword, Destination: &options.RLNRelay.CredentialsPassword,
}, },
&cli.IntFlag{
Name: "rln-relay-membership-index",
Value: 0,
Usage: "the index of credentials to use",
Destination: &options.RLNRelay.CredentialsIndex,
},
// TODO: this is a good candidate option for subcommands // TODO: this is a good candidate option for subcommands
// TODO: consider accepting a private key file and passwd // TODO: consider accepting a private key file and passwd
&cli.GenericFlag{ &cli.GenericFlag{

View File

@ -18,7 +18,7 @@ func checkForRLN(logger *zap.Logger, options Options, nodeOpts *[]node.WakuNodeO
failOnErr(errors.New("relay not available"), "Could not enable RLN Relay") failOnErr(errors.New("relay not available"), "Could not enable RLN Relay")
} }
if !options.RLNRelay.Dynamic { if !options.RLNRelay.Dynamic {
*nodeOpts = append(*nodeOpts, node.WithStaticRLNRelay(options.RLNRelay.PubsubTopic, options.RLNRelay.ContentTopic, rln.MembershipIndex(options.RLNRelay.MembershipIndex), nil)) *nodeOpts = append(*nodeOpts, node.WithStaticRLNRelay(options.RLNRelay.PubsubTopic, options.RLNRelay.ContentTopic, rln.MembershipIndex(options.RLNRelay.MembershipGroupIndex), nil))
} else { } else {
var ethPrivKey *ecdsa.PrivateKey var ethPrivKey *ecdsa.PrivateKey
@ -31,7 +31,9 @@ func checkForRLN(logger *zap.Logger, options Options, nodeOpts *[]node.WakuNodeO
options.RLNRelay.ContentTopic, options.RLNRelay.ContentTopic,
options.RLNRelay.CredentialsPath, options.RLNRelay.CredentialsPath,
options.RLNRelay.CredentialsPassword, options.RLNRelay.CredentialsPassword,
options.RLNRelay.CredentialsIndex,
options.RLNRelay.MembershipContractAddress, options.RLNRelay.MembershipContractAddress,
rln.MembershipIndex(options.RLNRelay.MembershipGroupIndex),
nil, nil,
options.RLNRelay.ETHClientAddress, options.RLNRelay.ETHClientAddress,
ethPrivKey, ethPrivKey,

View File

@ -37,7 +37,8 @@ type RLNRelayOptions struct {
Enable bool Enable bool
CredentialsPath string CredentialsPath string
CredentialsPassword string CredentialsPassword string
MembershipIndex int CredentialsIndex int
MembershipGroupIndex int
PubsubTopic string PubsubTopic string
ContentTopic string ContentTopic string
Dynamic bool Dynamic bool

View File

@ -76,7 +76,9 @@ func execute(options Options) {
options.RLNRelay.ContentTopic, options.RLNRelay.ContentTopic,
options.RLNRelay.CredentialsPath, options.RLNRelay.CredentialsPath,
options.RLNRelay.CredentialsPassword, options.RLNRelay.CredentialsPassword,
options.RLNRelay.CredentialsIndex,
options.RLNRelay.MembershipContractAddress, options.RLNRelay.MembershipContractAddress,
uint(options.RLNRelay.MembershipIndex),
spamHandler, spamHandler,
options.RLNRelay.ETHClientAddress, options.RLNRelay.ETHClientAddress,
options.RLNRelay.ETHPrivateKey, options.RLNRelay.ETHPrivateKey,

View File

@ -194,11 +194,17 @@ func getFlags() []cli.Flag {
Usage: "Enable spam protection through rln-relay", Usage: "Enable spam protection through rln-relay",
Destination: &options.RLNRelay.Enable, Destination: &options.RLNRelay.Enable,
}, },
&cli.IntFlag{
Name: "rln-relay-membership-group-index",
Value: 0,
Usage: "the index of credentials to use, within a specific rln membership set",
Destination: &options.RLNRelay.MembershipGroupIndex,
},
&cli.IntFlag{ &cli.IntFlag{
Name: "rln-relay-membership-index", Name: "rln-relay-membership-index",
Value: 0, Value: 0,
Usage: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive", Usage: "the index of credentials to use",
Destination: &options.RLNRelay.MembershipIndex, Destination: &options.RLNRelay.CredentialsIndex,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "rln-relay-pubsub-topic", Name: "rln-relay-pubsub-topic",

View File

@ -31,6 +31,8 @@ type RLNRelayOptions struct {
Enable bool Enable bool
CredentialsPath string CredentialsPath string
CredentialsPassword string CredentialsPassword string
CredentialsIndex int
MembershipGroupIndex int
MembershipIndex int MembershipIndex int
PubsubTopic string PubsubTopic string
ContentTopic string ContentTopic string

View File

@ -49,8 +49,10 @@ func (w *WakuNode) mountRlnRelay(ctx context.Context) error {
w.opts.rlnETHClientAddress, w.opts.rlnETHClientAddress,
w.opts.rlnETHPrivateKey, w.opts.rlnETHPrivateKey,
w.opts.rlnMembershipContractAddress, w.opts.rlnMembershipContractAddress,
w.opts.rlnRelayMemIndex,
w.opts.keystorePath, w.opts.keystorePath,
w.opts.keystorePassword, w.opts.keystorePassword,
w.opts.keystoreIndex,
true, true,
w.opts.rlnRegistrationHandler, w.opts.rlnRegistrationHandler,
w.log, w.log,

View File

@ -102,6 +102,7 @@ type WakuNodeParameters struct {
rlnETHClientAddress string rlnETHClientAddress string
keystorePath string keystorePath string
keystorePassword string keystorePassword string
keystoreIndex int
rlnMembershipContractAddress common.Address rlnMembershipContractAddress common.Address
rlnRegistrationHandler func(tx *types.Transaction) rlnRegistrationHandler func(tx *types.Transaction)

View File

@ -27,12 +27,13 @@ func WithStaticRLNRelay(pubsubTopic string, contentTopic string, memberIndex r.M
// WithDynamicRLNRelay enables the Waku V2 RLN protocol in onchain mode. // 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) // Requires the `gowaku_rln` build constrain (or the env variable RLN=true if building go-waku)
func WithDynamicRLNRelay(pubsubTopic string, contentTopic string, keystorePath string, keystorePassword string, membershipContract common.Address, spamHandler rln.SpamHandler, ethClientAddress string, ethPrivateKey *ecdsa.PrivateKey, registrationHandler rln.RegistrationHandler) WakuNodeOption { func WithDynamicRLNRelay(pubsubTopic string, contentTopic string, keystorePath string, keystorePassword string, keystoreIndex int, membershipContract common.Address, membershipGroupIndex uint, spamHandler rln.SpamHandler, ethClientAddress string, ethPrivateKey *ecdsa.PrivateKey, registrationHandler rln.RegistrationHandler) WakuNodeOption {
return func(params *WakuNodeParameters) error { return func(params *WakuNodeParameters) error {
params.enableRLN = true params.enableRLN = true
params.rlnRelayDynamic = true params.rlnRelayDynamic = true
params.keystorePassword = keystorePassword params.keystorePassword = keystorePassword
params.keystorePath = keystorePath params.keystorePath = keystorePath
params.keystoreIndex = keystoreIndex
params.rlnRelayPubsubTopic = pubsubTopic params.rlnRelayPubsubTopic = pubsubTopic
params.rlnRelayContentTopic = contentTopic params.rlnRelayContentTopic = contentTopic
params.rlnSpamHandler = spamHandler params.rlnSpamHandler = spamHandler
@ -40,6 +41,7 @@ func WithDynamicRLNRelay(pubsubTopic string, contentTopic string, keystorePath s
params.rlnETHPrivateKey = ethPrivateKey params.rlnETHPrivateKey = ethPrivateKey
params.rlnMembershipContractAddress = membershipContract params.rlnMembershipContractAddress = membershipContract
params.rlnRegistrationHandler = registrationHandler params.rlnRegistrationHandler = registrationHandler
params.rlnRelayMemIndex = membershipGroupIndex
return nil return nil
} }
} }

View File

@ -37,6 +37,7 @@ type DynamicGroupManager struct {
membershipIndex *rln.MembershipIndex membershipIndex *rln.MembershipIndex
membershipContractAddress common.Address membershipContractAddress common.Address
membershipGroupIndex uint
ethClientAddress string ethClientAddress string
ethClient *ethclient.Client ethClient *ethclient.Client
@ -55,6 +56,7 @@ type DynamicGroupManager struct {
saveKeystore bool saveKeystore bool
keystorePath string keystorePath string
keystorePassword string keystorePassword string
keystoreIndex int
rootTracker *group_manager.MerkleRootTracker rootTracker *group_manager.MerkleRootTracker
} }
@ -101,8 +103,10 @@ func NewDynamicGroupManager(
ethClientAddr string, ethClientAddr string,
ethAccountPrivateKey *ecdsa.PrivateKey, ethAccountPrivateKey *ecdsa.PrivateKey,
memContractAddr common.Address, memContractAddr common.Address,
membershipGroupIndex uint,
keystorePath string, keystorePath string,
keystorePassword string, keystorePassword string,
keystoreIndex int,
saveKeystore bool, saveKeystore bool,
registrationHandler RegistrationHandler, registrationHandler RegistrationHandler,
log *zap.Logger, log *zap.Logger,
@ -122,6 +126,7 @@ func NewDynamicGroupManager(
} }
return &DynamicGroupManager{ return &DynamicGroupManager{
membershipGroupIndex: membershipGroupIndex,
membershipContractAddress: memContractAddr, membershipContractAddress: memContractAddr,
ethClientAddress: ethClientAddr, ethClientAddress: ethClientAddr,
ethAccountPrivateKey: ethAccountPrivateKey, ethAccountPrivateKey: ethAccountPrivateKey,
@ -130,6 +135,7 @@ func NewDynamicGroupManager(
saveKeystore: saveKeystore, saveKeystore: saveKeystore,
keystorePath: path, keystorePath: path,
keystorePassword: password, keystorePassword: password,
keystoreIndex: keystoreIndex,
log: log, log: log,
}, nil }, nil
} }
@ -193,10 +199,9 @@ func (gm *DynamicGroupManager) Start(ctx context.Context, rlnInstance *rln.RLN,
return err return err
} }
// TODO: accept an index from the config if len(credentials) >= gm.keystoreIndex+1 {
if len(credentials) != 0 { gm.identityCredential = &credentials[gm.keystoreIndex].IdentityCredential
gm.identityCredential = &credentials[0].IdentityCredential gm.membershipIndex = &credentials[gm.keystoreIndex].MembershipGroups[gm.membershipGroupIndex].TreeIndex
gm.membershipIndex = &credentials[0].MembershipGroups[0].TreeIndex
} }
} }

View File

@ -138,7 +138,7 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() {
rt, err := group_manager.NewMerkleRootTracker(5, rlnInstance) rt, err := group_manager.NewMerkleRootTracker(5, rlnInstance)
s.Require().NoError(err) s.Require().NoError(err)
gm, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u1PrivKey, s.rlnAddr, "./test_onchain.json", "", false, nil, utils.Logger()) gm, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u1PrivKey, s.rlnAddr, 0, "./test_onchain.json", "", 0, false, nil, utils.Logger())
s.Require().NoError(err) s.Require().NoError(err)
// initialize the WakuRLNRelay // initialize the WakuRLNRelay
@ -239,7 +239,7 @@ func (s *WakuRLNRelayDynamicSuite) TestMerkleTreeConstruction() {
defer sub.Unsubscribe() defer sub.Unsubscribe()
// mount the rln relay protocol in the on-chain/dynamic mode // mount the rln relay protocol in the on-chain/dynamic mode
gm, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u1PrivKey, s.rlnAddr, "./test_onchain.json", "", false, nil, utils.Logger()) gm, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u1PrivKey, s.rlnAddr, 0, "./test_onchain.json", "", 0, false, nil, utils.Logger())
s.Require().NoError(err) s.Require().NoError(err)
rlnRelay, err := New(relay, gm, RLNRELAY_PUBSUB_TOPIC, RLNRELAY_CONTENT_TOPIC, nil, timesource.NewDefaultClock(), utils.Logger()) rlnRelay, err := New(relay, gm, RLNRELAY_PUBSUB_TOPIC, RLNRELAY_CONTENT_TOPIC, nil, timesource.NewDefaultClock(), utils.Logger())
@ -283,7 +283,7 @@ func (s *WakuRLNRelayDynamicSuite) TestCorrectRegistrationOfPeers() {
defer sub1.Unsubscribe() defer sub1.Unsubscribe()
// mount the rln relay protocol in the on-chain/dynamic mode // mount the rln relay protocol in the on-chain/dynamic mode
gm1, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u1PrivKey, s.rlnAddr, "./test_onchain.json", "", false, nil, utils.Logger()) gm1, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u1PrivKey, s.rlnAddr, 0, "./test_onchain.json", "", 0, false, nil, utils.Logger())
s.Require().NoError(err) s.Require().NoError(err)
rlnRelay1, err := New(relay1, gm1, RLNRELAY_PUBSUB_TOPIC, RLNRELAY_CONTENT_TOPIC, nil, timesource.NewDefaultClock(), utils.Logger()) rlnRelay1, err := New(relay1, gm1, RLNRELAY_PUBSUB_TOPIC, RLNRELAY_CONTENT_TOPIC, nil, timesource.NewDefaultClock(), utils.Logger())
@ -309,7 +309,7 @@ func (s *WakuRLNRelayDynamicSuite) TestCorrectRegistrationOfPeers() {
defer sub2.Unsubscribe() defer sub2.Unsubscribe()
// mount the rln relay protocol in the on-chain/dynamic mode // mount the rln relay protocol in the on-chain/dynamic mode
gm2, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u2PrivKey, s.rlnAddr, "./test_onchain.json", "", false, nil, utils.Logger()) gm2, err := dynamic.NewDynamicGroupManager(s.clientAddr, s.u2PrivKey, s.rlnAddr, 0, "./test_onchain.json", "", 0, false, nil, utils.Logger())
s.Require().NoError(err) s.Require().NoError(err)
rlnRelay2, err := New(relay2, gm2, RLNRELAY_PUBSUB_TOPIC, RLNRELAY_CONTENT_TOPIC, nil, timesource.NewDefaultClock(), utils.Logger()) rlnRelay2, err := New(relay2, gm2, RLNRELAY_PUBSUB_TOPIC, RLNRELAY_CONTENT_TOPIC, nil, timesource.NewDefaultClock(), utils.Logger())