MCPcopy Create free account
hub / github.com/ethstorage/es-node / NewConfig

Function NewConfig

cmd/es-node/config.go:31–136  ·  view source on GitHub ↗

NewConfig creates a Config from the provided flags or environment variables.

(ctx *cli.Context, lg log.Logger)

Source from the content-addressed store, hash-verified

29
30// NewConfig creates a Config from the provided flags or environment variables.
31func NewConfig(ctx *cli.Context, lg log.Logger) (*node.Config, error) {
32 if err := flags.CheckRequired(ctx); err != nil {
33 return nil, err
34 }
35
36 datadir := ctx.GlobalString(flags.DataDir.Name)
37
38 // TODO: blocktime is set to zero, need to update the value
39 p2pConfig, err := p2pcli.NewConfig(ctx, 0)
40 if err != nil {
41 return nil, fmt.Errorf("failed to load p2p config: %w", err)
42 }
43
44 l1Endpoint, client, err := NewL1EndpointConfig(ctx, lg)
45 if err != nil {
46 return nil, err
47 }
48 lg.Info("Read L1 config", flags.L1NodeAddr.Name, l1Endpoint.L1NodeAddr)
49 lg.Info("Read L1 config", flags.L1BeaconAddr.Name, l1Endpoint.L1BeaconURL)
50 defer client.Close()
51
52 storageConfig, err := NewStorageConfig(ctx, client, lg)
53 if err != nil {
54 return nil, fmt.Errorf("failed to load storage config: %w", err)
55 }
56
57 emailConfig, err := email.GetEmailConfig(ctx)
58 if err != nil {
59 lg.Warn("Failed to load email config, email notifications will be disabled.", "error", err)
60 }
61 dlConfig := NewDownloaderConfig(ctx)
62 if emailConfig != nil {
63 dlConfig.EmailConfig = emailConfig
64 }
65 minerConfig, err := NewMinerConfig(ctx, client, storageConfig.L1Contract, storageConfig.Miner, lg)
66 if err != nil {
67 return nil, fmt.Errorf("failed to load miner config: %w", err)
68 }
69 if minerConfig != nil && minerConfig.EmailEnabled {
70 if emailConfig == nil {
71 return nil, fmt.Errorf("email config is required by miner but not loaded")
72 }
73 minerConfig.EmailConfig = *emailConfig
74 }
75 chainId := new(big.Int).SetUint64(ctx.GlobalUint64(flags.ChainId.Name))
76 lg.Info("Read chain ID of EthStorage network", "chainID", chainId)
77 if minerConfig != nil {
78 minerConfig.ChainID = chainId
79 minerConfig.Slot = l1Endpoint.L1BeaconSlotTime
80 }
81 archiverConfig := archiver.NewConfig(ctx)
82 // l2Endpoint, err := NewL2EndpointConfig(ctx, lg)
83 // if err != nil {
84 // return nil, fmt.Errorf("failed to load l2 endpoints info: %w", err)
85 // }
86
87 // l2SyncEndpoint := NewL2SyncEndpointConfig(ctx)
88

Callers 1

EsNodeMainFunction · 0.70

Calls 11

CheckMethod · 0.95
CheckRequiredFunction · 0.92
GetEmailConfigFunction · 0.92
NewConfigFunction · 0.92
NewConfigFunction · 0.92
DefaultDBConfigFunction · 0.92
NewL1EndpointConfigFunction · 0.85
NewStorageConfigFunction · 0.85
NewDownloaderConfigFunction · 0.85
NewMinerConfigFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected