Skip to content

Commit

Permalink
client/core: fix updateAssetWalletRefs not setting base/quoteWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Feb 22, 2023
1 parent 189d35b commit ef84b8e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
33 changes: 23 additions & 10 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2734,18 +2734,31 @@ func (c *Core) ReconfigureWallet(appPW, newWalletPW []byte, form *WalletForm) er
// updateAssetWalletRefs sets all references of an asset's wallet to newWallet.
func (c *Core) updateAssetWalletRefs(newWallet *xcWallet) {
assetID := newWallet.AssetID
updateWalletSet := func(t *trackedTrade) {
t.mtx.Lock()
defer t.mtx.Unlock()

if t.wallets.fromWallet.AssetID == assetID {
t.wallets.fromWallet = newWallet
} else if t.wallets.toWallet.AssetID == assetID {
t.wallets.toWallet = newWallet
} else {
return // no need to check base/quote wallet aliases
}

// Also base/quote wallet aliases. The following is more fool-proof and
// concise than nested t.Trade().Sell conditions above:
if t.wallets.baseWallet.AssetID == assetID {
t.wallets.baseWallet = newWallet
} else /* t.wallets.quoteWallet.AssetID == assetID */ {
t.wallets.quoteWallet = newWallet
}
}

for _, dc := range c.dexConnections() {
dc.tradeMtx.RLock()
for _, tracker := range dc.trades {
tracker.mtx.Lock()
if tracker.wallets.fromWallet.AssetID == assetID {
tracker.wallets.fromWallet = newWallet
} else if tracker.wallets.toWallet.AssetID == assetID {
tracker.wallets.toWallet = newWallet
}
tracker.mtx.Unlock()
for _, tracker := range dc.trackedTrades() {
updateWalletSet(tracker)
}
dc.tradeMtx.RUnlock()
}

c.walletMtx.Lock()
Expand Down
11 changes: 7 additions & 4 deletions client/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7019,6 +7019,7 @@ func TestReconfigureWallet(t *testing.T) {

// For the last success, make sure that we also clear any related
// tickGovernors.
abcWallet, _ := newTWallet(tUTXOAssetA.ID) // for to/baseWallet
matchID := ordertest.RandomMatchID()
match := &matchTracker{
suspectSwap: true,
Expand All @@ -7042,10 +7043,12 @@ func TestReconfigureWallet(t *testing.T) {
},
},
wallets: &walletSet{
fromAsset: &dex.Asset{ID: assetID},
fromWallet: &xcWallet{AssetID: assetID},
toAsset: &dex.Asset{},
toWallet: &xcWallet{},
fromAsset: &dex.Asset{ID: assetID},
fromWallet: xyzWallet,
quoteWallet: xyzWallet, // sell=false
toAsset: &dex.Asset{},
toWallet: abcWallet,
baseWallet: abcWallet,
},
matches: map[order.MatchID]*matchTracker{
{}: match,
Expand Down

0 comments on commit ef84b8e

Please sign in to comment.