Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 79 additions & 3 deletions cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const (
optionNamePaymentEarly = "payment-early-percent"
optionNameResolverEndpoints = "resolver-options"
optionNameBootnodeMode = "bootnode-mode"
optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint"
optionNameSwapFactoryAddress = "swap-factory-address"
optionNameSwapInitialDeposit = "swap-initial-deposit"
optionNameSwapEnable = "swap-enable"
Expand Down Expand Up @@ -89,8 +88,36 @@ const (
optionAutoTLSDomain = "autotls-domain"
optionAutoTLSRegistrationEndpoint = "autotls-registration-endpoint"
optionAutoTLSCAEndpoint = "autotls-ca-endpoint"

// blockchain-rpc
optionNameBlockchainRpcEndpoint = "blockchain-rpc-endpoint"
optionNameBlockchainRpcDialTimeout = "blockchain-rpc-dial-timeout"
optionNameBlockchainRpcTLSTimeout = "blockchain-rpc-tls-timeout"
optionNameBlockchainRpcIdleTimeout = "blockchain-rpc-idle-timeout"
optionNameBlockchainRpcKeepalive = "blockchain-rpc-keepalive"
configKeyBlockchainRpcEndpoint = "blockchain-rpc.endpoint"
configKeyBlockchainRpcDialTimeout = "blockchain-rpc.dial-timeout"
configKeyBlockchainRpcTLSTimeout = "blockchain-rpc.tls-timeout"
configKeyBlockchainRpcIdleTimeout = "blockchain-rpc.idle-timeout"
configKeyBlockchainRpcKeepalive = "blockchain-rpc.keepalive"
)

var blockchainRpcConfigPairs = []struct{ flat, dotted string }{
{optionNameBlockchainRpcEndpoint, configKeyBlockchainRpcEndpoint},
{optionNameBlockchainRpcDialTimeout, configKeyBlockchainRpcDialTimeout},
{optionNameBlockchainRpcTLSTimeout, configKeyBlockchainRpcTLSTimeout},
{optionNameBlockchainRpcIdleTimeout, configKeyBlockchainRpcIdleTimeout},
{optionNameBlockchainRpcKeepalive, configKeyBlockchainRpcKeepalive},
}

var knownNestedKeys = func() map[string]bool {
m := make(map[string]bool, len(blockchainRpcConfigPairs))
for _, p := range blockchainRpcConfigPairs {
m[p.dotted] = true
}
return m
}()

// nolint:gochecknoinits
func init() {
cobra.EnableCommandSorting = false
Expand All @@ -99,6 +126,7 @@ func init() {
type command struct {
root *cobra.Command
config *viper.Viper
logger log.Logger
passwordReader passwordReader
cfgFile string
homeDir string
Expand Down Expand Up @@ -269,6 +297,10 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().StringSlice(optionNameResolverEndpoints, []string{}, "ENS compatible API endpoint for a TLD and with contract address, can be repeated, format [tld:][contract-addr@]url")
cmd.Flags().Bool(optionNameBootnodeMode, false, "cause the node to always accept incoming connections")
cmd.Flags().String(optionNameBlockchainRpcEndpoint, "", "rpc blockchain endpoint")
cmd.Flags().Duration(optionNameBlockchainRpcDialTimeout, 30*time.Second, "blockchain rpc TCP dial timeout")
cmd.Flags().Duration(optionNameBlockchainRpcTLSTimeout, 10*time.Second, "blockchain rpc TLS handshake timeout")
cmd.Flags().Duration(optionNameBlockchainRpcIdleTimeout, 90*time.Second, "blockchain rpc idle connection timeout")
cmd.Flags().Duration(optionNameBlockchainRpcKeepalive, 30*time.Second, "blockchain rpc TCP keepalive interval")
cmd.Flags().String(optionNameSwapFactoryAddress, "", "swap factory addresses")
cmd.Flags().String(optionNameSwapInitialDeposit, "0", "initial deposit if deploying a new chequebook")
cmd.Flags().Bool(optionNameSwapEnable, false, "enable swap")
Expand Down Expand Up @@ -307,6 +339,44 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().String(optionAutoTLSCAEndpoint, p2pforge.DefaultCAEndpoint, "autotls certificate authority endpoint")
}

// preRun must be called from every command's PreRunE, after which c.logger is
// ready for use in RunE. It binds CLI flags to viper and initialises the logger.
func (c *command) preRun(cmd *cobra.Command) error {
if err := c.config.BindPFlags(cmd.Flags()); err != nil {
return err
}
return c.initLogger(cmd)
}

func (c *command) initLogger(cmd *cobra.Command) error {
v := strings.ToLower(c.config.GetString(optionNameVerbosity))
logger, err := newLogger(cmd, v)
if err != nil {
return fmt.Errorf("new logger: %w", err)
}
if c.isWindowsService {
logger, err = createWindowsEventLogger(serviceName, logger)
if err != nil {
return fmt.Errorf("new windows logger: %w", err)
}
}
c.logger = logger
return nil
}

// bindBlockchainRpcConfig supports both flat (blockchain-rpc-endpoint) and
// nested (blockchain-rpc.endpoint) YAML forms, with nested taking precedence.
func (c *command) bindBlockchainRpcConfig(cmd *cobra.Command) {
for _, p := range blockchainRpcConfigPairs {
// Check before registering the alias; afterwards the flat value is unreachable.
if c.config.InConfig(p.flat) && c.config.InConfig(p.dotted) {
c.logger.Warning("config key conflict: nested form takes precedence", "ignored", p.flat, "used", p.dotted)
}
_ = c.config.BindPFlag(p.dotted, cmd.Flags().Lookup(p.flat))
c.config.RegisterAlias(p.flat, p.dotted)
}
}

func newLogger(cmd *cobra.Command, verbosity string) (log.Logger, error) {
var (
sink = cmd.OutOrStdout()
Expand Down Expand Up @@ -348,9 +418,15 @@ func (c *command) CheckUnknownParams(cmd *cobra.Command, args []string) error {
}
var unknownParams []string
for _, v := range c.config.AllKeys() {
if cmd.Flags().Lookup(v) == nil {
unknownParams = append(unknownParams, v)
if cmd.Flags().Lookup(v) != nil {
continue
}
// Only accept the dotted→hyphenated form for explicitly registered
// nested config keys.
if knownNestedKeys[v] && cmd.Flags().Lookup(strings.ReplaceAll(v, ".", "-")) != nil {
continue
}
unknownParams = append(unknownParams, v)
}

if len(unknownParams) > 0 {
Expand Down
24 changes: 13 additions & 11 deletions cmd/bee/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
package cmd

import (
"fmt"
"strings"

"github.com/ethersphere/bee/v2/pkg/node"
"github.com/ethersphere/bee/v2/pkg/settlement/swap/erc20"
"github.com/spf13/cobra"
Expand All @@ -25,16 +22,11 @@ func (c *command) initDeployCmd() error {
return cmd.Help()
}

v := strings.ToLower(c.config.GetString(optionNameVerbosity))
logger, err := newLogger(cmd, v)
if err != nil {
return fmt.Errorf("new logger: %w", err)
}
logger := c.logger

dataDir := c.config.GetString(optionNameDataDir)
factoryAddress := c.config.GetString(optionNameSwapFactoryAddress)
swapInitialDeposit := c.config.GetString(optionNameSwapInitialDeposit)
blockchainRpcEndpoint := c.config.GetString(optionNameBlockchainRpcEndpoint)
stateStore, _, err := node.InitStateStore(logger, dataDir, 1000)
if err != nil {
return err
Expand All @@ -54,13 +46,19 @@ func (c *command) initDeployCmd() error {
ctx,
logger,
stateStore,
blockchainRpcEndpoint,
0,
signer,
blocktime,
true,
c.config.GetUint64(optionNameMinimumGasTipCap),
c.config.GetUint64(optionNameGasLimitFallback),
node.BlockchainRPCConfig{
Endpoint: c.config.GetString(configKeyBlockchainRpcEndpoint),
DialTimeout: c.config.GetDuration(configKeyBlockchainRpcDialTimeout),
TLSTimeout: c.config.GetDuration(configKeyBlockchainRpcTLSTimeout),
IdleTimeout: c.config.GetDuration(configKeyBlockchainRpcIdleTimeout),
Keepalive: c.config.GetDuration(configKeyBlockchainRpcKeepalive),
},
)
if err != nil {
return err
Expand Down Expand Up @@ -100,7 +98,11 @@ func (c *command) initDeployCmd() error {
return err
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return c.config.BindPFlags(cmd.Flags())
if err := c.preRun(cmd); err != nil {
return err
}
c.bindBlockchainRpcConfig(cmd)
return nil
},
}

Expand Down
26 changes: 11 additions & 15 deletions cmd/bee/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,7 @@ func (c *command) initStartCmd() (err error) {
return cmd.Help()
}

v := strings.ToLower(c.config.GetString(optionNameVerbosity))

logger, err := newLogger(cmd, v)
if err != nil {
return fmt.Errorf("new logger: %w", err)
}

if c.isWindowsService {
logger, err = createWindowsEventLogger(serviceName, logger)
if err != nil {
return fmt.Errorf("failed to create windows logger %w", err)
}
}
logger := c.logger

fmt.Print(beeWelcomeMessage)
logger.Info("bee version", "version", bee.Version)
Expand Down Expand Up @@ -167,7 +155,11 @@ func (c *command) initStartCmd() (err error) {
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return c.config.BindPFlags(cmd.Flags())
if err := c.preRun(cmd); err != nil {
return err
}
c.bindBlockchainRpcConfig(cmd)
return nil
},
}

Expand Down Expand Up @@ -281,7 +273,11 @@ func buildBeeNode(ctx context.Context, c *command, cmd *cobra.Command, logger lo
EnableWSS: c.config.GetBool(optionNameP2PWSSEnable),
WSSAddr: c.config.GetString(optionP2PWSSAddr),
AutoTLSStorageDir: filepath.Join(c.config.GetString(optionNameDataDir), "autotls"),
BlockchainRpcEndpoint: c.config.GetString(optionNameBlockchainRpcEndpoint),
BlockchainRpcEndpoint: c.config.GetString(configKeyBlockchainRpcEndpoint),
BlockchainRpcDialTimeout: c.config.GetDuration(configKeyBlockchainRpcDialTimeout),
BlockchainRpcTLSTimeout: c.config.GetDuration(configKeyBlockchainRpcTLSTimeout),
BlockchainRpcIdleTimeout: c.config.GetDuration(configKeyBlockchainRpcIdleTimeout),
BlockchainRpcKeepalive: c.config.GetDuration(configKeyBlockchainRpcKeepalive),
BlockProfile: c.config.GetBool(optionNamePProfBlock),
BlockTime: networkConfig.blockTime,
BootnodeMode: bootNode,
Expand Down
9 changes: 7 additions & 2 deletions packaging/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
# api-addr: 127.0.0.1:1633
## chain block time
# block-time: "5"
## rpc blockchain endpoint
# blockchain-rpc-endpoint: ""
## blockchain rpc configuration
# blockchain-rpc:
# endpoint: ""
# dial-timeout: 30s
# tls-timeout: 10s
# idle-timeout: 90s
# keepalive: 30s
## initial nodes to connect to
# bootnode: ["/dnsaddr/mainnet.ethswarm.org"]
## cause the node to always accept incoming connections
Expand Down
4 changes: 4 additions & 0 deletions packaging/default
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Configuration for bee daemon

#BEE_BLOCKCHAIN_RPC_ENDPOINT=ws://localhost:8546
#BEE_BLOCKCHAIN_RPC_DIAL_TIMEOUT=30s
#BEE_BLOCKCHAIN_RPC_TLS_TIMEOUT=10s
#BEE_BLOCKCHAIN_RPC_IDLE_TIMEOUT=90s
#BEE_BLOCKCHAIN_RPC_KEEPALIVE=30s
#BEE_RESOLVER_OPTIONS=
4 changes: 4 additions & 0 deletions packaging/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ services:
- BEE_RESOLVER_OPTIONS
- BEE_SWAP_ENABLE
- BEE_BLOCKCHAIN_RPC_ENDPOINT
- BEE_BLOCKCHAIN_RPC_DIAL_TIMEOUT
- BEE_BLOCKCHAIN_RPC_TLS_TIMEOUT
- BEE_BLOCKCHAIN_RPC_IDLE_TIMEOUT
- BEE_BLOCKCHAIN_RPC_KEEPALIVE
- BEE_SWAP_FACTORY_ADDRESS
- BEE_SWAP_LEGACY_FACTORY_ADDRESSES
- BEE_SWAP_INITIAL_DEPOSIT
Expand Down
6 changes: 5 additions & 1 deletion packaging/docker/env
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@
# BEE_RESOLVER_OPTIONS=[]
## enable swap (default false)
# BEE_SWAP_ENABLE=false
## swap blockchain endpoint (default ws://localhost:8546)
## blockchain rpc endpoint (default ws://localhost:8546)
# BEE_BLOCKCHAIN_RPC_ENDPOINT=ws://localhost:8546
# BEE_BLOCKCHAIN_RPC_DIAL_TIMEOUT=30s
# BEE_BLOCKCHAIN_RPC_TLS_TIMEOUT=10s
# BEE_BLOCKCHAIN_RPC_IDLE_TIMEOUT=90s
# BEE_BLOCKCHAIN_RPC_KEEPALIVE=30s
## swap factory address
# BEE_SWAP_FACTORY_ADDRESS=
## legacy swap factory addresses
Expand Down
9 changes: 7 additions & 2 deletions packaging/homebrew-amd64/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
# api-addr: 127.0.0.1:1633
## chain block time
# block-time: "5"
## rpc blockchain endpoint
# blockchain-rpc-endpoint: ""
## blockchain rpc configuration
# blockchain-rpc:
# endpoint: ""
# dial-timeout: 30s
# tls-timeout: 10s
# idle-timeout: 90s
# keepalive: 30s
## initial nodes to connect to
# bootnode: ["/dnsaddr/mainnet.ethswarm.org"]
## cause the node to always accept incoming connections
Expand Down
9 changes: 7 additions & 2 deletions packaging/homebrew-arm64/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
# api-addr: 127.0.0.1:1633
## chain block time
# block-time: "5"
## rpc blockchain endpoint
# blockchain-rpc-endpoint: ""
## blockchain rpc configuration
# blockchain-rpc:
# endpoint: ""
# dial-timeout: 30s
# tls-timeout: 10s
# idle-timeout: 90s
# keepalive: 30s
## initial nodes to connect to
# bootnode: ["/dnsaddr/mainnet.ethswarm.org"]
## cause the node to always accept incoming connections
Expand Down
9 changes: 7 additions & 2 deletions packaging/scoop/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
# api-addr: 127.0.0.1:1633
## chain block time
# block-time: "5"
## rpc blockchain endpoint
# blockchain-rpc-endpoint: ""
## blockchain rpc configuration
# blockchain-rpc:
# endpoint: ""
# dial-timeout: 30s
# tls-timeout: 10s
# idle-timeout: 90s
# keepalive: 30s
## initial nodes to connect to
# bootnode: ["/dnsaddr/mainnet.ethswarm.org"]
## cause the node to always accept incoming connections
Expand Down
Loading
Loading