Skip to content

Commit

Permalink
Wire OverridePragueTime into txpool (#12185)
Browse files Browse the repository at this point in the history
Cherry pick #11234
  • Loading branch information
yperbasis authored and AskAlexSharov committed Oct 21, 2024
1 parent 1cabe82 commit 8b2de54
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 54 deletions.
1 change: 1 addition & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C

if ctx.IsSet(OverridePragueFlag.Name) {
cfg.OverridePragueTime = flags.GlobalBig(ctx, OverridePragueFlag.Name)
cfg.TxPool.OverridePragueTime = cfg.OverridePragueTime
}

if ctx.IsSet(InternalConsensusFlag.Name) && clparams.EmbeddedSupported(cfg.NetworkID) {
Expand Down
67 changes: 14 additions & 53 deletions erigon-lib/txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,31 +985,34 @@ func requiredBalance(txn *types.TxSlot) *uint256.Int {
return total
}

func (p *TxPool) isShanghai() bool {
func isTimeBasedForkActivated(isPostFlag *atomic.Bool, forkTime *uint64) bool {
// once this flag has been set for the first time we no longer need to check the timestamp
set := p.isPostShanghai.Load()
set := isPostFlag.Load()
if set {
return true
}
if p.shanghaiTime == nil {
if forkTime == nil { // the fork is not enabled
return false
}
shanghaiTime := *p.shanghaiTime

// a zero here means Shanghai is always active
if shanghaiTime == 0 {
p.isPostShanghai.Swap(true)
// a zero here means the fork is always active
if *forkTime == 0 {
isPostFlag.Swap(true)
return true
}

now := time.Now().Unix()
activated := uint64(now) >= shanghaiTime
activated := uint64(now) >= *forkTime
if activated {
p.isPostShanghai.Swap(true)
isPostFlag.Swap(true)
}
return activated
}

func (p *TxPool) isShanghai() bool {
return isTimeBasedForkActivated(&p.isPostShanghai, p.shanghaiTime)
}

func (p *TxPool) isAgra() bool {
// once this flag has been set for the first time we no longer need to check the block
set := p.isPostAgra.Load()
Expand Down Expand Up @@ -1047,53 +1050,11 @@ func (p *TxPool) isAgra() bool {
}

func (p *TxPool) isCancun() bool {
// once this flag has been set for the first time we no longer need to check the timestamp
set := p.isPostCancun.Load()
if set {
return true
}
if p.cancunTime == nil {
return false
}
cancunTime := *p.cancunTime

// a zero here means Cancun is always active
if cancunTime == 0 {
p.isPostCancun.Swap(true)
return true
}

now := time.Now().Unix()
activated := uint64(now) >= cancunTime
if activated {
p.isPostCancun.Swap(true)
}
return activated
return isTimeBasedForkActivated(&p.isPostCancun, p.cancunTime)
}

func (p *TxPool) isPrague() bool {
// once this flag has been set for the first time we no longer need to check the timestamp
set := p.isPostPrague.Load()
if set {
return true
}
if p.pragueTime == nil {
return false
}
pragueTime := *p.pragueTime

// a zero here means Prague is always active
if pragueTime == 0 {
p.isPostPrague.Swap(true)
return true
}

now := time.Now().Unix()
activated := uint64(now) >= pragueTime
if activated {
p.isPostPrague.Swap(true)
}
return activated
return isTimeBasedForkActivated(&p.isPostPrague, p.pragueTime)
}

// Check that the serialized txn should not exceed a certain max size
Expand Down
2 changes: 2 additions & 0 deletions erigon-lib/txpool/txpoolcfg/txpoolcfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package txpoolcfg
import (
"fmt"
"math"
"math/big"
"time"

"github.com/c2h5oh/datasize"
Expand All @@ -44,6 +45,7 @@ type Config struct {
TotalBlobPoolLimit uint64 // Total number of blobs (not txs) allowed within the txpool
PriceBump uint64 // Price bump percentage to replace an already existing transaction
BlobPriceBump uint64 //Price bump percentage to replace an existing 4844 blob tx (type-3)
OverridePragueTime *big.Int

// regular batch tasks processing
SyncToNewPeersEvery time.Duration
Expand Down
6 changes: 5 additions & 1 deletion erigon-lib/txpool/txpoolutil/all_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ func AllComponents(ctx context.Context, cfg txpoolcfg.Config, cache kvcache.Cach
}
cancunTime := chainConfig.CancunTime
pragueTime := chainConfig.PragueTime
if cfg.OverridePragueTime != nil {
pragueTime = cfg.OverridePragueTime
}

txPool, err := txpool.New(newTxs, chainDB, cfg, cache, *chainID, shanghaiTime, agraBlock, cancunTime, pragueTime, maxBlobsPerBlock, feeCalculator, logger)
txPool, err := txpool.New(newTxs, chainDB, cfg, cache, *chainID, shanghaiTime, agraBlock, cancunTime, pragueTime,
maxBlobsPerBlock, feeCalculator, logger)
if err != nil {
return nil, nil, nil, nil, nil, err
}
Expand Down

0 comments on commit 8b2de54

Please sign in to comment.