mirror of https://github.com/status-im/go-waku.git
fix: close eth connection on stop
This commit is contained in:
parent
d14e3be64e
commit
7943f8f657
|
@ -57,6 +57,7 @@ type RLNRelay interface {
|
||||||
MembershipKeyPair() MembershipKeyPair
|
MembershipKeyPair() MembershipKeyPair
|
||||||
MembershipIndex() uint
|
MembershipIndex() uint
|
||||||
AppendRLNProof(msg *pb.WakuMessage, senderEpochTime time.Time) error
|
AppendRLNProof(msg *pb.WakuMessage, senderEpochTime time.Time) error
|
||||||
|
Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
type WakuNode struct {
|
type WakuNode struct {
|
||||||
|
@ -363,6 +364,7 @@ func (w *WakuNode) Stop() {
|
||||||
w.relay.Stop()
|
w.relay.Stop()
|
||||||
w.lightPush.Stop()
|
w.lightPush.Stop()
|
||||||
w.store.Stop()
|
w.store.Stop()
|
||||||
|
w.stopRlnRelay()
|
||||||
|
|
||||||
w.host.Close()
|
w.host.Close()
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
package node
|
package node
|
||||||
|
|
||||||
// RLNRelay is used to access any operation related to Waku RLN protocol
|
|
||||||
func (w *WakuNode) RLNRelay() RLNRelay {
|
func (w *WakuNode) RLNRelay() RLNRelay {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -11,3 +10,7 @@ func (w *WakuNode) RLNRelay() RLNRelay {
|
||||||
func (w *WakuNode) mountRlnRelay() error {
|
func (w *WakuNode) mountRlnRelay() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WakuNode) stopRlnRelay() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -94,3 +94,8 @@ func (w *WakuNode) mountRlnRelay() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WakuNode) stopRlnRelay() error {
|
||||||
|
w.rlnRelay.Stop()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -140,8 +140,10 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errChan := make(chan error, 1)
|
||||||
|
|
||||||
// mount the handler for listening to the contract events
|
// mount the handler for listening to the contract events
|
||||||
go rlnPeer.HandleGroupUpdates(handler)
|
go rlnPeer.HandleGroupUpdates(handler, errChan)
|
||||||
|
|
||||||
// Register first member
|
// Register first member
|
||||||
s.register(s.u1PrivKey, toBigInt(keyPair.IDCommitment[:]))
|
s.register(s.u1PrivKey, toBigInt(keyPair.IDCommitment[:]))
|
||||||
|
@ -150,6 +152,14 @@ func (s *WakuRLNRelayDynamicSuite) TestDynamicGroupManagement() {
|
||||||
s.register(s.u2PrivKey, toBigInt(keyPair2.IDCommitment[:]))
|
s.register(s.u2PrivKey, toBigInt(keyPair2.IDCommitment[:]))
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
timer1 := time.NewTimer(2 * time.Second)
|
||||||
|
select {
|
||||||
|
case <-timer1.C:
|
||||||
|
return
|
||||||
|
case err = <-errChan:
|
||||||
|
s.Require().NoError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WakuRLNRelayDynamicSuite) TestInsertKeyMembershipContract() {
|
func (s *WakuRLNRelayDynamicSuite) TestInsertKeyMembershipContract() {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
proto "github.com/golang/protobuf/proto"
|
proto "github.com/golang/protobuf/proto"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
|
@ -40,7 +41,9 @@ type WakuRLNRelay struct {
|
||||||
// TODO may need to erase this ethAccountPrivateKey when is not used
|
// TODO may need to erase this ethAccountPrivateKey when is not used
|
||||||
// TODO may need to make ethAccountPrivateKey mandatory
|
// TODO may need to make ethAccountPrivateKey mandatory
|
||||||
ethAccountPrivateKey *ecdsa.PrivateKey
|
ethAccountPrivateKey *ecdsa.PrivateKey
|
||||||
RLN *r.RLN
|
ethClient *ethclient.Client
|
||||||
|
|
||||||
|
RLN *r.RLN
|
||||||
// pubsubTopic is the topic for which rln relay is mounted
|
// pubsubTopic is the topic for which rln relay is mounted
|
||||||
pubsubTopic string
|
pubsubTopic string
|
||||||
contentTopic string
|
contentTopic string
|
||||||
|
@ -50,6 +53,12 @@ type WakuRLNRelay struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rln *WakuRLNRelay) Stop() {
|
||||||
|
if rln.ethClient != nil {
|
||||||
|
rln.ethClient.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func StaticSetup(rlnRelayMemIndex r.MembershipIndex) ([]r.IDCommitment, r.MembershipKeyPair, r.MembershipIndex, error) {
|
func StaticSetup(rlnRelayMemIndex r.MembershipIndex) ([]r.IDCommitment, r.MembershipKeyPair, r.MembershipIndex, error) {
|
||||||
// static group
|
// static group
|
||||||
groupKeys := r.STATIC_GROUP_KEYS
|
groupKeys := r.STATIC_GROUP_KEYS
|
||||||
|
|
|
@ -125,7 +125,7 @@ func (rln *WakuRLNRelay) HandleGroupUpdates(handler RegistrationEventHandler, er
|
||||||
errChan <- err
|
errChan <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer backend.Close()
|
rln.ethClient = backend
|
||||||
|
|
||||||
rlnContract, err := contracts.NewRLN(rln.membershipContractAddress, backend)
|
rlnContract, err := contracts.NewRLN(rln.membershipContractAddress, backend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -181,6 +181,7 @@ func (rln *WakuRLNRelay) watchNewEvents(rlnContract *contracts.RLN, handler Regi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCh <- err
|
errCh <- err
|
||||||
}
|
}
|
||||||
|
defer subs.Unsubscribe()
|
||||||
|
|
||||||
close(doneCh)
|
close(doneCh)
|
||||||
|
|
||||||
|
@ -189,7 +190,6 @@ func (rln *WakuRLNRelay) watchNewEvents(rlnContract *contracts.RLN, handler Regi
|
||||||
case evt := <-logSink:
|
case evt := <-logSink:
|
||||||
err = processLogs(evt, handler)
|
err = processLogs(evt, handler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: should this stop the chat app?
|
|
||||||
rln.log.Error("processing rln log", zap.Error(err))
|
rln.log.Error("processing rln log", zap.Error(err))
|
||||||
}
|
}
|
||||||
case <-rln.ctx.Done():
|
case <-rln.ctx.Done():
|
||||||
|
@ -197,7 +197,9 @@ func (rln *WakuRLNRelay) watchNewEvents(rlnContract *contracts.RLN, handler Regi
|
||||||
close(logSink)
|
close(logSink)
|
||||||
return
|
return
|
||||||
case err := <-subs.Err():
|
case err := <-subs.Err():
|
||||||
rln.log.Error("watching new events", zap.Error(err))
|
if err != nil {
|
||||||
|
rln.log.Error("watching new events", zap.Error(err))
|
||||||
|
}
|
||||||
close(logSink)
|
close(logSink)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue