2022-10-12 21:47:06 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-10-16 17:54:12 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-10-12 21:47:06 +00:00
|
|
|
|
2022-10-23 18:22:33 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/cltypes"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/rpc/lightrpc"
|
2022-10-12 21:47:06 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel/service"
|
2022-10-16 17:54:12 +00:00
|
|
|
lcCli "github.com/ledgerwatch/erigon/cmd/sentinel_node/cli"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/sentinel_node/cli/flags"
|
|
|
|
sentinelapp "github.com/ledgerwatch/erigon/turbo/app"
|
|
|
|
"github.com/urfave/cli"
|
2022-10-12 21:47:06 +00:00
|
|
|
|
2022-10-16 17:54:12 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2022-10-12 21:47:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2022-10-16 17:54:12 +00:00
|
|
|
app := sentinelapp.MakeApp(runSentinelNode, flags.LightClientDefaultFlags)
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
_, printErr := fmt.Fprintln(os.Stderr, err)
|
|
|
|
if printErr != nil {
|
|
|
|
log.Warn("Fprintln error", "err", printErr)
|
|
|
|
}
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runSentinelNode(cliCtx *cli.Context) {
|
2022-10-17 17:13:23 +00:00
|
|
|
lcCfg, _ := lcCli.SetUpLightClientCfg(cliCtx)
|
2022-10-12 21:47:06 +00:00
|
|
|
ctx := context.Background()
|
2022-10-16 17:54:12 +00:00
|
|
|
|
|
|
|
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(lcCfg.LogLvl), log.StderrHandler))
|
2022-10-17 17:13:23 +00:00
|
|
|
log.Info("[Sentinel] running sentinel with configuration", "cfg", lcCfg)
|
2022-10-23 18:22:33 +00:00
|
|
|
sent, err := service.StartSentinelService(&sentinel.SentinelConfig{
|
2022-10-17 17:13:23 +00:00
|
|
|
IpAddr: lcCfg.Addr,
|
|
|
|
Port: int(lcCfg.Port),
|
|
|
|
TCPPort: lcCfg.ServerTcpPort,
|
|
|
|
GenesisConfig: lcCfg.GenesisCfg,
|
|
|
|
NetworkConfig: lcCfg.NetworkCfg,
|
|
|
|
BeaconConfig: lcCfg.BeaconCfg,
|
|
|
|
NoDiscovery: lcCfg.NoDiscovery,
|
2022-10-16 17:54:12 +00:00
|
|
|
}, &service.ServerConfig{Network: lcCfg.ServerProtocol, Addr: lcCfg.ServerAddr})
|
2022-10-12 21:47:06 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("Could not start sentinel", "err", err)
|
2022-10-23 18:22:33 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
subscription, err := sent.SubscribeGossip(ctx, &lightrpc.EmptyRequest{})
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Could not start sentinel", "err", err)
|
|
|
|
return
|
2022-10-12 21:47:06 +00:00
|
|
|
}
|
2022-10-16 17:54:12 +00:00
|
|
|
log.Info("Sentinel started", "addr", lcCfg.ServerAddr)
|
2022-10-23 18:22:33 +00:00
|
|
|
for {
|
|
|
|
data, err := subscription.Recv()
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if data.Type != lightrpc.GossipType_AggregateAndProofGossipType {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
block := &cltypes.SignedAggregateAndProof{}
|
|
|
|
if err := block.UnmarshalSSZ(data.Data); err != nil {
|
|
|
|
log.Error("Error", "err", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.Info("Received", "msg", block)
|
|
|
|
}
|
2022-10-12 21:47:06 +00:00
|
|
|
}
|