rename build.{BlockDelay=>BlockDelaySecs}.
Since this global is not typed as a time.Duration, rather as an int, it makes sense to clarify the unit.
This commit is contained in:
parent
612b2fe9d7
commit
4f9c907248
@ -21,7 +21,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Seconds
|
// Seconds
|
||||||
const BlockDelay = 2
|
const BlockDelaySecs = 2
|
||||||
|
|
||||||
const PropagationDelay = 3
|
const PropagationDelay = 3
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ var (
|
|||||||
BlocksPerEpoch = uint64(builtin.ExpectedLeadersPerEpoch)
|
BlocksPerEpoch = uint64(builtin.ExpectedLeadersPerEpoch)
|
||||||
BlockMessageLimit = 512
|
BlockMessageLimit = 512
|
||||||
BlockGasLimit = int64(100_000_000_000)
|
BlockGasLimit = int64(100_000_000_000)
|
||||||
BlockDelay = uint64(builtin.EpochDurationSeconds)
|
BlockDelaySecs = uint64(builtin.EpochDurationSeconds)
|
||||||
PropagationDelay = uint64(6)
|
PropagationDelay = uint64(6)
|
||||||
|
|
||||||
AllowableClockDrift = uint64(1)
|
AllowableClockDrift = uint64(1)
|
||||||
|
@ -21,6 +21,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Seconds
|
// Seconds
|
||||||
const BlockDelay = builtin.EpochDurationSeconds
|
const BlockDelaySecs = builtin.EpochDurationSeconds
|
||||||
|
|
||||||
const PropagationDelay = 6
|
const PropagationDelay = 6
|
||||||
|
@ -196,7 +196,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
|
|||||||
*genm2,
|
*genm2,
|
||||||
},
|
},
|
||||||
NetworkName: "",
|
NetworkName: "",
|
||||||
Timestamp: uint64(time.Now().Add(-500 * time.Duration(build.BlockDelay) * time.Second).Unix()),
|
Timestamp: uint64(time.Now().Add(-500 * time.Duration(build.BlockDelaySecs) * time.Second).Unix()),
|
||||||
}
|
}
|
||||||
|
|
||||||
genb, err := genesis2.MakeGenesisBlock(context.TODO(), bs, sys, tpl)
|
genb, err := genesis2.MakeGenesisBlock(context.TODO(), bs, sys, tpl)
|
||||||
@ -223,7 +223,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
|
|||||||
miners := []address.Address{maddr1, maddr2}
|
miners := []address.Address{maddr1, maddr2}
|
||||||
|
|
||||||
beac := beacon.NewMockBeacon(time.Second)
|
beac := beacon.NewMockBeacon(time.Second)
|
||||||
//beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay)
|
//beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelaySecs)
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
//return nil, xerrors.Errorf("creating drand beacon: %w", err)
|
//return nil, xerrors.Errorf("creating drand beacon: %w", err)
|
||||||
//}
|
//}
|
||||||
@ -414,7 +414,7 @@ func (cg *ChainGen) makeBlock(parents *types.TipSet, m address.Address, vrfticke
|
|||||||
if cg.Timestamper != nil {
|
if cg.Timestamper != nil {
|
||||||
ts = cg.Timestamper(parents, height-parents.Height())
|
ts = cg.Timestamper(parents, height-parents.Height())
|
||||||
} else {
|
} else {
|
||||||
ts = parents.MinTimestamp() + uint64(height-parents.Height())*uint64(build.BlockDelay)
|
ts = parents.MinTimestamp() + uint64(height-parents.Height())*uint64(build.BlockDelaySecs)
|
||||||
}
|
}
|
||||||
|
|
||||||
fblk, err := MinerCreateBlock(context.TODO(), cg.sm, cg.w, &api.BlockTemplate{
|
fblk, err := MinerCreateBlock(context.TODO(), cg.sm, cg.w, &api.BlockTemplate{
|
||||||
|
@ -187,7 +187,7 @@ func New(api Provider, ds dtypes.MetadataDS, netName dtypes.NetworkName) (*Messa
|
|||||||
|
|
||||||
mp := &MessagePool{
|
mp := &MessagePool{
|
||||||
closer: make(chan struct{}),
|
closer: make(chan struct{}),
|
||||||
repubTk: time.NewTicker(time.Duration(build.BlockDelay) * 10 * time.Second),
|
repubTk: time.NewTicker(time.Duration(build.BlockDelaySecs) * 10 * time.Second),
|
||||||
localAddrs: make(map[address.Address]struct{}),
|
localAddrs: make(map[address.Address]struct{}),
|
||||||
pending: make(map[address.Address]*msgSet),
|
pending: make(map[address.Address]*msgSet),
|
||||||
minGasPrice: types.NewInt(0),
|
minGasPrice: types.NewInt(0),
|
||||||
|
@ -664,11 +664,11 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er
|
|||||||
log.Warn("Got block from the future, but within threshold", h.Timestamp, time.Now().Unix())
|
log.Warn("Got block from the future, but within threshold", h.Timestamp, time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
if h.Timestamp < baseTs.MinTimestamp()+(build.BlockDelay*uint64(h.Height-baseTs.Height())) {
|
if h.Timestamp < baseTs.MinTimestamp()+(build.BlockDelaySecs*uint64(h.Height-baseTs.Height())) {
|
||||||
log.Warn("timestamp funtimes: ", h.Timestamp, baseTs.MinTimestamp(), h.Height, baseTs.Height())
|
log.Warn("timestamp funtimes: ", h.Timestamp, baseTs.MinTimestamp(), h.Height, baseTs.Height())
|
||||||
diff := (baseTs.MinTimestamp() + (build.BlockDelay * uint64(h.Height-baseTs.Height()))) - h.Timestamp
|
diff := (baseTs.MinTimestamp() + (build.BlockDelaySecs * uint64(h.Height-baseTs.Height()))) - h.Timestamp
|
||||||
|
|
||||||
return xerrors.Errorf("block was generated too soon (h.ts:%d < base.mints:%d + BLOCK_DELAY:%d * deltaH:%d; diff %d)", h.Timestamp, baseTs.MinTimestamp(), build.BlockDelay, h.Height-baseTs.Height(), diff)
|
return xerrors.Errorf("block was generated too soon (h.ts:%d < base.mints:%d + BLOCK_DELAY:%d * deltaH:%d; diff %d)", h.Timestamp, baseTs.MinTimestamp(), build.BlockDelaySecs, h.Height-baseTs.Height(), diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
msgsCheck := async.Err(func() error {
|
msgsCheck := async.Err(func() error {
|
||||||
|
@ -408,7 +408,7 @@ func TestSyncBadTimestamp(t *testing.T) {
|
|||||||
|
|
||||||
base := tu.g.CurTipset
|
base := tu.g.CurTipset
|
||||||
tu.g.Timestamper = func(pts *types.TipSet, tl abi.ChainEpoch) uint64 {
|
tu.g.Timestamper = func(pts *types.TipSet, tl abi.ChainEpoch) uint64 {
|
||||||
return pts.MinTimestamp() + (build.BlockDelay / 2)
|
return pts.MinTimestamp() + (build.BlockDelaySecs / 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("BASE: ", base.Cids())
|
fmt.Println("BASE: ", base.Cids())
|
||||||
|
@ -186,7 +186,7 @@ func SyncWait(ctx context.Context, napi api.FullNode) error {
|
|||||||
|
|
||||||
fmt.Printf("\r\x1b[2KWorker %d: Target: %s\tState: %s\tHeight: %d", working, target, chain.SyncStageString(ss.Stage), ss.Height)
|
fmt.Printf("\r\x1b[2KWorker %d: Target: %s\tState: %s\tHeight: %d", working, target, chain.SyncStageString(ss.Stage), ss.Height)
|
||||||
|
|
||||||
if time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelay) {
|
if time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs) {
|
||||||
fmt.Println("\nDone!")
|
fmt.Println("\nDone!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ var watchHeadCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "interval",
|
Name: "interval",
|
||||||
Value: int(build.BlockDelay),
|
Value: int(build.BlockDelaySecs),
|
||||||
Usage: "interval in seconds between chain head checks",
|
Usage: "interval in seconds between chain head checks",
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@ -74,7 +74,7 @@ var watchHeadCmd = &cli.Command{
|
|||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
Name: "api-timeout",
|
Name: "api-timeout",
|
||||||
// TODO: this default value seems spurious.
|
// TODO: this default value seems spurious.
|
||||||
Value: int(build.BlockDelay),
|
Value: int(build.BlockDelaySecs),
|
||||||
Usage: "timeout between API retries",
|
Usage: "timeout between API retries",
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
@ -237,7 +237,7 @@ func waitForSyncComplete(ctx context.Context, a api.FullNode, r int, t time.Dura
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelay) {
|
if time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ var infoCmd = &cli.Command{
|
|||||||
if expWinChance > 1 {
|
if expWinChance > 1 {
|
||||||
expWinChance = 1
|
expWinChance = 1
|
||||||
}
|
}
|
||||||
winRate := time.Duration(float64(time.Second*time.Duration(build.BlockDelay)) / expWinChance)
|
winRate := time.Duration(float64(time.Second*time.Duration(build.BlockDelaySecs)) / expWinChance)
|
||||||
winPerDay := float64(time.Hour*24) / float64(winRate)
|
winPerDay := float64(time.Hour*24) / float64(winRate)
|
||||||
|
|
||||||
fmt.Print("Expected block win rate: ")
|
fmt.Print("Expected block win rate: ")
|
||||||
|
@ -123,7 +123,7 @@ var setAskCmd = &cli.Command{
|
|||||||
return xerrors.Errorf("cannot parse duration: %w", err)
|
return xerrors.Errorf("cannot parse duration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
qty := dur.Seconds() / float64(build.BlockDelay)
|
qty := dur.Seconds() / float64(build.BlockDelaySecs)
|
||||||
|
|
||||||
min, err := units.RAMInBytes(cctx.String("min-piece-size"))
|
min, err := units.RAMInBytes(cctx.String("min-piece-size"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -208,7 +208,7 @@ var getAskCmd = &cli.Command{
|
|||||||
dlt := ask.Expiry - head.Height()
|
dlt := ask.Expiry - head.Height()
|
||||||
rem := "<expired>"
|
rem := "<expired>"
|
||||||
if dlt > 0 {
|
if dlt > 0 {
|
||||||
rem = (time.Second * time.Duration(int64(dlt)*int64(build.BlockDelay))).String()
|
rem = (time.Second * time.Duration(int64(dlt)*int64(build.BlockDelaySecs))).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize))), ask.Expiry, rem, ask.SeqNo)
|
fmt.Fprintf(w, "%s\t%s\t%s\t%d\t%s\t%d\n", ask.Price, types.SizeStr(types.NewInt(uint64(ask.MinPieceSize))), types.SizeStr(types.NewInt(uint64(ask.MaxPieceSize))), ask.Expiry, rem, ask.SeqNo)
|
||||||
|
@ -211,11 +211,11 @@ var provingInfoCmd = &cli.Command{
|
|||||||
func epochTime(curr, e abi.ChainEpoch) string {
|
func epochTime(curr, e abi.ChainEpoch) string {
|
||||||
switch {
|
switch {
|
||||||
case curr > e:
|
case curr > e:
|
||||||
return fmt.Sprintf("%d (%s ago)", e, time.Second*time.Duration(int64(build.BlockDelay)*int64(curr-e)))
|
return fmt.Sprintf("%d (%s ago)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e)))
|
||||||
case curr == e:
|
case curr == e:
|
||||||
return fmt.Sprintf("%d (now)", e)
|
return fmt.Sprintf("%d (now)", e)
|
||||||
case curr < e:
|
case curr < e:
|
||||||
return fmt.Sprintf("%d (in %s)", e, time.Second*time.Duration(int64(build.BlockDelay)*int64(e-curr)))
|
return fmt.Sprintf("%d (in %s)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr)))
|
||||||
}
|
}
|
||||||
|
|
||||||
panic("math broke")
|
panic("math broke")
|
||||||
|
@ -69,7 +69,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
// TODO: beacon
|
// TODO: beacon
|
||||||
|
|
||||||
uts := head.MinTimestamp() + uint64(build.BlockDelay)
|
uts := head.MinTimestamp() + uint64(build.BlockDelaySecs)
|
||||||
nheight := head.Height() + 1
|
nheight := head.Height() + 1
|
||||||
blk, err := api.MinerCreateBlock(ctx, &lapi.BlockTemplate{
|
blk, err := api.MinerCreateBlock(ctx, &lapi.BlockTemplate{
|
||||||
addr, head.Key(), ticket, &types.ElectionProof{}, nil, msgs, nheight, uts, gen.ValidWpostForTesting,
|
addr, head.Key(), ticket, &types.ElectionProof{}, nil, msgs, nheight, uts, gen.ValidWpostForTesting,
|
||||||
|
@ -150,7 +150,7 @@ func (m *Miner) mine(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
if base.TipSet.Equals(lastBase.TipSet) && lastBase.NullRounds == base.NullRounds {
|
if base.TipSet.Equals(lastBase.TipSet) && lastBase.NullRounds == base.NullRounds {
|
||||||
log.Warnf("BestMiningCandidate from the previous round: %s (nulls:%d)", lastBase.TipSet.Cids(), lastBase.NullRounds)
|
log.Warnf("BestMiningCandidate from the previous round: %s (nulls:%d)", lastBase.TipSet.Cids(), lastBase.NullRounds)
|
||||||
m.niceSleep(time.Duration(build.BlockDelay) * time.Second)
|
m.niceSleep(time.Duration(build.BlockDelaySecs) * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ func (m *Miner) mine(ctx context.Context) {
|
|||||||
// has enough time to form.
|
// has enough time to form.
|
||||||
//
|
//
|
||||||
// See: https://github.com/filecoin-project/lotus/issues/1845
|
// See: https://github.com/filecoin-project/lotus/issues/1845
|
||||||
nextRound := time.Unix(int64(base.TipSet.MinTimestamp()+build.BlockDelay*uint64(base.NullRounds))+int64(build.PropagationDelay), 0)
|
nextRound := time.Unix(int64(base.TipSet.MinTimestamp()+build.BlockDelaySecs*uint64(base.NullRounds))+int64(build.PropagationDelay), 0)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Until(nextRound)):
|
case <-time.After(time.Until(nextRound)):
|
||||||
@ -356,7 +356,7 @@ func (m *Miner) mineOne(ctx context.Context, base *MiningBase) (*types.BlockMsg,
|
|||||||
tCreateBlock := time.Now()
|
tCreateBlock := time.Now()
|
||||||
dur := tCreateBlock.Sub(start)
|
dur := tCreateBlock.Sub(start)
|
||||||
log.Infow("mined new block", "cid", b.Cid(), "height", b.Header.Height, "took", dur)
|
log.Infow("mined new block", "cid", b.Cid(), "height", b.Header.Height, "took", dur)
|
||||||
if dur > time.Second*time.Duration(build.BlockDelay) {
|
if dur > time.Second*time.Duration(build.BlockDelaySecs) {
|
||||||
log.Warn("CAUTION: block production took longer than the block delay. Your computer may not be fast enough to keep up")
|
log.Warn("CAUTION: block production took longer than the block delay. Your computer may not be fast enough to keep up")
|
||||||
|
|
||||||
log.Warnw("tMinerBaseInfo ", "duration", tMBI.Sub(start))
|
log.Warnw("tMinerBaseInfo ", "duration", tMBI.Sub(start))
|
||||||
@ -417,7 +417,7 @@ func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *type
|
|||||||
msgs = msgs[:build.BlockMessageLimit]
|
msgs = msgs[:build.BlockMessageLimit]
|
||||||
}
|
}
|
||||||
|
|
||||||
uts := base.TipSet.MinTimestamp() + build.BlockDelay*(uint64(base.NullRounds)+1)
|
uts := base.TipSet.MinTimestamp() + build.BlockDelaySecs*(uint64(base.NullRounds)+1)
|
||||||
|
|
||||||
nheight := base.TipSet.Height() + base.NullRounds + 1
|
nheight := base.TipSet.Height() + base.NullRounds + 1
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ func (a *CommonAPI) Version(context.Context) (api.Version, error) {
|
|||||||
Version: build.UserVersion(),
|
Version: build.UserVersion(),
|
||||||
APIVersion: build.APIVersion,
|
APIVersion: build.APIVersion,
|
||||||
|
|
||||||
BlockDelay: uint64(build.BlockDelay),
|
BlockDelay: uint64(build.BlockDelaySecs),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,6 @@ func RandomBeacon(p RandomBeaconParams, _ dtypes.AfterGenesisSet) (beacon.Random
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//return beacon.NewMockBeacon(build.BlockDelay * time.Second)
|
//return beacon.NewMockBeacon(build.BlockDelaySecs * time.Second)
|
||||||
return drand.NewDrandBeacon(gen.Timestamp, build.BlockDelay, p.PubSub, p.DrandConfig)
|
return drand.NewDrandBeacon(gen.Timestamp, build.BlockDelaySecs, p.PubSub, p.DrandConfig)
|
||||||
}
|
}
|
||||||
|
@ -8,5 +8,5 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func RandomBeacon() (beacon.RandomBeacon, error) {
|
func RandomBeacon() (beacon.RandomBeacon, error) {
|
||||||
return beacon.NewMockBeacon(time.Duration(build.BlockDelay) * time.Second), nil
|
return beacon.NewMockBeacon(time.Duration(build.BlockDelaySecs) * time.Second), nil
|
||||||
}
|
}
|
||||||
|
@ -349,7 +349,7 @@ func mockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test
|
|||||||
templ := &genesis.Template{
|
templ := &genesis.Template{
|
||||||
Accounts: genaccs,
|
Accounts: genaccs,
|
||||||
Miners: genms,
|
Miners: genms,
|
||||||
Timestamp: uint64(time.Now().Unix() - (build.BlockDelay * 20000)),
|
Timestamp: uint64(time.Now().Unix() - (build.BlockDelaySecs * 20000)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// END PRESEAL SECTION
|
// END PRESEAL SECTION
|
||||||
|
@ -114,7 +114,7 @@ sync_complete:
|
|||||||
// If we get within 20 blocks of the current exected block height we
|
// If we get within 20 blocks of the current exected block height we
|
||||||
// consider sync complete. Block propagation is not always great but we still
|
// consider sync complete. Block propagation is not always great but we still
|
||||||
// want to be recording stats as soon as we can
|
// want to be recording stats as soon as we can
|
||||||
if timestampDelta < int64(build.BlockDelay)*20 {
|
if timestampDelta < int64(build.BlockDelaySecs)*20 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user