From 04a4b2708111f933b39edd6fa4fc9833c16560af Mon Sep 17 00:00:00 2001 From: Valentin Staykov <79150443+V-Staykov@users.noreply.github.com> Date: Mon, 29 Jul 2024 13:16:05 +0300 Subject: [PATCH] fixed setting 0 value to baseFee (#857) --- zk/txpool/pool.go | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/zk/txpool/pool.go b/zk/txpool/pool.go index 0b7f747cbe3..886748c9c9a 100644 --- a/zk/txpool/pool.go +++ b/zk/txpool/pool.go @@ -411,14 +411,7 @@ func (p *TxPool) OnNewBlock(ctx context.Context, stateChanges *remote.StateChang return err } - var baseFee uint64 - if !p.ethCfg.AllowFreeTransactions { - baseFee = stateChanges.PendingBlockBaseFee - } else { - baseFee = uint64(0) - } - - pendingBaseFee, baseFeeChanged := p.setBaseFee(baseFee) + pendingBaseFee, baseFeeChanged := p.setBaseFee(stateChanges.PendingBlockBaseFee, p.ethCfg.AllowFreeTransactions) // Update pendingBase for all pool queues and slices if baseFeeChanged { p.pending.best.pendingBaseFee = pendingBaseFee @@ -1048,10 +1041,23 @@ func addTxs(blockNum uint64, cacheView kvcache.CacheView, senders *sendersBatch, return announcements, discardReasons, nil } -func addTxsOnNewBlock(blockNum uint64, cacheView kvcache.CacheView, stateChanges *remote.StateChangeBatch, - senders *sendersBatch, newTxs types.TxSlots, pendingBaseFee uint64, blockGasLimit uint64, - pending *PendingPool, baseFee, queued *SubPool, - byNonce *BySenderAndNonce, byHash map[string]*metaTx, sendersWithChangedStateBeforeLimboTrim *LimboSendersWithChangedState, add func(*metaTx, *types.Announcements) DiscardReason, discard func(*metaTx, DiscardReason)) (types.Announcements, error) { +func addTxsOnNewBlock( + blockNum uint64, + cacheView kvcache.CacheView, + stateChanges *remote.StateChangeBatch, + senders *sendersBatch, + newTxs types.TxSlots, + pendingBaseFee uint64, + blockGasLimit uint64, + pending *PendingPool, + baseFee, + queued *SubPool, + byNonce *BySenderAndNonce, + byHash map[string]*metaTx, + sendersWithChangedStateBeforeLimboTrim *LimboSendersWithChangedState, + add func(*metaTx, *types.Announcements) DiscardReason, + discard func(*metaTx, DiscardReason), +) (types.Announcements, error) { protocolBaseFee := calcProtocolBaseFee(pendingBaseFee) if assert.Enable { for _, txn := range newTxs.Txs { @@ -1121,8 +1127,14 @@ func addTxsOnNewBlock(blockNum uint64, cacheView kvcache.CacheView, stateChanges return announcements, nil } -func (p *TxPool) setBaseFee(baseFee uint64) (uint64, bool) { +func (p *TxPool) setBaseFee(baseFee uint64, allowFreeTransactions bool) (uint64, bool) { changed := false + if allowFreeTransactions { + changed = uint64(0) != p.pendingBaseFee.Load() + p.pendingBaseFee.Store(0) + return 0, changed + } + if baseFee > 0 { changed = baseFee != p.pendingBaseFee.Load() p.pendingBaseFee.Store(baseFee)