Skip to content

Commit 7d35c6b

Browse files
authored
EIP-4844: Rename "data gas" to "blob gas" (#7937)
See ethereum/EIPs#7354 & ethereum/consensus-specs#3461. Prerequisite: ledgerwatch/erigon-lib#1058
1 parent d3f8b58 commit 7d35c6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+336
-319
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/ledgerwatch/erigon-lib/chain"
3232
libcommon "github.com/ledgerwatch/erigon-lib/common"
33+
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
3334
"github.com/ledgerwatch/erigon-lib/common/hexutility"
3435
"github.com/ledgerwatch/erigon-lib/kv"
3536
state2 "github.com/ledgerwatch/erigon-lib/state"
@@ -172,7 +173,7 @@ func (b *SimulatedBackend) emptyPendingBlock() {
172173
b.pendingBlock = blockChain.Blocks[0]
173174
b.pendingReceipts = blockChain.Receipts[0]
174175
b.pendingHeader = blockChain.Headers[0]
175-
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddDataGas(chain.MaxDataGasPerBlock)
176+
b.gasPool = new(core.GasPool).AddGas(b.pendingHeader.GasLimit).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
176177
if b.pendingReaderTx != nil {
177178
b.pendingReaderTx.Rollback()
178179
}
@@ -723,7 +724,7 @@ func (b *SimulatedBackend) callContract(_ context.Context, call ethereum.CallMsg
723724
// Create a new environment which holds all relevant information
724725
// about the transaction and calling mechanisms.
725726
vmEnv := vm.NewEVM(evmContext, txContext, statedb, b.m.ChainConfig, vm.Config{})
726-
gasPool := new(core.GasPool).AddGas(math.MaxUint64).AddDataGas(math.MaxUint64)
727+
gasPool := new(core.GasPool).AddGas(math.MaxUint64).AddBlobGas(math.MaxUint64)
727728

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

838-
func (m callMsg) DataGas() uint64 { return misc.GetDataGasUsed(len(m.CallMsg.DataHashes)) }
839-
func (m callMsg) MaxFeePerDataGas() *uint256.Int { return m.CallMsg.MaxFeePerDataGas }
839+
func (m callMsg) BlobGas() uint64 { return misc.GetBlobGasUsed(len(m.CallMsg.DataHashes)) }
840+
func (m callMsg) MaxFeePerBlobGas() *uint256.Int { return m.CallMsg.MaxFeePerBlobGas }
840841
func (m callMsg) DataHashes() []libcommon.Hash { return m.CallMsg.DataHashes }

cl/cltypes/eth1_block.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type Eth1Block struct {
3232
BlockHash libcommon.Hash
3333
Transactions *solid.TransactionsSSZ
3434
Withdrawals *solid.ListSSZ[*types.Withdrawal]
35-
DataGasUsed uint64
36-
ExcessDataGas uint64
35+
BlobGasUsed uint64
36+
ExcessBlobGas uint64
3737
// internals
3838
version clparams.StateVersion
3939
}
@@ -72,9 +72,9 @@ func NewEth1BlockFromHeaderAndBody(header *types.Header, body *types.RawBody) *E
7272
Withdrawals: solid.NewStaticListSSZFromList(body.Withdrawals, 16, 44),
7373
}
7474

75-
if header.DataGasUsed != nil && header.ExcessDataGas != nil {
76-
block.DataGasUsed = *header.DataGasUsed
77-
block.ExcessDataGas = *header.ExcessDataGas
75+
if header.BlobGasUsed != nil && header.ExcessBlobGas != nil {
76+
block.BlobGasUsed = *header.BlobGasUsed
77+
block.ExcessBlobGas = *header.ExcessBlobGas
7878
block.version = clparams.DenebVersion
7979
} else if header.WithdrawalsHash != nil {
8080
block.version = clparams.CapellaVersion
@@ -102,10 +102,10 @@ func (b *Eth1Block) PayloadHeader() (*Eth1Header, error) {
102102
}
103103
}
104104

105-
var dataGasUsed, excessDataGas uint64
105+
var blobGasUsed, excessBlobGas uint64
106106
if b.version >= clparams.DenebVersion {
107-
dataGasUsed = b.DataGasUsed
108-
excessDataGas = b.ExcessDataGas
107+
blobGasUsed = b.BlobGasUsed
108+
excessBlobGas = b.ExcessBlobGas
109109
}
110110

111111
return &Eth1Header{
@@ -124,8 +124,8 @@ func (b *Eth1Block) PayloadHeader() (*Eth1Header, error) {
124124
BlockHash: b.BlockHash,
125125
TransactionsRoot: transactionsRoot,
126126
WithdrawalsRoot: withdrawalsRoot,
127-
DataGasUsed: dataGasUsed,
128-
ExcessDataGas: excessDataGas,
127+
BlobGasUsed: blobGasUsed,
128+
ExcessBlobGas: excessBlobGas,
129129
version: b.version,
130130
}, nil
131131
}
@@ -149,7 +149,7 @@ func (b *Eth1Block) EncodingSizeSSZ() (size int) {
149149
}
150150

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

155155
return
@@ -181,7 +181,7 @@ func (b *Eth1Block) getSchema() []interface{} {
181181
s = append(s, b.Withdrawals)
182182
}
183183
if b.version >= clparams.DenebVersion {
184-
s = append(s, &b.DataGasUsed, &b.ExcessDataGas)
184+
s = append(s, &b.BlobGasUsed, &b.ExcessBlobGas)
185185
}
186186
return s
187187
}
@@ -228,10 +228,10 @@ func (b *Eth1Block) RlpHeader() (*types.Header, error) {
228228
}
229229

230230
if b.version >= clparams.DenebVersion {
231-
dataGasUsed := b.DataGasUsed
232-
header.DataGasUsed = &dataGasUsed
233-
excessDataGas := b.ExcessDataGas
234-
header.ExcessDataGas = &excessDataGas
231+
blobGasUsed := b.BlobGasUsed
232+
header.BlobGasUsed = &blobGasUsed
233+
excessBlobGas := b.ExcessBlobGas
234+
header.ExcessBlobGas = &excessBlobGas
235235
}
236236

237237
// If the header hash does not match the block hash, return an error.

cl/cltypes/eth1_header.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type Eth1Header struct {
3030
BlockHash libcommon.Hash
3131
TransactionsRoot libcommon.Hash
3232
WithdrawalsRoot libcommon.Hash
33-
DataGasUsed uint64
34-
ExcessDataGas uint64
33+
BlobGasUsed uint64
34+
ExcessBlobGas uint64
3535
// internals
3636
version clparams.StateVersion
3737
}
@@ -60,8 +60,8 @@ func (e *Eth1Header) Capella() {
6060
// Capella converts the header to capella version.
6161
func (e *Eth1Header) Deneb() {
6262
e.version = clparams.DenebVersion
63-
e.DataGasUsed = 0
64-
e.ExcessDataGas = 0
63+
e.BlobGasUsed = 0
64+
e.ExcessBlobGas = 0
6565
}
6666

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

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

100100
if h.version >= clparams.DenebVersion {
101-
size += 8 * 2 // DataGasUsed + ExcessDataGas
101+
size += 8 * 2 // BlobGasUsed + ExcessBlobGas
102102
}
103103
if h.Extra == nil {
104104
h.Extra = solid.NewExtraData()
@@ -121,7 +121,7 @@ func (h *Eth1Header) getSchema() []interface{} {
121121
s = append(s, h.WithdrawalsRoot[:])
122122
}
123123
if h.version >= clparams.DenebVersion {
124-
s = append(s, &h.DataGasUsed, &h.ExcessDataGas)
124+
s = append(s, &h.BlobGasUsed, &h.ExcessBlobGas)
125125
}
126126
return s
127127
}

cl/cltypes/eth1_header_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func TestEth1Header(t *testing.T) {
3434
blockHash := libcommon.Hash{}
3535
transactionsRoot := libcommon.Hash{}
3636
withdrawalsRoot := libcommon.Hash{}
37-
dataGasUsed := uint64(50)
38-
excessDataGas := uint64(60)
37+
blobGasUsed := uint64(50)
38+
excessBlobGas := uint64(60)
3939

4040
// Test Eth1Header
4141
header = &Eth1Header{
@@ -54,8 +54,8 @@ func TestEth1Header(t *testing.T) {
5454
BlockHash: blockHash,
5555
TransactionsRoot: transactionsRoot,
5656
WithdrawalsRoot: withdrawalsRoot,
57-
DataGasUsed: dataGasUsed,
58-
ExcessDataGas: excessDataGas,
57+
BlobGasUsed: blobGasUsed,
58+
ExcessBlobGas: excessBlobGas,
5959
version: version,
6060
}
6161

cl/phase1/execution_client/execution_client_direct.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ func (cc *ExecutionClientDirect) NewPayload(payload *cltypes.Eth1Block) (invalid
6363
}
6464
// Process Deneb
6565
if payload.Version() >= clparams.DenebVersion {
66-
request.DataGasUsed = new(hexutil.Uint64)
67-
request.ExcessDataGas = new(hexutil.Uint64)
68-
*request.DataGasUsed = hexutil.Uint64(payload.DataGasUsed)
69-
*request.ExcessDataGas = hexutil.Uint64(payload.ExcessDataGas)
66+
request.BlobGasUsed = new(hexutil.Uint64)
67+
request.ExcessBlobGas = new(hexutil.Uint64)
68+
*request.BlobGasUsed = hexutil.Uint64(payload.BlobGasUsed)
69+
*request.ExcessBlobGas = hexutil.Uint64(payload.ExcessBlobGas)
7070
}
7171

7272
payloadStatus := &engine_types.PayloadStatus{} // As it is done in the rpcdaemon

cl/phase1/execution_client/execution_client_rpc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ func (cc *ExecutionClientRpc) NewPayload(payload *cltypes.Eth1Block) (invalid bo
102102
}
103103
// Process Deneb
104104
if payload.Version() >= clparams.DenebVersion {
105-
request.DataGasUsed = new(hexutil.Uint64)
106-
request.ExcessDataGas = new(hexutil.Uint64)
107-
*request.DataGasUsed = hexutil.Uint64(payload.DataGasUsed)
108-
*request.ExcessDataGas = hexutil.Uint64(payload.ExcessDataGas)
105+
request.BlobGasUsed = new(hexutil.Uint64)
106+
request.ExcessBlobGas = new(hexutil.Uint64)
107+
*request.BlobGasUsed = hexutil.Uint64(payload.BlobGasUsed)
108+
*request.ExcessBlobGas = hexutil.Uint64(payload.ExcessBlobGas)
109109
}
110110

111111
payloadStatus := &engine_types.PayloadStatus{} // As it is done in the rpcdaemon

cl/transition/impl/eth2/utils.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package eth2
22

33
import (
44
"encoding/binary"
5+
56
libcommon "github.com/ledgerwatch/erigon-lib/common"
7+
68
"github.com/ledgerwatch/erigon/cl/abstract"
79
"github.com/ledgerwatch/erigon/cl/cltypes"
810
"github.com/ledgerwatch/erigon/cl/utils"
@@ -40,7 +42,7 @@ func txPeekBlobVersionedHashes(txBytes []byte) []libcommon.Hash {
4042
value: 32 bytes
4143
data: 4 bytes - offset to C (relative to A)
4244
access_list: 4 bytes - offset to D (relative to A)
43-
max_fee_per_data_gas: 32 bytes
45+
max_fee_per_blob_gas: 32 bytes
4446
blob_versioned_hashes: 4 bytes - offset to E (relative to A)
4547
*/
4648
// field offset: 32 + 8 + 32 + 32 + 8 + 4 + 32 + 4 + 4 + 32 = 188

cmd/integration/commands/state_domains.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
libcommon "github.com/ledgerwatch/erigon-lib/common"
2323
"github.com/ledgerwatch/erigon-lib/common/datadir"
2424
"github.com/ledgerwatch/erigon-lib/common/dbg"
25+
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
2526
"github.com/ledgerwatch/erigon-lib/common/length"
2627
"github.com/ledgerwatch/erigon-lib/kv"
2728
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
@@ -500,9 +501,9 @@ func (b *blockProcessor) applyBlock(
500501

501502
header := block.Header()
502503
b.vmConfig.Debug = true
503-
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(chain2.MaxDataGasPerBlock)
504+
gp := new(core.GasPool).AddGas(block.GasLimit()).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
504505
usedGas := new(uint64)
505-
usedDataGas := new(uint64)
506+
usedBlobGas := new(uint64)
506507
var receipts types.Receipts
507508
rules := b.chainConfig.Rules(block.NumberU64(), block.Time())
508509

@@ -535,7 +536,7 @@ func (b *blockProcessor) applyBlock(
535536
ibs.SetTxContext(tx.Hash(), block.Hash(), i)
536537
ct := exec3.NewCallTracer()
537538
b.vmConfig.Tracer = ct
538-
receipt, _, err := core.ApplyTransaction(b.chainConfig, getHashFn, b.engine, nil, gp, ibs, b.writer, header, tx, usedGas, usedDataGas, b.vmConfig)
539+
receipt, _, err := core.ApplyTransaction(b.chainConfig, getHashFn, b.engine, nil, gp, ibs, b.writer, header, tx, usedGas, usedBlobGas, b.vmConfig)
539540
if err != nil {
540541
return nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
541542
}

cmd/state/commands/erigon4.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
libcommon "github.com/ledgerwatch/erigon-lib/common"
2424
"github.com/ledgerwatch/erigon-lib/common/datadir"
2525
"github.com/ledgerwatch/erigon-lib/common/dbg"
26+
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
2627
"github.com/ledgerwatch/erigon-lib/kv"
2728
kv2 "github.com/ledgerwatch/erigon-lib/kv/mdbx"
2829
libstate "github.com/ledgerwatch/erigon-lib/state"
@@ -384,9 +385,9 @@ func processBlock23(startTxNum uint64, trace bool, txNumStart uint64, rw *StateR
384385

385386
header := block.Header()
386387
vmConfig.Debug = true
387-
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(chain2.MaxDataGasPerBlock)
388+
gp := new(core.GasPool).AddGas(block.GasLimit()).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
388389
usedGas := new(uint64)
389-
usedDataGas := new(uint64)
390+
usedBlobGas := new(uint64)
390391
var receipts types.Receipts
391392
rules := chainConfig.Rules(block.NumberU64(), block.Time())
392393
txNum := txNumStart
@@ -420,7 +421,7 @@ func processBlock23(startTxNum uint64, trace bool, txNumStart uint64, rw *StateR
420421
ibs.SetTxContext(tx.Hash(), block.Hash(), i)
421422
ct := exec3.NewCallTracer()
422423
vmConfig.Tracer = ct
423-
receipt, _, err := core.ApplyTransaction(chainConfig, getHashFn, engine, nil, gp, ibs, ww, header, tx, usedGas, usedDataGas, vmConfig)
424+
receipt, _, err := core.ApplyTransaction(chainConfig, getHashFn, engine, nil, gp, ibs, ww, header, tx, usedGas, usedBlobGas, vmConfig)
424425
if err != nil {
425426
return 0, nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
426427
}

cmd/state/commands/opcode_tracer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
chain2 "github.com/ledgerwatch/erigon-lib/chain"
2020
libcommon "github.com/ledgerwatch/erigon-lib/common"
21+
"github.com/ledgerwatch/erigon-lib/common/fixedgas"
2122
"github.com/ledgerwatch/erigon-lib/kv"
2223
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
2324
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
@@ -710,9 +711,9 @@ func runBlock(engine consensus.Engine, ibs *state.IntraBlockState, txnWriter sta
710711
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) {
711712
header := block.Header()
712713
vmConfig.TraceJumpDest = true
713-
gp := new(core.GasPool).AddGas(block.GasLimit()).AddDataGas(chain2.MaxDataGasPerBlock)
714+
gp := new(core.GasPool).AddGas(block.GasLimit()).AddBlobGas(fixedgas.MaxBlobGasPerBlock)
714715
usedGas := new(uint64)
715-
usedDataGas := new(uint64)
716+
usedBlobGas := new(uint64)
716717
var receipts types.Receipts
717718
if chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(block.Number()) == 0 {
718719
misc.ApplyDAOHardFork(ibs)
@@ -721,7 +722,7 @@ func runBlock(engine consensus.Engine, ibs *state.IntraBlockState, txnWriter sta
721722
rules := chainConfig.Rules(block.NumberU64(), block.Time())
722723
for i, tx := range block.Transactions() {
723724
ibs.SetTxContext(tx.Hash(), block.Hash(), i)
724-
receipt, _, err := core.ApplyTransaction(chainConfig, core.GetHashFn(header, getHeader), engine, nil, gp, ibs, txnWriter, header, tx, usedGas, usedDataGas, vmConfig)
725+
receipt, _, err := core.ApplyTransaction(chainConfig, core.GetHashFn(header, getHeader), engine, nil, gp, ibs, txnWriter, header, tx, usedGas, usedBlobGas, vmConfig)
725726
if err != nil {
726727
return nil, fmt.Errorf("could not apply tx %d [%x] failed: %w", i, tx.Hash(), err)
727728
}

0 commit comments

Comments
 (0)