Commit b8e478a4 authored by acud's avatar acud Committed by GitHub

node: fix standalone mode, fix panic (#1607)

parent dda4d163
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethersphere/bee/pkg/accounting" "github.com/ethersphere/bee/pkg/accounting"
"github.com/ethersphere/bee/pkg/addressbook" "github.com/ethersphere/bee/pkg/addressbook"
"github.com/ethersphere/bee/pkg/api" "github.com/ethersphere/bee/pkg/api"
...@@ -56,6 +57,7 @@ import ( ...@@ -56,6 +57,7 @@ import (
"github.com/ethersphere/bee/pkg/settlement/pseudosettle" "github.com/ethersphere/bee/pkg/settlement/pseudosettle"
"github.com/ethersphere/bee/pkg/settlement/swap" "github.com/ethersphere/bee/pkg/settlement/swap"
"github.com/ethersphere/bee/pkg/settlement/swap/chequebook" "github.com/ethersphere/bee/pkg/settlement/swap/chequebook"
"github.com/ethersphere/bee/pkg/settlement/swap/transaction"
"github.com/ethersphere/bee/pkg/storage" "github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/tags" "github.com/ethersphere/bee/pkg/tags"
...@@ -200,12 +202,19 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -200,12 +202,19 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
addressbook := addressbook.New(stateStore) addressbook := addressbook.New(stateStore)
var chequebookFactory chequebook.Factory var (
var chequebookService chequebook.Service swapBackend *ethclient.Client
var chequeStore chequebook.ChequeStore overlayEthAddress common.Address
var cashoutService chequebook.CashoutService chainID int64
transactionService transaction.Service
swapBackend, overlayEthAddress, chainID, transactionMonitor, transactionService, err := InitChain( transactionMonitor transaction.Monitor
chequebookFactory chequebook.Factory
chequebookService chequebook.Service
chequeStore chequebook.ChequeStore
cashoutService chequebook.CashoutService
)
if !o.Standalone {
swapBackend, overlayEthAddress, chainID, transactionMonitor, transactionService, err = InitChain(
p2pCtx, p2pCtx,
logger, logger,
stateStore, stateStore,
...@@ -213,11 +222,11 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -213,11 +222,11 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
signer, signer,
) )
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("init chain: %w", err)
} }
b.ethClientCloser = swapBackend.Close b.ethClientCloser = swapBackend.Close
b.transactionMonitorCloser = transactionMonitor b.transactionMonitorCloser = transactionMonitor
}
if o.SwapEnable { if o.SwapEnable {
chequebookFactory, err = InitChequebookFactory( chequebookFactory, err = InitChequebookFactory(
...@@ -398,8 +407,9 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -398,8 +407,9 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
hive.SetAddPeersHandler(kad.AddPeers) hive.SetAddPeersHandler(kad.AddPeers)
p2ps.SetPickyNotifier(kad) p2ps.SetPickyNotifier(kad)
batchStore.SetRadiusSetter(kad) batchStore.SetRadiusSetter(kad)
syncedChan := batchSvc.Start()
if batchSvc != nil {
syncedChan := batchSvc.Start()
// wait for the postage contract listener to sync // wait for the postage contract listener to sync
logger.Info("waiting to sync postage contract data, this may take a while... more info available in Debug loglevel") logger.Info("waiting to sync postage contract data, this may take a while... more info available in Debug loglevel")
...@@ -409,6 +419,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey, ...@@ -409,6 +419,7 @@ func NewBee(addr string, swarmAddress swarm.Address, publicKey ecdsa.PublicKey,
// this stage // this stage
<-syncedChan <-syncedChan
}
paymentThreshold, ok := new(big.Int).SetString(o.PaymentThreshold, 10) paymentThreshold, ok := new(big.Int).SetString(o.PaymentThreshold, 10)
if !ok { if !ok {
return nil, fmt.Errorf("invalid payment threshold: %s", paymentThreshold) return nil, fmt.Errorf("invalid payment threshold: %s", paymentThreshold)
...@@ -683,9 +694,11 @@ func (b *Bee) Shutdown(ctx context.Context) error { ...@@ -683,9 +694,11 @@ func (b *Bee) Shutdown(ctx context.Context) error {
errs.add(fmt.Errorf("p2p server: %w", err)) errs.add(fmt.Errorf("p2p server: %w", err))
} }
if b.transactionMonitorCloser != nil {
if err := b.transactionMonitorCloser.Close(); err != nil { if err := b.transactionMonitorCloser.Close(); err != nil {
errs.add(fmt.Errorf("transaction monitor: %w", err)) errs.add(fmt.Errorf("transaction monitor: %w", err))
} }
}
if c := b.ethClientCloser; c != nil { if c := b.ethClientCloser; c != nil {
c() c()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment