Skip to content

Commit bf20dbc

Browse files
authored
Merge pull request #2 from ethpandaops/feat/shanghai
feat(execution): shanghai compatibility
2 parents 43a892f + f610bf5 commit bf20dbc

10 files changed

Lines changed: 143 additions & 46 deletions

File tree

.github/workflows/golangci-lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: golangci/golangci-lint-action@v3
2424
with:
2525
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
26-
version: v1.50.1
26+
version: v1.51.2
2727

2828
# Optional: working directory, useful for monorepos
2929
# working-directory: somedir

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ jobs:
2828

2929
- name: Annotate tests
3030
if: always()
31-
uses: guyarb/golang-test-annotations@v0.5.1
31+
uses: guyarb/golang-test-annotations@v0.6.0
3232
with:
3333
test-results: test.json

.golangci.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,48 @@ linters-settings:
2020
linters:
2121
disable-all: true
2222
enable:
23+
- asasalint
24+
- bidichk
2325
- bodyclose
24-
- deadcode
26+
- containedctx
27+
- decorder
2528
- depguard
2629
- dogsled
30+
- durationcheck
2731
- errcheck
32+
- errname
2833
- exportloopref
2934
- goconst
3035
- gocritic
36+
- gocyclo
3137
- gofmt
38+
- goheader
3239
- goimports
33-
- gocyclo
3440
- gosec
3541
- gosimple
3642
- govet
43+
- ineffassign
3744
- misspell
38-
- nolintlint
3945
- nakedret
46+
- nilerr
47+
- nilerr
48+
- nilnil
49+
- nlreturn
50+
- nolintlint
51+
- nosprintfhostport
4052
- prealloc
53+
- predeclared
54+
- promlinter
55+
- reassign
4156
- revive
4257
- staticcheck
43-
- structcheck
4458
- stylecheck
59+
- tagliatelle
4560
- thelper
4661
- tparallel
4762
- typecheck
4863
- unconvert
49-
- varcheck
64+
- unused
5065
- whitespace
5166
- wsl
5267

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ require (
1616
github.com/cespare/xxhash/v2 v2.2.0 // indirect
1717
github.com/golang/protobuf v1.5.2 // indirect
1818
github.com/inconshreveable/mousetrap v1.1.0 // indirect
19+
github.com/json-iterator/go v1.1.12 // indirect
1920
github.com/kr/pretty v0.3.0 // indirect
2021
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
22+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
23+
github.com/modern-go/reflect2 v1.0.2 // indirect
2124
github.com/prometheus/client_model v0.3.0 // indirect
22-
github.com/prometheus/common v0.39.0 // indirect
25+
github.com/prometheus/common v0.40.0 // indirect
2326
github.com/prometheus/procfs v0.9.0 // indirect
2427
github.com/spf13/pflag v1.0.5 // indirect
2528
github.com/stretchr/testify v1.8.1 // indirect
26-
golang.org/x/sys v0.4.0 // indirect
29+
golang.org/x/sys v0.5.0 // indirect
2730
google.golang.org/protobuf v1.28.1 // indirect
2831
)

go.sum

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
1616
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
1717
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1818
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
19+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
1920
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
2021
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
2122
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
23+
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
24+
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
2225
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
2326
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
2427
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -30,14 +33,19 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
3033
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
3134
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
3235
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
36+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
37+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
38+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
39+
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
40+
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
3341
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3442
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3543
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
3644
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
3745
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
3846
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
39-
github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI=
40-
github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y=
47+
github.com/prometheus/common v0.40.0 h1:Afz7EVRqGg2Mqqf4JuF9vdvp1pi220m55Pi9T2JnO4Q=
48+
github.com/prometheus/common v0.40.0/go.mod h1:L65ZJPSmfn/UBWLQIHV7dBrKFidB/wPlF1y5TlSt9OE=
4149
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
4250
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
4351
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
@@ -52,15 +60,16 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
5260
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5361
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
5462
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
63+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
5564
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5665
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
5766
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
5867
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
5968
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
6069
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6170
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
62-
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
63-
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
71+
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
72+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6473
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6574
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
6675
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=

pkg/api/response.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ type ContentTypeResolver func() ([]byte, error)
99
type ContentTypeResolvers map[ContentType]ContentTypeResolver
1010

1111
type HTTPResponse struct {
12-
resolvers ContentTypeResolvers
12+
resolvers ContentTypeResolvers
13+
//nolint:tagliatelle // spec requires this field to be named "status_code"
1314
StatusCode int `json:"status_code"`
1415
Headers map[string]string `json:"headers"`
1516
ExtraData map[string]interface{}

pkg/execution/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package execution
22

33
type Config struct {
4-
ChainID string `yaml:"chainID" default:"0x1"`
4+
ChainID string `yaml:"chainId" default:"0x1"`
55
TerminalTotalDifficulty string `yaml:"terminalTotalDifficulty" default:"0x0"`
66
TerminalBlockHash string `yaml:"terminalBlockHash" default:"0x0000000000000000000000000000000000000000000000000000000000000000"`
77
TerminalBlockNumber string `yaml:"terminalBlockNumber" default:"0x0"`

pkg/execution/execution.go

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/sirupsen/logrus"
1010
)
1111

12+
var ErrUnsupportedGetBlockQuery = errors.New("unsupported get block query")
13+
1214
type Handler struct {
1315
log logrus.FieldLogger
1416
Cfg Config
@@ -49,63 +51,126 @@ func (h *Handler) Request(ctx context.Context, id int, method string, params []*
4951
TerminalBlockNumber: h.Cfg.TerminalBlockNumber,
5052
}
5153
case "engine_forkchoiceUpdatedV1":
52-
if len(params) < 1 || params[0] == nil {
53-
return nil, errors.New("missing params")
54+
result, err := h.forkChoiceUpdated(params)
55+
if err != nil {
56+
return nil, err
5457
}
5558

56-
var forkchoiceState RequestParamsForkchoiceUpdatedV1
57-
58-
err := json.Unmarshal([]byte(*params[0]), &forkchoiceState)
59+
resp.Result = result
60+
case "engine_forkchoiceUpdatedV2":
61+
result, err := h.forkChoiceUpdated(params)
5962
if err != nil {
6063
return nil, err
6164
}
6265

63-
resp.Result = ResultForkchoiceUpdatedV1{
64-
PayloadStatus: ResultForkchoiceUpdatedV1PayloadStatus{
65-
Status: "VALID",
66-
LatestValidHash: forkchoiceState.HeadBlockHash,
67-
ValidationError: "",
68-
},
69-
PayloadID: "0xa247243752eb10b4",
70-
}
66+
resp.Result = result
7167
case "engine_newPayloadV1":
72-
if len(params) < 1 || params[0] == nil {
73-
return nil, errors.New("missing params")
68+
result, err := h.newPayload(params)
69+
if err != nil {
70+
return nil, err
7471
}
7572

76-
var payload RequestParamsNewPayloadV1
77-
78-
err := json.Unmarshal([]byte(*params[0]), &payload)
73+
resp.Result = result
74+
case "engine_newPayloadV2":
75+
result, err := h.newPayload(params)
7976
if err != nil {
8077
return nil, err
8178
}
8279

83-
h.latestBlock.UpdateToLatest(payload, params[0])
80+
resp.Result = result
81+
case "eth_getBlockByNumber":
82+
result, err := h.getBlock(params)
83+
if err != nil && err != ErrUnsupportedGetBlockQuery {
84+
return nil, err
85+
}
8486

85-
resp.Result = ResultNewPayloadV1{
86-
Status: "VALID",
87-
LatestValidHash: payload.BlockHash,
88-
ValidationError: "",
87+
resp.Result = result
88+
case "eth_getBlockByHash":
89+
result, err := h.getBlock(params)
90+
if err != nil && err != ErrUnsupportedGetBlockQuery {
91+
return nil, err
8992
}
90-
case "eth_getBlockByNumber":
93+
94+
resp.Result = result
95+
case "eth_chainId":
96+
resp.Result = ResultChainID(h.Cfg.ChainID)
97+
case "engine_exchangeCapabilities":
9198
if len(params) < 1 || params[0] == nil {
9299
return nil, errors.New("missing params")
93100
}
94101

95-
var query string
102+
var payload RequestParamsExchangeCapabilities
96103

97-
err := json.Unmarshal([]byte(*params[0]), &query)
104+
err := json.Unmarshal([]byte(*params[0]), &payload)
98105
if err != nil {
99106
return nil, err
100107
}
101108

102-
if query != "latest" {
103-
resp.Result = ResultGetBlockByNumber(h.latestBlock.raw)
104-
}
105-
case "eth_chainId":
106-
resp.Result = ResultChainID(h.Cfg.ChainID)
109+
resp.Result = ResultexchangeCapabilities(payload)
107110
default:
108111
}
109112

110113
return resp, nil
111114
}
115+
116+
func (h *Handler) forkChoiceUpdated(params []*json.RawMessage) (interface{}, error) {
117+
if len(params) < 1 || params[0] == nil {
118+
return nil, errors.New("missing params")
119+
}
120+
121+
var forkchoiceState RequestParamsForkchoiceUpdatedV1
122+
123+
err := json.Unmarshal([]byte(*params[0]), &forkchoiceState)
124+
if err != nil {
125+
return nil, err
126+
}
127+
128+
return ResultForkchoiceUpdatedV1{
129+
PayloadStatus: ResultForkchoiceUpdatedV1PayloadStatus{
130+
Status: "VALID",
131+
LatestValidHash: forkchoiceState.HeadBlockHash,
132+
ValidationError: "",
133+
},
134+
PayloadID: "0xa247243752eb10b4",
135+
}, nil
136+
}
137+
138+
func (h *Handler) newPayload(params []*json.RawMessage) (interface{}, error) {
139+
if len(params) < 1 || params[0] == nil {
140+
return nil, errors.New("missing params")
141+
}
142+
143+
var payload RequestParamsNewPayloadV1
144+
145+
err := json.Unmarshal([]byte(*params[0]), &payload)
146+
if err != nil {
147+
return nil, err
148+
}
149+
150+
h.latestBlock.UpdateToLatest(payload, params[0])
151+
152+
return ResultNewPayloadV1{
153+
Status: "VALID",
154+
LatestValidHash: payload.BlockHash,
155+
ValidationError: "",
156+
}, nil
157+
}
158+
159+
func (h *Handler) getBlock(params []*json.RawMessage) (interface{}, error) {
160+
if len(params) < 1 || params[0] == nil {
161+
return nil, errors.New("missing params")
162+
}
163+
164+
var query string
165+
166+
err := json.Unmarshal([]byte(*params[0]), &query)
167+
if err != nil {
168+
return nil, err
169+
}
170+
171+
if query == "latest" {
172+
return ResultGetBlockByNumber(h.latestBlock.raw), nil
173+
}
174+
175+
return nil, ErrUnsupportedGetBlockQuery
176+
}

pkg/execution/request.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ type RequestParamsNewPayloadV1 struct {
88
BlockHash string `json:"blockHash"`
99
BlockNumber string `json:"blockNumber"`
1010
}
11+
12+
type RequestParamsExchangeCapabilities []string

pkg/execution/response.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ type ResultNewPayloadV1 struct {
3636
type ResultGetBlockByNumber *json.RawMessage
3737

3838
type ResultChainID string
39+
40+
type ResultexchangeCapabilities []string

0 commit comments

Comments
 (0)