diff --git a/swarm/swap/swap.go b/swarm/swap/swap.go index 5c95288447..7821f035df 100644 --- a/swarm/swap/swap.go +++ b/swarm/swap/swap.go @@ -54,7 +54,10 @@ func (s *Swap) Add(amount int64, peer *protocols.Peer) (err error) { defer s.lock.Unlock() //load existing balances from the state store - s.loadState(peer) + err = s.loadState(peer) + if err != nil && err != state.ErrNotFound { + return + } //adjust the balance //if amount is negative, it will decrease, otherwise increase s.balances[peer.ID()] += amount @@ -77,13 +80,13 @@ func (swap *Swap) GetPeerBalance(peer enode.ID) (int64, error) { } //load balances from the state store (persisted) -func (s *Swap) loadState(peer *protocols.Peer) { +func (s *Swap) loadState(peer *protocols.Peer) (err error) { var peerBalance int64 peerID := peer.ID() //only load if the current instance doesn't already have this peer's //balance in memory if _, ok := s.balances[peerID]; !ok { - s.stateStore.Get(peerID.String(), &peerBalance) + err = s.stateStore.Get(peerID.String(), &peerBalance) s.balances[peerID] = peerBalance } return diff --git a/swarm/swarm.go b/swarm/swarm.go index dbc33c1629..91782b6c86 100644 --- a/swarm/swarm.go +++ b/swarm/swarm.go @@ -176,7 +176,7 @@ func NewSwarm(config *api.Config, mockStore *mock.NodeStore) (self *Swarm, err e if config.SwapEnabled { balancesStore, err := state.NewDBStore(filepath.Join(config.Path, "balances.db")) if err != nil { - return + return nil, err } self.swap = swap.New(balancesStore) }