BlockTimeInterval = 500
// MaxTimeOffsetMs is the maximum number of seconds a block time is allowed to be ahead of the current time
- MaxTimeOffsetMs = uint64(60 * 60 * 1000)
+ MaxTimeOffsetMs = uint64(7 * 1000)
MedianTimeBlocks = 11
PayToWitnessPubKeyHashDataSize = 20
bestBlockHeader := b.chain.BestBlockHeader()
bestBlockHash := bestBlockHeader.Hash()
- nextBlockTime := uint64(time.Now().UnixNano() / 1e6)
- if minNextBlockTime := bestBlockHeader.Timestamp + consensus.BlockTimeInterval; nextBlockTime < minNextBlockTime {
- nextBlockTime = minNextBlockTime
+ now := uint64(time.Now().UnixNano() / 1e6)
+ base := max(now, bestBlockHeader.Timestamp)
+ minTimeToNextBlock := consensus.BlockTimeInterval - now%consensus.BlockTimeInterval
+ nextBlockTime := base + minTimeToNextBlock
+ if nextBlockTime-now < consensus.BlockTimeInterval/10 {
+ nextBlockTime += consensus.BlockTimeInterval
}
+ // nextBlockTime := uint64(time.Now().UnixNano() / 1e6)
+ // if minNextBlockTime := bestBlockHeader.Timestamp + consensus.BlockTimeInterval; nextBlockTime < minNextBlockTime {
+ // nextBlockTime = minNextBlockTime
+ // }
if isBlocker, err := b.chain.IsBlocker(&bestBlockHash, xpubStr, nextBlockTime); !isBlocker {
log.WithFields(log.Fields{"module": logModule, "error": err, "pubKey": xpubStr}).Debug("fail on check is next blocker")
}
}
+func max(x, y uint64) uint64 {
+ if x > y {
+ return x
+ }
+ return y
+}
+
// Start begins the block propose process as well as the speed monitor used to
// track hashing metrics. Calling this function when the block proposer has
// already been started will have no effect.