Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mm: allocate for redemptions when fee asset mismatch #2863

Merged
merged 21 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7188710
allocate for redemptions when fee asset mismatch
buck54321 Jul 11, 2024
3a04611
missing mutex lock
buck54321 Jul 11, 2024
90ab9fb
bump usdt redeem gas on mainnet
buck54321 Jul 12, 2024
3fec74e
avoid duplicate slugs in bnc ticker request
buck54321 Jul 12, 2024
ba09efa
fix withdraw error deadlock
buck54321 Jul 13, 2024
ef464be
enforce min transfers
buck54321 Jul 13, 2024
5f9b062
add base fees to correct field
buck54321 Jul 14, 2024
7f881f2
account for transferable in unbalanced state
buck54321 Jul 14, 2024
5b40f35
display startup errors
buck54321 Jul 14, 2024
b1faaba
a couple more ui fixes and improvements
buck54321 Jul 15, 2024
c718996
scale booking fees by order reserves. allow starting with insufficien…
buck54321 Jul 15, 2024
5d43f76
default log level info. other logging fixes
buck54321 Jul 15, 2024
ece36c7
don't show tx history for disabled wallets
buck54321 Jul 15, 2024
2da077d
remove overly-restrictive checkTrades warning. more logging fixes
buck54321 Jul 15, 2024
78d876c
add fiat conversions for cex inventory in running mmbot display
buck54321 Jul 15, 2024
24223f3
martonp review followup
buck54321 Jul 18, 2024
d4d07ac
fundedAndNotBalance only if can rebalance
buck54321 Jul 18, 2024
3a4d075
allow over-allocating one side in starved condition
buck54321 Jul 18, 2024
afb3013
avoid double counting tokens or counting both eth and weth
buck54321 Jul 18, 2024
10d3a76
more cex reconfig buttons
buck54321 Jul 18, 2024
50be3c5
tokenids whoopsie and cex balance stuff
buck54321 Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/asset/btc/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5865,6 +5865,9 @@ func (btc *baseWallet) addUnknownTransactionsToHistory(tip uint64) {
}

for _, tx := range txs {
if btc.ctx.Err() != nil {
return
}
txHash, err := chainhash.NewHashFromStr(tx.TxID)
if err != nil {
btc.log.Errorf("Error decoding tx hash %s: %v", tx.TxID, err)
Expand Down Expand Up @@ -6014,6 +6017,9 @@ func (btc *intermediaryWallet) syncTxHistory(tip uint64) {
}

for hash, tx := range pendingTxsCopy {
if btc.ctx.Err() != nil {
return
}
handlePendingTx(hash, &tx)
}
}
Expand Down
3 changes: 3 additions & 0 deletions client/asset/btc/electrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ func (btc *ExchangeWalletElectrum) syncTxHistory(tip uint64) {
}

for hash, tx := range pendingTxsCopy {
if btc.ctx.Err() != nil {
return
}
handlePendingTx(hash, &tx)
}
}
Expand Down
6 changes: 6 additions & 0 deletions client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6174,6 +6174,9 @@ func (dcr *ExchangeWallet) addUnknownTransactionsToHistory(tip uint64) {
}

for _, tx := range txs {
if dcr.ctx.Err() != nil {
return
}
txHash, err := chainhash.NewHashFromStr(tx.TxID)
if err != nil {
dcr.log.Errorf("Error decoding tx hash %s: %v", tx.TxID, err)
Expand Down Expand Up @@ -6325,6 +6328,9 @@ func (dcr *ExchangeWallet) syncTxHistory(ctx context.Context, tip uint64) {
}

for hash, tx := range pendingTxsCopy {
if dcr.ctx.Err() != nil {
return
}
handlePendingTx(hash, &tx)
}
}
Expand Down
3 changes: 1 addition & 2 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ func NewEVMWallet(cfg *EVMWalletConfig) (w *ETHWallet, err error) {

maxSwaps, maxRedeems := aw.maxSwapsAndRedeems()

cfg.Logger.Infof("ETH wallet will support a maximum of %d swaps and %d redeems per transaction.",
cfg.Logger.Debugf("ETH wallet will support a maximum of %d swaps and %d redeems per transaction.",
maxSwaps, maxRedeems)

aw.wallets = map[uint32]*assetWallet{
Expand Down Expand Up @@ -1716,7 +1716,6 @@ func (w *TokenWallet) FundOrder(ord *asset.Order) (asset.Coins, []dex.Bytes, uin
}

ethToLock := ord.MaxFeeRate * g.Swap * ord.MaxSwapCount

var success bool
if err = w.lockFunds(ord.Value, initiationReserve); err != nil {
return nil, nil, 0, fmt.Errorf("error locking token funds: %v", err)
Expand Down
12 changes: 12 additions & 0 deletions client/asset/eth/txdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,24 @@ func (log *badgerLoggerWrapper) Debugf(s string, a ...interface{}) {
log.Tracef(s, a...)
}

func (log *badgerLoggerWrapper) Debug(a ...interface{}) {
log.Trace(a...)
}

// Infof -> dex.Logger.Debugf
func (log *badgerLoggerWrapper) Infof(s string, a ...interface{}) {
log.Debugf(s, a...)
}

func (log *badgerLoggerWrapper) Info(a ...interface{}) {
log.Debug(a...)
}

// Warningf -> dex.Logger.Warnf
func (log *badgerLoggerWrapper) Warningf(s string, a ...interface{}) {
log.Warnf(s, a...)
}

func (log *badgerLoggerWrapper) Warning(a ...interface{}) {
log.Warn(a...)
}
6 changes: 6 additions & 0 deletions client/asset/zec/zec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3560,6 +3560,9 @@ func (w *zecWallet) addUnknownTransactionsToHistory(tip uint64) {
}

for _, tx := range txs {
if w.ctx.Err() != nil {
return
}
txHash, err := chainhash.NewHashFromStr(tx.TxID)
if err != nil {
w.log.Errorf("Error decoding tx hash %s: %v", tx.TxID, err)
Expand Down Expand Up @@ -3654,6 +3657,9 @@ func (w *zecWallet) syncTxHistory(tip uint64) {
return
}
if err != nil {
if w.ctx.Err() != nil {
return
}
w.log.Errorf("Error getting transaction %s: %v", txHash, err)
return
}
Expand Down
1 change: 0 additions & 1 deletion client/core/bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,6 @@ func (c *Core) bondConfirmed(dc *dexConnection, assetID uint32, coinID []byte, p
if err != nil {
return fmt.Errorf("db.ConfirmBond failure: %w", err)
}
c.log.Infof("Bond %s (%s) confirmed.", bondIDStr, unbip(assetID))
subject, details := c.formatDetails(TopicBondConfirmed, effectiveTier, targetTier)
c.notify(newBondPostNoteWithTier(TopicBondConfirmed, subject, details, db.Success, dc.acct.host, bondedTier, c.exchangeAuth(dc)))
} else if !foundConfirmed {
Expand Down
8 changes: 4 additions & 4 deletions client/core/bookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,13 @@ func (dc *dexConnection) syncBook(base, quote uint32) (*orderbook.OrderBook, Boo
// request. The response, which includes book's snapshot, is returned. Proper
// synchronization is required by the caller to ensure that order feed messages
// aren't processed before they are prepared to handle this subscription.
func (dc *dexConnection) subscribe(base, quote uint32) (*msgjson.OrderBook, error) {
mkt := marketName(base, quote)
func (dc *dexConnection) subscribe(baseID, quoteID uint32) (*msgjson.OrderBook, error) {
mkt := marketName(baseID, quoteID)
// Subscribe via the 'orderbook' request.
dc.log.Debugf("Subscribing to the %v order book for %v", mkt, dc.acct.host)
req, err := msgjson.NewRequest(dc.NextID(), msgjson.OrderBookRoute, &msgjson.OrderBookSubscription{
Base: base,
Quote: quote,
Base: baseID,
Quote: quoteID,
})
if err != nil {
return nil, fmt.Errorf("error encoding 'orderbook' request: %w", err)
Expand Down
19 changes: 5 additions & 14 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,7 @@ func (c *Core) connectAndUpdateWalletResumeTrades(w *xcWallet, resumeTrades bool
}
}

c.log.Infof("Connecting wallet for %s", unbip(assetID))
c.log.Debugf("Connecting wallet for %s", unbip(assetID))
addr := w.currentDepositAddress()
newAddr, err := c.connectWalletResumeTrades(w, resumeTrades)
if err != nil {
Expand Down Expand Up @@ -3133,7 +3133,7 @@ func (c *Core) walletCheckAndNotify(w *xcWallet) bool {
}
if synced && !wasSynced {
c.updateWalletBalance(w)
c.log.Infof("Wallet synced for asset %s", unbip(w.AssetID))
c.log.Debugf("Wallet synced for asset %s", unbip(w.AssetID))
c.updateBondReserves(w.AssetID)
}
return synced
Expand Down Expand Up @@ -6287,7 +6287,7 @@ func (c *Core) prepareMultiTradeRequests(pw []byte, form *MultiTradeForm) ([]*tr
}

if len(allCoins) != len(form.Placements) {
c.log.Infof("FundMultiOrder only funded %d orders out of %d", len(allCoins), len(form.Placements))
c.log.Infof("FundMultiOrder only funded %d orders out of %d (options = %+v)", len(allCoins), len(form.Placements), form.Options)
}
defer func() {
if _, err := c.updateWalletBalance(fromWallet); err != nil {
Expand Down Expand Up @@ -7161,7 +7161,7 @@ func (c *Core) initialize() error {
continue
}
// Wallet is loaded from the DB, but not yet connected.
c.log.Infof("Loaded %s wallet configuration.", unbip(assetID))
c.log.Tracef("Loaded %s wallet configuration.", unbip(assetID))
c.updateWallet(assetID, wallet)
}

Expand Down Expand Up @@ -8765,15 +8765,6 @@ func (c *Core) listen(dc *dexConnection) {
}()

checkTrades := func() {
// checkTrades should be snappy. If it takes too long we are creating
// lock contention.
tStart := time.Now()
defer func() {
if eTime := time.Since(tStart); eTime > 250*time.Millisecond {
c.log.Warnf("checkTrades completed in %v (slow)", eTime)
}
}()

var doneTrades, activeTrades []*trackedTrade
// NOTE: Don't lock tradeMtx while also locking a trackedTrade's mtx
// since we risk blocking access to the trades map if there is lock
Expand Down Expand Up @@ -8813,7 +8804,7 @@ func (c *Core) listen(dc *dexConnection) {
updatedAssets := make(assetMap)
for _, trade := range doneTrades {
trade.mtx.Lock()
c.log.Infof("Retiring inactive order %v in status %v", trade.ID(), trade.metaData.Status)
c.log.Debugf("Retiring inactive order %v in status %v", trade.ID(), trade.metaData.Status)
trade.returnCoins()
trade.mtx.Unlock()
updatedAssets.count(trade.wallets.fromWallet.AssetID)
Expand Down
9 changes: 5 additions & 4 deletions client/core/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ func (t *trackedTrade) negotiate(msgMatches []*msgjson.Match) error {
// Record any cancel order Match and update order status.
var metaCancelMatch *db.MetaMatch
if cancelMatch != nil {
t.dc.log.Infof("Maker notification for cancel order received for order %s. match id = %s",
t.dc.log.Infof("Order %s canceled. match id = %s",
t.ID(), cancelMatch.MatchID)

// Set this order status to Canceled and unlock any locked coins
Expand Down Expand Up @@ -1092,7 +1092,8 @@ func (t *trackedTrade) processCancelMatch(msgMatch *msgjson.Match) error {
if oid != t.cancel.ID() {
return fmt.Errorf("negotiate called for wrong order. %s != %s", oid, t.cancel.ID())
}
t.dc.log.Infof("Taker notification for cancel order %v received. Match id = %s", oid, mid)
// Maker notification is logged at info.
t.dc.log.Debugf("Taker notification for cancel order %v received. Match id = %s", oid, mid)
t.cancel.matches.taker = msgMatch
// Store the completed taker cancel match.
takerCancelMeta := t.makeMetaMatch(t.cancel.matches.taker)
Expand Down Expand Up @@ -2541,7 +2542,7 @@ func (c *Core) sendInitAsync(t *trackedTrade, match *matchTracker, coinID, contr
return
}

c.log.Infof("Notifying DEX %s of our %s swap contract %v for match %s",
c.log.Debugf("Notifying DEX %s of our %s swap contract %v for match %s",
t.dc.acct.host, t.wallets.fromWallet.Symbol, coinIDString(t.wallets.fromWallet.AssetID, coinID), match)

// Send the init request asynchronously.
Expand Down Expand Up @@ -2811,7 +2812,7 @@ func (c *Core) sendRedeemAsync(t *trackedTrade, match *matchTracker, coinID, sec
return
}

c.log.Infof("Notifying DEX %s of our %s swap redemption %v for match %s",
c.log.Debugf("Notifying DEX %s of our %s swap redemption %v for match %s",
t.dc.acct.host, t.wallets.toWallet.Symbol, coinIDString(t.wallets.toWallet.AssetID, coinID), match)

// Send the redeem request asynchronously.
Expand Down
1 change: 1 addition & 0 deletions client/mm/exchange_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,7 @@ func (u *unifiedExchangeAdaptor) withdraw(ctx context.Context, assetID uint32, a
u.balancesMtx.Lock()
withdrawalID, err := u.CEX.Withdraw(ctx, assetID, amount, addr)
if err != nil {
u.balancesMtx.Unlock()
return err
}
u.log.Infof("Withdrew %s", u.fmtQty(assetID, amount))
Expand Down
Loading
Loading