Skip to content

Commit

Permalink
Txpool 4844 upgrades Part 2 (#8213)
Browse files Browse the repository at this point in the history
Some peer-review changes from the last related PR. 
Addition of a flag for BlobSlots - for max allowed blobs per account in
txpool.
Use BlobFee from the block to validate txs in the pool.

See also ledgerwatch/erigon-lib#1125
  • Loading branch information
somnathb1 authored Sep 20, 2023
1 parent f6a6ab9 commit f51d9b6
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 9 deletions.
3 changes: 3 additions & 0 deletions cmd/txpool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (

priceLimit uint64
accountSlots uint64
blobSlots uint64
priceBump uint64
blobPriceBump uint64

Expand All @@ -75,6 +76,7 @@ func init() {
rootCmd.PersistentFlags().IntVar(&queuedPoolLimit, "txpool.globalqueue", txpoolcfg.DefaultConfig.QueuedSubPoolLimit, "Maximum number of non-executable transaction slots for all accounts")
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(&blobSlots, "txpool.blobslots", txpoolcfg.DefaultConfig.BlobSlots, "Max allowed total number of blobs (within type-3 txs) 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)
Expand Down Expand Up @@ -141,6 +143,7 @@ func doTxpool(ctx context.Context, logger log.Logger) error {
cfg.QueuedSubPoolLimit = queuedPoolLimit
cfg.MinFeeCap = priceLimit
cfg.AccountSlots = accountSlots
cfg.BlobSlots = blobSlots
cfg.PriceBump = priceBump
cfg.BlobPriceBump = blobPriceBump

Expand Down
11 changes: 11 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ var (
Usage: "Minimum number of executable transaction slots guaranteed per account",
Value: ethconfig.Defaults.DeprecatedTxPool.AccountSlots,
}
TxPoolBlobSlotsFlag = cli.Uint64Flag{
Name: "txpool.blobslots",
Usage: "Max allowed total number of blobs (within type-3 txs) per account",
Value: txpoolcfg.DefaultConfig.BlobSlots,
}
TxPoolGlobalSlotsFlag = cli.Uint64Flag{
Name: "txpool.globalslots",
Usage: "Maximum number of executable transaction slots for all accounts",
Expand Down Expand Up @@ -1250,9 +1255,15 @@ func setTxPool(ctx *cli.Context, fullCfg *ethconfig.Config) {
if ctx.IsSet(TxPoolPriceBumpFlag.Name) {
cfg.PriceBump = ctx.Uint64(TxPoolPriceBumpFlag.Name)
}
if ctx.IsSet(TxPoolBlobPriceBumpFlag.Name) {
fullCfg.TxPool.BlobPriceBump = ctx.Uint64(TxPoolBlobPriceBumpFlag.Name)
}
if ctx.IsSet(TxPoolAccountSlotsFlag.Name) {
cfg.AccountSlots = ctx.Uint64(TxPoolAccountSlotsFlag.Name)
}
if ctx.IsSet(TxPoolBlobSlotsFlag.Name) {
fullCfg.TxPool.BlobSlots = ctx.Uint64(TxPoolBlobSlotsFlag.Name)
}
if ctx.IsSet(TxPoolGlobalSlotsFlag.Name) {
cfg.GlobalSlots = ctx.Uint64(TxPoolGlobalSlotsFlag.Name)
}
Expand Down
13 changes: 10 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import (
"github.com/ledgerwatch/erigon/consensus/clique"
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/consensus/merge"
"github.com/ledgerwatch/erigon/consensus/misc"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state/temporal"
Expand Down Expand Up @@ -645,11 +646,17 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
time.Sleep(10 * time.Millisecond)
baseFee := uint64(0)
if currentBlock.BaseFee() != nil {
baseFee = currentBlock.BaseFee().Uint64()
baseFee = misc.CalcBaseFee(chainConfig, currentBlock.Header()).Uint64()
}
blobFee := uint64(params.MinBlobGasPrice)
if currentBlock.Header().ExcessBlobGas != nil {
b, err := misc.GetBlobGasPrice(misc.CalcExcessBlobGas(currentBlock.Header()))
if err == nil && b.Cmp(uint256.NewInt(0)) > 0 {
blobFee = b.Uint64()
}
}
backend.notifications.Accumulator.StartChange(currentBlock.NumberU64(), currentBlock.Hash(), nil, false)
backend.notifications.Accumulator.SendAndReset(ctx, backend.notifications.StateChangesConsumer, baseFee, currentBlock.GasLimit(), 0)

backend.notifications.Accumulator.SendAndReset(ctx, backend.notifications.StateChangesConsumer, baseFee, blobFee, currentBlock.GasLimit(), 0)
}()

if !config.DeprecatedTxPool.Disable {
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var DefaultTxPool2Config = func(fullCfg *Config) txpoolcfg.Config {
cfg.BlobPriceBump = fullCfg.TxPool.BlobPriceBump
cfg.MinFeeCap = pool1Cfg.PriceLimit
cfg.AccountSlots = pool1Cfg.AccountSlots
cfg.BlobSlots = fullCfg.TxPool.BlobSlots
cfg.LogEvery = 1 * time.Minute
cfg.CommitEvery = 5 * time.Minute
cfg.TracedSenders = pool1Cfg.TracedSenders
Expand Down
2 changes: 1 addition & 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.33.1
github.com/ledgerwatch/erigon-lib v0.0.0-20230918032038-e77827a43066
github.com/ledgerwatch/erigon-lib v0.0.0-20230920112310-93d9c9d9fe4b
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230911054727-4e865b051314
github.com/ledgerwatch/log/v3 v3.9.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230918032038-e77827a43066 h1:hyax1voOfuHvfUYrL+IhScvUATvpa3ni9h1ijAJxOnA=
github.com/ledgerwatch/erigon-lib v0.0.0-20230918032038-e77827a43066/go.mod h1:WTy84hKK3Z939hGTqew2AMjVSnbMrPBxUDILCzCOw9k=
github.com/ledgerwatch/erigon-lib v0.0.0-20230920112310-93d9c9d9fe4b h1:vP4mKRv6R8NsG8q+mzTzNqpbL0mrGs9JkJVgY8oeaXM=
github.com/ledgerwatch/erigon-lib v0.0.0-20230920112310-93d9c9d9fe4b/go.mod h1:l1i6+H9MgizD+ObQ5cXsfA9S3egYTOCnnYGjbrJMqR4=
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230911054727-4e865b051314 h1:TeQoOW2o0rL5jF4ava+SlB8l0mhzM8ISnq81okJ790c=
github.com/ledgerwatch/erigon-snapshot v1.2.1-0.20230911054727-4e865b051314/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=
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 @@ -19,6 +19,7 @@ var DefaultFlags = []cli.Flag{
&utils.TxPoolPriceBumpFlag,
&utils.TxPoolBlobPriceBumpFlag,
&utils.TxPoolAccountSlotsFlag,
&utils.TxPoolBlobSlotsFlag,
&utils.TxPoolGlobalSlotsFlag,
&utils.TxPoolGlobalBaseFeeSlotsFlag,
&utils.TxPoolAccountQueueFlag,
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, finalizedBlock uint64) {
func (a *Accumulator) SendAndReset(ctx context.Context, c StateChangeConsumer, pendingBaseFee uint64, pendingBlobFee 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, FinalizedBlock: finalizedBlock}
sc := &remote.StateChangeBatch{StateVersionId: a.plainStateID, ChangeBatch: a.changes, PendingBlockBaseFee: pendingBaseFee, BlockGasLimit: blockGasLimit, FinalizedBlock: finalizedBlock, PendingBlobFeePerGas: pendingBlobFee}
c.SendStateChanges(ctx, sc)
a.Reset(0) // reset here for GC, but there will be another Reset with correct viewID
}
Expand Down
14 changes: 13 additions & 1 deletion turbo/stages/stageloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/memdb"
"github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/engineapi/engine_helpers"
"github.com/ledgerwatch/erigon/turbo/services"

Expand Down Expand Up @@ -308,8 +309,19 @@ func (h *Hook) AfterRun(tx kv.Tx, finishProgressBefore uint64) error {
if currentHeder.Number.Uint64() == 0 {
notifications.Accumulator.StartChange(0, currentHeder.Hash(), nil, false)
}
var pendingBlobFee uint64 = params.MinBlobGasPrice
excessBlobGas := misc.CalcExcessBlobGas(currentHeder)
if currentHeder.ExcessBlobGas != nil {
f, err := misc.GetBlobGasPrice(excessBlobGas)
if err != nil {
return err
}
if f != nil && f.Cmp(uint256.NewInt(1)) >= 0 {
pendingBlobFee = f.Uint64()
}
}

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

0 comments on commit f51d9b6

Please sign in to comment.