From 9e8f2c470f4c5f3a7ad26db61e5fe7b4eff14606 Mon Sep 17 00:00:00 2001 From: Fabio Barone Date: Thu, 8 Nov 2018 08:44:55 -0500 Subject: [PATCH] swarm/swap: ignore ErrNotFound on stateStore.Get() --- swarm/swap/swap.go | 9 ++++++--- swarm/swarm.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) 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) }