diff --git a/cmd/txpool/main.go b/cmd/txpool/main.go index 0cd049edb16..1dc3d7541fb 100644 --- a/cmd/txpool/main.go +++ b/cmd/txpool/main.go @@ -51,6 +51,7 @@ var ( priceLimit uint64 accountSlots uint64 + blobSlots uint64 priceBump uint64 blobPriceBump uint64 @@ -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) @@ -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 diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 77b23ad5ca9..c50f9dbd222 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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", @@ -1243,9 +1248,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) } diff --git a/eth/backend.go b/eth/backend.go index 73b99919a63..93789c8c6e8 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -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" @@ -639,11 +640,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 { diff --git a/eth/ethconfig/tx_pool.go b/eth/ethconfig/tx_pool.go index 5918d90d969..1bdcfe0c950 100644 --- a/eth/ethconfig/tx_pool.go +++ b/eth/ethconfig/tx_pool.go @@ -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 diff --git a/go.mod b/go.mod index 49ea06cf31a..32573073670 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 4b4abd0eb12..356688e0fd6 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/turbo/cli/default_flags.go b/turbo/cli/default_flags.go index 7344934f272..acd96696949 100644 --- a/turbo/cli/default_flags.go +++ b/turbo/cli/default_flags.go @@ -19,6 +19,7 @@ var DefaultFlags = []cli.Flag{ &utils.TxPoolPriceBumpFlag, &utils.TxPoolBlobPriceBumpFlag, &utils.TxPoolAccountSlotsFlag, + &utils.TxPoolBlobSlotsFlag, &utils.TxPoolGlobalSlotsFlag, &utils.TxPoolGlobalBaseFeeSlotsFlag, &utils.TxPoolAccountQueueFlag, diff --git a/turbo/shards/state_change_accumulator.go b/turbo/shards/state_change_accumulator.go index f4ab627bf49..8ba19686ee5 100644 --- a/turbo/shards/state_change_accumulator.go +++ b/turbo/shards/state_change_accumulator.go @@ -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 } diff --git a/turbo/stages/stageloop.go b/turbo/stages/stageloop.go index 189c6455fea..a0a45b9585d 100644 --- a/turbo/stages/stageloop.go +++ b/turbo/stages/stageloop.go @@ -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" @@ -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