Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions beacon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"slices"

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

var SupportedVersions = []string{"deneb", "electra"}

type Client struct {
endpoint string
}
Expand All @@ -18,8 +21,8 @@ func NewClient(endpoint string) Client {
return Client{endpoint: endpoint}
}

func (Client) SupportedVersion() string {
return "deneb"
func IsSupportedVersion(v string) bool {
return slices.Contains(SupportedVersions, v)
}

func (cl Client) GetGenesis() (*Genesis, error) {
Expand Down Expand Up @@ -57,7 +60,7 @@ func (cl Client) GetBootstrap(finalizedRoot []byte) (*LightClientBootstrapRespon
if err := cl.get(fmt.Sprintf("/eth/v1/beacon/light_client/bootstrap/0x%v", hex.EncodeToString(finalizedRoot[:])), &res); err != nil {
return nil, err
}
if res.Version != cl.SupportedVersion() {
if !IsSupportedVersion(res.Version) {
return nil, fmt.Errorf("unsupported version: %v", res.Version)
}
return &res, nil
Expand All @@ -72,7 +75,7 @@ func (cl Client) GetLightClientUpdates(period uint64, count uint64) (LightClient
return nil, fmt.Errorf("unexpected response length: expected=%v actual=%v", count, len(res))
}
for i := range res {
if res[i].Version != cl.SupportedVersion() {
if !IsSupportedVersion(res[i].Version) {
return nil, fmt.Errorf("unsupported version: %v", res[i].Version)
}
}
Expand All @@ -92,7 +95,7 @@ func (cl Client) GetLightClientFinalityUpdate() (*LightClientFinalityUpdateRespo
if err := cl.get("/eth/v1/beacon/light_client/finality_update", &res); err != nil {
return nil, err
}
if res.Version != cl.SupportedVersion() {
if !IsSupportedVersion(res.Version) {
return nil, fmt.Errorf("unsupported version: %v", res.Version)
}
return &res, nil
Expand All @@ -105,7 +108,7 @@ func (cl Client) get(path string, res any) error {
return err
}
defer r.Body.Close()
bz, err := ioutil.ReadAll(r.Body)
bz, err := io.ReadAll(r.Body)
if err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions relay/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ var (
ExecutionPayloadStateRootGindex: 34,
ExecutionPayloadBlockNumberGindex: 38,
}
ElectraSpec = lctypes.ForkSpec{
FinalizedRootGindex: 169,
CurrentSyncCommitteeGindex: 86,
NextSyncCommitteeGindex: 87,
ExecutionPayloadGindex: DenebSpec.ExecutionPayloadGindex,
ExecutionPayloadStateRootGindex: DenebSpec.ExecutionPayloadStateRootGindex,
ExecutionPayloadBlockNumberGindex: DenebSpec.ExecutionPayloadBlockNumberGindex,
}
)

var _ core.ProverConfig = (*ProverConfig)(nil)
Expand Down Expand Up @@ -169,6 +177,11 @@ func (prc *ProverConfig) getForkParameters() *lctypes.ForkParameters {
Epoch: 0,
Spec: &DenebSpec,
},
{
Version: []byte{5, 0, 0, 1},
Epoch: 0,
Spec: &ElectraSpec,
},
},
}
case Goerli:
Expand Down