Skip to content

Commit

Permalink
add infra service
Browse files Browse the repository at this point in the history
  • Loading branch information
uranuswch committed Nov 13, 2023
1 parent 29c5a5b commit 43d59ec
Show file tree
Hide file tree
Showing 11 changed files with 8,066 additions and 26 deletions.
20 changes: 18 additions & 2 deletions cmd/erigon/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package main

import (
"context"
"errors"
"fmt"
"github.com/ledgerwatch/erigon-lib/metrics"
"net/http"
"os"
"path/filepath"
"reflect"
"strings"

"github.com/ledgerwatch/erigon-lib/metrics"
"github.com/ledgerwatch/erigon/mev-lib"

"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon/diagnostics"
Expand Down Expand Up @@ -76,12 +79,25 @@ func runErigon(cliCtx *cli.Context) error {
}

ethCfg := node.NewEthConfigUrfave(cliCtx, nodeCfg, logger)

mevFlag := node.NewMEVFlagUrfave(cliCtx)
ethNode, err := node.New(cliCtx.Context, nodeCfg, ethCfg, logger)
if err != nil {
log.Error("Erigon startup", "err", err)
return err
}
if mevFlag.Enable {
mev.MainInit()
mevCtx, cancel := context.WithCancel(context.Background())
defer func() {
cancel()
mev.WaitForShutdown()
}()
if err := mev.LaunchInfraServer(mevCtx, mevFlag.ConfigPath,
ethNode.Backend(), ethNode.Backend().APIs()); err != nil {
log.Error("MEV infra server failed", "err", err)
return err
}
}

if metricsMux != nil {
diagnostics.Setup(cliCtx, metricsMux, ethNode)
Expand Down
17 changes: 13 additions & 4 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ var (
Usage: "Port for sentinel",
Value: 7777,
}

OtsSearchMaxCapFlag = cli.Uint64Flag{
Name: "ots.search.max.pagesize",
Usage: "Max allowed page size for search methods",
Expand Down Expand Up @@ -853,6 +852,16 @@ var (
Name: "silkworm.sentry",
Usage: "Enable embedded Silkworm Sentry service",
}
EnableMEVInfra = cli.BoolFlag{
Name: "mev-infra.enable",
Usage: "Enable MEV infrastructure",
Value: false,
}
MEVInfraConfigPath = cli.StringFlag{
Name: "mev-infra.config",
Usage: "Path to the MEV infrastructure config file",
Value: "",
}
)

var MetricFlags = []cli.Flag{&MetricsEnabledFlag, &MetricsHTTPFlag, &MetricsPortFlag}
Expand Down Expand Up @@ -1188,7 +1197,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config, nodeName, datadir string, l

if ctx.String(ChainFlag.Name) == networkname.DevChainName {
// --dev mode can't use p2p networking.
//cfg.MaxPeers = 0 // It can have peers otherwise local sync is not possible
// cfg.MaxPeers = 0 // It can have peers otherwise local sync is not possible
if !ctx.IsSet(ListenPortFlag.Name) {
cfg.ListenAddr = ":0"
}
Expand All @@ -1209,7 +1218,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logger) {

func SetNodeConfigCobra(cmd *cobra.Command, cfg *nodecfg.Config) {
flags := cmd.Flags()
//SetP2PConfig(ctx, &cfg.P2P)
// SetP2PConfig(ctx, &cfg.P2P)
setNodeUserIdentCobra(flags, cfg)
setDataDirCobra(flags, cfg)
}
Expand Down Expand Up @@ -1533,7 +1542,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
cfg.ForcePartialCommit = ctx.Bool(ForcePartialCommitFlag.Name)

cfg.Sync.UseSnapshots = ethconfig.UseSnapshotsByChainName(ctx.String(ChainFlag.Name))
if ctx.IsSet(SnapshotFlag.Name) { //force override default by cli
if ctx.IsSet(SnapshotFlag.Name) { // force override default by cli
cfg.Sync.UseSnapshots = ctx.Bool(SnapshotFlag.Name)
}

Expand Down
20 changes: 10 additions & 10 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,11 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
if config.DeprecatedTxPool.Disable {
backend.txPoolGrpcServer = &txpool.GrpcDisabled{}
} else {
//cacheConfig := kvcache.DefaultCoherentCacheConfig
//cacheConfig.MetricsLabel = "txpool"
// cacheConfig := kvcache.DefaultCoherentCacheConfig
// cacheConfig.MetricsLabel = "txpool"

backend.newTxs = make(chan types2.Announcements, 1024)
//defer close(newTxs)
// defer close(newTxs)
backend.txPoolDB, backend.txPool, backend.txPoolFetch, backend.txPoolSend, backend.txPoolGrpcServer, err = txpooluitl.AllComponents(
ctx, config.TxPool, kvcache.NewDummy(), backend.newTxs, backend.chainDB, backend.sentriesClient.Sentries(), stateDiffClient, logger,
)
Expand Down Expand Up @@ -753,9 +753,9 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
}
backend.sentriesClient.Bd.AddToPrefetch(b.Header(), b.RawBody())

//p2p
//backend.sentriesClient.BroadcastNewBlock(context.Background(), b, b.Difficulty())
//rpcdaemon
// p2p
// backend.sentriesClient.BroadcastNewBlock(context.Background(), b, b.Difficulty())
// rpcdaemon
if err := miningRPC.(*privateapi.MiningServer).BroadcastMinedBlock(b); err != nil {
logger.Error("txpool rpc mined block broadcast", "err", err)
}
Expand Down Expand Up @@ -889,12 +889,12 @@ func (s *Ethereum) Init(stack *node.Node, config *ethconfig.Config) error {
}
}

//eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
// eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
gpoParams := config.GPO
if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice
}
//eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
// eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
if config.Ethstats != "" {
var headCh chan [][]byte
headCh, s.unsubscribeEthstat = s.notifications.Events.AddHeaderSubscription()
Expand Down Expand Up @@ -999,11 +999,11 @@ func (s *Ethereum) StartMining(ctx context.Context, db kv.RwDB, mining *stagedsy
}
}

//if borcfg == nil {
// if borcfg == nil {
if !cfg.Enabled {
return nil
}
//}
// }

// Configure the local mining address
eb, err := s.Etherbase()
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ require (
github.com/valyala/fastjson v1.6.4
github.com/vektah/gqlparser/v2 v2.5.6
github.com/xsleonard/go-merkle v1.1.0
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0
go.opentelemetry.io/otel/sdk v1.19.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.14.0
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
Expand Down Expand Up @@ -262,8 +265,8 @@ require (
github.com/valyala/histogram v1.2.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.opentelemetry.io/otel v1.8.0 // indirect
go.opentelemetry.io/otel/trace v1.8.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.uber.org/dig v1.17.0 // indirect
go.uber.org/fx v1.20.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down
14 changes: 10 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,16 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opentelemetry.io/otel v1.8.0 h1:zcvBFizPbpa1q7FehvFiHbQwGzmPILebO0tyqIR5Djg=
go.opentelemetry.io/otel v1.8.0/go.mod h1:2pkj+iMj0o03Y+cW6/m8Y4WkRdYN3AvCXCnzRMp9yvM=
go.opentelemetry.io/otel/trace v1.8.0 h1:cSy0DF9eGI5WIfNwZ1q2iUyGj00tGzP24dE1lOlHrfY=
go.opentelemetry.io/otel/trace v1.8.0/go.mod h1:0Bt3PXY8w+3pheS3hQUt+wow8b1ojPaTBoTCh2zIFI4=
go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs=
go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 h1:Nw7Dv4lwvGrI68+wULbcq7su9K2cebeCUrDjVrUJHxM=
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0/go.mod h1:1MsF6Y7gTqosgoZvHlzcaaM8DIMNZgJh87ykokoNH7Y=
go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE=
go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8=
go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o=
go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A=
go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg=
go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI=
Expand Down
Loading

0 comments on commit 43d59ec

Please sign in to comment.