eip-4844: adding data_gas to gaspool ()

Adding `data_gas` to gas pool. EIP-4844 gas pool includes data_gas which
is used to fee blob transactions.
This commit is contained in:
racytech 2023-05-03 08:02:30 +06:00 committed by GitHub
parent 9644e6d220
commit 40947f6c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 36 additions and 26 deletions

View File

@ -172,7 +172,7 @@ func (b *SimulatedBackend) emptyPendingBlock() {
b.pendingBlock = chain.Blocks[0]
b.pendingReceipts = chain.Receipts[0]
b.pendingHeader = chain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit)
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddDataGas(params.MaxDataGasPerBlock)
if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback()
}
@ -693,7 +693,7 @@ func (b *SimulatedBackend) callContract(_ context.Context, call ethereum.CallMsg
// Create a new environment which holds all relevant information
// about the transaction and calling mechanisms.
vmEnv := vm.NewEVM(evmContext, txContext, statedb, b.m.ChainConfig, vm.Config{})
gasPool := new(core.GasPool).AddGas(math.MaxUint64)
gasPool := new(core.GasPool).AddGas(math.MaxUint64).AddDataGas(math.MaxUint64)
return core.NewStateTransition(vmEnv, msg, gasPool).TransitionDb(true /* refunds */, false /* gasBailout */)
}

View File

@ -150,7 +150,7 @@ func (api *APIImpl) CallBundle(ctx context.Context, txHashes []common.Hash, stat
// Setup the gas pool (also for unmetered requests)
// and apply the message.
gp := new(core.GasPool).AddGas(math.MaxUint64)
gp := new(core.GasPool).AddGas(math.MaxUint64).AddDataGas(math.MaxUint64)
results := []map[string]interface{}{}

View File

@ -543,7 +543,7 @@ func (api *APIImpl) CreateAccessList(ctx context.Context, args ethapi2.CallArgs,
txCtx := core.NewEVMTxContext(msg)
evm := vm.NewEVM(blockCtx, txCtx, state, chainConfig, config)
gp := new(core.GasPool).AddGas(msg.Gas())
gp := new(core.GasPool).AddGas(msg.Gas()).AddDataGas(msg.DataGas())
res, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */)
if err != nil {
return nil, err

View File

@ -205,7 +205,7 @@ func (api *APIImpl) CallMany(ctx context.Context, bundles []Bundle, simulateCont
// Setup the gas pool (also for unmetered requests)
// and apply the message.
gp := new(core.GasPool).AddGas(math.MaxUint64)
gp := new(core.GasPool).AddGas(math.MaxUint64).AddDataGas(math.MaxUint64)
for idx, txn := range replayTransactions {
st.SetTxContext(txn.Hash(), block.Hash(), idx)
msg, err := txn.AsMessage(*signer, block.BaseFee(), rules)

View File

@ -31,6 +31,7 @@ import (
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/eth/filters"
"github.com/ledgerwatch/erigon/ethdb/cbor"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
"github.com/ledgerwatch/erigon/turbo/services"
@ -49,7 +50,7 @@ func (api *BaseAPI) getReceipts(ctx context.Context, tx kv.Tx, chainConfig *chai
}
usedGas := new(uint64)
gp := new(core.GasPool).AddGas(block.GasLimit())
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(params.MaxDataGasPerBlock)
noopWriter := state.NewNoopWriter()
@ -516,7 +517,7 @@ func (e *intraBlockExec) execTx(txNum uint64, txIndex int, txn types.Transaction
txHash := txn.Hash()
e.ibs.Reset()
e.ibs.SetTxContext(txHash, e.blockHash, txIndex)
gp := new(core.GasPool).AddGas(txn.GetGas())
gp := new(core.GasPool).AddGas(txn.GetGas()).AddDataGas(txn.GetDataGas())
msg, err := txn.AsMessage(*e.signer, e.header.BaseFee, e.rules)
if err != nil {
return nil, nil, err

View File

@ -142,7 +142,7 @@ func (api *OtterscanAPIImpl) runTracer(ctx context.Context, tx kv.Tx, hash commo
}
vmenv := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vmConfig)
result, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()), true, false /* gasBailout */)
result, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas()).AddDataGas(msg.DataGas()), true, false /* gasBailout */)
if err != nil {
return nil, fmt.Errorf("tracing failed: %v", err)
}

View File

@ -93,7 +93,7 @@ func (api *OtterscanAPIImpl) genericTracer(dbtx kv.Tx, ctx context.Context, bloc
TxContext := core.NewEVMTxContext(msg)
vmenv := vm.NewEVM(BlockContext, TxContext, ibs, chainConfig, vm.Config{Debug: true, Tracer: tracer})
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.GetGas()), true /* refunds */, false /* gasBailout */); err != nil {
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.GetGas()).AddDataGas(tx.GetDataGas()), true /* refunds */, false /* gasBailout */); err != nil {
return err
}
_ = ibs.FinalizeTx(rules, cachedWriter)

View File

@ -90,7 +90,7 @@ func (api *OtterscanAPIImpl) traceBlock(dbtx kv.Tx, ctx context.Context, blockNu
TxContext := core.NewEVMTxContext(msg)
vmenv := vm.NewEVM(BlockContext, TxContext, ibs, chainConfig, vm.Config{Debug: true, Tracer: tracer})
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.GetGas()), true /* refunds */, false /* gasBailout */); err != nil {
if _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(tx.GetGas()).AddDataGas(tx.GetDataGas()), true /* refunds */, false /* gasBailout */); err != nil {
return false, nil, err
}
_ = ibs.FinalizeTx(rules, cachedWriter)

View File

@ -971,7 +971,7 @@ func (api *TraceAPIImpl) Call(ctx context.Context, args TraceCallParam, traceTyp
evm.Cancel()
}()
gp := new(core.GasPool).AddGas(msg.Gas())
gp := new(core.GasPool).AddGas(msg.Gas()).AddDataGas(msg.DataGas())
var execResult *core.ExecutionResult
ibs.SetTxContext(libcommon.Hash{}, libcommon.Hash{}, 0)
execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, true /* gasBailout */)
@ -1187,7 +1187,7 @@ func (api *TraceAPIImpl) doCallMany(ctx context.Context, dbtx kv.Tx, msgs []type
evm := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vmConfig)
gp := new(core.GasPool).AddGas(msg.Gas())
gp := new(core.GasPool).AddGas(msg.Gas()).AddDataGas(msg.DataGas())
var execResult *core.ExecutionResult
// Clone the state cache before applying the changes, clone is discarded
var cloneReader state.StateReader

View File

@ -835,7 +835,7 @@ func (api *TraceAPIImpl) filterV3(ctx context.Context, dbtx kv.TemporalTx, fromB
txCtx := core.NewEVMTxContext(msg)
evm := vm.NewEVM(blockCtx, txCtx, ibs, chainConfig, vmConfig)
gp := new(core.GasPool).AddGas(msg.Gas())
gp := new(core.GasPool).AddGas(msg.Gas()).AddDataGas(msg.DataGas())
ibs.SetTxContext(txHash, lastBlockHash, txIndex)
var execResult *core.ExecutionResult
execResult, err = core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */)

View File

@ -449,7 +449,7 @@ func (api *PrivateDebugAPIImpl) TraceCallMany(ctx context.Context, bundles []Bun
// Setup the gas pool (also for unmetered requests)
// and apply the message.
gp := new(core.GasPool).AddGas(math.MaxUint64)
gp := new(core.GasPool).AddGas(math.MaxUint64).AddDataGas(math.MaxUint64)
for idx, txn := range replayTransactions {
st.SetTxContext(txn.Hash(), block.Hash(), idx)
msg, err := txn.AsMessage(*signer, block.BaseFee(), rules)

View File

@ -30,6 +30,7 @@ import (
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
)
@ -235,7 +236,7 @@ func runHistory22(trace bool, blockNum, txNumStart uint64, hw *state.HistoryRead
excessDataGas := header.ParentExcessDataGas(getHeader)
vmConfig.TraceJumpDest = true
engine := ethash.NewFullFaker()
gp := new(core.GasPool).AddGas(block.GasLimit())
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(params.MaxDataGasPerBlock)
usedGas := new(uint64)
var receipts types.Receipts
rules := chainConfig.Rules(block.NumberU64(), block.Time())

View File

@ -18,6 +18,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/rpchelper"
"github.com/ledgerwatch/log/v3"
"github.com/spf13/cobra"
@ -705,7 +706,7 @@ func runBlock(engine consensus.Engine, ibs *state.IntraBlockState, txnWriter sta
header := block.Header()
excessDataGas := header.ParentExcessDataGas(getHeader)
vmConfig.TraceJumpDest = true
gp := new(core.GasPool).AddGas(block.GasLimit())
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(params.MaxDataGasPerBlock)
usedGas := new(uint64)
var receipts types.Receipts
if chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(block.Number()) == 0 {

View File

@ -37,6 +37,7 @@ import (
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/core/vm/evmtypes"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rlp"
)
@ -87,7 +88,7 @@ func ExecuteBlockEphemerally(
usedGas := new(uint64)
gp := new(GasPool)
gp.AddGas(block.GasLimit())
gp.AddGas(block.GasLimit()).AddDataGas(params.MaxDataGasPerBlock)
var (
rejectedTxs []*RejectedTx
@ -201,7 +202,7 @@ func ExecuteBlockEphemerallyBor(
usedGas := new(uint64)
gp := new(GasPool)
gp.AddGas(block.GasLimit())
gp.AddGas(block.GasLimit()).AddDataGas(params.MaxDataGasPerBlock)
var (
rejectedTxs []*RejectedTx

View File

@ -57,6 +57,10 @@ func (ct CommonTx) GetTo() *libcommon.Address {
return ct.To
}
func (ct CommonTx) GetDataGas() uint64 {
return 0
}
func (ct CommonTx) GetGas() uint64 {
return ct.Gas
}

View File

@ -67,6 +67,7 @@ type Transaction interface {
Cost() *uint256.Int
GetDataHashes() []libcommon.Hash
GetGas() uint64
GetDataGas() uint64
GetValue() *uint256.Int
Time() time.Time
GetTo() *libcommon.Address

View File

@ -168,7 +168,7 @@ func testCallTracer(tracerName string, dirPath string, t *testing.T) {
if err != nil {
t.Fatalf("failed to prepare transaction for tracing: %v", err)
}
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.GetGas()), true /* refunds */, false /* gasBailout */)
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.GetGas()).AddDataGas(tx.GetDataGas()), true /* refunds */, false /* gasBailout */)
if err != nil {
t.Fatalf("failed to execute transaction: %v", err)
}
@ -273,7 +273,7 @@ func benchTracer(b *testing.B, tracerName string, test *callTracerTest) {
}
evm := vm.NewEVM(context, txContext, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
snap := statedb.Snapshot()
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.GetGas()))
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.GetGas()).AddDataGas(tx.GetDataGas()))
if _, err = st.TransitionDb(true /* refunds */, false /* gasBailout */); err != nil {
b.Fatalf("failed to execute transaction: %v", err)
}
@ -350,7 +350,7 @@ func TestZeroValueToNotExitCall(t *testing.T) {
if err != nil {
t.Fatalf("failed to prepare transaction for tracing: %v", err)
}
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.GetGas()))
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.GetGas()).AddDataGas(tx.GetDataGas()))
if _, err = st.TransitionDb(true /* refunds */, false /* gasBailout */); err != nil {
t.Fatalf("failed to execute transaction: %v", err)
}

View File

@ -131,7 +131,7 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
if err != nil {
t.Fatalf("failed to prepare transaction for tracing: %v", err)
}
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.GetGas()))
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.GetGas()).AddDataGas(tx.GetDataGas()))
if _, err = st.TransitionDb(true /* refunds */, false /* gasBailout */); err != nil {
t.Fatalf("failed to execute transaction: %v", err)
}

View File

@ -113,7 +113,7 @@ func TestPrestateTracerCreate2(t *testing.T) {
if err != nil {
t.Fatalf("failed to prepare transaction for tracing: %v", err)
}
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(txn.GetGas()))
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(txn.GetGas()).AddDataGas(txn.GetDataGas()))
if _, err = st.TransitionDb(false, false); err != nil {
t.Fatalf("failed to execute transaction: %v", err)
}

View File

@ -42,6 +42,7 @@ import (
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/erigon/turbo/trie"
)
@ -237,7 +238,7 @@ func (t *StateTest) RunNoVerify(tx kv.RwTx, subtest StateSubtest, vmconfig vm.Co
// Execute the message.
snapshot := statedb.Snapshot()
gaspool := new(core.GasPool)
gaspool.AddGas(block.GasLimit())
gaspool.AddGas(block.GasLimit()).AddDataGas(params.MaxDataGasPerBlock)
if _, err = core.ApplyMessage(evm, msg, gaspool, true /* refunds */, false /* gasBailout */); err != nil {
statedb.RevertToSnapshot(snapshot)
}

View File

@ -94,7 +94,7 @@ func DoCall(
evm.Cancel()
}()
gp := new(core.GasPool).AddGas(msg.Gas())
gp := new(core.GasPool).AddGas(msg.Gas()).AddDataGas(msg.DataGas())
result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */)
if err != nil {
return nil, err
@ -172,7 +172,7 @@ func (r *ReusableCaller) DoCallWithNewGas(
timedOut = true
}()
gp := new(core.GasPool).AddGas(r.message.Gas())
gp := new(core.GasPool).AddGas(r.message.Gas()).AddDataGas(r.message.DataGas())
result, err := core.ApplyMessage(r.evm, r.message, gp, true /* refunds */, false /* gasBailout */)
if err != nil {