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)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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/node"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
"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"
|
"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,
|
Payload: payload,
|
||||||
Version: version,
|
Version: version,
|
||||||
ContentTopic: req.Topic.ContentTopic(),
|
ContentTopic: req.Topic.ContentTopic(),
|
||||||
Timestamp: utils.GetUnixEpoch(),
|
Timestamp: api.w.timestamp(),
|
||||||
Ephemeral: req.Ephemeral,
|
Ephemeral: req.Ephemeral,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
|
func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
|
||||||
w, err := New("", "", nil, nil, nil)
|
w, err := New("", "", nil, nil, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating WakuV2 client: %v", err)
|
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/filter"
|
||||||
"github.com/waku-org/go-waku/waku/v2/protocol/peer_exchange"
|
"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/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/eth-node/types"
|
||||||
"github.com/status-im/status-go/signal"
|
"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/common"
|
||||||
"github.com/status-im/status-go/wakuv2/persistence"
|
"github.com/status-im/status-go/wakuv2/persistence"
|
||||||
|
|
||||||
|
@ -127,10 +129,13 @@ type Waku struct {
|
||||||
timeSource func() time.Time // source of time for waku
|
timeSource func() time.Time // source of time for waku
|
||||||
|
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
|
|
||||||
|
// NTP Synced timesource
|
||||||
|
timesource *timesource.NTPTimeSource
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a WakuV2 client ready to communicate through the LibP2P network.
|
// 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 {
|
if logger == nil {
|
||||||
logger = zap.NewNop()
|
logger = zap.NewNop()
|
||||||
}
|
}
|
||||||
|
@ -1276,6 +1281,13 @@ func (w *Waku) AddStorePeer(address string) (string, error) {
|
||||||
return string(*peerID), nil
|
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 {
|
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))
|
w.logger.Debug("auto-relay asking for peers", zap.Int("num-peers", numPeers))
|
||||||
|
|
Loading…
Reference in New Issue