Skip to content

Commit

Permalink
add reward blob_fee, make baseFeePerGas compatibility mode show a 0 b…
Browse files Browse the repository at this point in the history
…yte when set to 0
  • Loading branch information
sduchesneau committed Feb 12, 2025
1 parent d46cb5f commit f5c74d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
blobFee := new(big.Int).SetUint64(st.blobGasUsed())
blobFee.Mul(blobFee, st.evm.Context.BlobBaseFee)
blobFeeU256, _ := uint256.FromBig(blobFee)
st.state.AddBalance(consensus.SystemAddress, blobFeeU256, tracing.BalanceIncreaseRewardTransactionFee)
st.state.AddBalance(consensus.SystemAddress, blobFeeU256, tracing.BalanceIncreaseRewardBlobFee)
}
} else {
st.state.AddBalance(st.evm.Context.Coinbase, fee, tracing.BalanceIncreaseRewardTransactionFee)
Expand Down
2 changes: 2 additions & 0 deletions core/tracing/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ const (
// BalanceIncreaseBSCDistributeReward is a balance change that increases the block validator's balance and
// happens when BSC is distributing rewards to validator.
BalanceIncreaseBSCDistributeReward BalanceChangeReason = 211
// BalanceIncreaseRewardBlobFee was introduced in Tycho
BalanceIncreaseRewardBlobFee BalanceChangeReason = 212
)

// GasChangeReason is used to indicate the reason for a gas change, useful
Expand Down
23 changes: 20 additions & 3 deletions eth/tracers/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (f *Firehose) OnBlockStart(event tracing.BlockEvent) {
Hash: hash.Bytes(),
Number: block.NumberU64(),
// FIXME: Avoid calling 'Header()', it makes a copy while accessing event.Block getters directly avoids it
Header: newBlockHeaderFromChainHeader(hash, block.Header(), firehoseBigIntFromNative(new(big.Int).Add(event.TD, block.Difficulty()))),
Header: newBlockHeaderFromChainHeader(hash, block.Header(), firehoseBigIntFromNative(new(big.Int).Add(event.TD, block.Difficulty())), *f.applyBackwardCompatibility),
Ver: 4,

// FIXME: 'block.Size()' is a relatively heavy operation, could we do it async?
Expand All @@ -366,7 +366,7 @@ func (f *Firehose) OnBlockStart(event tracing.BlockEvent) {
}

for _, uncle := range block.Uncles() {
f.block.Uncles = append(f.block.Uncles, newBlockHeaderFromChainHeader(uncle.Hash(), uncle, nil))
f.block.Uncles = append(f.block.Uncles, newBlockHeaderFromChainHeader(uncle.Hash(), uncle, nil, *f.applyBackwardCompatibility))
}

if f.block.Header.BaseFeePerGas != nil {
Expand Down Expand Up @@ -1698,7 +1698,7 @@ func (f *Firehose) InternalTestingBuffer() *bytes.Buffer {
}

// FIXME: Create a unit test that is going to fail as soon as any header is added in
func newBlockHeaderFromChainHeader(hash common.Hash, h *types.Header, td *pbeth.BigInt) *pbeth.BlockHeader {
func newBlockHeaderFromChainHeader(hash common.Hash, h *types.Header, td *pbeth.BigInt, compatibilityMode bool) *pbeth.BlockHeader {
var withdrawalsHashBytes []byte
if hash := h.WithdrawalsHash; hash != nil {
withdrawalsHashBytes = hash.Bytes()
Expand Down Expand Up @@ -1743,6 +1743,10 @@ func newBlockHeaderFromChainHeader(hash common.Hash, h *types.Header, td *pbeth.
TxDependency: nil,
}

if compatibilityMode {
pbHead.BaseFeePerGas = firehoseBigIntFromNativeExplicitZero(h.BaseFee)
}

if pbHead.Difficulty == nil {
pbHead.Difficulty = &pbeth.BigInt{Bytes: []byte{0}}
}
Expand Down Expand Up @@ -1897,6 +1901,7 @@ var balanceChangeReasonToPb = map[tracing.BalanceChangeReason]pbeth.BalanceChang
tracing.BalanceIncreaseWithdrawal: pbeth.BalanceChange_REASON_WITHDRAWAL,
tracing.BalanceDecreaseBSCDistributeReward: pbeth.BalanceChange_REASON_REWARD_TRANSACTION_FEE,
tracing.BalanceIncreaseBSCDistributeReward: pbeth.BalanceChange_REASON_REWARD_TRANSACTION_FEE,
tracing.BalanceIncreaseRewardBlobFee: pbeth.BalanceChange_REASON_REWARD_BLOB_FEE,

tracing.BalanceChangeUnspecified: pbeth.BalanceChange_REASON_UNKNOWN,
}
Expand Down Expand Up @@ -2267,6 +2272,18 @@ func firehoseBigIntFromNative(in *big.Int) *pbeth.BigInt {
return &pbeth.BigInt{Bytes: in.Bytes()}
}

// this version of firehoseBigIntFromNative will return a single byte with value 0 if the input is zero
func firehoseBigIntFromNativeExplicitZero(in *big.Int) *pbeth.BigInt {
if in == nil {
return nil
}
if in.Sign() == 0 {
return &pbeth.BigInt{Bytes: []byte{0}}
}

return &pbeth.BigInt{Bytes: in.Bytes()}
}

type FinalityStatus struct {
LastIrreversibleBlockNumber uint64
LastIrreversibleBlockHash []byte
Expand Down

0 comments on commit f5c74d6

Please sign in to comment.