Commit 624db0cf authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #4870 from ethereum-optimism/sc/opn-expose-gasused

feat(opn): expose GasUsed in BlockInfo type
parents c1153b27 417e5dd9
...@@ -20,6 +20,7 @@ type BlockInfo interface { ...@@ -20,6 +20,7 @@ type BlockInfo interface {
MixDigest() common.Hash MixDigest() common.Hash
BaseFee() *big.Int BaseFee() *big.Int
ReceiptHash() common.Hash ReceiptHash() common.Hash
GasUsed() uint64
} }
func InfoToL1BlockRef(info BlockInfo) L1BlockRef { func InfoToL1BlockRef(info BlockInfo) L1BlockRef {
...@@ -79,6 +80,10 @@ func (h headerBlockInfo) ReceiptHash() common.Hash { ...@@ -79,6 +80,10 @@ func (h headerBlockInfo) ReceiptHash() common.Hash {
return h.Header.ReceiptHash return h.Header.ReceiptHash
} }
func (h headerBlockInfo) GasUsed() uint64 {
return h.Header.GasUsed
}
// HeaderBlockInfo returns h as a BlockInfo implementation. // HeaderBlockInfo returns h as a BlockInfo implementation.
func HeaderBlockInfo(h *types.Header) BlockInfo { func HeaderBlockInfo(h *types.Header) BlockInfo {
return headerBlockInfo{h} return headerBlockInfo{h}
......
...@@ -46,6 +46,7 @@ type HeaderInfo struct { ...@@ -46,6 +46,7 @@ type HeaderInfo struct {
baseFee *big.Int baseFee *big.Int
txHash common.Hash txHash common.Hash
receiptHash common.Hash receiptHash common.Hash
gasUsed uint64
} }
var _ eth.BlockInfo = (*HeaderInfo)(nil) var _ eth.BlockInfo = (*HeaderInfo)(nil)
...@@ -90,6 +91,10 @@ func (info *HeaderInfo) ReceiptHash() common.Hash { ...@@ -90,6 +91,10 @@ func (info *HeaderInfo) ReceiptHash() common.Hash {
return info.receiptHash return info.receiptHash
} }
func (info *HeaderInfo) GasUsed() uint64 {
return info.gasUsed
}
type rpcHeader struct { type rpcHeader struct {
ParentHash common.Hash `json:"parentHash"` ParentHash common.Hash `json:"parentHash"`
UncleHash common.Hash `json:"sha3Uncles"` UncleHash common.Hash `json:"sha3Uncles"`
...@@ -182,6 +187,7 @@ func (hdr *rpcHeader) Info(trustCache bool, mustBePostMerge bool) (*HeaderInfo, ...@@ -182,6 +187,7 @@ func (hdr *rpcHeader) Info(trustCache bool, mustBePostMerge bool) (*HeaderInfo,
baseFee: (*big.Int)(hdr.BaseFee), baseFee: (*big.Int)(hdr.BaseFee),
txHash: hdr.TxHash, txHash: hdr.TxHash,
receiptHash: hdr.ReceiptHash, receiptHash: hdr.ReceiptHash,
gasUsed: uint64(hdr.GasUsed),
} }
return &info, nil return &info, nil
} }
......
...@@ -21,6 +21,7 @@ type MockBlockInfo struct { ...@@ -21,6 +21,7 @@ type MockBlockInfo struct {
InfoMixDigest [32]byte InfoMixDigest [32]byte
InfoBaseFee *big.Int InfoBaseFee *big.Int
InfoReceiptRoot common.Hash InfoReceiptRoot common.Hash
InfoGasUsed uint64
} }
func (l *MockBlockInfo) Hash() common.Hash { func (l *MockBlockInfo) Hash() common.Hash {
...@@ -59,6 +60,10 @@ func (l *MockBlockInfo) ReceiptHash() common.Hash { ...@@ -59,6 +60,10 @@ func (l *MockBlockInfo) ReceiptHash() common.Hash {
return l.InfoReceiptRoot return l.InfoReceiptRoot
} }
func (l *MockBlockInfo) GasUsed() uint64 {
return l.InfoGasUsed
}
func (l *MockBlockInfo) ID() eth.BlockID { func (l *MockBlockInfo) ID() eth.BlockID {
return eth.BlockID{Hash: l.InfoHash, Number: l.InfoNum} return eth.BlockID{Hash: l.InfoHash, Number: l.InfoNum}
} }
...@@ -81,6 +86,7 @@ func RandomBlockInfo(rng *rand.Rand) *MockBlockInfo { ...@@ -81,6 +86,7 @@ func RandomBlockInfo(rng *rand.Rand) *MockBlockInfo {
InfoBaseFee: big.NewInt(rng.Int63n(1000_000 * 1e9)), // a million GWEI InfoBaseFee: big.NewInt(rng.Int63n(1000_000 * 1e9)), // a million GWEI
InfoReceiptRoot: types.EmptyRootHash, InfoReceiptRoot: types.EmptyRootHash,
InfoRoot: RandomHash(rng), 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