Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire OverridePragueTime into txpool #11234

Merged
merged 6 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,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 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 @@ -983,31 +983,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 {
sudeepdino008 marked this conversation as resolved.
Show resolved Hide resolved
// 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 @@ -1045,53 +1048,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 txn (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
Loading