all: rename dataGas to blobGas (#27789)

This commit is contained in:
Péter Szilágyi
2023-07-27 16:53:28 +03:00
committed by GitHub
parent 0f4b21feac
commit 57268f7e6c
32 changed files with 224 additions and 225 deletions
+4 -4
View File
@@ -84,14 +84,14 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
// Blob transactions may be present after the Cancun fork.
var blobs int
for _, tx := range block.Transactions() {
// Count the number of blobs to validate against the header's dataGasUsed
// Count the number of blobs to validate against the header's blobGasUsed
blobs += len(tx.BlobHashes())
// The individual checks for blob validity (version-check + not empty)
// happens in the state_transition check.
}
if header.DataGasUsed != nil {
if want := *header.DataGasUsed / params.BlobTxDataGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated
return fmt.Errorf("data gas used mismatch (header %v, calculated %v)", *header.DataGasUsed, blobs*params.BlobTxDataGasPerBlob)
if header.BlobGasUsed != nil {
if want := *header.BlobGasUsed / params.BlobTxBlobGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated
return fmt.Errorf("data gas used mismatch (header %v, calculated %v)", *header.BlobGasUsed, blobs*params.BlobTxBlobGasPerBlob)
}
} else {
if blobs > 0 {
+5 -7
View File
@@ -2028,17 +2028,15 @@ func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error)
// collectLogs collects the logs that were generated or removed during
// the processing of a block. These logs are later announced as deleted or reborn.
func (bc *BlockChain) collectLogs(b *types.Block, removed bool) []*types.Log {
var dataGasPrice *big.Int
excessDataGas := b.ExcessDataGas()
if excessDataGas != nil {
dataGasPrice = eip4844.CalcBlobFee(*excessDataGas)
var blobGasPrice *big.Int
excessBlobGas := b.ExcessBlobGas()
if excessBlobGas != nil {
blobGasPrice = eip4844.CalcBlobFee(*excessBlobGas)
}
receipts := rawdb.ReadRawReceipts(bc.db, b.Hash(), b.NumberU64())
if err := receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), dataGasPrice, b.Transactions()); err != nil {
if err := receipts.DeriveFields(bc.chainConfig, b.Hash(), b.NumberU64(), b.Time(), b.BaseFee(), blobGasPrice, b.Transactions()); err != nil {
log.Error("Failed to derive block receipts fields", "hash", b.Hash(), "number", b.NumberU64(), "err", err)
}
var logs []*types.Log
for _, receipt := range receipts {
for _, log := range receipt.Logs {
+1 -1
View File
@@ -66,7 +66,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
BaseFee: baseFee,
GasLimit: header.GasLimit,
Random: random,
ExcessDataGas: header.ExcessDataGas,
ExcessBlobGas: header.ExcessBlobGas,
}
}
+10 -10
View File
@@ -31,8 +31,8 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
ExcessDataGas *math.HexOrDecimal64 `json:"excessDataGas"`
DataGasUsed *math.HexOrDecimal64 `json:"dataGasUsed"`
ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"`
BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"`
}
var enc Genesis
enc.Config = g.Config
@@ -53,8 +53,8 @@ func (g Genesis) MarshalJSON() ([]byte, error) {
enc.GasUsed = math.HexOrDecimal64(g.GasUsed)
enc.ParentHash = g.ParentHash
enc.BaseFee = (*math.HexOrDecimal256)(g.BaseFee)
enc.ExcessDataGas = (*math.HexOrDecimal64)(g.ExcessDataGas)
enc.DataGasUsed = (*math.HexOrDecimal64)(g.DataGasUsed)
enc.ExcessBlobGas = (*math.HexOrDecimal64)(g.ExcessBlobGas)
enc.BlobGasUsed = (*math.HexOrDecimal64)(g.BlobGasUsed)
return json.Marshal(&enc)
}
@@ -74,8 +74,8 @@ func (g *Genesis) UnmarshalJSON(input []byte) error {
GasUsed *math.HexOrDecimal64 `json:"gasUsed"`
ParentHash *common.Hash `json:"parentHash"`
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
ExcessDataGas *math.HexOrDecimal64 `json:"excessDataGas"`
DataGasUsed *math.HexOrDecimal64 `json:"dataGasUsed"`
ExcessBlobGas *math.HexOrDecimal64 `json:"excessBlobGas"`
BlobGasUsed *math.HexOrDecimal64 `json:"blobGasUsed"`
}
var dec Genesis
if err := json.Unmarshal(input, &dec); err != nil {
@@ -126,11 +126,11 @@ func (g *Genesis) UnmarshalJSON(input []byte) error {
if dec.BaseFee != nil {
g.BaseFee = (*big.Int)(dec.BaseFee)
}
if dec.ExcessDataGas != nil {
g.ExcessDataGas = (*uint64)(dec.ExcessDataGas)
if dec.ExcessBlobGas != nil {
g.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
}
if dec.DataGasUsed != nil {
g.DataGasUsed = (*uint64)(dec.DataGasUsed)
if dec.BlobGasUsed != nil {
g.BlobGasUsed = (*uint64)(dec.BlobGasUsed)
}
return nil
}
+12 -12
View File
@@ -63,8 +63,8 @@ type Genesis struct {
GasUsed uint64 `json:"gasUsed"`
ParentHash common.Hash `json:"parentHash"`
BaseFee *big.Int `json:"baseFeePerGas"` // EIP-1559
ExcessDataGas *uint64 `json:"excessDataGas"` // EIP-4844
DataGasUsed *uint64 `json:"dataGasUsed"` // EIP-4844
ExcessBlobGas *uint64 `json:"excessBlobGas"` // EIP-4844
BlobGasUsed *uint64 `json:"blobGasUsed"` // EIP-4844
}
func ReadGenesis(db ethdb.Database) (*Genesis, error) {
@@ -99,8 +99,8 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) {
genesis.Mixhash = genesisHeader.MixDigest
genesis.Coinbase = genesisHeader.Coinbase
genesis.BaseFee = genesisHeader.BaseFee
genesis.ExcessDataGas = genesisHeader.ExcessDataGas
genesis.DataGasUsed = genesisHeader.DataGasUsed
genesis.ExcessBlobGas = genesisHeader.ExcessBlobGas
genesis.BlobGasUsed = genesisHeader.BlobGasUsed
return &genesis, nil
}
@@ -228,8 +228,8 @@ type genesisSpecMarshaling struct {
Difficulty *math.HexOrDecimal256
Alloc map[common.UnprefixedAddress]GenesisAccount
BaseFee *math.HexOrDecimal256
ExcessDataGas *math.HexOrDecimal64
DataGasUsed *math.HexOrDecimal64
ExcessBlobGas *math.HexOrDecimal64
BlobGasUsed *math.HexOrDecimal64
}
type genesisAccountMarshaling struct {
@@ -477,13 +477,13 @@ func (g *Genesis) ToBlock() *types.Block {
withdrawals = make([]*types.Withdrawal, 0)
}
if conf.IsCancun(num, g.Timestamp) {
head.ExcessDataGas = g.ExcessDataGas
head.DataGasUsed = g.DataGasUsed
if head.ExcessDataGas == nil {
head.ExcessDataGas = new(uint64)
head.ExcessBlobGas = g.ExcessBlobGas
head.BlobGasUsed = g.BlobGasUsed
if head.ExcessBlobGas == nil {
head.ExcessBlobGas = new(uint64)
}
if head.DataGasUsed == nil {
head.DataGasUsed = new(uint64)
if head.BlobGasUsed == nil {
head.BlobGasUsed = new(uint64)
}
}
}
+4 -6
View File
@@ -645,14 +645,12 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, time uint64,
} else {
baseFee = header.BaseFee
}
// Compute effective data gas price.
var dataGasPrice *big.Int
if header != nil && header.ExcessDataGas != nil {
dataGasPrice = eip4844.CalcBlobFee(*header.ExcessDataGas)
var blobGasPrice *big.Int
if header != nil && header.ExcessBlobGas != nil {
blobGasPrice = eip4844.CalcBlobFee(*header.ExcessBlobGas)
}
if err := receipts.DeriveFields(config, hash, number, time, baseFee, dataGasPrice, body.Transactions); err != nil {
if err := receipts.DeriveFields(config, hash, number, time, baseFee, blobGasPrice, body.Transactions); err != nil {
log.Error("Failed to derive block receipts fields", "hash", hash, "number", number, "err", err)
return nil
}
+7 -7
View File
@@ -402,14 +402,14 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
header.Root = common.BytesToHash(hasher.Sum(nil))
if config.IsCancun(header.Number, header.Time) {
var pExcess, pUsed = uint64(0), uint64(0)
if parent.ExcessDataGas() != nil {
pExcess = *parent.ExcessDataGas()
pUsed = *parent.DataGasUsed()
if parent.ExcessBlobGas() != nil {
pExcess = *parent.ExcessBlobGas()
pUsed = *parent.BlobGasUsed()
}
excess := eip4844.CalcExcessDataGas(pExcess, pUsed)
used := uint64(nBlobs * params.BlobTxDataGasPerBlob)
header.ExcessDataGas = &excess
header.DataGasUsed = &used
excess := eip4844.CalcExcessBlobGas(pExcess, pUsed)
used := uint64(nBlobs * params.BlobTxBlobGasPerBlob)
header.ExcessBlobGas = &excess
header.BlobGasUsed = &used
}
// Assemble and return the final block for sealing
if config.IsShanghai(header.Number, header.Time) {
+12 -12
View File
@@ -241,18 +241,18 @@ func (st *StateTransition) buyGas() error {
balanceCheck.Add(balanceCheck, st.msg.Value)
}
if st.evm.ChainConfig().IsCancun(st.evm.Context.BlockNumber, st.evm.Context.Time) {
if dataGas := st.dataGasUsed(); dataGas > 0 {
if st.evm.Context.ExcessDataGas == nil {
if blobGas := st.blobGasUsed(); blobGas > 0 {
if st.evm.Context.ExcessBlobGas == nil {
// programming error
panic("missing field excess data gas")
}
// Check that the user has enough funds to cover dataGasUsed * tx.BlobGasFeeCap
blobBalanceCheck := new(big.Int).SetUint64(dataGas)
// Check that the user has enough funds to cover blobGasUsed * tx.BlobGasFeeCap
blobBalanceCheck := new(big.Int).SetUint64(blobGas)
blobBalanceCheck.Mul(blobBalanceCheck, st.msg.BlobGasFeeCap)
balanceCheck.Add(balanceCheck, blobBalanceCheck)
// Pay for dataGasUsed * actual blob fee
blobFee := new(big.Int).SetUint64(dataGas)
blobFee.Mul(blobFee, eip4844.CalcBlobFee(*st.evm.Context.ExcessDataGas))
// Pay for blobGasUsed * actual blob fee
blobFee := new(big.Int).SetUint64(blobGas)
blobFee.Mul(blobFee, eip4844.CalcBlobFee(*st.evm.Context.ExcessBlobGas))
mgval.Add(mgval, blobFee)
}
}
@@ -331,9 +331,9 @@ func (st *StateTransition) preCheck() error {
}
if st.evm.ChainConfig().IsCancun(st.evm.Context.BlockNumber, st.evm.Context.Time) {
if st.dataGasUsed() > 0 {
if st.blobGasUsed() > 0 {
// Check that the user is paying at least the current blob fee
blobFee := eip4844.CalcBlobFee(*st.evm.Context.ExcessDataGas)
blobFee := eip4844.CalcBlobFee(*st.evm.Context.ExcessBlobGas)
if st.msg.BlobGasFeeCap.Cmp(blobFee) < 0 {
return fmt.Errorf("%w: address %v have %v want %v", ErrBlobFeeCapTooLow, st.msg.From.Hex(), st.msg.BlobGasFeeCap, blobFee)
}
@@ -471,7 +471,7 @@ func (st *StateTransition) gasUsed() uint64 {
return st.initialGas - st.gasRemaining
}
// dataGasUsed returns the amount of data gas used by the message.
func (st *StateTransition) dataGasUsed() uint64 {
return uint64(len(st.msg.BlobHashes) * params.BlobTxDataGasPerBlob)
// blobGasUsed returns the amount of data gas used by the message.
func (st *StateTransition) blobGasUsed() uint64 {
return uint64(len(st.msg.BlobHashes) * params.BlobTxBlobGasPerBlob)
}
+7 -7
View File
@@ -53,7 +53,7 @@ const (
// maxBlobsPerTransaction is the maximum number of blobs a single transaction
// is allowed to contain. Whilst the spec states it's unlimited, the block
// data slots are protocol bound, which implicitly also limit this.
maxBlobsPerTransaction = params.BlobTxMaxDataGasPerBlock / params.BlobTxDataGasPerBlob
maxBlobsPerTransaction = params.BlobTxMaxBlobGasPerBlock / params.BlobTxBlobGasPerBlob
// txAvgSize is an approximate byte size of a transaction metadata to avoid
// tiny overflows causing all txs to move a shelf higher, wasting disk space.
@@ -400,10 +400,10 @@ func (p *BlobPool) Init(gasTip *big.Int, head *types.Header, reserve txpool.Addr
}
var (
basefee = uint256.MustFromBig(misc.CalcBaseFee(p.chain.Config(), p.head))
blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinDataGasprice))
blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinBlobGasprice))
)
if p.head.ExcessDataGas != nil {
blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*p.head.ExcessDataGas))
if p.head.ExcessBlobGas != nil {
blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*p.head.ExcessBlobGas))
}
p.evict = newPriceHeap(basefee, blobfee, &p.index)
@@ -773,10 +773,10 @@ func (p *BlobPool) Reset(oldHead, newHead *types.Header) {
// Reset the price heap for the new set of basefee/blobfee pairs
var (
basefee = uint256.MustFromBig(misc.CalcBaseFee(p.chain.Config(), newHead))
blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinDataGasprice))
blobfee = uint256.MustFromBig(big.NewInt(params.BlobTxMinBlobGasprice))
)
if newHead.ExcessDataGas != nil {
blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*newHead.ExcessDataGas))
if newHead.ExcessBlobGas != nil {
blobfee = uint256.MustFromBig(eip4844.CalcBlobFee(*newHead.ExcessBlobGas))
}
p.evict.reinit(basefee, blobfee, false)
+4 -4
View File
@@ -137,14 +137,14 @@ func (bc *testBlockChain) CurrentBlock() *types.Header {
lo = mid
}
}
excessDataGas := lo.Uint64()
excessBlobGas := lo.Uint64()
return &types.Header{
Number: blockNumber,
Time: blockTime,
GasLimit: gasLimit,
BaseFee: baseFee,
ExcessDataGas: &excessDataGas,
ExcessBlobGas: &excessBlobGas,
}
}
@@ -523,7 +523,7 @@ func TestOpenDrops(t *testing.T) {
chain := &testBlockChain{
config: testChainConfig,
basefee: uint256.NewInt(params.InitialBaseFee),
blobfee: uint256.NewInt(params.BlobTxMinDataGasprice),
blobfee: uint256.NewInt(params.BlobTxMinBlobGasprice),
statedb: statedb,
}
pool := New(Config{Datadir: storage}, chain)
@@ -638,7 +638,7 @@ func TestOpenIndex(t *testing.T) {
chain := &testBlockChain{
config: testChainConfig,
basefee: uint256.NewInt(params.InitialBaseFee),
blobfee: uint256.NewInt(params.BlobTxMinDataGasprice),
blobfee: uint256.NewInt(params.BlobTxMinBlobGasprice),
statedb: statedb,
}
pool := New(Config{Datadir: storage}, chain)
+2 -2
View File
@@ -116,8 +116,8 @@ func ValidateTransaction(tx *types.Transaction, blobs []kzg4844.Blob, commits []
if len(hashes) == 0 {
return fmt.Errorf("blobless blob transaction")
}
if len(hashes) > params.BlobTxMaxDataGasPerBlock/params.BlobTxDataGasPerBlob {
return fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.BlobTxMaxDataGasPerBlock/params.BlobTxDataGasPerBlob)
if len(hashes) > params.BlobTxMaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob {
return fmt.Errorf("too many blobs in transaction: have %d, permitted %d", len(hashes), params.BlobTxMaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob)
}
if len(blobs) != len(hashes) {
return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(blobs), len(hashes))
+24 -24
View File
@@ -85,11 +85,11 @@ type Header struct {
// WithdrawalsHash was added by EIP-4895 and is ignored in legacy headers.
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
// ExcessDataGas was added by EIP-4844 and is ignored in legacy headers.
ExcessDataGas *uint64 `json:"excessDataGas" rlp:"optional"`
// ExcessBlobGas was added by EIP-4844 and is ignored in legacy headers.
ExcessBlobGas *uint64 `json:"excessBlobGas" rlp:"optional"`
// DataGasUsed was added by EIP-4844 and is ignored in legacy headers.
DataGasUsed *uint64 `json:"dataGasUsed" rlp:"optional"`
// BlobGasUsed was added by EIP-4844 and is ignored in legacy headers.
BlobGasUsed *uint64 `json:"blobGasUsed" rlp:"optional"`
}
// field type overrides for gencodec
@@ -102,8 +102,8 @@ type headerMarshaling struct {
Extra hexutil.Bytes
BaseFee *hexutil.Big
Hash common.Hash `json:"hash"` // adds call to Hash() in MarshalJSON
ExcessDataGas *hexutil.Uint64
DataGasUsed *hexutil.Uint64
ExcessBlobGas *hexutil.Uint64
BlobGasUsed *hexutil.Uint64
}
// Hash returns the block hash of the header, which is simply the keccak256 hash of its
@@ -284,13 +284,13 @@ func CopyHeader(h *Header) *Header {
cpy.WithdrawalsHash = new(common.Hash)
*cpy.WithdrawalsHash = *h.WithdrawalsHash
}
if h.ExcessDataGas != nil {
cpy.ExcessDataGas = new(uint64)
*cpy.ExcessDataGas = *h.ExcessDataGas
if h.ExcessBlobGas != nil {
cpy.ExcessBlobGas = new(uint64)
*cpy.ExcessBlobGas = *h.ExcessBlobGas
}
if h.DataGasUsed != nil {
cpy.DataGasUsed = new(uint64)
*cpy.DataGasUsed = *h.DataGasUsed
if h.BlobGasUsed != nil {
cpy.BlobGasUsed = new(uint64)
*cpy.BlobGasUsed = *h.BlobGasUsed
}
return &cpy
}
@@ -360,22 +360,22 @@ func (b *Block) Withdrawals() Withdrawals {
return b.withdrawals
}
func (b *Block) ExcessDataGas() *uint64 {
var excessDataGas *uint64
if b.header.ExcessDataGas != nil {
excessDataGas = new(uint64)
*excessDataGas = *b.header.ExcessDataGas
func (b *Block) ExcessBlobGas() *uint64 {
var excessBlobGas *uint64
if b.header.ExcessBlobGas != nil {
excessBlobGas = new(uint64)
*excessBlobGas = *b.header.ExcessBlobGas
}
return excessDataGas
return excessBlobGas
}
func (b *Block) DataGasUsed() *uint64 {
var dataGasUsed *uint64
if b.header.DataGasUsed != nil {
dataGasUsed = new(uint64)
*dataGasUsed = *b.header.DataGasUsed
func (b *Block) BlobGasUsed() *uint64 {
var blobGasUsed *uint64
if b.header.BlobGasUsed != nil {
blobGasUsed = new(uint64)
*blobGasUsed = *b.header.BlobGasUsed
}
return dataGasUsed
return blobGasUsed
}
func (b *Block) Header() *Header { return CopyHeader(b.header) }
+10 -10
View File
@@ -33,8 +33,8 @@ func (h Header) MarshalJSON() ([]byte, error) {
Nonce BlockNonce `json:"nonce"`
BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"`
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
ExcessDataGas *hexutil.Uint64 `json:"excessDataGas" rlp:"optional"`
DataGasUsed *hexutil.Uint64 `json:"dataGasUsed" rlp:"optional"`
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"`
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"`
Hash common.Hash `json:"hash"`
}
var enc Header
@@ -55,8 +55,8 @@ func (h Header) MarshalJSON() ([]byte, error) {
enc.Nonce = h.Nonce
enc.BaseFee = (*hexutil.Big)(h.BaseFee)
enc.WithdrawalsHash = h.WithdrawalsHash
enc.ExcessDataGas = (*hexutil.Uint64)(h.ExcessDataGas)
enc.DataGasUsed = (*hexutil.Uint64)(h.DataGasUsed)
enc.ExcessBlobGas = (*hexutil.Uint64)(h.ExcessBlobGas)
enc.BlobGasUsed = (*hexutil.Uint64)(h.BlobGasUsed)
enc.Hash = h.Hash()
return json.Marshal(&enc)
}
@@ -81,8 +81,8 @@ func (h *Header) UnmarshalJSON(input []byte) error {
Nonce *BlockNonce `json:"nonce"`
BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"`
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
ExcessDataGas *hexutil.Uint64 `json:"excessDataGas" rlp:"optional"`
DataGasUsed *hexutil.Uint64 `json:"dataGasUsed" rlp:"optional"`
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"`
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"`
}
var dec Header
if err := json.Unmarshal(input, &dec); err != nil {
@@ -151,11 +151,11 @@ func (h *Header) UnmarshalJSON(input []byte) error {
if dec.WithdrawalsHash != nil {
h.WithdrawalsHash = dec.WithdrawalsHash
}
if dec.ExcessDataGas != nil {
h.ExcessDataGas = (*uint64)(dec.ExcessDataGas)
if dec.ExcessBlobGas != nil {
h.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
}
if dec.DataGasUsed != nil {
h.DataGasUsed = (*uint64)(dec.DataGasUsed)
if dec.BlobGasUsed != nil {
h.BlobGasUsed = (*uint64)(dec.BlobGasUsed)
}
return nil
}
+6 -6
View File
@@ -42,8 +42,8 @@ func (obj *Header) EncodeRLP(_w io.Writer) error {
w.WriteBytes(obj.Nonce[:])
_tmp1 := obj.BaseFee != nil
_tmp2 := obj.WithdrawalsHash != nil
_tmp3 := obj.ExcessDataGas != nil
_tmp4 := obj.DataGasUsed != nil
_tmp3 := obj.ExcessBlobGas != nil
_tmp4 := obj.BlobGasUsed != nil
if _tmp1 || _tmp2 || _tmp3 || _tmp4 {
if obj.BaseFee == nil {
w.Write(rlp.EmptyString)
@@ -62,17 +62,17 @@ func (obj *Header) EncodeRLP(_w io.Writer) error {
}
}
if _tmp3 || _tmp4 {
if obj.ExcessDataGas == nil {
if obj.ExcessBlobGas == nil {
w.Write([]byte{0x80})
} else {
w.WriteUint64((*obj.ExcessDataGas))
w.WriteUint64((*obj.ExcessBlobGas))
}
}
if _tmp4 {
if obj.DataGasUsed == nil {
if obj.BlobGasUsed == nil {
w.Write([]byte{0x80})
} else {
w.WriteUint64((*obj.DataGasUsed))
w.WriteUint64((*obj.BlobGasUsed))
}
}
w.ListEnd(_tmp0)
+10 -10
View File
@@ -26,8 +26,8 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
ContractAddress common.Address `json:"contractAddress"`
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
EffectiveGasPrice *hexutil.Big `json:"effectiveGasPrice"`
DataGasUsed uint64 `json:"dataGasUsed,omitempty"`
DataGasPrice *big.Int `json:"dataGasPrice,omitempty"`
BlobGasUsed uint64 `json:"blobGasUsed,omitempty"`
BlobGasPrice *big.Int `json:"blobGasPrice,omitempty"`
BlockHash common.Hash `json:"blockHash,omitempty"`
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
TransactionIndex hexutil.Uint `json:"transactionIndex"`
@@ -43,8 +43,8 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
enc.ContractAddress = r.ContractAddress
enc.GasUsed = hexutil.Uint64(r.GasUsed)
enc.EffectiveGasPrice = (*hexutil.Big)(r.EffectiveGasPrice)
enc.DataGasUsed = r.DataGasUsed
enc.DataGasPrice = r.DataGasPrice
enc.BlobGasUsed = r.BlobGasUsed
enc.BlobGasPrice = r.BlobGasPrice
enc.BlockHash = r.BlockHash
enc.BlockNumber = (*hexutil.Big)(r.BlockNumber)
enc.TransactionIndex = hexutil.Uint(r.TransactionIndex)
@@ -64,8 +64,8 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
ContractAddress *common.Address `json:"contractAddress"`
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
EffectiveGasPrice *hexutil.Big `json:"effectiveGasPrice"`
DataGasUsed *uint64 `json:"dataGasUsed,omitempty"`
DataGasPrice *big.Int `json:"dataGasPrice,omitempty"`
BlobGasUsed *uint64 `json:"blobGasUsed,omitempty"`
BlobGasPrice *big.Int `json:"blobGasPrice,omitempty"`
BlockHash *common.Hash `json:"blockHash,omitempty"`
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
TransactionIndex *hexutil.Uint `json:"transactionIndex"`
@@ -109,11 +109,11 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
if dec.EffectiveGasPrice != nil {
r.EffectiveGasPrice = (*big.Int)(dec.EffectiveGasPrice)
}
if dec.DataGasUsed != nil {
r.DataGasUsed = *dec.DataGasUsed
if dec.BlobGasUsed != nil {
r.BlobGasUsed = *dec.BlobGasUsed
}
if dec.DataGasPrice != nil {
r.DataGasPrice = dec.DataGasPrice
if dec.BlobGasPrice != nil {
r.BlobGasPrice = dec.BlobGasPrice
}
if dec.BlockHash != nil {
r.BlockHash = *dec.BlockHash
+5 -5
View File
@@ -63,8 +63,8 @@ type Receipt struct {
ContractAddress common.Address `json:"contractAddress"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
EffectiveGasPrice *big.Int `json:"effectiveGasPrice"` // required, but tag omitted for backwards compatibility
DataGasUsed uint64 `json:"dataGasUsed,omitempty"`
DataGasPrice *big.Int `json:"dataGasPrice,omitempty"`
BlobGasUsed uint64 `json:"blobGasUsed,omitempty"`
BlobGasPrice *big.Int `json:"blobGasPrice,omitempty"`
// Inclusion information: These fields provide information about the inclusion of the
// transaction corresponding to this receipt.
@@ -315,7 +315,7 @@ func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer) {
// DeriveFields fills the receipts with their computed fields based on consensus
// data and contextual infos like containing block and transactions.
func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, number uint64, time uint64, baseFee *big.Int, dataGasPrice *big.Int, txs []*Transaction) error {
func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, number uint64, time uint64, baseFee *big.Int, blobGasPrice *big.Int, txs []*Transaction) error {
signer := MakeSigner(config, new(big.Int).SetUint64(number), time)
logIndex := uint(0)
@@ -330,8 +330,8 @@ func (rs Receipts) DeriveFields(config *params.ChainConfig, hash common.Hash, nu
// EIP-4844 blob transaction fields
if txs[i].Type() == BlobTxType {
rs[i].DataGasUsed = txs[i].BlobGas()
rs[i].DataGasPrice = dataGasPrice
rs[i].BlobGasUsed = txs[i].BlobGas()
rs[i].BlobGasPrice = blobGasPrice
}
// block location fields
+8 -8
View File
@@ -272,8 +272,8 @@ var (
TxHash: txs[5].Hash(),
GasUsed: 6,
EffectiveGasPrice: big.NewInt(1066),
DataGasUsed: params.BlobTxDataGasPerBlob,
DataGasPrice: big.NewInt(920),
BlobGasUsed: params.BlobTxBlobGasPerBlob,
BlobGasPrice: big.NewInt(920),
BlockHash: blockHash,
BlockNumber: blockNumber,
TransactionIndex: 5,
@@ -287,8 +287,8 @@ var (
TxHash: txs[6].Hash(),
GasUsed: 7,
EffectiveGasPrice: big.NewInt(1077),
DataGasUsed: 3 * params.BlobTxDataGasPerBlob,
DataGasPrice: big.NewInt(920),
BlobGasUsed: 3 * params.BlobTxBlobGasPerBlob,
BlobGasPrice: big.NewInt(920),
BlockHash: blockHash,
BlockNumber: blockNumber,
TransactionIndex: 6,
@@ -309,9 +309,9 @@ func TestDecodeEmptyTypedReceipt(t *testing.T) {
func TestDeriveFields(t *testing.T) {
// Re-derive receipts.
basefee := big.NewInt(1000)
dataGasPrice := big.NewInt(920)
blobGasPrice := big.NewInt(920)
derivedReceipts := clearComputedFieldsOnReceipts(receipts)
err := Receipts(derivedReceipts).DeriveFields(params.TestChainConfig, blockHash, blockNumber.Uint64(), blockTime, basefee, dataGasPrice, txs)
err := Receipts(derivedReceipts).DeriveFields(params.TestChainConfig, blockHash, blockNumber.Uint64(), blockTime, basefee, blobGasPrice, txs)
if err != nil {
t.Fatalf("DeriveFields(...) = %v, want <nil>", err)
}
@@ -509,8 +509,8 @@ func clearComputedFieldsOnReceipt(receipt *Receipt) *Receipt {
cpy.GasUsed = 0xffffffff
cpy.Logs = clearComputedFieldsOnLogs(receipt.Logs)
cpy.EffectiveGasPrice = big.NewInt(0)
cpy.DataGasUsed = 0
cpy.DataGasPrice = nil
cpy.BlobGasUsed = 0
cpy.BlobGasPrice = nil
return &cpy
}
+5 -5
View File
@@ -37,7 +37,7 @@ type txJSON struct {
GasPrice *hexutil.Big `json:"gasPrice"`
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"`
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"`
MaxFeePerDataGas *hexutil.Big `json:"maxFeePerDataGas,omitempty"`
MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"`
Value *hexutil.Big `json:"value"`
Input *hexutil.Bytes `json:"input"`
AccessList *AccessList `json:"accessList,omitempty"`
@@ -106,7 +106,7 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
enc.Gas = (*hexutil.Uint64)(&itx.Gas)
enc.MaxFeePerGas = (*hexutil.Big)(itx.GasFeeCap.ToBig())
enc.MaxPriorityFeePerGas = (*hexutil.Big)(itx.GasTipCap.ToBig())
enc.MaxFeePerDataGas = (*hexutil.Big)(itx.BlobFeeCap.ToBig())
enc.MaxFeePerBlobGas = (*hexutil.Big)(itx.BlobFeeCap.ToBig())
enc.Value = (*hexutil.Big)(itx.Value.ToBig())
enc.Input = (*hexutil.Bytes)(&itx.Data)
enc.AccessList = &itx.AccessList
@@ -309,10 +309,10 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
return errors.New("missing required field 'maxFeePerGas' for txdata")
}
itx.GasFeeCap = uint256.MustFromBig((*big.Int)(dec.MaxFeePerGas))
if dec.MaxFeePerDataGas == nil {
return errors.New("missing required field 'maxFeePerDataGas' for txdata")
if dec.MaxFeePerBlobGas == nil {
return errors.New("missing required field 'maxFeePerBlobGas' for txdata")
}
itx.BlobFeeCap = uint256.MustFromBig((*big.Int)(dec.MaxFeePerDataGas))
itx.BlobFeeCap = uint256.MustFromBig((*big.Int)(dec.MaxFeePerBlobGas))
if dec.Value == nil {
return errors.New("missing required field 'value' in transaction")
}
+2 -2
View File
@@ -35,7 +35,7 @@ type BlobTx struct {
Value *uint256.Int
Data []byte
AccessList AccessList
BlobFeeCap *uint256.Int // a.k.a. maxFeePerDataGas
BlobFeeCap *uint256.Int // a.k.a. maxFeePerBlobGas
BlobHashes []common.Hash
// Signature values
@@ -105,7 +105,7 @@ func (tx *BlobTx) gasPrice() *big.Int { return tx.GasFeeCap.ToBig() }
func (tx *BlobTx) value() *big.Int { return tx.Value.ToBig() }
func (tx *BlobTx) nonce() uint64 { return tx.Nonce }
func (tx *BlobTx) to() *common.Address { tmp := tx.To; return &tmp }
func (tx *BlobTx) blobGas() uint64 { return params.BlobTxDataGasPerBlob * uint64(len(tx.BlobHashes)) }
func (tx *BlobTx) blobGas() uint64 { return params.BlobTxBlobGasPerBlob * uint64(len(tx.BlobHashes)) }
func (tx *BlobTx) blobGasFeeCap() *big.Int { return tx.BlobFeeCap.ToBig() }
func (tx *BlobTx) blobHashes() []common.Hash { return tx.BlobHashes }
+1 -1
View File
@@ -74,7 +74,7 @@ type BlockContext struct {
Difficulty *big.Int // Provides information for DIFFICULTY
BaseFee *big.Int // Provides information for BASEFEE
Random *common.Hash // Provides information for PREVRANDAO
ExcessDataGas *uint64 // ExcessDataGas field in the header, needed to compute the data
ExcessBlobGas *uint64 // ExcessBlobGas field in the header, needed to compute the data
}
// TxContext provides the EVM with information about a transaction.