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

client/core: resolve xcWallet.peerCount race (parent part) #2178

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
18 changes: 9 additions & 9 deletions client/core/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,24 +251,17 @@ func (w *xcWallet) amtStringSigned(amt int64) string {
// state returns the current WalletState.
func (w *xcWallet) state() *WalletState {
winfo := w.Info()
lockable := w
if w.parent != nil {
lockable = w.parent
}

w.mtx.RLock()
defer w.mtx.RUnlock()

var peerCount uint32
if w.peerCount > 0 { // initialized to -1 initially, means no count yet
peerCount = uint32(w.peerCount)
}

return &WalletState{
state := &WalletState{
Symbol: unbip(w.AssetID),
AssetID: w.AssetID,
Version: winfo.Version,
Open: len(lockable.encPass) == 0 || len(lockable.pw) > 0,
Open: len(w.encPass) == 0 || len(w.pw) > 0,
Running: w.connector.On(),
Balance: w.balance,
Address: w.address,
Expand All @@ -281,6 +274,13 @@ func (w *xcWallet) state() *WalletState {
Traits: w.traits,
Disabled: w.disabled,
}
w.mtx.RUnlock()

if w.parent != nil {
state.Open = len(w.parent.encPass) == 0 || len(w.parent.pw) > 0
}

return state
}

// setBalance sets the wallet balance.
Expand Down
4 changes: 2 additions & 2 deletions server/db/driver/pg/internal/matches.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const (
$3, $4, $5,
$6, $7, $8,
$9, $10,
$11, $12, $13, $14, $15) ` // do not terminate with ;
$11, $12, $13, $14, $15) ` // do not terminate with ;

UpsertMatch = InsertMatch + ` ON CONFLICT (matchid) DO
UPDATE SET quantity = $11, status = $15;`
Expand All @@ -92,7 +92,7 @@ const (
$2, $3,
$4, $5,
$6, $7,
$8, $9, $10) ` // status should be MatchComplete although there is no swap
$8, $9, $10) ` // status should be MatchComplete although there is no swap
chappjc marked this conversation as resolved.
Show resolved Hide resolved

UpsertCancelMatch = InsertCancelMatch + ` ON CONFLICT (matchid) DO NOTHING;`

Expand Down
8 changes: 4 additions & 4 deletions server/db/driver/pg/internal/orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const (
WHERE account_id = $1
AND status >= 0 -- exclude forgiven
ORDER BY epochCloseTime DESC
LIMIT $2` // no ;
LIMIT $2` // no ;
// NOTE: we could join with the epochs table if we really want match_time instead of epoch close time

// SelectUserOrders retrieves all columns of all orders for the given
Expand All @@ -80,7 +80,7 @@ const (
JOIN %[2]s ON %[2]s.epoch_idx = %[1]s.epoch_idx AND %[2]s.epoch_dur = %[1]s.epoch_dur -- join on epochs table PK
WHERE account_id = $1 AND status = ANY($2) -- {orderStatusCanceled, orderStatusRevoked}
ORDER BY match_time DESC
LIMIT $3;` // The matchTime is when the order was booked, not canceled!!!
LIMIT $3;` // The matchTime is when the order was booked, not canceled!!!

// SelectOrderByCommit retrieves the order ID for any order with the given
// commitment value. This applies to the cancel order tables as well.
Expand Down Expand Up @@ -199,7 +199,7 @@ const (
AND commit IS NOT NULL -- commit NOT NULL to exclude server-generated cancels
AND status >= 0 -- not forgiven
ORDER BY epochCloseTime DESC
LIMIT $2` // no ;
LIMIT $2` // no ;

// SelectRevokeCancels retrieves server-initiated cancels (revokes).
SelectRevokeCancels = `SELECT oid, target_order, server_time, epoch_idx
Expand Down Expand Up @@ -227,7 +227,7 @@ const (
JOIN %[2]s ON %[2]s.epoch_idx = %[1]s.epoch_idx AND %[2]s.epoch_dur = %[1]s.epoch_dur -- join on epochs table PK
WHERE account_id = $1 AND status = $2
ORDER BY match_time DESC
LIMIT $3;` // NOTE: find revoked orders via SelectRevokeCancels
LIMIT $3;` // NOTE: find revoked orders via SelectRevokeCancels

// InsertCancelOrder inserts a cancel order row into the specified table.
InsertCancelOrder = `INSERT INTO %s (oid, account_id, client_time, server_time,
Expand Down