Enable lightclient
This commit is contained in:
parent
9a30674590
commit
c3ae0e98fe
|
@ -169,6 +169,10 @@ func defaultNodeConfig(installationID string, request *requests.CreateAccount) (
|
|||
PeerExchange: true,
|
||||
}
|
||||
|
||||
if request.WakuV2LightClient {
|
||||
nodeConfig.WakuV2Config.LightClient = true
|
||||
}
|
||||
|
||||
if request.WakuV2Nameserver != nil {
|
||||
nodeConfig.WakuV2Config.Nameserver = *request.WakuV2Nameserver
|
||||
}
|
||||
|
|
2
go.mod
2
go.mod
|
@ -83,7 +83,7 @@ require (
|
|||
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
||||
github.com/schollz/peerdiscovery v1.7.0
|
||||
github.com/siphiuel/lc-proxy-wrapper v0.0.0-20230516150924-246507cee8c7
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230630125546-47cdb86aaf07
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230703171720-78ed073c7542
|
||||
github.com/wk8/go-ordered-map/v2 v2.1.7
|
||||
github.com/yeqown/go-qrcode/v2 v2.2.1
|
||||
github.com/yeqown/go-qrcode/writer/standard v1.2.1
|
||||
|
|
4
go.sum
4
go.sum
|
@ -2090,8 +2090,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-waku v0.7.1-0.20230630125546-47cdb86aaf07 h1:lH7mSbj0CIjCpCSQDDj9j/YNbI5XEyKXBNFP0lGucE4=
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230630125546-47cdb86aaf07/go.mod h1:+7GhIHEjU3g6dMsYYlmLMJYIGc6ufnEkFxSQ83cSclI=
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230703171720-78ed073c7542 h1:AFsXEAMdzd3v1QmPjWWlnrWGS2bM+cMxLdVJdtO5j3c=
|
||||
github.com/waku-org/go-waku v0.7.1-0.20230703171720-78ed073c7542/go.mod h1:AxFv7fMqSEEi23O7Kq87Hmlqnx4QVVbh0Rvc3f71NQM=
|
||||
github.com/waku-org/go-zerokit-rln v0.1.12 h1:66+tU6sTlmUpuUlEv7kCFOGZ37MwZYFJBXHcm8QquwU=
|
||||
github.com/waku-org/go-zerokit-rln v0.1.12/go.mod h1:MUW+wB6Yj7UBMdZrhko7oHfUZeY2wchggXYjpUiMoac=
|
||||
github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327 h1:Q5XQqo+PEmvrybT8D7BEsKCwIYDi80s+00Q49cfm9Gs=
|
||||
|
|
|
@ -21,7 +21,8 @@ type CreateAccount struct {
|
|||
ImagePath string `json:"imagePath"`
|
||||
CustomizationColor string `json:"customizationColor"`
|
||||
|
||||
WakuV2Nameserver *string `json:"wakuV2Nameserver"`
|
||||
WakuV2Nameserver *string `json:"wakuV2Nameserver"`
|
||||
WakuV2LightClient bool `json:"wakuV2LightClient"`
|
||||
|
||||
LogLevel *string `json:"logLevel"`
|
||||
LogFilePath string `json:"logFilePath"`
|
||||
|
|
|
@ -256,10 +256,6 @@ func (wf *WakuFilterLightnode) getUnsubscribeParameters(opts ...FilterUnsubscrib
|
|||
opt(params)
|
||||
}
|
||||
|
||||
if !params.unsubscribeAll && params.selectedPeer == "" {
|
||||
return nil, ErrNoPeersAvailable
|
||||
}
|
||||
|
||||
return params, nil
|
||||
}
|
||||
|
||||
|
@ -350,7 +346,7 @@ func (wf *WakuFilterLightnode) Unsubscribe(ctx context.Context, contentFilter Co
|
|||
resultChan := make(chan WakuFilterPushResult, len(wf.subscriptions.items))
|
||||
|
||||
for peerID := range wf.subscriptions.items {
|
||||
if !params.unsubscribeAll && peerID != params.selectedPeer {
|
||||
if params.selectedPeer != "" && peerID != params.selectedPeer {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -363,8 +359,13 @@ func (wf *WakuFilterLightnode) Unsubscribe(ctx context.Context, contentFilter Co
|
|||
pb.FilterSubscribeRequest_UNSUBSCRIBE,
|
||||
contentFilter)
|
||||
if err != nil {
|
||||
wf.log.Error("could not unsubscribe from peer", logging.HostID("peerID", peerID), zap.Error(err))
|
||||
return
|
||||
ferr, ok := err.(*FilterError)
|
||||
if ok && ferr.Code == http.StatusNotFound {
|
||||
wf.log.Warn("peer does not have a subscription", logging.HostID("peerID", peerID), zap.Error(err))
|
||||
} else {
|
||||
wf.log.Error("could not unsubscribe from peer", logging.HostID("peerID", peerID), zap.Error(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
wf.cleanupSubscriptions(peerID, contentFilter)
|
||||
|
@ -408,7 +409,7 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte
|
|||
resultChan := make(chan WakuFilterPushResult, len(wf.subscriptions.items))
|
||||
|
||||
for peerID := range wf.subscriptions.items {
|
||||
if !params.unsubscribeAll && peerID != params.selectedPeer {
|
||||
if params.selectedPeer != "" && peerID != params.selectedPeer {
|
||||
continue
|
||||
}
|
||||
localWg.Add(1)
|
||||
|
|
|
@ -999,7 +999,7 @@ github.com/waku-org/go-discover/discover/v5wire
|
|||
github.com/waku-org/go-libp2p-rendezvous
|
||||
github.com/waku-org/go-libp2p-rendezvous/db
|
||||
github.com/waku-org/go-libp2p-rendezvous/pb
|
||||
# github.com/waku-org/go-waku v0.7.1-0.20230630125546-47cdb86aaf07
|
||||
# github.com/waku-org/go-waku v0.7.1-0.20230703171720-78ed073c7542
|
||||
## explicit; go 1.19
|
||||
github.com/waku-org/go-waku/logging
|
||||
github.com/waku-org/go-waku/waku/persistence
|
||||
|
|
|
@ -1462,42 +1462,53 @@ func (w *Waku) seedBootnodesForDiscV5() {
|
|||
return
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(200 * time.Millisecond)
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
var lastTry = time.Now().UnixNano() / int64(time.Millisecond)
|
||||
var retries = 0
|
||||
|
||||
now := func() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||
|
||||
}
|
||||
|
||||
var lastTry = now()
|
||||
|
||||
canQuery := func() bool {
|
||||
backoff := bootnodesQueryBackoffMs * int64(math.Exp2(float64(retries)))
|
||||
|
||||
return lastTry+backoff < now()
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if w.seededBootnodesForDiscV5 {
|
||||
w.logger.Info("stopped querying bootnodes")
|
||||
return
|
||||
if w.seededBootnodesForDiscV5 && len(w.node.Host().Network().Peers()) > 3 {
|
||||
w.logger.Info("not querying bootnodes", zap.Bool("seeded", w.seededBootnodesForDiscV5), zap.Int("peer-count", len(w.node.Host().Network().Peers())))
|
||||
continue
|
||||
}
|
||||
now := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
backoff := bootnodesQueryBackoffMs * int64(math.Exp2(float64(retries)))
|
||||
|
||||
if lastTry+backoff < now {
|
||||
if canQuery() {
|
||||
w.logger.Info("querying bootnodes", zap.Int("peer-count", len(w.node.Host().Network().Peers())))
|
||||
w.logger.Info("querying bootnodes to restore connectivity")
|
||||
err := w.restartDiscV5()
|
||||
if err != nil {
|
||||
w.logger.Warn("failed to restart discv5", zap.Error(err))
|
||||
}
|
||||
|
||||
lastTry = now
|
||||
lastTry = now()
|
||||
retries++
|
||||
// We reset the retries after a while and restart
|
||||
if retries > bootnodesMaxRetries {
|
||||
retries = 0
|
||||
}
|
||||
|
||||
} else {
|
||||
w.logger.Info("can't query bootnodes", zap.Int("peer-count", len(w.node.Host().Network().Peers())))
|
||||
w.logger.Info("can't query", zap.Int64("lastTry", lastTry), zap.Int64("now", now()), zap.Int64("backoff", bootnodesQueryBackoffMs*int64(math.Exp2(float64(retries)))), zap.Int("retries", retries))
|
||||
|
||||
}
|
||||
// If we go online, trigger immediately
|
||||
case <-w.connectionChanged:
|
||||
now := time.Now().UnixNano() / int64(time.Millisecond)
|
||||
backoff := bootnodesQueryBackoffMs * int64(math.Exp2(float64(retries)))
|
||||
// check we haven't run too eagerly, in case connection
|
||||
// is flapping
|
||||
if lastTry+backoff < now {
|
||||
if canQuery() {
|
||||
err := w.restartDiscV5()
|
||||
if err != nil {
|
||||
w.logger.Warn("failed to restart discv5", zap.Error(err))
|
||||
|
@ -1505,7 +1516,7 @@ func (w *Waku) seedBootnodesForDiscV5() {
|
|||
|
||||
}
|
||||
retries = 0
|
||||
lastTry = now
|
||||
lastTry = now()
|
||||
|
||||
case <-w.quit:
|
||||
return
|
||||
|
@ -1525,6 +1536,21 @@ func (w *Waku) restartDiscV5() error {
|
|||
return errors.New("failed to fetch bootnodes")
|
||||
}
|
||||
|
||||
if !w.node.DiscV5().IsStarted() {
|
||||
w.logger.Info("is not started restarting")
|
||||
err := w.node.DiscV5().Start(ctx)
|
||||
if err != nil {
|
||||
w.logger.Error("Could not start DiscV5", zap.Error(err))
|
||||
}
|
||||
} else {
|
||||
w.node.DiscV5().Stop()
|
||||
w.logger.Info("is started restarting")
|
||||
err := w.node.DiscV5().Start(ctx)
|
||||
if err != nil {
|
||||
w.logger.Error("Could not start DiscV5", zap.Error(err))
|
||||
}
|
||||
}
|
||||
|
||||
w.logger.Info("restarting discv5 with nodes", zap.Any("nodes", bootnodes))
|
||||
return w.node.SetDiscV5Bootnodes(bootnodes)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue