Skip to content

Commit b43ca03

Browse files
committed
Support cancun.
1 parent 23e63aa commit b43ca03

13 files changed

+458
-42
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ require (
88
github.com/rs/zerolog v1.29.0
99
github.com/stretchr/testify v1.8.2
1010
github.com/ybbus/jsonrpc/v2 v2.1.7
11-
golang.org/x/crypto v0.17.0
11+
golang.org/x/crypto v0.18.0
1212
)
1313

1414
require (
1515
github.com/davecgh/go-spew v1.1.1 // indirect
1616
github.com/mattn/go-colorable v0.1.12 // indirect
1717
github.com/mattn/go-isatty v0.0.14 // indirect
1818
github.com/pmezard/go-difflib v1.0.0 // indirect
19-
golang.org/x/sys v0.15.0 // indirect
19+
golang.org/x/sys v0.16.0 // indirect
2020
gopkg.in/yaml.v3 v3.0.1 // indirect
2121
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ
3131
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
3232
github.com/ybbus/jsonrpc/v2 v2.1.7 h1:QjoXuZhkXZ3oLBkrONBe2avzFkYeYLorpeA+d8175XQ=
3333
github.com/ybbus/jsonrpc/v2 v2.1.7/go.mod h1:rIuG1+ORoiqocf9xs/v+ecaAVeo3zcZHQgInyKFMeg0=
34-
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
35-
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
34+
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
35+
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
3636
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
3737
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
3838
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3939
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4040
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4141
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
42-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
43-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
42+
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
43+
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4444
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4545
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
4646
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

jsonrpc/transactionreceipt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import (
2323
)
2424

2525
// TransactionReceipt returns the transaction receipt for the given transaction hash.
26-
func (s *Service) TransactionReceipt(_ context.Context, hash types.Hash) (*spec.BerlinTransactionReceipt, error) {
26+
func (s *Service) TransactionReceipt(_ context.Context, hash types.Hash) (*spec.TransactionReceipt, error) {
2727
if len(hash) == 0 {
2828
return nil, errors.New("hash nil")
2929
}
3030

31-
var receipt spec.BerlinTransactionReceipt
31+
var receipt spec.TransactionReceipt
3232
if err := s.client.CallFor(&receipt, "eth_getTransactionReceipt", fmt.Sprintf("%#x", hash)); err != nil {
3333
return nil, err
3434
}

service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ type TransactionsProvider interface {
116116
// TransactionReceiptsProvider is the interface for providing transaction receipts.
117117
type TransactionReceiptsProvider interface {
118118
// TransactionReceipt returns the transaction receipt for the given transaction hash.
119-
TransactionReceipt(ctx context.Context, hash types.Hash) (*spec.BerlinTransactionReceipt, error)
119+
TransactionReceipt(ctx context.Context, hash types.Hash) (*spec.TransactionReceipt, error)
120120
}
121121

122122
// CallProvider is the interface for making calls to the execution client.

spec/berlintransactionreceipt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (t *BerlinTransactionReceipt) MarshalJSON() ([]byte, error) {
7171
tmp := util.MarshalNullableAddress(t.To[:])
7272
to = &tmp
7373
}
74+
7475
return json.Marshal(&berlinTransactionReceiptJSON{
7576
BlockHash: util.MarshalByteArray(t.BlockHash[:]),
7677
BlockNumber: util.MarshalUint32(t.BlockNumber),

spec/block.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ type Block struct {
3535

3636
// blockTypeJSON is a struct that helps us identify the block type.
3737
type blockTypeJSON struct {
38-
BaseFeePerGas string `json:"baseFeePerGas"`
39-
Withdrawals []map[string]interface{} `json:"withdrawals"`
40-
ParentBeaconBlockRoot string `json:"parentBeaconBlockRoot"`
38+
// Present from London onwards.
39+
BaseFeePerGas string `json:"baseFeePerGas"`
40+
// Present from Shanghai onwards.
41+
Withdrawals []map[string]interface{} `json:"withdrawals"`
42+
// Present from Cancun onwards.
43+
ParentBeaconBlockRoot string `json:"parentBeaconBlockRoot"`
4144
}
4245

4346
// MarshalJSON marshals a typed transaction.
@@ -478,6 +481,28 @@ func (b *Block) ParentBeaconBlockRoot() (types.Root, bool) {
478481
}
479482
}
480483

484+
// BlobGasUsed returns the blob gas used of the block.
485+
// This is not available in all forks, so also returns a presence flag.
486+
func (b *Block) BlobGasUsed() (uint64, bool) {
487+
switch b.Fork {
488+
case ForkCancun:
489+
return b.Cancun.BlobGasUsed, true
490+
default:
491+
return 0, false
492+
}
493+
}
494+
495+
// ExcessBlobGas returns the excess blob gas of the block.
496+
// This is not available in all forks, so also returns a presence flag.
497+
func (b *Block) ExcessBlobGas() (uint64, bool) {
498+
switch b.Fork {
499+
case ForkCancun:
500+
return b.Cancun.ExcessBlobGas, true
501+
default:
502+
return 0, false
503+
}
504+
}
505+
481506
// String returns a string version of the structure.
482507
func (b *Block) String() string {
483508
data, err := json.Marshal(b)

spec/block_test.go

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

spec/cancunblock.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2023 Attestant Limited.
1+
// Copyright © 2023, 2024 Attestant Limited.
22
// Licensed under the Apache License, Version 2.0 (the "License");
33
// you may not use this file except in compliance with the License.
44
// You may obtain a copy of the License at
@@ -30,7 +30,9 @@ import (
3030
// CancunBlock contains a block after the Cancun hardfork.
3131
type CancunBlock struct {
3232
BaseFeePerGas uint64
33+
BlobGasUsed uint64
3334
Difficulty uint64
35+
ExcessBlobGas uint64
3436
ExtraData []byte
3537
GasLimit uint32
3638
GasUsed uint32
@@ -58,7 +60,9 @@ type CancunBlock struct {
5860
// cancunBlockJSON is the spec representation of the struct.
5961
type cancunBlockJSON struct {
6062
BaseFeePerGas string `json:"baseFeePerGas"`
63+
BlobGasUsed string `json:"blobGasUsed"`
6164
Difficulty string `json:"difficulty"`
65+
ExcessBlobGas string `json:"excessBlobGas"`
6266
ExtraData string `json:"extraData"`
6367
GasLimit string `json:"gasLimit"`
6468
GasUsed string `json:"gasUsed"`
@@ -92,7 +96,9 @@ func (b *CancunBlock) MarshalJSON() ([]byte, error) {
9296

9397
return json.Marshal(&cancunBlockJSON{
9498
BaseFeePerGas: util.MarshalUint64(b.BaseFeePerGas),
99+
BlobGasUsed: util.MarshalUint64(b.BlobGasUsed),
95100
Difficulty: util.MarshalUint64(b.Difficulty),
101+
ExcessBlobGas: util.MarshalUint64(b.ExcessBlobGas),
96102
ExtraData: util.MarshalByteArray(b.ExtraData),
97103
GasLimit: util.MarshalUint32(b.GasLimit),
98104
GasUsed: util.MarshalUint32(b.GasUsed),
@@ -137,6 +143,15 @@ func (b *CancunBlock) UnmarshalJSON(input []byte) error {
137143
}
138144
}
139145

146+
if data.BlobGasUsed == "" {
147+
return errors.New("blob gas used missing")
148+
}
149+
tmp, err := strconv.ParseUint(util.PreUnmarshalHexString(data.BlobGasUsed), 16, 32)
150+
if err != nil {
151+
return errors.Wrap(err, "blob gas used invalid")
152+
}
153+
b.BlobGasUsed = tmp
154+
140155
if data.Difficulty == "" {
141156
return errors.New("difficulty missing")
142157
}
@@ -145,6 +160,15 @@ func (b *CancunBlock) UnmarshalJSON(input []byte) error {
145160
return errors.Wrap(err, "difficulty invalid")
146161
}
147162

163+
if data.ExcessBlobGas == "" {
164+
return errors.New("excess blob gas missing")
165+
}
166+
tmp, err = strconv.ParseUint(util.PreUnmarshalHexString(data.ExcessBlobGas), 16, 32)
167+
if err != nil {
168+
return errors.Wrap(err, "excess blob gas invalid")
169+
}
170+
b.ExcessBlobGas = tmp
171+
148172
if data.ExtraData == "" {
149173
return errors.New("extra data missing")
150174
}
@@ -156,7 +180,7 @@ func (b *CancunBlock) UnmarshalJSON(input []byte) error {
156180
if data.GasUsed == "" {
157181
return errors.New("gas used missing")
158182
}
159-
tmp, err := strconv.ParseUint(util.PreUnmarshalHexString(data.GasUsed), 16, 32)
183+
tmp, err = strconv.ParseUint(util.PreUnmarshalHexString(data.GasUsed), 16, 32)
160184
if err != nil {
161185
return errors.Wrap(err, "gas used invalid")
162186
}

0 commit comments

Comments
 (0)