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

EIP-4844: Rename "data gas" to "blob gas" #7937

Merged
merged 3 commits into from
Jul 28, 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
11 changes: 6 additions & 5 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
"github.com/ledgerwatch/erigon-lib/common/hexutility"
"github.com/ledgerwatch/erigon-lib/kv"
state2 "github.com/ledgerwatch/erigon-lib/state"
Expand Down Expand Up @@ -172,7 +173,7 @@ func (b *SimulatedBackend) emptyPendingBlock() {
b.pendingBlock = blockChain.Blocks[0]
b.pendingReceipts = blockChain.Receipts[0]
b.pendingHeader = blockChain.Headers[0]
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddDataGas(chain.MaxDataGasPerBlock)
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
if b.pendingReaderTx != nil {
b.pendingReaderTx.Rollback()
}
Expand Down Expand Up @@ -723,7 +724,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).AddDataGas(math.MaxUint64)
gasPool := new(core.GasPool).AddGas(math.MaxUint64).AddBlobGas(math.MaxUint64)

return core.NewStateTransition(vmEnv, msg, gasPool).TransitionDb(true /* refunds */, false /* gasBailout */)
}
Expand Down Expand Up @@ -752,7 +753,7 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx types.Transac
&b.pendingHeader.Coinbase, b.gasPool,
b.pendingState, state.NewNoopWriter(),
b.pendingHeader, tx,
&b.pendingHeader.GasUsed, b.pendingHeader.DataGasUsed,
&b.pendingHeader.GasUsed, b.pendingHeader.BlobGasUsed,
vm.Config{}); err != nil {
return err
}
Expand Down Expand Up @@ -835,6 +836,6 @@ func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types2.AccessList { return m.CallMsg.AccessList }
func (m callMsg) IsFree() bool { return false }

func (m callMsg) DataGas() uint64 { return misc.GetDataGasUsed(len(m.CallMsg.DataHashes)) }
func (m callMsg) MaxFeePerDataGas() *uint256.Int { return m.CallMsg.MaxFeePerDataGas }
func (m callMsg) BlobGas() uint64 { return misc.GetBlobGasUsed(len(m.CallMsg.DataHashes)) }
func (m callMsg) MaxFeePerBlobGas() *uint256.Int { return m.CallMsg.MaxFeePerBlobGas }
func (m callMsg) DataHashes() []libcommon.Hash { return m.CallMsg.DataHashes }
32 changes: 16 additions & 16 deletions cl/cltypes/eth1_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type Eth1Block struct {
BlockHash libcommon.Hash
Transactions *solid.TransactionsSSZ
Withdrawals *solid.ListSSZ[*types.Withdrawal]
DataGasUsed uint64
ExcessDataGas uint64
BlobGasUsed uint64
ExcessBlobGas uint64
// internals
version clparams.StateVersion
}
Expand Down Expand Up @@ -72,9 +72,9 @@ func NewEth1BlockFromHeaderAndBody(header *types.Header, body *types.RawBody) *E
Withdrawals: solid.NewStaticListSSZFromList(body.Withdrawals, 16, 44),
}

if header.DataGasUsed != nil && header.ExcessDataGas != nil {
block.DataGasUsed = *header.DataGasUsed
block.ExcessDataGas = *header.ExcessDataGas
if header.BlobGasUsed != nil && header.ExcessBlobGas != nil {
block.BlobGasUsed = *header.BlobGasUsed
block.ExcessBlobGas = *header.ExcessBlobGas
block.version = clparams.DenebVersion
} else if header.WithdrawalsHash != nil {
block.version = clparams.CapellaVersion
Expand Down Expand Up @@ -102,10 +102,10 @@ func (b *Eth1Block) PayloadHeader() (*Eth1Header, error) {
}
}

var dataGasUsed, excessDataGas uint64
var blobGasUsed, excessBlobGas uint64
if b.version >= clparams.DenebVersion {
dataGasUsed = b.DataGasUsed
excessDataGas = b.ExcessDataGas
blobGasUsed = b.BlobGasUsed
excessBlobGas = b.ExcessBlobGas
}

return &Eth1Header{
Expand All @@ -124,8 +124,8 @@ func (b *Eth1Block) PayloadHeader() (*Eth1Header, error) {
BlockHash: b.BlockHash,
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalsRoot,
DataGasUsed: dataGasUsed,
ExcessDataGas: excessDataGas,
BlobGasUsed: blobGasUsed,
ExcessBlobGas: excessBlobGas,
version: b.version,
}, nil
}
Expand All @@ -149,7 +149,7 @@ func (b *Eth1Block) EncodingSizeSSZ() (size int) {
}

if b.version >= clparams.DenebVersion {
size += 8 * 2 // DataGasUsed + ExcessDataGas
size += 8 * 2 // BlobGasUsed + ExcessBlobGas
}

return
Expand Down Expand Up @@ -181,7 +181,7 @@ func (b *Eth1Block) getSchema() []interface{} {
s = append(s, b.Withdrawals)
}
if b.version >= clparams.DenebVersion {
s = append(s, &b.DataGasUsed, &b.ExcessDataGas)
s = append(s, &b.BlobGasUsed, &b.ExcessBlobGas)
}
return s
}
Expand Down Expand Up @@ -228,10 +228,10 @@ func (b *Eth1Block) RlpHeader() (*types.Header, error) {
}

if b.version >= clparams.DenebVersion {
dataGasUsed := b.DataGasUsed
header.DataGasUsed = &dataGasUsed
excessDataGas := b.ExcessDataGas
header.ExcessDataGas = &excessDataGas
blobGasUsed := b.BlobGasUsed
header.BlobGasUsed = &blobGasUsed
excessBlobGas := b.ExcessBlobGas
header.ExcessBlobGas = &excessBlobGas
}

// If the header hash does not match the block hash, return an error.
Expand Down
14 changes: 7 additions & 7 deletions cl/cltypes/eth1_header.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type Eth1Header struct {
BlockHash libcommon.Hash
TransactionsRoot libcommon.Hash
WithdrawalsRoot libcommon.Hash
DataGasUsed uint64
ExcessDataGas uint64
BlobGasUsed uint64
ExcessBlobGas uint64
// internals
version clparams.StateVersion
}
Expand Down Expand Up @@ -60,8 +60,8 @@ func (e *Eth1Header) Capella() {
// Capella converts the header to capella version.
func (e *Eth1Header) Deneb() {
e.version = clparams.DenebVersion
e.DataGasUsed = 0
e.ExcessDataGas = 0
e.BlobGasUsed = 0
e.ExcessBlobGas = 0
}

func (e *Eth1Header) IsZero() bool {
Expand All @@ -72,7 +72,7 @@ func (e *Eth1Header) IsZero() bool {
e.ReceiptsRoot == libcommon.Hash{} && e.LogsBloom == types.Bloom{} && e.PrevRandao == libcommon.Hash{} && e.BlockNumber == 0 &&
e.GasLimit == 0 && e.GasUsed == 0 && e.Time == 0 && e.Extra.EncodingSizeSSZ() == 0 && e.BaseFeePerGas == [32]byte{} &&
e.BlockHash == libcommon.Hash{} && e.TransactionsRoot == libcommon.Hash{} && e.WithdrawalsRoot == libcommon.Hash{} &&
e.DataGasUsed == 0 && e.ExcessDataGas == 0
e.BlobGasUsed == 0 && e.ExcessBlobGas == 0
}

// EncodeSSZ encodes the header in SSZ format.
Expand All @@ -98,7 +98,7 @@ func (h *Eth1Header) EncodingSizeSSZ() int {
}

if h.version >= clparams.DenebVersion {
size += 8 * 2 // DataGasUsed + ExcessDataGas
size += 8 * 2 // BlobGasUsed + ExcessBlobGas
}
if h.Extra == nil {
h.Extra = solid.NewExtraData()
Expand All @@ -121,7 +121,7 @@ func (h *Eth1Header) getSchema() []interface{} {
s = append(s, h.WithdrawalsRoot[:])
}
if h.version >= clparams.DenebVersion {
s = append(s, &h.DataGasUsed, &h.ExcessDataGas)
s = append(s, &h.BlobGasUsed, &h.ExcessBlobGas)
}
return s
}
Expand Down
8 changes: 4 additions & 4 deletions cl/cltypes/eth1_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestEth1Header(t *testing.T) {
blockHash := libcommon.Hash{}
transactionsRoot := libcommon.Hash{}
withdrawalsRoot := libcommon.Hash{}
dataGasUsed := uint64(50)
excessDataGas := uint64(60)
blobGasUsed := uint64(50)
excessBlobGas := uint64(60)

// Test Eth1Header
header = &Eth1Header{
Expand All @@ -54,8 +54,8 @@ func TestEth1Header(t *testing.T) {
BlockHash: blockHash,
TransactionsRoot: transactionsRoot,
WithdrawalsRoot: withdrawalsRoot,
DataGasUsed: dataGasUsed,
ExcessDataGas: excessDataGas,
BlobGasUsed: blobGasUsed,
ExcessBlobGas: excessBlobGas,
version: version,
}

Expand Down
8 changes: 4 additions & 4 deletions cl/phase1/execution_client/execution_client_direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func (cc *ExecutionClientDirect) NewPayload(payload *cltypes.Eth1Block) (invalid
}
// Process Deneb
if payload.Version() >= clparams.DenebVersion {
request.DataGasUsed = new(hexutil.Uint64)
request.ExcessDataGas = new(hexutil.Uint64)
*request.DataGasUsed = hexutil.Uint64(payload.DataGasUsed)
*request.ExcessDataGas = hexutil.Uint64(payload.ExcessDataGas)
request.BlobGasUsed = new(hexutil.Uint64)
request.ExcessBlobGas = new(hexutil.Uint64)
*request.BlobGasUsed = hexutil.Uint64(payload.BlobGasUsed)
*request.ExcessBlobGas = hexutil.Uint64(payload.ExcessBlobGas)
}

payloadStatus := &engine_types.PayloadStatus{} // As it is done in the rpcdaemon
Expand Down
8 changes: 4 additions & 4 deletions cl/phase1/execution_client/execution_client_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func (cc *ExecutionClientRpc) NewPayload(payload *cltypes.Eth1Block) (invalid bo
}
// Process Deneb
if payload.Version() >= clparams.DenebVersion {
request.DataGasUsed = new(hexutil.Uint64)
request.ExcessDataGas = new(hexutil.Uint64)
*request.DataGasUsed = hexutil.Uint64(payload.DataGasUsed)
*request.ExcessDataGas = hexutil.Uint64(payload.ExcessDataGas)
request.BlobGasUsed = new(hexutil.Uint64)
request.ExcessBlobGas = new(hexutil.Uint64)
*request.BlobGasUsed = hexutil.Uint64(payload.BlobGasUsed)
*request.ExcessBlobGas = hexutil.Uint64(payload.ExcessBlobGas)
}

payloadStatus := &engine_types.PayloadStatus{} // As it is done in the rpcdaemon
Expand Down
4 changes: 3 additions & 1 deletion cl/transition/impl/eth2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package eth2

import (
"encoding/binary"

libcommon "github.com/ledgerwatch/erigon-lib/common"

"github.com/ledgerwatch/erigon/cl/abstract"
"github.com/ledgerwatch/erigon/cl/cltypes"
"github.com/ledgerwatch/erigon/cl/utils"
Expand Down Expand Up @@ -40,7 +42,7 @@ func txPeekBlobVersionedHashes(txBytes []byte) []libcommon.Hash {
value: 32 bytes
data: 4 bytes - offset to C (relative to A)
access_list: 4 bytes - offset to D (relative to A)
max_fee_per_data_gas: 32 bytes
max_fee_per_blob_gas: 32 bytes
blob_versioned_hashes: 4 bytes - offset to E (relative to A)
*/
// field offset: 32 + 8 + 32 + 32 + 8 + 4 + 32 + 4 + 4 + 32 = 188
Expand Down
7 changes: 4 additions & 3 deletions cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
"github.com/ledgerwatch/erigon-lib/common/length"
"github.com/ledgerwatch/erigon-lib/kv"
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
Expand Down Expand Up @@ -500,9 +501,9 @@ func (b *blockProcessor) applyBlock(

header := block.Header()
b.vmConfig.Debug = true
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(chain2.MaxDataGasPerBlock)
gp := new(core.GasPool).AddGas(block.GasLimit()).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
usedGas := new(uint64)
usedDataGas := new(uint64)
usedBlobGas := new(uint64)
var receipts types.Receipts
rules := b.chainConfig.Rules(block.NumberU64(), block.Time())

Expand Down Expand Up @@ -535,7 +536,7 @@ func (b *blockProcessor) applyBlock(
ibs.SetTxContext(tx.Hash(), block.Hash(), i)
ct := exec3.NewCallTracer()
b.vmConfig.Tracer = ct
receipt, _, err := core.ApplyTransaction(b.chainConfig, getHashFn, b.engine, nil, gp, ibs, b.writer, header, tx, usedGas, usedDataGas, b.vmConfig)
receipt, _, err := core.ApplyTransaction(b.chainConfig, getHashFn, b.engine, nil, gp, ibs, b.writer, header, tx, usedGas, usedBlobGas, b.vmConfig)
if err != nil {
return nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/state/commands/erigon4.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
"github.com/ledgerwatch/erigon-lib/kv"
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
libstate "github.com/ledgerwatch/erigon-lib/state"
Expand Down Expand Up @@ -384,9 +385,9 @@ func processBlock23(startTxNum uint64, trace bool, txNumStart uint64, rw *StateR

header := block.Header()
vmConfig.Debug = true
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(chain2.MaxDataGasPerBlock)
gp := new(core.GasPool).AddGas(block.GasLimit()).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
usedGas := new(uint64)
usedDataGas := new(uint64)
usedBlobGas := new(uint64)
var receipts types.Receipts
rules := chainConfig.Rules(block.NumberU64(), block.Time())
txNum := txNumStart
Expand Down Expand Up @@ -420,7 +421,7 @@ func processBlock23(startTxNum uint64, trace bool, txNumStart uint64, rw *StateR
ibs.SetTxContext(tx.Hash(), block.Hash(), i)
ct := exec3.NewCallTracer()
vmConfig.Tracer = ct
receipt, _, err := core.ApplyTransaction(chainConfig, getHashFn, engine, nil, gp, ibs, ww, header, tx, usedGas, usedDataGas, vmConfig)
receipt, _, err := core.ApplyTransaction(chainConfig, getHashFn, engine, nil, gp, ibs, ww, header, tx, usedGas, usedBlobGas, vmConfig)
if err != nil {
return 0, nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/state/commands/opcode_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

chain2 "github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
Expand Down Expand Up @@ -710,9 +711,9 @@ func runBlock(engine consensus.Engine, ibs *state.IntraBlockState, txnWriter sta
chainConfig *chain2.Config, getHeader func(hash libcommon.Hash, number uint64) *types.Header, block *types.Block, vmConfig vm.Config, trace bool, logger log.Logger) (types.Receipts, error) {
header := block.Header()
vmConfig.TraceJumpDest = true
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(chain2.MaxDataGasPerBlock)
gp := new(core.GasPool).AddGas(block.GasLimit()).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
usedGas := new(uint64)
usedDataGas := new(uint64)
usedBlobGas := new(uint64)
var receipts types.Receipts
if chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(block.Number()) == 0 {
misc.ApplyDAOHardFork(ibs)
Expand All @@ -721,7 +722,7 @@ func runBlock(engine consensus.Engine, ibs *state.IntraBlockState, txnWriter sta
rules := chainConfig.Rules(block.NumberU64(), block.Time())
for i, tx := range block.Transactions() {
ibs.SetTxContext(tx.Hash(), block.Hash(), i)
receipt, _, err := core.ApplyTransaction(chainConfig, core.GetHashFn(header, getHeader), engine, nil, gp, ibs, txnWriter, header, tx, usedGas, usedDataGas, vmConfig)
receipt, _, err := core.ApplyTransaction(chainConfig, core.GetHashFn(header, getHeader), engine, nil, gp, ibs, txnWriter, header, tx, usedGas, usedBlobGas, vmConfig)
if err != nil {
return nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
}
Expand Down
8 changes: 4 additions & 4 deletions consensus/clique/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
// Verify the header's EIP-1559 attributes.
return err
}
if header.DataGasUsed != nil {
return fmt.Errorf("invalid dataGasUsed before fork: have %v, expected 'nil'", header.DataGasUsed)
if header.BlobGasUsed != nil {
return fmt.Errorf("invalid blobGasUsed before fork: have %v, expected 'nil'", header.BlobGasUsed)
}
if header.ExcessDataGas != nil {
return fmt.Errorf("invalid excessDataGas before fork: have %v, expected 'nil'", header.ExcessDataGas)
if header.ExcessBlobGas != nil {
return fmt.Errorf("invalid excessBlobGas before fork: have %v, expected 'nil'", header.ExcessBlobGas)
}

// Retrieve the snapshot needed to verify this header and cache it
Expand Down
8 changes: 4 additions & 4 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types
// Verify the header's EIP-1559 attributes.
return err
}
if header.DataGasUsed != nil {
return fmt.Errorf("invalid dataGasUsed before fork: have %v, expected 'nil'", header.DataGasUsed)
if header.BlobGasUsed != nil {
return fmt.Errorf("invalid blobGasUsed before fork: have %v, expected 'nil'", header.BlobGasUsed)
}
if header.ExcessDataGas != nil {
return fmt.Errorf("invalid excessDataGas before fork: have %v, expected 'nil'", header.ExcessDataGas)
if header.ExcessBlobGas != nil {
return fmt.Errorf("invalid excessBlobGas before fork: have %v, expected 'nil'", header.ExcessBlobGas)
}

// Verify that the block number is parent's +1
Expand Down
8 changes: 4 additions & 4 deletions consensus/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ func (s *Merge) verifyHeader(chain consensus.ChainHeaderReader, header, parent *
}

if !chain.Config().IsCancun(header.Time) {
if header.DataGasUsed != nil {
return fmt.Errorf("invalid dataGasUsed before fork: have %v, expected 'nil'", header.DataGasUsed)
if header.BlobGasUsed != nil {
return fmt.Errorf("invalid blobGasUsed before fork: have %v, expected 'nil'", header.BlobGasUsed)
}
if header.ExcessDataGas != nil {
return fmt.Errorf("invalid excessDataGas before fork: have %v, expected 'nil'", header.ExcessDataGas)
if header.ExcessBlobGas != nil {
return fmt.Errorf("invalid excessBlobGas before fork: have %v, expected 'nil'", header.ExcessBlobGas)
}
} else if err := misc.VerifyEip4844Header(chain.Config(), parent, header); err != nil {
// Verify the header's EIP-4844 attributes.
Expand Down
Loading