Commit 90473ad6 authored by Kelvin Fichter's avatar Kelvin Fichter

feat(opn): expose GasUsed in BlockInfo type

Exposes the GasUsed field in the BlockInfo type. This has no impact on
the op-node for Optimism Mainnet, but it will be used in the OP Stack
Getting Started guide.
parent e468b66e
......@@ -20,6 +20,7 @@ type BlockInfo interface {
MixDigest() common.Hash
BaseFee() *big.Int
ReceiptHash() common.Hash
GasUsed() uint64
}
func InfoToL1BlockRef(info BlockInfo) L1BlockRef {
......@@ -79,6 +80,10 @@ func (h headerBlockInfo) ReceiptHash() common.Hash {
return h.Header.ReceiptHash
}
func (h headerBlockInfo) GasUsed() uint64 {
return h.Header.GasUsed
}
// HeaderBlockInfo returns h as a BlockInfo implementation.
func HeaderBlockInfo(h *types.Header) BlockInfo {
return headerBlockInfo{h}
......
......@@ -46,6 +46,7 @@ type HeaderInfo struct {
baseFee *big.Int
txHash common.Hash
receiptHash common.Hash
gasUsed uint64
}
var _ eth.BlockInfo = (*HeaderInfo)(nil)
......@@ -90,6 +91,10 @@ func (info *HeaderInfo) ReceiptHash() common.Hash {
return info.receiptHash
}
func (info *HeaderInfo) GasUsed() uint64 {
return info.gasUsed
}
type rpcHeader struct {
ParentHash common.Hash `json:"parentHash"`
UncleHash common.Hash `json:"sha3Uncles"`
......@@ -182,6 +187,7 @@ func (hdr *rpcHeader) Info(trustCache bool, mustBePostMerge bool) (*HeaderInfo,
baseFee: (*big.Int)(hdr.BaseFee),
txHash: hdr.TxHash,
receiptHash: hdr.ReceiptHash,
gasUsed: uint64(hdr.GasUsed),
}
return &info, nil
}
......
......@@ -21,6 +21,7 @@ type MockBlockInfo struct {
InfoMixDigest [32]byte
InfoBaseFee *big.Int
InfoReceiptRoot common.Hash
InfoGasUsed uint64
}
func (l *MockBlockInfo) Hash() common.Hash {
......@@ -59,6 +60,10 @@ func (l *MockBlockInfo) ReceiptHash() common.Hash {
return l.InfoReceiptRoot
}
func (l *MockBlockInfo) GasUsed() uint64 {
return l.InfoGasUsed
}
func (l *MockBlockInfo) ID() eth.BlockID {
return eth.BlockID{Hash: l.InfoHash, Number: l.InfoNum}
}
......@@ -81,6 +86,7 @@ func RandomBlockInfo(rng *rand.Rand) *MockBlockInfo {
InfoBaseFee: big.NewInt(rng.Int63n(1000_000 * 1e9)), // a million GWEI
InfoReceiptRoot: types.EmptyRootHash,
InfoRoot: RandomHash(rng),
InfoGasUsed: rng.Uint64(),
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment