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