mirror of https://github.com/status-im/go-waku.git
feat(rln-relay): pass in index to keystore credentials
This commit is contained in:
parent
2b494a384e
commit
a4b038730c
|
@ -17,10 +17,10 @@ func rlnFlags() []cli.Flag {
|
|||
Destination: &options.RLNRelay.Enable,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Name: "rln-relay-membership-index",
|
||||
Name: "rln-relay-membership-group-index",
|
||||
Value: 0,
|
||||
Usage: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
|
||||
Destination: &options.RLNRelay.MembershipIndex,
|
||||
Usage: "the index of credentials to use, within a specific rln membership set",
|
||||
Destination: &options.RLNRelay.MembershipGroupIndex,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "rln-relay-pubsub-topic",
|
||||
|
@ -51,6 +51,12 @@ func rlnFlags() []cli.Flag {
|
|||
Usage: "Password for encrypting RLN credentials",
|
||||
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: consider accepting a private key file and passwd
|
||||
&cli.GenericFlag{
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
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 {
|
||||
|
||||
var ethPrivKey *ecdsa.PrivateKey
|
||||
|
@ -31,7 +31,9 @@ func checkForRLN(logger *zap.Logger, options Options, nodeOpts *[]node.WakuNodeO
|
|||
options.RLNRelay.ContentTopic,
|
||||
options.RLNRelay.CredentialsPath,
|
||||
options.RLNRelay.CredentialsPassword,
|
||||
options.RLNRelay.CredentialsIndex,
|
||||
options.RLNRelay.MembershipContractAddress,
|
||||
rln.MembershipIndex(options.RLNRelay.MembershipGroupIndex),
|
||||
nil,
|
||||
options.RLNRelay.ETHClientAddress,
|
||||
ethPrivKey,
|
||||
|
|
|
@ -37,7 +37,8 @@ type RLNRelayOptions struct {
|
|||
Enable bool
|
||||
CredentialsPath string
|
||||
CredentialsPassword string
|
||||
MembershipIndex int
|
||||
CredentialsIndex int
|
||||
MembershipGroupIndex int
|
||||
PubsubTopic string
|
||||
ContentTopic string
|
||||
Dynamic bool
|
||||
|
|
|
@ -76,7 +76,9 @@ func execute(options Options) {
|
|||
options.RLNRelay.ContentTopic,
|
||||
options.RLNRelay.CredentialsPath,
|
||||
options.RLNRelay.CredentialsPassword,
|
||||
options.RLNRelay.CredentialsIndex,
|
||||
options.RLNRelay.MembershipContractAddress,
|
||||
uint(options.RLNRelay.MembershipIndex),
|
||||
spamHandler,
|
||||
options.RLNRelay.ETHClientAddress,
|
||||
options.RLNRelay.ETHPrivateKey,
|
||||
|
|
|
@ -194,11 +194,17 @@ func getFlags() []cli.Flag {
|
|||
Usage: "Enable spam protection through rln-relay",
|
||||
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{
|
||||
Name: "rln-relay-membership-index",
|
||||
Value: 0,
|
||||
Usage: "(experimental) the index of node in the rln-relay group: a value between 0-99 inclusive",
|
||||
Destination: &options.RLNRelay.MembershipIndex,
|
||||
Usage: "the index of credentials to use",
|
||||
Destination: &options.RLNRelay.CredentialsIndex,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "rln-relay-pubsub-topic",
|
||||
|
|
|
@ -31,6 +31,8 @@ type RLNRelayOptions struct {
|
|||
Enable bool
|
||||
CredentialsPath string
|
||||
CredentialsPassword string
|
||||
CredentialsIndex int
|
||||
MembershipGroupIndex int
|
||||
MembershipIndex int
|
||||
PubsubTopic string
|
||||
ContentTopic string
|
||||
|
|
|
@ -49,8 +49,10 @@ func (w *WakuNode) mountRlnRelay(ctx context.Context) error {
|
|||
w.opts.rlnETHClientAddress,
|
||||
w.opts.rlnETHPrivateKey,
|
||||
w.opts.rlnMembershipContractAddress,
|
||||
w.opts.rlnRelayMemIndex,
|
||||
w.opts.keystorePath,
|
||||
w.opts.keystorePassword,
|
||||
w.opts.keystoreIndex,
|
||||
true,
|
||||
w.opts.rlnRegistrationHandler,
|
||||
w.log,
|
||||
|
|
|
@ -102,6 +102,7 @@ type WakuNodeParameters struct {
|
|||
rlnETHClientAddress string
|
||||
keystorePath string
|
||||
keystorePassword string
|
||||
keystoreIndex int
|
||||
rlnMembershipContractAddress common.Address
|
||||
rlnRegistrationHandler func(tx *types.Transaction)
|
||||
|
||||
|
|
|
@ -27,12 +27,13 @@ func WithStaticRLNRelay(pubsubTopic string, contentTopic string, memberIndex r.M
|
|||
|
||||
// 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(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 {
|
||||
params.enableRLN = true
|
||||
params.rlnRelayDynamic = true
|
||||
params.keystorePassword = keystorePassword
|
||||
params.keystorePath = keystorePath
|
||||
params.keystoreIndex = keystoreIndex
|
||||
params.rlnRelayPubsubTopic = pubsubTopic
|
||||
params.rlnRelayContentTopic = contentTopic
|
||||
params.rlnSpamHandler = spamHandler
|
||||
|
@ -40,6 +41,7 @@ func WithDynamicRLNRelay(pubsubTopic string, contentTopic string, keystorePath s
|
|||
params.rlnETHPrivateKey = ethPrivateKey
|
||||
params.rlnMembershipContractAddress = membershipContract
|
||||
params.rlnRegistrationHandler = registrationHandler
|
||||
params.rlnRelayMemIndex = membershipGroupIndex
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ type DynamicGroupManager struct {
|
|||
membershipIndex *rln.MembershipIndex
|
||||
|
||||
membershipContractAddress common.Address
|
||||
membershipGroupIndex uint
|
||||
ethClientAddress string
|
||||
ethClient *ethclient.Client
|
||||
|
||||
|
@ -55,6 +56,7 @@ type DynamicGroupManager struct {
|
|||
saveKeystore bool
|
||||
keystorePath string
|
||||
keystorePassword string
|
||||
keystoreIndex int
|
||||
|
||||
rootTracker *group_manager.MerkleRootTracker
|
||||
}
|
||||
|
@ -101,8 +103,10 @@ func NewDynamicGroupManager(
|
|||
ethClientAddr string,
|
||||
ethAccountPrivateKey *ecdsa.PrivateKey,
|
||||
memContractAddr common.Address,
|
||||
membershipGroupIndex uint,
|
||||
keystorePath string,
|
||||
keystorePassword string,
|
||||
keystoreIndex int,
|
||||
saveKeystore bool,
|
||||
registrationHandler RegistrationHandler,
|
||||
log *zap.Logger,
|
||||
|
@ -122,6 +126,7 @@ func NewDynamicGroupManager(
|
|||
}
|
||||
|
||||
return &DynamicGroupManager{
|
||||
membershipGroupIndex: membershipGroupIndex,
|
||||
membershipContractAddress: memContractAddr,
|
||||
ethClientAddress: ethClientAddr,
|
||||
ethAccountPrivateKey: ethAccountPrivateKey,
|
||||
|
@ -130,6 +135,7 @@ func NewDynamicGroupManager(
|
|||
saveKeystore: saveKeystore,
|
||||
keystorePath: path,
|
||||
keystorePassword: password,
|
||||
keystoreIndex: keystoreIndex,
|
||||
log: log,
|
||||
}, nil
|
||||
}
|
||||
|
@ -193,10 +199,9 @@ func (gm *DynamicGroupManager) Start(ctx context.Context, rlnInstance *rln.RLN,
|
|||
return err
|
||||
}
|
||||
|
||||
// TODO: accept an index from the config
|
||||
if len(credentials) != 0 {
|
||||
gm.identityCredential = &credentials[0].IdentityCredential
|
||||
gm.membershipIndex = &credentials[0].MembershipGroups[0].TreeIndex
|
||||
if len(credentials) >= gm.keystoreIndex+1 {
|
||||
gm.identityCredential = &credentials[gm.keystoreIndex].IdentityCredential
|
||||
gm.membershipIndex = &credentials[gm.keystoreIndex].MembershipGroups[gm.membershipGroupIndex].TreeIndex
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() {
|
|||
rt, err := group_manager.NewMerkleRootTracker(5, rlnInstance)
|
||||
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)
|
||||
|
||||
// initialize the WakuRLNRelay
|
||||
|
@ -239,7 +239,7 @@ func (s *WakuRLNRelayDynamicSuite) TestMerkleTreeConstruction() {
|
|||
defer sub.Unsubscribe()
|
||||
|
||||
// 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)
|
||||
|
||||
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()
|
||||
|
||||
// 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)
|
||||
|
||||
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()
|
||||
|
||||
// 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)
|
||||
|
||||
rlnRelay2, err := New(relay2, gm2, RLNRELAY_PUBSUB_TOPIC, RLNRELAY_CONTENT_TOPIC, nil, timesource.NewDefaultClock(), utils.Logger())
|
||||
|
|
Loading…
Reference in New Issue