Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove standalone mode #2331

Merged
merged 1 commit into from
Jul 15, 2021
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
2 changes: 0 additions & 2 deletions cmd/bee/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const (
optionNameNetworkID = "network-id"
optionWelcomeMessage = "welcome-message"
optionCORSAllowedOrigins = "cors-allowed-origins"
optionNameStandalone = "standalone"
optionNameTracingEnabled = "tracing-enable"
optionNameTracingEndpoint = "tracing-endpoint"
optionNameTracingHost = "tracing-host"
Expand Down Expand Up @@ -217,7 +216,6 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd.Flags().String(optionNameDebugAPIAddr, ":1635", "debug HTTP API listen address")
cmd.Flags().Uint64(optionNameNetworkID, 10, "ID of the Swarm network")
cmd.Flags().StringSlice(optionCORSAllowedOrigins, []string{}, "origins with CORS headers enabled")
cmd.Flags().Bool(optionNameStandalone, false, "whether we want the node to start with no listen addresses for p2p")
cmd.Flags().Bool(optionNameTracingEnabled, false, "enable tracing")
cmd.Flags().String(optionNameTracingEndpoint, "127.0.0.1:6831", "endpoint to send tracing data")
cmd.Flags().String(optionNameTracingHost, "", "host to send tracing data")
Expand Down
1 change: 0 additions & 1 deletion cmd/bee/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ inability to use, or your interaction with other nodes or the software.`)
WelcomeMessage: c.config.GetString(optionWelcomeMessage),
Bootnodes: networkConfig.bootNodes,
CORSAllowedOrigins: c.config.GetStringSlice(optionCORSAllowedOrigins),
Standalone: c.config.GetBool(optionNameStandalone),
TracingEnabled: c.config.GetBool(optionNameTracingEnabled),
TracingEndpoint: tracingEndpoint,
TracingServiceName: c.config.GetString(optionNameTracingServiceName),
Expand Down
2 changes: 0 additions & 2 deletions packaging/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ password-file: /var/lib/bee/password
# postage-stamp-address: ""
## ENS compatible API endpoint for a TLD and with contract address, can be repeated, format [tld:][contract-addr@]url
# resolver-options: []
## whether we want the node to start with no listen addresses for p2p
# standalone: false
## enable swap (default true)
# swap-enable: true
## swap ethereum blockchain endpoint (default "ws://localhost:8546")
Expand Down
1 change: 0 additions & 1 deletion packaging/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ services:
- BEE_PAYMENT_TOLERANCE
- BEE_POSTAGE_STAMP_ADDRESS
- BEE_RESOLVER_OPTIONS
- BEE_STANDALONE
- BEE_SWAP_ENABLE
- BEE_SWAP_ENDPOINT
- BEE_SWAP_FACTORY_ADDRESS
Expand Down
2 changes: 0 additions & 2 deletions packaging/docker/env
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ BEE_CLEF_SIGNER_ENABLE=true
# BEE_POSTAGE_STAMP_ADDRESS=
## ENS compatible API endpoint for a TLD and with contract address, can be repeated, format [tld:][contract-addr@]url
# BEE_RESOLVER_OPTIONS=[]
## whether we want the node to start with no listen addresses for p2p
# BEE_STANDALONE=false
## enable swap (default true)
# BEE_SWAP_ENABLE=true
## swap ethereum blockchain endpoint (default ws://localhost:8546)
Expand Down
2 changes: 0 additions & 2 deletions packaging/homebrew/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ password-file: /usr/local/var/lib/swarm-bee/password
# postage-stamp-address: ""
## ENS compatible API endpoint for a TLD and with contract address, can be repeated, format [tld:][contract-addr@]url
# resolver-options: []
## whether we want the node to start with no listen addresses for p2p
# standalone: false
## enable swap (default true)
# swap-enable: true
## swap ethereum blockchain endpoint (default "ws://localhost:8546")
Expand Down
2 changes: 0 additions & 2 deletions packaging/scoop/bee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ password-file: ./password
# postage-stamp-address: ""
## ENS compatible API endpoint for a TLD and with contract address, can be repeated, format [tld:][contract-addr@]url
# resolver-options: []
## whether we want the node to start with no listen addresses for p2p
# standalone: false
## enable swap (default true)
# swap-enable: true
## swap ethereum blockchain endpoint (default "ws://localhost:8546")
Expand Down
163 changes: 75 additions & 88 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ type Options struct {
Bootnodes []string
CORSAllowedOrigins []string
Logger logging.Logger
Standalone bool
TracingEnabled bool
TracingEndpoint string
TracingServiceName string
Expand Down Expand Up @@ -212,25 +211,23 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
cashoutService chequebook.CashoutService
pollingInterval = time.Duration(o.BlockTime) * time.Second
)
if !o.Standalone {
swapBackend, overlayEthAddress, chainID, transactionMonitor, transactionService, err = InitChain(
p2pCtx,
logger,
stateStore,
o.SwapEndpoint,
signer,
pollingInterval,
)
if err != nil {
return nil, fmt.Errorf("init chain: %w", err)
}
b.ethClientCloser = swapBackend.Close
b.transactionCloser = tracerCloser
b.transactionMonitorCloser = transactionMonitor
swapBackend, overlayEthAddress, chainID, transactionMonitor, transactionService, err = InitChain(
p2pCtx,
logger,
stateStore,
o.SwapEndpoint,
signer,
pollingInterval,
)
if err != nil {
return nil, fmt.Errorf("init chain: %w", err)
}
b.ethClientCloser = swapBackend.Close
b.transactionCloser = tracerCloser
b.transactionMonitorCloser = transactionMonitor

if o.ChainID != -1 && o.ChainID != chainID {
return nil, fmt.Errorf("connected to wrong ethereum network: got chainID %d, want %d", chainID, o.ChainID)
}
if o.ChainID != -1 && o.ChainID != chainID {
return nil, fmt.Errorf("connected to wrong ethereum network: got chainID %d, want %d", chainID, o.ChainID)
}

var debugAPIService *debugapi.Service
Expand Down Expand Up @@ -266,19 +263,17 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
b.debugAPIServer = debugAPIServer
}

if !o.Standalone {
// Sync the with the given Ethereum backend:
isSynced, _, err := transaction.IsSynced(p2pCtx, swapBackend, maxDelay)
if err != nil {
return nil, fmt.Errorf("is synced: %w", err)
}
if !isSynced {
logger.Infof("waiting to sync with the Ethereum backend")
// Sync the with the given Ethereum backend:
isSynced, _, err := transaction.IsSynced(p2pCtx, swapBackend, maxDelay)
if err != nil {
return nil, fmt.Errorf("is synced: %w", err)
}
if !isSynced {
logger.Infof("waiting to sync with the Ethereum backend")

err := transaction.WaitSynced(p2pCtx, logger, swapBackend, maxDelay)
if err != nil {
return nil, fmt.Errorf("waiting backend sync: %w", err)
}
err := transaction.WaitSynced(p2pCtx, logger, swapBackend, maxDelay)
if err != nil {
return nil, fmt.Errorf("waiting backend sync: %w", err)
}
}

Expand Down Expand Up @@ -362,7 +357,6 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
NATAddr: o.NATAddr,
EnableWS: o.EnableWS,
EnableQUIC: o.EnableQUIC,
Standalone: o.Standalone,
WelcomeMessage: o.WelcomeMessage,
FullNode: o.FullNodeMode,
Transaction: txHash,
Expand Down Expand Up @@ -422,56 +416,52 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
)

var postageSyncStart uint64 = 0
if !o.Standalone {
chainCfg, found := config.GetChainConfig(chainID)
postageContractAddress, startBlock := chainCfg.PostageStamp, chainCfg.StartBlock
if o.PostageContractAddress != "" {
if !common.IsHexAddress(o.PostageContractAddress) {
return nil, errors.New("malformed postage stamp address")
}
postageContractAddress = common.HexToAddress(o.PostageContractAddress)
} else if !found {
return nil, errors.New("no known postage stamp addresses for this network")
}
if found {
postageSyncStart = startBlock
chainCfg, found := config.GetChainConfig(chainID)
postageContractAddress, startBlock := chainCfg.PostageStamp, chainCfg.StartBlock
if o.PostageContractAddress != "" {
if !common.IsHexAddress(o.PostageContractAddress) {
return nil, errors.New("malformed postage stamp address")
}
postageContractAddress = common.HexToAddress(o.PostageContractAddress)
} else if !found {
return nil, errors.New("no known postage stamp addresses for this network")
}
if found {
postageSyncStart = startBlock
}

eventListener = listener.New(logger, swapBackend, postageContractAddress, o.BlockTime, &pidKiller{node: b})
b.listenerCloser = eventListener

batchSvc, err = batchservice.New(stateStore, batchStore, logger, eventListener, overlayEthAddress.Bytes(), post, sha3.New256)
if err != nil {
return nil, err
}
eventListener = listener.New(logger, swapBackend, postageContractAddress, o.BlockTime, &pidKiller{node: b})
b.listenerCloser = eventListener

erc20Address, err := postagecontract.LookupERC20Address(p2pCtx, transactionService, postageContractAddress)
if err != nil {
return nil, err
}
batchSvc, err = batchservice.New(stateStore, batchStore, logger, eventListener, overlayEthAddress.Bytes(), post, sha3.New256)
if err != nil {
return nil, err
}

postageContractService = postagecontract.New(
overlayEthAddress,
postageContractAddress,
erc20Address,
transactionService,
post,
)
erc20Address, err := postagecontract.LookupERC20Address(p2pCtx, transactionService, postageContractAddress)
if err != nil {
return nil, err
}

if !o.Standalone {
if natManager := p2ps.NATManager(); natManager != nil {
// wait for nat manager to init
logger.Debug("initializing NAT manager")
select {
case <-natManager.Ready():
// this is magic sleep to give NAT time to sync the mappings
// this is a hack, kind of alchemy and should be improved
time.Sleep(3 * time.Second)
logger.Debug("NAT manager initialized")
case <-time.After(10 * time.Second):
logger.Warning("NAT manager init timeout")
}
postageContractService = postagecontract.New(
overlayEthAddress,
postageContractAddress,
erc20Address,
transactionService,
post,
)

if natManager := p2ps.NATManager(); natManager != nil {
// wait for nat manager to init
logger.Debug("initializing NAT manager")
select {
case <-natManager.Ready():
// this is magic sleep to give NAT time to sync the mappings
// this is a hack, kind of alchemy and should be improved
time.Sleep(3 * time.Second)
logger.Debug("NAT manager initialized")
case <-time.After(10 * time.Second):
logger.Warning("NAT manager init timeout")
}
}

Expand All @@ -488,19 +478,16 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
}

var bootnodes []ma.Multiaddr
if o.Standalone {
logger.Info("Starting node in standalone mode, no p2p connections will be made or accepted")
} else {
for _, a := range o.Bootnodes {
addr, err := ma.NewMultiaddr(a)
if err != nil {
logger.Debugf("multiaddress fail %s: %v", a, err)
logger.Warningf("invalid bootnode address %s", a)
continue
}

bootnodes = append(bootnodes, addr)
for _, a := range o.Bootnodes {
addr, err := ma.NewMultiaddr(a)
if err != nil {
logger.Debugf("multiaddress fail %s: %v", a, err)
logger.Warningf("invalid bootnode address %s", a)
continue
}

bootnodes = append(bootnodes, addr)
}

var swapService *swap.Service
Expand All @@ -510,7 +497,7 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
return nil, fmt.Errorf("unable to create metrics storage for kademlia: %w", err)
}

kad := kademlia.New(swarmAddress, addressbook, hive, p2ps, metricsDB, logger, kademlia.Options{Bootnodes: bootnodes, StandaloneMode: o.Standalone, BootnodeMode: o.BootnodeMode})
kad := kademlia.New(swarmAddress, addressbook, hive, p2ps, metricsDB, logger, kademlia.Options{Bootnodes: bootnodes, BootnodeMode: o.BootnodeMode})
b.topologyCloser = kad
b.topologyHalter = kad
hive.SetAddPeersHandler(kad.AddPeers)
Expand Down
5 changes: 0 additions & 5 deletions pkg/p2p/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type Options struct {
NATAddr string
EnableWS bool
EnableQUIC bool
Standalone bool
FullNode bool
LightNodeLimit int
WelcomeMessage string
Expand Down Expand Up @@ -178,10 +177,6 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
transports = append(transports, libp2p.Transport(libp2pquic.NewTransport))
}

if o.Standalone {
opts = append(opts, libp2p.NoListenAddrs)
}

opts = append(opts, transports...)

h, err := libp2p.New(ctx, opts...)
Expand Down
7 changes: 0 additions & 7 deletions pkg/topology/kademlia/kademlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ var noopSanctionedPeerFn = func(_ swarm.Address) bool { return false }
type Options struct {
SaturationFunc binSaturationFunc
Bootnodes []ma.Multiaddr
StandaloneMode bool
BootnodeMode bool
BitSuffixLength int
}
Expand All @@ -90,7 +89,6 @@ type Kad struct {
peerSig []chan struct{}
peerSigMtx sync.Mutex
logger logging.Logger // logger
standalone bool // indicates whether the node is working in standalone mode
bootnode bool // indicates whether the node is working in bootnode mode
collector *im.Collector
quit chan struct{} // quit channel
Expand Down Expand Up @@ -136,7 +134,6 @@ func New(
manageC: make(chan struct{}, 1),
waitNext: waitnext.New(),
logger: logger,
standalone: o.StandaloneMode,
bootnode: o.BootnodeMode,
collector: im.NewCollector(metricsDB),
quit: make(chan struct{}),
Expand Down Expand Up @@ -529,10 +526,6 @@ func (k *Kad) manage() {
default:
}

if k.standalone {
continue
}

oldDepth := k.NeighborhoodDepth()
k.connectNeighbours(&wg, peerConnChan, peerConnChan2)
k.connectBalanced(&wg, peerConnChan2)
Expand Down