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

Txpool upgrades for EIP-4844 Blob Transactions #8004

Merged
merged 7 commits into from
Sep 11, 2023
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
9 changes: 6 additions & 3 deletions cmd/txpool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ var (
baseFeePoolLimit int
queuedPoolLimit int

priceLimit uint64
accountSlots uint64
priceBump uint64
priceLimit uint64
accountSlots uint64
priceBump uint64
blobPriceBump uint64

commitEvery time.Duration
)
Expand All @@ -75,6 +76,7 @@ func init() {
rootCmd.PersistentFlags().Uint64Var(&priceLimit, "txpool.pricelimit", txpoolcfg.DefaultConfig.MinFeeCap, "Minimum gas price (fee cap) limit to enforce for acceptance into the pool")
rootCmd.PersistentFlags().Uint64Var(&accountSlots, "txpool.accountslots", txpoolcfg.DefaultConfig.AccountSlots, "Minimum number of executable transaction slots guaranteed per account")
rootCmd.PersistentFlags().Uint64Var(&priceBump, "txpool.pricebump", txpoolcfg.DefaultConfig.PriceBump, "Price bump percentage to replace an already existing transaction")
rootCmd.PersistentFlags().Uint64Var(&blobPriceBump, "txpool.blobpricebump", txpoolcfg.DefaultConfig.BlobPriceBump, "Price bump percentage to replace an existing blob (type-3) transaction")
rootCmd.PersistentFlags().DurationVar(&commitEvery, utils.TxPoolCommitEveryFlag.Name, utils.TxPoolCommitEveryFlag.Value, utils.TxPoolCommitEveryFlag.Usage)
rootCmd.Flags().StringSliceVar(&traceSenders, utils.TxPoolTraceSendersFlag.Name, []string{}, utils.TxPoolTraceSendersFlag.Usage)
}
Expand Down Expand Up @@ -140,6 +142,7 @@ func doTxpool(ctx context.Context, logger log.Logger) error {
cfg.MinFeeCap = priceLimit
cfg.AccountSlots = accountSlots
cfg.PriceBump = priceBump
cfg.BlobPriceBump = blobPriceBump

cacheConfig := kvcache.DefaultCoherentConfig
cacheConfig.MetricsLabel = "txpool"
Expand Down
16 changes: 12 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ var (
Usage: "Price bump percentage to replace an already existing transaction",
Value: txpoolcfg.DefaultConfig.PriceBump,
}
TxPoolBlobPriceBumpFlag = cli.Uint64Flag{
Name: "txpool.blobpricebump",
Usage: "Price bump percentage to replace existing (type-3) blob transaction",
Value: txpoolcfg.DefaultConfig.BlobPriceBump,
}
TxPoolAccountSlotsFlag = cli.Uint64Flag{
Name: "txpool.accountslots",
Usage: "Minimum number of executable transaction slots guaranteed per account",
Expand Down Expand Up @@ -1221,7 +1226,8 @@ func setGPOCobra(f *pflag.FlagSet, cfg *gaspricecfg.Config) {
}
}

func setTxPool(ctx *cli.Context, cfg *ethconfig.DeprecatedTxPoolConfig) {
func setTxPool(ctx *cli.Context, fullCfg *ethconfig.Config) {
cfg := &fullCfg.DeprecatedTxPool
if ctx.IsSet(TxPoolDisableFlag.Name) {
cfg.Disable = true
}
Expand Down Expand Up @@ -1271,7 +1277,9 @@ func setTxPool(ctx *cli.Context, cfg *ethconfig.DeprecatedTxPoolConfig) {
cfg.TracedSenders[i] = string(sender[:])
}
}

if ctx.IsSet(TxPoolBlobPriceBumpFlag.Name) {
fullCfg.TxPool.BlobPriceBump = ctx.Uint64(TxPoolBlobPriceBumpFlag.Name)
}
cfg.CommitEvery = common2.RandomizeDuration(ctx.Duration(TxPoolCommitEveryFlag.Name))
}

Expand Down Expand Up @@ -1506,8 +1514,8 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
setEtherbase(ctx, cfg)
setGPO(ctx, &cfg.GPO)

setTxPool(ctx, &cfg.DeprecatedTxPool)
cfg.TxPool = ethconfig.DefaultTxPool2Config(cfg.DeprecatedTxPool)
setTxPool(ctx, cfg)
cfg.TxPool = ethconfig.DefaultTxPool2Config(cfg)
cfg.TxPool.DBDir = nodeConfig.Dirs.TxPool

setEthash(ctx, nodeConfig.Dirs.DataDir, cfg)
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
baseFee = currentBlock.BaseFee().Uint64()
}
backend.notifications.Accumulator.StartChange(currentBlock.NumberU64(), currentBlock.Hash(), nil, false)
backend.notifications.Accumulator.SendAndReset(ctx, backend.notifications.StateChangesConsumer, baseFee, currentBlock.GasLimit())
backend.notifications.Accumulator.SendAndReset(ctx, backend.notifications.StateChangesConsumer, baseFee, currentBlock.GasLimit(), 0)

}()

Expand Down
4 changes: 3 additions & 1 deletion eth/ethconfig/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ var DeprecatedDefaultTxPoolConfig = DeprecatedTxPoolConfig{
Lifetime: 3 * time.Hour,
}

var DefaultTxPool2Config = func(pool1Cfg DeprecatedTxPoolConfig) txpoolcfg.Config {
var DefaultTxPool2Config = func(fullCfg *Config) txpoolcfg.Config {
pool1Cfg := &fullCfg.DeprecatedTxPool
cfg := txpoolcfg.DefaultConfig
cfg.PendingSubPoolLimit = int(pool1Cfg.GlobalSlots)
cfg.BaseFeeSubPoolLimit = int(pool1Cfg.GlobalBaseFeeQueue)
cfg.QueuedSubPoolLimit = int(pool1Cfg.GlobalQueue)
cfg.PriceBump = pool1Cfg.PriceBump
cfg.BlobPriceBump = fullCfg.TxPool.BlobPriceBump
cfg.MinFeeCap = pool1Cfg.PriceLimit
cfg.AccountSlots = pool1Cfg.AccountSlots
cfg.LogEvery = 1 * time.Minute
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/erigontech/mdbx-go v0.27.14
github.com/ledgerwatch/erigon-lib v0.0.0-20230910084807-0d0bcd007134
github.com/ledgerwatch/erigon-lib v0.0.0-20230910123533-109504cb0906
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230909101632-42a1d412f95f
github.com/ledgerwatch/log/v3 v3.9.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down Expand Up @@ -167,6 +167,7 @@ require (
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/ledgerwatch/interfaces v0.0.0-20230909005156-bff86c603a43 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
Expand All @@ -179,6 +180,7 @@ require (
github.com/libp2p/go-yamux/v4 v4.0.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/matryer/moq v0.3.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,16 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230910084807-0d0bcd007134 h1:2cO+/6tT/W2/um5kUhs2mQUrA8RA/7ggWAyGkndgoJk=
github.com/ledgerwatch/erigon-lib v0.0.0-20230910084807-0d0bcd007134/go.mod h1:DwA1ahg61GGxVr3IJIq5Bx/79QufL4tIyOwUxuyQDCY=
github.com/ledgerwatch/erigon-lib v0.0.0-20230910102346-adef9719957a h1:KO+91sQT80QErDrd7Z+6HezeYt73x/W5kyKPVTg94Ew=
github.com/ledgerwatch/erigon-lib v0.0.0-20230910102346-adef9719957a/go.mod h1:DwA1ahg61GGxVr3IJIq5Bx/79QufL4tIyOwUxuyQDCY=
github.com/ledgerwatch/erigon-lib v0.0.0-20230910123533-109504cb0906 h1:RJFQIJxwtlfwSunPaMXaHS2rn5ft6Dv00xYo0dqhDUs=
github.com/ledgerwatch/erigon-lib v0.0.0-20230910123533-109504cb0906/go.mod h1:c3YZgk6jvLFJHfEUZkQq+pl5EX2aZ1tXNEdHY2sVSgo=
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230909101632-42a1d412f95f h1:DVjZZpZBRTUXdJn6iZlwJkJ8zF0hwdBucIZFheNfF6w=
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230909101632-42a1d412f95f/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/interfaces v0.0.0-20230906081535-2d4029205941 h1:HConnUr7iAMFp0haM06QLLsO+c92Oh6v3XpuGom1Gzw=
github.com/ledgerwatch/interfaces v0.0.0-20230906081535-2d4029205941/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/interfaces v0.0.0-20230909005156-bff86c603a43 h1:AXQ1vPkmuBPtVRpAehMAXzmsRmdqUpNvl93wWE6gjCU=
github.com/ledgerwatch/interfaces v0.0.0-20230909005156-bff86c603a43/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=
github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=
Expand Down Expand Up @@ -542,6 +550,8 @@ github.com/maticnetwork/crand v1.0.2 h1:Af0tAivC8zrxXDpGWNWVT/0s1fOz8w0eRbahZgUR
github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxpj5ZKxfHjyg=
github.com/maticnetwork/polyproto v0.0.2 h1:cPxuxbIDItdwGnucc3lZB58U8Zfe1mH73PWTGd15554=
github.com/maticnetwork/polyproto v0.0.2/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/matryer/moq v0.3.2 h1:z7oltmpTxiQ9nKNg0Jc7z45TM+eO7OhCVohxRxwaudM=
github.com/matryer/moq v0.3.2/go.mod h1:RJ75ZZZD71hejp39j4crZLsEDszGk6iH4v4YsWFKH4s=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var DefaultFlags = []cli.Flag{
&utils.TxPoolNoLocalsFlag,
&utils.TxPoolPriceLimitFlag,
&utils.TxPoolPriceBumpFlag,
&utils.TxPoolBlobPriceBumpFlag,
&utils.TxPoolAccountSlotsFlag,
&utils.TxPoolGlobalSlotsFlag,
&utils.TxPoolGlobalBaseFeeSlotsFlag,
Expand Down
4 changes: 2 additions & 2 deletions turbo/shards/state_change_accumulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (a *Accumulator) Reset(plainStateID uint64) {
a.storageChangeIndex = nil
a.plainStateID = plainStateID
}
func (a *Accumulator) SendAndReset(ctx context.Context, c StateChangeConsumer, pendingBaseFee uint64, blockGasLimit uint64) {
func (a *Accumulator) SendAndReset(ctx context.Context, c StateChangeConsumer, pendingBaseFee uint64, blockGasLimit uint64, finalizedBlock uint64) {
if a == nil || c == nil || len(a.changes) == 0 {
return
}
sc := &remote.StateChangeBatch{StateVersionId: a.plainStateID, ChangeBatch: a.changes, PendingBlockBaseFee: pendingBaseFee, BlockGasLimit: blockGasLimit}
sc := &remote.StateChangeBatch{StateVersionId: a.plainStateID, ChangeBatch: a.changes, PendingBlockBaseFee: pendingBaseFee, BlockGasLimit: blockGasLimit, FinalizedBlock: finalizedBlock}
c.SendStateChanges(ctx, sc)
a.Reset(0) // reset here for GC, but there will be another Reset with correct viewID
}
Expand Down
9 changes: 6 additions & 3 deletions turbo/stages/stageloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (h *Hook) AfterRun(tx kv.Tx, finishProgressBefore uint64) error {

// Update sentry status for peers to see our sync status
var headTd *big.Int
var plainStateVersion uint64
var plainStateVersion, finalizedBlock uint64
head, err := stages.GetStageProgress(tx, stages.Headers)
if err != nil {
return err
Expand All @@ -276,7 +276,10 @@ func (h *Hook) AfterRun(tx kv.Tx, finishProgressBefore uint64) error {
}
headHeader = rawdb.ReadHeader(tx, headHash, head)
currentHeder = rawdb.ReadCurrentHeader(tx)

finalizedHeaderHash := rawdb.ReadForkchoiceFinalized(tx)
if fb := rawdb.ReadHeaderNumber(tx, finalizedHeaderHash); fb != nil {
finalizedBlock = *fb
}
// update the accumulator with a new plain state version so the cache can be notified that
// state has moved on
if plainStateVersion, err = rawdb.GetStateVersion(tx); err != nil {
Expand Down Expand Up @@ -306,7 +309,7 @@ func (h *Hook) AfterRun(tx kv.Tx, finishProgressBefore uint64) error {
notifications.Accumulator.StartChange(0, currentHeder.Hash(), nil, false)
}

notifications.Accumulator.SendAndReset(h.ctx, notifications.StateChangesConsumer, pendingBaseFee.Uint64(), currentHeder.GasLimit)
notifications.Accumulator.SendAndReset(h.ctx, notifications.StateChangesConsumer, pendingBaseFee.Uint64(), currentHeder.GasLimit, finalizedBlock)
}
// -- send notifications END
return nil
Expand Down
Loading