-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathmain.go
100 lines (87 loc) · 3.24 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2022 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"context"
"fmt"
"os"
"github.com/erigontech/erigon-lib/common/disk"
"github.com/erigontech/erigon-lib/common/mem"
"github.com/erigontech/erigon/cl/clparams"
"github.com/erigontech/erigon/cl/phase1/core/checkpoint_sync"
"github.com/erigontech/erigon/cl/sentinel"
"github.com/erigontech/erigon/cl/sentinel/service"
"github.com/erigontech/erigon/cl/utils/eth_clock"
"github.com/erigontech/erigon/cmd/sentinel/sentinelcli"
"github.com/erigontech/erigon/cmd/sentinel/sentinelflags"
"github.com/erigontech/erigon/cmd/utils"
"github.com/urfave/cli/v2"
"github.com/erigontech/erigon-lib/log/v3"
sentinelapp "github.com/erigontech/erigon/turbo/app"
)
func main() {
app := sentinelapp.MakeApp("sentinel", runSentinelNode, sentinelflags.CliFlags)
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) error {
cfg, err := sentinelcli.SetupSentinelCli(cliCtx)
if err != nil {
return err
}
log.Root().SetHandler(log.LvlFilterHandler(log.Lvl(cfg.LogLvl), log.StderrHandler))
log.Info("[Sentinel] running sentinel with configuration", "cfg", cfg)
chainName := cliCtx.String(utils.ChainFlag.Name)
networkCfg, beaconCfg, networkType, err := clparams.GetConfigsByNetworkName(chainName)
if err != nil {
return err
}
if len(cfg.Bootnodes) > 0 {
networkCfg.BootNodes = cfg.Bootnodes
}
if len(cfg.StaticPeers) > 0 {
networkCfg.StaticPeers = cfg.StaticPeers
}
// setup periodic logging and prometheus updates
go mem.LogMemStats(cliCtx.Context, log.Root())
go disk.UpdateDiskStats(cliCtx.Context, log.Root())
bs, err := checkpoint_sync.NewRemoteCheckpointSync(beaconCfg, networkType).GetLatestBeaconState(cliCtx.Context)
if err != nil {
return err
}
_, err = service.StartSentinelService(&sentinel.SentinelConfig{
IpAddr: cfg.Addr,
Port: int(cfg.Port),
TCPPort: cfg.ServerTcpPort,
NetworkConfig: networkCfg,
BeaconConfig: beaconCfg,
NoDiscovery: cfg.NoDiscovery,
LocalDiscovery: cfg.LocalDiscovery,
EnableBlocks: false,
}, nil, nil, nil, &service.ServerConfig{Network: cfg.ServerProtocol, Addr: cfg.ServerAddr}, eth_clock.NewEthereumClock(bs.GenesisTime(), bs.GenesisValidatorsRoot(), beaconCfg), nil, log.Root())
if err != nil {
log.Error("[Sentinel] Could not start sentinel", "err", err)
return err
}
log.Info("[Sentinel] Sentinel started", "addr", cfg.ServerAddr)
<-context.Background().Done()
return nil
}