Use NTP sync source when available
This commit is contained in:
parent
8ac154ee0c
commit
d63d2ca754
|
@ -305,7 +305,7 @@ func (b *StatusNode) wakuV2Service(nodeConfig *params.NodeConfig) (*wakuv2.Waku,
|
|||
}
|
||||
logging.SetAllLoggers(lvl)
|
||||
|
||||
w, err := wakuv2.New(nodeConfig.NodeKey, nodeConfig.ClusterConfig.Fleet, cfg, logutils.ZapLogger(), b.appDB)
|
||||
w, err := wakuv2.New(nodeConfig.NodeKey, nodeConfig.ClusterConfig.Fleet, cfg, logutils.ZapLogger(), b.appDB, b.timeSource())
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
|
||||
"github.com/waku-org/go-waku/waku/v2/node"
|
||||
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
||||
"github.com/waku-org/go-waku/waku/v2/utils"
|
||||
|
||||
"github.com/status-im/status-go/wakuv2/common"
|
||||
|
||||
|
@ -253,7 +252,7 @@ func (api *PublicWakuAPI) Post(ctx context.Context, req NewMessage) (hexutil.Byt
|
|||
Payload: payload,
|
||||
Version: version,
|
||||
ContentTopic: req.Topic.ContentTopic(),
|
||||
Timestamp: utils.GetUnixEpoch(),
|
||||
Timestamp: api.w.timestamp(),
|
||||
Ephemeral: req.Ephemeral,
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
)
|
||||
|
||||
func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
|
||||
w, err := New("", "", nil, nil, nil)
|
||||
w, err := New("", "", nil, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating WakuV2 client: %v", err)
|
||||
}
|
||||
|
|
|
@ -60,9 +60,11 @@ import (
|
|||
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
|
||||
"github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange"
|
||||
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
|
||||
"github.com/waku-org/go-waku/waku/v2/utils"
|
||||
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/signal"
|
||||
"github.com/status-im/status-go/timesource"
|
||||
"github.com/status-im/status-go/wakuv2/common"
|
||||
"github.com/status-im/status-go/wakuv2/persistence"
|
||||
|
||||
|
@ -127,10 +129,13 @@ type Waku struct {
|
|||
timeSource func() time.Time // source of time for waku
|
||||
|
||||
logger *zap.Logger
|
||||
|
||||
// NTP Synced timesource
|
||||
timesource *timesource.NTPTimeSource
|
||||
}
|
||||
|
||||
// New creates a WakuV2 client ready to communicate through the LibP2P network.
|
||||
func New(nodeKey string, fleet string, cfg *Config, logger *zap.Logger, appDB *sql.DB) (*Waku, error) {
|
||||
func New(nodeKey string, fleet string, cfg *Config, logger *zap.Logger, appDB *sql.DB, timesource *timesource.NTPTimeSource) (*Waku, error) {
|
||||
if logger == nil {
|
||||
logger = zap.NewNop()
|
||||
}
|
||||
|
@ -1276,6 +1281,13 @@ func (w *Waku) AddStorePeer(address string) (string, error) {
|
|||
return string(*peerID), nil
|
||||
}
|
||||
|
||||
func (w *Waku) timestamp() int64 {
|
||||
if w.timesource != nil {
|
||||
return w.timesource.Now().UnixNano()
|
||||
}
|
||||
return utils.GetUnixEpoch()
|
||||
}
|
||||
|
||||
func (w *Waku) autoRelayPeerSource(ctx context.Context, numPeers int) <-chan peer.AddrInfo {
|
||||
|
||||
w.logger.Debug("auto-relay asking for peers", zap.Int("num-peers", numPeers))
|
||||
|
|
Loading…
Reference in New Issue