Skip to content

Commit

Permalink
fix: Eth2NewBlock, add: tip check in commit txn
Browse files Browse the repository at this point in the history
  • Loading branch information
anshalshukla committed Aug 31, 2024
1 parent c0ff6db commit da49748
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
13 changes: 5 additions & 8 deletions core/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2211,15 +2211,12 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon
defer chain.Stop()

// Activate the transition since genesis if required
// if mergePoint == 0 {
// mergeBlock = 0
if mergePoint == 0 {
mergeBlock = 0

// merger.ReachTTD()
// merger.FinalizePoS()

// // Set the terminal total difficulty in the config
// gspec.Config.TerminalTotalDifficulty = big.NewInt(0)
// }
// Set the terminal total difficulty in the config
gspec.Config.TerminalTotalDifficulty = big.NewInt(0)
}
genDb, blocks, _ := GenerateChainWithGenesis(gspec, engine, 2*state.TriesInMemory, func(i int, gen *BlockGen) {
tx, err := types.SignTx(types.NewTransaction(nonce, common.HexToAddress("deadbeef"), big.NewInt(100), 21000, big.NewInt(int64(i+1)*params.GWei), nil), signer, key)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion eth/filters/filter_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ const (
// rmLogsChanSize is the size of channel listening to RemovedLogsEvent.
rmLogsChanSize = 10
// logsChanSize is the size of channel listening to LogsEvent.
logsChanSize = 10
// Updated to fix TestEth2NeBlock testcase, as the feed was unable to send
// logs to the channel. check - @anshalshukla
logsChanSize = 100
// chainEvChanSize is the size of channel listening to ChainEvent.
chainEvChanSize = 10
// stateEvChanSize is the size of channel listening to StateSyncEvent.
Expand Down
2 changes: 1 addition & 1 deletion miner/test_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (w *worker) mainLoopWithDelay(ctx context.Context, delay uint, opcodeDelay
}
txset := newTransactionsByPriceAndNonce(w.current.signer, txs, w.current.header.BaseFee)
tcount := w.current.tcount
w.commitTransactions(w.current, txset, nil, nil, context.Background())
w.commitTransactions(w.current, txset, nil, nil, new(uint256.Int), context.Background())

// Only update the snapshot if any new transactons were added
// to the pending block
Expand Down
39 changes: 11 additions & 28 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func (w *worker) mainLoop(ctx context.Context) {

tcount := w.current.tcount

w.commitTransactions(w.current, plainTxs, blobTxs, nil, context.Background())
w.commitTransactions(w.current, plainTxs, blobTxs, nil, new(uint256.Int), context.Background())

// Only update the snapshot if any new transactons were added
// to the pending block
Expand Down Expand Up @@ -915,7 +915,7 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction, inte
return receipt.Logs, nil
}

func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transactionsByPriceAndNonce, interrupt *atomic.Int32, interruptCtx context.Context) error {
func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transactionsByPriceAndNonce, interrupt *atomic.Int32, minTip *uint256.Int, interruptCtx context.Context) error {
gasLimit := env.header.GasLimit
if env.gasPool == nil {
env.gasPool = new(core.GasPool).AddGas(gasLimit)
Expand Down Expand Up @@ -1028,7 +1028,11 @@ mainloop:
txs.Pop()
continue
}

// If we don't receive enough tip for the next transaction, skip the account
if ptip.Cmp(minTip) < 0 {
log.Trace("Not enough tip for transaction", "hash", ltx.Hash, "tip", ptip, "needed", minTip)
break // If the next-best is too low, surely no better will be available
}
// Transaction seems to fit, pull it up from the pool
tx := ltx.Resolve()
if tx == nil {
Expand Down Expand Up @@ -1518,7 +1522,7 @@ func (w *worker) fillTransactions(ctx context.Context, interrupt *atomic.Int32,
})

tracing.Exec(ctx, "", "worker.LocalCommitTransactions", func(ctx context.Context, span trace.Span) {
err = w.commitTransactions(env, plainTxs, blobTxs, interrupt, interruptCtx)
err = w.commitTransactions(env, plainTxs, blobTxs, interrupt, new(uint256.Int), interruptCtx)
})

if err != nil {
Expand All @@ -1542,7 +1546,7 @@ func (w *worker) fillTransactions(ctx context.Context, interrupt *atomic.Int32,
})

tracing.Exec(ctx, "", "worker.RemoteCommitTransactions", func(ctx context.Context, span trace.Span) {
err = w.commitTransactions(env, plainTxs, blobTxs, interrupt, interruptCtx)
err = w.commitTransactions(env, plainTxs, blobTxs, interrupt, new(uint256.Int), interruptCtx)
})

if err != nil {
Expand Down Expand Up @@ -1734,7 +1738,7 @@ func getInterruptTimer(ctx context.Context, work *environment, current *types.Bl
// the deep copy first.
func (w *worker) commit(ctx context.Context, env *environment, interval func(), update bool, start time.Time) error {
if w.IsRunning() {
ctx, span := tracing.StartSpan(ctx, "commit")
_, span := tracing.StartSpan(ctx, "commit")
defer tracing.EndSpan(span)

if interval != nil {
Expand All @@ -1744,7 +1748,7 @@ func (w *worker) commit(ctx context.Context, env *environment, interval func(),
// https://github.com/ethereum/go-ethereum/issues/24299
env := env.copy()
// Withdrawals are set to nil here, because this is only called in PoW.
block, err := w.engine.FinalizeAndAssemble(w.chain, env.header, env.state, &types.Body{
_, err := w.engine.FinalizeAndAssemble(w.chain, env.header, env.state, &types.Body{
Transactions: env.txs,
}, env.receipts)
tracing.SetAttributes(
Expand All @@ -1760,20 +1764,6 @@ func (w *worker) commit(ctx context.Context, env *environment, interval func(),
return err
}

// If we're post merge, just ignore
if !w.isTTDReached(block.Header()) {
select {
case w.taskCh <- &task{ctx: ctx, receipts: env.receipts, state: env.state, block: block, createdAt: time.Now()}:
fees := totalFees(block, env.receipts)
feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether))
log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()),
"txs", env.tcount, "gas", block.GasUsed(), "fees", feesInEther,
"elapsed", common.PrettyDuration(time.Since(start)))

case <-w.exitCh:
log.Info("Worker has exited")
}
}
}

if update {
Expand Down Expand Up @@ -1802,13 +1792,6 @@ func (w *worker) getSealingBlock(params *generateParams) *newPayloadResult {
}
}

// isTTDReached returns the indicator if the given block has reached the total
// terminal difficulty for The Merge transition.
func (w *worker) isTTDReached(header *types.Header) bool {
td, ttd := w.chain.GetTd(header.ParentHash, header.Number.Uint64()-1), w.chain.Config().TerminalTotalDifficulty
return td != nil && ttd != nil && td.Cmp(ttd) >= 0
}

// adjustResubmitInterval adjusts the resubmit interval.
func (w *worker) adjustResubmitInterval(message *intervalAdjust) {
select {
Expand Down

0 comments on commit da49748

Please sign in to comment.