Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into cometbft-bump-fix
Browse files Browse the repository at this point in the history
Signed-off-by: Devon Bear <itsdevbear@berachain.com>
  • Loading branch information
itsdevbear authored Jun 1, 2024
2 parents c671ab9 + e74ef39 commit f69806f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cosmos/runtime/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,28 @@ func (m *Miner) buildBlock(ctx sdk.Context, payloadTimestamp uint64) ([]byte, ui
// submitPayloadForBuilding submits a payload for building.
func (m *Miner) submitPayloadForBuilding(ctx context.Context, payloadTimestamp uint64) error {
var (
err error
payload *miner.Payload
sCtx = sdk.UnwrapSDKContext(ctx)
payloadArgs = m.constructPayloadArgs(payloadTimestamp)
err error
payload *miner.Payload
sCtx = sdk.UnwrapSDKContext(ctx)
)

// Set the mining context for geth to build the payload with.
m.bc.StatePluginFactory().SetLatestMiningContext(ctx)
m.bc.PrimePlugins(ctx)

// Ensure that we make progress sine the last block. This is necessary
// since CometBFT timestamps are based on the median of all timestamps
// included in the last commit, and thus it is theoretically possible due
// 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
}
ts := max(uint64(sCtx.BlockTime().Unix()), prevBlockTs+1)

// Build Payload.
if payload, err = m.miner.BuildPayload(payloadArgs); err != nil {
if payload, err = m.miner.BuildPayload(m.constructPayloadArgs(ts)); err != nil {
sCtx.Logger().Error("failed to build payload", "err", err)
return err
}
Expand Down

0 comments on commit f69806f

Please sign in to comment.