diff --git a/relayer/cmd/generate_beacon_data.go b/relayer/cmd/generate_beacon_data.go index 29daa553a8..643ddfd232 100644 --- a/relayer/cmd/generate_beacon_data.go +++ b/relayer/cmd/generate_beacon_data.go @@ -40,7 +40,7 @@ func generateBeaconDataCmd() *cobra.Command { RunE: generateBeaconTestFixture, } - cmd.Flags().String("url", "http://127.0.0.1:9596", "Beacon URL") + cmd.Flags().String("config", "/tmp/snowbridge/beacon-relay.json", "Path to the beacon relay config") cmd.Flags().Bool("wait_until_next_period", true, "Waiting until next period") cmd.Flags().Uint32("nonce", 1, "Nonce of the inbound message") cmd.Flags().String("test_case", "register_token", "Inbound test case") @@ -55,8 +55,8 @@ func generateBeaconCheckpointCmd() *cobra.Command { RunE: generateBeaconCheckpoint, } - cmd.Flags().String("url", "http://127.0.0.1:9596", "Beacon URL") - cmd.Flags().Bool("export_json", false, "Export Json") + cmd.Flags().String("config", "/tmp/snowbridge/beacon-relay.json", "Path to the beacon relay config") + cmd.Flags().Bool("export-json", false, "Export Json") return cmd } @@ -68,7 +68,7 @@ func generateExecutionUpdateCmd() *cobra.Command { RunE: generateExecutionUpdate, } - cmd.Flags().String("url", "http://127.0.0.1:9596", "Beacon URL") + cmd.Flags().String("config", "/tmp/snowbridge/beacon-relay.json", "Path to the beacon relay config") cmd.Flags().Uint32("slot", 1, "slot number") return cmd } @@ -97,12 +97,12 @@ const ( // Only print the hex encoded call as output of this command func generateBeaconCheckpoint(cmd *cobra.Command, _ []string) error { err := func() error { - endpoint, err := cmd.Flags().GetString("url") + config, err := cmd.Flags().GetString("config") if err != nil { return err } - viper.SetConfigFile("web/packages/test/config/beacon-relay.json") + viper.SetConfigFile(config) if err := viper.ReadInConfig(); err != nil { return err @@ -119,7 +119,7 @@ func generateBeaconCheckpoint(cmd *cobra.Command, _ []string) error { store.Connect() defer store.Close() - client := api.NewBeaconClient(endpoint) + client := api.NewBeaconClient(conf.Source.Beacon.Endpoint, conf.Source.Beacon.StateEndpoint) s := syncer.New(client, &store, p) checkPointScale, err := s.GetCheckpoint() @@ -153,12 +153,12 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error { err := func() error { ctx := context.Background() - endpoint, err := cmd.Flags().GetString("url") + config, err := cmd.Flags().GetString("config") if err != nil { return err } - viper.SetConfigFile("web/packages/test/config/beacon-relay.json") + viper.SetConfigFile(config) if err = viper.ReadInConfig(); err != nil { return err } @@ -172,11 +172,14 @@ func generateBeaconTestFixture(cmd *cobra.Command, _ []string) error { p := protocol.New(conf.Source.Beacon.Spec) store := store.New(conf.Source.Beacon.DataStore.Location, conf.Source.Beacon.DataStore.MaxEntries, *p) - store.Connect() + err = store.Connect() + if err != nil { + return err + } defer store.Close() - log.WithFields(log.Fields{"endpoint": endpoint}).Info("connecting to beacon API") - client := api.NewBeaconClient(endpoint) + log.WithFields(log.Fields{"endpoint": conf.Source.Beacon.Endpoint}).Info("connecting to beacon API") + client := api.NewBeaconClient(conf.Source.Beacon.Endpoint, conf.Source.Beacon.StateEndpoint) s := syncer.New(client, &store, p) viper.SetConfigFile("/tmp/snowbridge/execution-relay-asset-hub.json") @@ -503,19 +506,25 @@ func writeBenchmarkDataFile(path string, fileContents string) error { func generateExecutionUpdate(cmd *cobra.Command, _ []string) error { err := func() error { - endpoint, _ := cmd.Flags().GetString("url") - beaconSlot, _ := cmd.Flags().GetUint32("slot") + config, err := cmd.Flags().GetString("config") + if err != nil { + return err + } + beaconSlot, err := cmd.Flags().GetUint32("slot") + if err != nil { + return err + } - viper.SetConfigFile("web/packages/test/config/beacon-relay.json") + viper.SetConfigFile(config) if err := viper.ReadInConfig(); err != nil { return err } var conf beaconConf.Config - err := viper.Unmarshal(&conf) + err = viper.Unmarshal(&conf) if err != nil { return err } - log.WithFields(log.Fields{"endpoint": endpoint}).Info("connecting to beacon API") + log.WithFields(log.Fields{"endpoint": conf.Source.Beacon.Endpoint}).Info("connecting to beacon API") p := protocol.New(conf.Source.Beacon.Spec) @@ -524,7 +533,7 @@ func generateExecutionUpdate(cmd *cobra.Command, _ []string) error { defer store.Close() // generate executionUpdate - client := api.NewBeaconClient(endpoint) + client := api.NewBeaconClient(conf.Source.Beacon.Endpoint, conf.Source.Beacon.StateEndpoint) s := syncer.New(client, &store, p) blockRoot, err := s.Client.GetBeaconBlockRoot(uint64(beaconSlot)) if err != nil { diff --git a/relayer/cmd/import_execution_header.go b/relayer/cmd/import_execution_header.go index ed7e20b0fd..121fac298b 100644 --- a/relayer/cmd/import_execution_header.go +++ b/relayer/cmd/import_execution_header.go @@ -114,7 +114,7 @@ func importExecutionHeaderFn(cmd *cobra.Command, _ []string) error { store.Connect() defer store.Close() - client := api.NewBeaconClient(lodestarEndpoint) + client := api.NewBeaconClient(lodestarEndpoint, lodestarEndpoint) syncer := syncer.New(client, &store, p) beaconHeaderHash := common.HexToHash(finalizedHeader) diff --git a/relayer/cmd/store_beacon_state.go b/relayer/cmd/store_beacon_state.go index 3e05132992..8001df4d1b 100644 --- a/relayer/cmd/store_beacon_state.go +++ b/relayer/cmd/store_beacon_state.go @@ -51,7 +51,7 @@ func storeBeaconStateInDB(cmd *cobra.Command, _ []string) error { p := protocol.New(conf.Source.Beacon.Spec) store := store.New(conf.Source.Beacon.DataStore.Location, conf.Source.Beacon.DataStore.MaxEntries, *p) - beaconClient := api.NewBeaconClient(conf.Source.Beacon.Endpoint) + beaconClient := api.NewBeaconClient(conf.Source.Beacon.Endpoint, conf.Source.Beacon.StateEndpoint) syncer := syncer.New(beaconClient, &store, p) err = store.Connect() diff --git a/relayer/relays/beacon/config/config.go b/relayer/relays/beacon/config/config.go index c8ab4a4807..95351f40af 100644 --- a/relayer/relays/beacon/config/config.go +++ b/relayer/relays/beacon/config/config.go @@ -26,9 +26,10 @@ type DataStore struct { } type BeaconConfig struct { - Endpoint string `mapstructure:"endpoint"` - Spec SpecSettings `mapstructure:"spec"` - DataStore DataStore `mapstructure:"datastore"` + Endpoint string `mapstructure:"endpoint"` + StateEndpoint string `mapstructure:"stateEndpoint"` + Spec SpecSettings `mapstructure:"spec"` + DataStore DataStore `mapstructure:"datastore"` } type SinkConfig struct { diff --git a/relayer/relays/beacon/header/syncer/api/api.go b/relayer/relays/beacon/header/syncer/api/api.go index 446daa969e..0e0b34bbd7 100644 --- a/relayer/relays/beacon/header/syncer/api/api.go +++ b/relayer/relays/beacon/header/syncer/api/api.go @@ -43,14 +43,16 @@ type BeaconAPI interface { } type BeaconClient struct { - httpClient http.Client - endpoint string + httpClient http.Client + endpoint string + stateEndpoint string } -func NewBeaconClient(endpoint string) *BeaconClient { +func NewBeaconClient(endpoint, stateEndpoint string) *BeaconClient { return &BeaconClient{ http.Client{}, endpoint, + stateEndpoint, } } @@ -401,7 +403,7 @@ func (b *BeaconClient) GetLatestFinalizedUpdate() (LatestFinalisedUpdateResponse func (b *BeaconClient) GetBeaconState(stateIdOrSlot string) ([]byte, error) { var data []byte - req, err := http.NewRequest("GET", fmt.Sprintf("%s/eth/v2/debug/beacon/states/%s", b.endpoint, stateIdOrSlot), nil) + req, err := http.NewRequest("GET", fmt.Sprintf("%s/eth/v2/debug/beacon/states/%s", b.stateEndpoint, stateIdOrSlot), nil) if err != nil { return data, err } diff --git a/relayer/relays/beacon/header/syncer/syncer_test.go b/relayer/relays/beacon/header/syncer/syncer_test.go index 46851e9b7e..5e7e87ddd1 100644 --- a/relayer/relays/beacon/header/syncer/syncer_test.go +++ b/relayer/relays/beacon/header/syncer/syncer_test.go @@ -21,7 +21,7 @@ import ( const TestUrl = "https://lodestar-sepolia.chainsafe.io" func newTestRunner() *Syncer { - return New(api.NewBeaconClient(TestUrl), &mock.Store{}, protocol.New(config.SpecSettings{ + return New(api.NewBeaconClient(TestUrl, TestUrl), &mock.Store{}, protocol.New(config.SpecSettings{ SlotsInEpoch: 32, EpochsPerSyncCommitteePeriod: 256, DenebForkEpoch: 0, diff --git a/relayer/relays/beacon/main.go b/relayer/relays/beacon/main.go index 9ca801fed1..4c6a5cef28 100644 --- a/relayer/relays/beacon/main.go +++ b/relayer/relays/beacon/main.go @@ -61,7 +61,7 @@ func (r *Relay) Start(ctx context.Context, eg *errgroup.Group) error { } defer s.Close() - beaconAPI := api.NewBeaconClient(r.config.Source.Beacon.Endpoint) + beaconAPI := api.NewBeaconClient(r.config.Source.Beacon.Endpoint, r.config.Source.Beacon.StateEndpoint) headers := header.New( writer, beaconAPI, diff --git a/web/packages/test/config/beacon-relay.json b/web/packages/test/config/beacon-relay.json index b51189e87c..bbc033b5cd 100644 --- a/web/packages/test/config/beacon-relay.json +++ b/web/packages/test/config/beacon-relay.json @@ -2,6 +2,7 @@ "source": { "beacon": { "endpoint": "http://127.0.0.1:9596", + "stateEndpoint": "http://127.0.0.1:9596", "spec": { "syncCommitteeSize": 512, "slotsInEpoch": 32,