Skip to content

Commit

Permalink
ff
Browse files Browse the repository at this point in the history
  • Loading branch information
jhgdike committed Aug 27, 2024
1 parent d5d41ca commit e5435ce
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
23 changes: 15 additions & 8 deletions beacon/fakebeacon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ package fakebeacon

import (
"net/http"
"strconv"

"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/gorilla/mux"
"github.com/prysmaticlabs/prysm/v5/api/server"
)

const (
DefaultHostPort = "0.0.0.0:8686"
DefaultAddr = "localhost"
DefaultPort = 8686
)

type Config struct {
Enable bool
HostPort string
Enable bool
Addr string
Port int
}

func defaultConfig() *Config {
return &Config{
Enable: false,
HostPort: DefaultHostPort,
Enable: false,
Addr: DefaultAddr,
Port: DefaultPort,
}
}

Expand All @@ -32,8 +36,11 @@ type Service struct {

func NewService(cfg *Config, backend ethapi.Backend) *Service {
cfgs := defaultConfig()
if cfg.HostPort != "" {
cfgs.HostPort = cfg.HostPort
if cfg.Addr != "" {
cfgs.Addr = cfg.Addr
}
if cfg.Port > 0 {
cfgs.Port = cfg.Port
}

s := &Service{
Expand All @@ -46,7 +53,7 @@ func NewService(cfg *Config, backend ethapi.Backend) *Service {
}

func (s *Service) Run() {
_ = http.ListenAndServe(s.cfg.HostPort, s.router)
_ = http.ListenAndServe(s.cfg.Addr+strconv.Itoa(s.cfg.Port), s.router)
}

func (s *Service) newRouter() *mux.Router {
Expand Down
23 changes: 13 additions & 10 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ type ethstatsConfig struct {
}

type gethConfig struct {
Eth ethconfig.Config
Node node.Config
Ethstats ethstatsConfig
Metrics metrics.Config
FkBeacon fakebeacon.Config
Eth ethconfig.Config
Node node.Config
Ethstats ethstatsConfig
Metrics metrics.Config
FakeBeacon fakebeacon.Config
}

func loadConfig(file string, cfg *gethConfig) error {
Expand Down Expand Up @@ -245,13 +245,16 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
}

if ctx.IsSet(utils.FakeBeaconEnabledFlag.Name) {
cfg.FkBeacon.Enable = ctx.Bool(utils.FakeBeaconEnabledFlag.Name)
cfg.FakeBeacon.Enable = ctx.Bool(utils.FakeBeaconEnabledFlag.Name)
}
if ctx.IsSet(utils.FakeBeaconHTTPHostPortFlag.Name) {
cfg.FkBeacon.HostPort = ctx.String(utils.FakeBeaconHTTPHostPortFlag.Name)
if ctx.IsSet(utils.FakeBeaconAddrFlag.Name) {
cfg.FakeBeacon.Addr = ctx.String(utils.FakeBeaconAddrFlag.Name)
}
if cfg.FkBeacon.Enable {
go fakebeacon.NewService(&cfg.FkBeacon, backend).Run()
if ctx.IsSet(utils.FakeBeaconPortFlag.Name) {
cfg.FakeBeacon.Port = ctx.Int(utils.FakeBeaconPortFlag.Name)
}
if cfg.FakeBeacon.Enable {
go fakebeacon.NewService(&cfg.FakeBeacon, backend).Run()
}

git, _ := version.VCS()
Expand Down
3 changes: 2 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ var (

fakeBeaconFlags = []cli.Flag{
utils.FakeBeaconEnabledFlag,
utils.FakeBeaconHTTPHostPortFlag,
utils.FakeBeaconAddrFlag,
utils.FakeBeaconPortFlag,
}
)

Expand Down
14 changes: 10 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,14 +1150,20 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.

// Fake beacon
FakeBeaconEnabledFlag = &cli.BoolFlag{
Name: "fake-beacon.enable",
Name: "fake-beacon",
Usage: "Enable the HTTP-RPC server of fake-beacon",
Category: flags.APICategory,
}
FakeBeaconHTTPHostPortFlag = &cli.StringFlag{
Name: "fake-beacon.hostport",
FakeBeaconAddrFlag = &cli.StringFlag{
Name: "fake-beacon.addr",
Usage: "HTTP-RPC server listening addr of fake-beacon",
Value: fakebeacon.DefaultAddr,
Category: flags.APICategory,
}
FakeBeaconPortFlag = &cli.IntFlag{
Name: "fake-beacon.port",
Usage: "HTTP-RPC server listening port of fake-beacon",
Value: fakebeacon.DefaultHostPort,
Value: fakebeacon.DefaultPort,
Category: flags.APICategory,
}
)
Expand Down

0 comments on commit e5435ce

Please sign in to comment.