diff --git a/cosmos/runtime/miner/miner.go b/cosmos/runtime/miner/miner.go index 3bc862c17..e77407d33 100644 --- a/cosmos/runtime/miner/miner.go +++ b/cosmos/runtime/miner/miner.go @@ -114,9 +114,20 @@ func (m *Miner) submitPayloadForBuilding(ctx context.Context) error { // to clock skew / rounding to commit two blocks in succession with the same // unix time. This will prevent the block from being built. prevBlockTs := uint64(0) - if finalBlock := m.bc.CurrentFinalBlock(); finalBlock != nil { - prevBlockTs = finalBlock.Time + if finalBlock := m.bc.GetBlockByNumber(uint64(sCtx.BlockHeight()) - 1); finalBlock != nil { + prevBlockTs = finalBlock.Time() + } else { + // If we fail to find the previous block, we minimum of the current time + // and the next block time, time.Now() is always increasing, so eventually + // time.Now() > sCtx.BlockTime() + 1. + prevBlockTs = min(uint64(time.Now().Unix()), uint64(sCtx.BlockTime().Unix())+1) } + + // Ensure that the block time is always increasing. + if prevBlockTs <= uint64(sCtx.BlockTime().Unix()) { + prevBlockTs = uint64(sCtx.BlockTime().Unix()) + } + ts := max(uint64(sCtx.BlockTime().Unix()), prevBlockTs+1) // Build Payload.