2022-09-25 19:01:39 +00:00
|
|
|
/*
|
|
|
|
Copyright 2022 Erigon-Lightclient contributors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-09-23 23:53:27 +00:00
|
|
|
package main
|
|
|
|
|
2022-10-12 23:05:01 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-10-13 16:26:29 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/clparams"
|
2022-10-12 23:05:01 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/lightclient"
|
2022-10-13 16:26:29 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel/service"
|
2022-10-12 23:05:01 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
)
|
|
|
|
|
2022-10-13 16:26:29 +00:00
|
|
|
var (
|
|
|
|
defaultIpAddr = "127.0.0.1" // Localhost
|
|
|
|
defaultPort = 8080
|
|
|
|
defaultTcpPort = uint(9000)
|
|
|
|
)
|
|
|
|
|
2022-10-12 23:05:01 +00:00
|
|
|
const DefaultUri = "https://beaconstate.ethstaker.cc/eth/v2/debug/beacon/states/finalized"
|
|
|
|
|
2022-09-23 23:53:27 +00:00
|
|
|
func main() {
|
2022-10-13 16:26:29 +00:00
|
|
|
ctx := context.Background()
|
2022-10-12 23:05:01 +00:00
|
|
|
log.Root().SetHandler(log.LvlFilterHandler(log.LvlInfo, log.StderrHandler))
|
2022-10-13 16:26:29 +00:00
|
|
|
addr := "localhost:7777"
|
|
|
|
genesisCfg, networkCfg, beaconCfg := clparams.GetConfigsByNetwork(clparams.MainnetNetwork)
|
|
|
|
sentinel, err := service.StartSentinelService(&sentinel.SentinelConfig{
|
|
|
|
IpAddr: defaultIpAddr,
|
|
|
|
Port: defaultPort,
|
|
|
|
TCPPort: defaultTcpPort,
|
|
|
|
GenesisConfig: genesisCfg,
|
|
|
|
NetworkConfig: networkCfg,
|
|
|
|
BeaconConfig: beaconCfg,
|
|
|
|
}, &service.ServerConfig{Network: "tcp", Addr: "localhost:7777"})
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Could not start sentinel", "err", err)
|
|
|
|
}
|
|
|
|
log.Info("Sentinel started", "addr", addr)
|
|
|
|
|
|
|
|
bs, err := lightclient.RetrieveBeaconState(ctx, DefaultUri)
|
2022-10-04 20:03:30 +00:00
|
|
|
|
2022-10-12 23:05:01 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("[Checkpoint Sync] Failed", "reason", err)
|
|
|
|
return
|
|
|
|
}
|
2022-10-13 16:26:29 +00:00
|
|
|
log.Info("Finalized Checkpoint", "Epoch", bs.FinalizedCheckpoint.Epoch)
|
2022-10-14 13:24:44 +00:00
|
|
|
lc := lightclient.NewLightClient(genesisCfg, beaconCfg, nil, sentinel)
|
2022-10-13 16:26:29 +00:00
|
|
|
if err := lc.BootstrapCheckpoint(ctx, bs.FinalizedCheckpoint.Root); err != nil {
|
|
|
|
log.Error("[Bootstrap] failed to bootstrap", "err", err)
|
|
|
|
return
|
|
|
|
}
|
2022-10-14 13:24:44 +00:00
|
|
|
lc.Start(ctx)
|
2022-10-04 20:03:30 +00:00
|
|
|
}
|