Skip to content

Commit 47539ca

Browse files
authored
exchange_adaptor: Fix withdrawal amount race. (#3301)
1 parent 745b6ff commit 47539ca

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

client/mm/exchange_adaptor.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,14 @@ type pendingWithdrawal struct {
164164
timestamp int64
165165
withdrawalID string
166166
assetID uint32
167-
// amtWithdrawn is the amount the CEX balance is decreased by.
168-
// It will not be the same as the amount received in the dex wallet.
169-
amtWithdrawn uint64
170167

171168
txMtx sync.RWMutex
172-
txID string
173-
tx *asset.WalletTransaction
169+
// amtWithdrawn is the amount the CEX balance is decreased by.
170+
// It will not be the same as the amount received in the dex wallet. It
171+
// will be updated when the transaction is confirmed.
172+
amtWithdrawn uint64
173+
txID string
174+
tx *asset.WalletTransaction
174175
}
175176

176177
func withdrawalBalanceEffects(tx *asset.WalletTransaction, cexDebit uint64, assetID uint32) (dex, cex *BalanceEffects) {
@@ -859,6 +860,9 @@ func combineBalanceEffects(dex, cex *BalanceEffects) *BalanceEffects {
859860
// pending withdrawal and sends an event notification.
860861
func (u *unifiedExchangeAdaptor) updateWithdrawalEvent(withdrawal *pendingWithdrawal, tx *asset.WalletTransaction) {
861862
complete := tx != nil && tx.Confirmed
863+
withdrawal.txMtx.RLock()
864+
amt := withdrawal.amtWithdrawn
865+
withdrawal.txMtx.RUnlock()
862866
e := &MarketMakingEvent{
863867
ID: withdrawal.eventLogID,
864868
TimeStamp: withdrawal.timestamp,
@@ -868,7 +872,7 @@ func (u *unifiedExchangeAdaptor) updateWithdrawalEvent(withdrawal *pendingWithdr
868872
AssetID: withdrawal.assetID,
869873
ID: withdrawal.withdrawalID,
870874
Transaction: tx,
871-
CEXDebit: withdrawal.amtWithdrawn,
875+
CEXDebit: amt,
872876
},
873877
}
874878

0 commit comments

Comments
 (0)