Skip to content

Commit 3158c68

Browse files
github-actions[bot]rezzmahcalbera
authored
fix(payload-builder): include PoL tx in empty payload (#94) (#98)
* Update worker.go * make updates * nit * add log for payload update count * fix bug * cleanup metric/logs * 1s recommit + with more descriptive logs --------- (cherry picked from commit 817107f) Co-authored-by: Rez <rez@berachain.com> Co-authored-by: Cal Bera <calbera@berachain.com>
1 parent 3e0f94c commit 3158c68

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

miner/miner.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ var DefaultConfig = Config{
5555
GasCeil: 36_000_000, // Berachain: set to 36mil to match Prague default
5656
GasPrice: big.NewInt(1), // Berachain: set to 1 wei to match reth's default
5757

58-
// The default recommit time is chosen as two seconds since
59-
// consensus-layer usually will wait a half slot of time(6s)
60-
// for payload generation. It should be enough for Geth to
61-
// run 3 rounds.
62-
Recommit: 2 * time.Second,
58+
// Berachain: The default recommit time is chosen as 1s to allow for around
59+
// 1-2 rounds of payload generation. On average with 2s stable block time,
60+
// there is 1.5s gap between start and stop payload generation.
61+
Recommit: 1 * time.Second,
6362
}
6463

6564
// Miner is the main object which takes care of submitting new work to consensus

miner/payload_building.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func newPayload(empty *types.Block, emptyRequests [][]byte, witness *stateless.W
102102
}
103103

104104
// update updates the full-block with latest built version.
105-
func (payload *Payload) update(r *newPayloadResult, elapsed time.Duration) {
105+
func (payload *Payload) update(r *newPayloadResult, elapsed time.Duration, numPayloadUpdates int) {
106106
payload.lock.Lock()
107107
defer payload.lock.Unlock()
108108

@@ -132,6 +132,7 @@ func (payload *Payload) update(r *newPayloadResult, elapsed time.Duration) {
132132
"fees", feesInEther,
133133
"root", r.block.Root(),
134134
"elapsed", common.PrettyDuration(elapsed),
135+
"count", numPayloadUpdates,
135136
)
136137
}
137138
payload.cond.Broadcast() // fire signal for notifying full block
@@ -260,22 +261,24 @@ func (miner *Miner) buildPayload(args *BuildPayloadArgs, witness bool) (*Payload
260261
noTxs: false,
261262
}
262263

264+
numPayloadUpdates := 0
263265
for {
264266
select {
265267
case <-timer.C:
266268
start := time.Now()
267269
r := miner.generateWork(fullParams, witness)
268270
if r.err == nil {
269-
payload.update(r, time.Since(start))
271+
numPayloadUpdates++
272+
payload.update(r, time.Since(start), numPayloadUpdates)
270273
} else {
271274
log.Info("Error while generating work", "id", payload.id, "err", r.err)
272275
}
273276
timer.Reset(miner.config.Recommit)
274277
case <-payload.stop:
275-
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
278+
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery", "full", payload.full != nil)
276279
return
277280
case <-endTimer.C:
278-
log.Info("Stopping work on payload", "id", payload.id, "reason", "timeout")
281+
log.Info("Stopping work on payload", "id", payload.id, "reason", "timeout", "full", payload.full != nil)
279282
return
280283
}
281284
}

miner/worker.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay
122122
// Also add size of withdrawals to work block size.
123123
work.size += uint64(genParam.withdrawals.Size())
124124

125+
// Berachain: Post-Prague1 we commit the PoL tx even when building an empty block.
126+
// This is a safety measure to ensure that if the payload is requested early, the
127+
// returned payload satisfies the Prague1 requirements, i.e. include the PoL tx.
128+
if err = miner.commitPoLTx(work); err != nil {
129+
return &newPayloadResult{err: err}
130+
}
131+
125132
if !genParam.noTxs {
126133
interrupt := new(atomic.Int32)
127134
timer := time.AfterFunc(miner.config.Recommit, func() {
@@ -483,16 +490,8 @@ func (miner *Miner) commitTransactions(env *environment, plainTxs, blobTxs *tran
483490
return nil
484491
}
485492

486-
// fillTransactions retrieves the pending transactions from the txpool and fills them
487-
// into the given sealing block. The transaction selection and ordering strategy can
488-
// be customized with the plugin in the future.
489-
func (miner *Miner) fillTransactions(interrupt *atomic.Int32, env *environment) error {
490-
miner.confMu.RLock()
491-
tip := miner.config.GasPrice
492-
prio := miner.prio
493-
miner.confMu.RUnlock()
494-
495-
// Berachain: Post-Prague1, add PoL tx to the block according to BRIP-0004.
493+
// Berachain: Post-Prague1, add PoL tx to the block according to BRIP-0004.
494+
func (miner *Miner) commitPoLTx(env *environment) error {
496495
if env.gasPool == nil {
497496
// NOTE: this check is moved here from the commitTransactions loop because we are
498497
// "committing" a transaction outside of the loop.
@@ -519,6 +518,17 @@ func (miner *Miner) fillTransactions(interrupt *atomic.Int32, env *environment)
519518
return err
520519
}
521520
}
521+
return nil
522+
}
523+
524+
// fillTransactions retrieves the pending transactions from the txpool and fills them
525+
// into the given sealing block. The transaction selection and ordering strategy can
526+
// be customized with the plugin in the future.
527+
func (miner *Miner) fillTransactions(interrupt *atomic.Int32, env *environment) error {
528+
miner.confMu.RLock()
529+
tip := miner.config.GasPrice
530+
prio := miner.prio
531+
miner.confMu.RUnlock()
522532

523533
// Retrieve the pending transactions pre-filtered by the 1559/4844 dynamic fees
524534
filter := txpool.PendingFilter{

0 commit comments

Comments
 (0)