Skip to content

Commit 339bf22

Browse files
authored
Merge pull request #30 from siburu/pectra-support
Add Pectra support
2 parents 5633f42 + 963f462 commit 339bf22

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

beacon/client.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import (
44
"encoding/hex"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
9+
"slices"
910

1011
"github.com/hyperledger-labs/yui-relayer/log"
1112
)
1213

14+
var SupportedVersions = []string{"deneb", "electra"}
15+
1316
type Client struct {
1417
endpoint string
1518
}
@@ -18,8 +21,8 @@ func NewClient(endpoint string) Client {
1821
return Client{endpoint: endpoint}
1922
}
2023

21-
func (Client) SupportedVersion() string {
22-
return "deneb"
24+
func IsSupportedVersion(v string) bool {
25+
return slices.Contains(SupportedVersions, v)
2326
}
2427

2528
func (cl Client) GetGenesis() (*Genesis, error) {
@@ -57,7 +60,7 @@ func (cl Client) GetBootstrap(finalizedRoot []byte) (*LightClientBootstrapRespon
5760
if err := cl.get(fmt.Sprintf("/eth/v1/beacon/light_client/bootstrap/0x%v", hex.EncodeToString(finalizedRoot[:])), &res); err != nil {
5861
return nil, err
5962
}
60-
if res.Version != cl.SupportedVersion() {
63+
if !IsSupportedVersion(res.Version) {
6164
return nil, fmt.Errorf("unsupported version: %v", res.Version)
6265
}
6366
return &res, nil
@@ -72,7 +75,7 @@ func (cl Client) GetLightClientUpdates(period uint64, count uint64) (LightClient
7275
return nil, fmt.Errorf("unexpected response length: expected=%v actual=%v", count, len(res))
7376
}
7477
for i := range res {
75-
if res[i].Version != cl.SupportedVersion() {
78+
if !IsSupportedVersion(res[i].Version) {
7679
return nil, fmt.Errorf("unsupported version: %v", res[i].Version)
7780
}
7881
}
@@ -92,7 +95,7 @@ func (cl Client) GetLightClientFinalityUpdate() (*LightClientFinalityUpdateRespo
9295
if err := cl.get("/eth/v1/beacon/light_client/finality_update", &res); err != nil {
9396
return nil, err
9497
}
95-
if res.Version != cl.SupportedVersion() {
98+
if !IsSupportedVersion(res.Version) {
9699
return nil, fmt.Errorf("unsupported version: %v", res.Version)
97100
}
98101
return &res, nil
@@ -105,7 +108,7 @@ func (cl Client) get(path string, res any) error {
105108
return err
106109
}
107110
defer r.Body.Close()
108-
bz, err := ioutil.ReadAll(r.Body)
111+
bz, err := io.ReadAll(r.Body)
109112
if err != nil {
110113
return err
111114
}

relay/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ var (
4444
ExecutionPayloadStateRootGindex: 34,
4545
ExecutionPayloadBlockNumberGindex: 38,
4646
}
47+
ElectraSpec = lctypes.ForkSpec{
48+
FinalizedRootGindex: 169,
49+
CurrentSyncCommitteeGindex: 86,
50+
NextSyncCommitteeGindex: 87,
51+
ExecutionPayloadGindex: DenebSpec.ExecutionPayloadGindex,
52+
ExecutionPayloadStateRootGindex: DenebSpec.ExecutionPayloadStateRootGindex,
53+
ExecutionPayloadBlockNumberGindex: DenebSpec.ExecutionPayloadBlockNumberGindex,
54+
}
4755
)
4856

4957
var _ core.ProverConfig = (*ProverConfig)(nil)
@@ -169,6 +177,11 @@ func (prc *ProverConfig) getForkParameters() *lctypes.ForkParameters {
169177
Epoch: 0,
170178
Spec: &DenebSpec,
171179
},
180+
{
181+
Version: []byte{5, 0, 0, 1},
182+
Epoch: 0,
183+
Spec: &ElectraSpec,
184+
},
172185
},
173186
}
174187
case Goerli:

0 commit comments

Comments
 (0)