introduce the ability to mock time.
This commit is contained in:
+7
-6
@@ -15,6 +15,7 @@ import (
|
||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||
|
||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@@ -67,7 +68,7 @@ func (hs *Service) HandleStream(s inet.Stream) {
|
||||
_ = s.Conn().Close()
|
||||
return
|
||||
}
|
||||
arrived := time.Now()
|
||||
arrived := build.Clock.Now()
|
||||
|
||||
log.Debugw("genesis from hello",
|
||||
"tipset", hmsg.HeaviestTipSet,
|
||||
@@ -82,7 +83,7 @@ func (hs *Service) HandleStream(s inet.Stream) {
|
||||
go func() {
|
||||
defer s.Close() //nolint:errcheck
|
||||
|
||||
sent := time.Now()
|
||||
sent := build.Clock.Now()
|
||||
msg := &LatencyMessage{
|
||||
TArrial: arrived.UnixNano(),
|
||||
TSent: sent.UnixNano(),
|
||||
@@ -99,7 +100,7 @@ func (hs *Service) HandleStream(s inet.Stream) {
|
||||
if len(protos) == 0 {
|
||||
log.Warn("other peer hasnt completed libp2p identify, waiting a bit")
|
||||
// TODO: this better
|
||||
time.Sleep(time.Millisecond * 300)
|
||||
build.Clock.Sleep(time.Millisecond * 300)
|
||||
}
|
||||
|
||||
ts, err := hs.syncer.FetchTipSet(context.Background(), s.Conn().RemotePeer(), types.NewTipSetKey(hmsg.HeaviestTipSet...))
|
||||
@@ -146,7 +147,7 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
|
||||
}
|
||||
log.Debug("Sending hello message: ", hts.Cids(), hts.Height(), gen.Cid())
|
||||
|
||||
t0 := time.Now()
|
||||
t0 := build.Clock.Now()
|
||||
if err := cborutil.WriteCborRPC(s, hmsg); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -155,13 +156,13 @@ func (hs *Service) SayHello(ctx context.Context, pid peer.ID) error {
|
||||
defer s.Close() //nolint:errcheck
|
||||
|
||||
lmsg := &LatencyMessage{}
|
||||
_ = s.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||
_ = s.SetReadDeadline(build.Clock.Now().Add(10 * time.Second))
|
||||
err := cborutil.ReadCborRPC(s, lmsg)
|
||||
if err != nil {
|
||||
log.Infow("reading latency message", "error", err)
|
||||
}
|
||||
|
||||
t3 := time.Now()
|
||||
t3 := build.Clock.Now()
|
||||
lat := t3.Sub(t0)
|
||||
// add to peer tracker
|
||||
if hs.pmgr != nil {
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/ipfs/go-blockservice"
|
||||
"github.com/ipfs/go-cid"
|
||||
@@ -20,6 +19,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime"
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/gen"
|
||||
genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@@ -71,7 +71,7 @@ func MakeGenesis(outFile, genesisTemplate string) func(bs dtypes.ChainBlockstore
|
||||
}
|
||||
|
||||
if template.Timestamp == 0 {
|
||||
template.Timestamp = uint64(time.Now().Unix())
|
||||
template.Timestamp = uint64(build.Clock.Now().Unix())
|
||||
}
|
||||
|
||||
b, err := genesis2.MakeGenesisBlock(context.TODO(), bs, syscalls, template)
|
||||
|
||||
Reference in New Issue
Block a user