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

core: Make wallet connection synchronous #2801

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
core: Make wallet connection synchronous
Two wallet connections running in parallel was causing a panic.
  • Loading branch information
martonp committed Jun 7, 2024
commit 5012536ff30ba25e83e87f428241c046c8177969
2 changes: 2 additions & 0 deletions client/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2856,6 +2856,7 @@ func trade(t *testing.T, async bool) {
defer rig.shutdown()
tCore := rig.core
dcrWallet, tDcrWallet := newTWallet(tUTXOAssetA.ID)
dcrWallet.hookedUp = false
tCore.wallets[tUTXOAssetA.ID] = dcrWallet
dcrWallet.address = "DsVmA7aqqWeKWy461hXjytbZbgCqbB8g2dq"
dcrWallet.Unlock(rig.crypter)
Expand Down Expand Up @@ -9548,6 +9549,7 @@ func TestWalletSyncing(t *testing.T) {
dcrWallet, tDcrWallet := newTWallet(tUTXOAssetA.ID)
dcrWallet.synced = false
dcrWallet.syncProgress = 0
dcrWallet.hookedUp = false
// Connect with tCore.connectWallet below.

tStart := time.Now()
Expand Down
8 changes: 8 additions & 0 deletions client/core/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type xcWallet struct {
traits asset.WalletTrait
parent *xcWallet
feeState atomic.Value // *FeeState
connectMtx sync.Mutex

mtx sync.RWMutex
encPass []byte // empty means wallet not password protected
Expand Down Expand Up @@ -393,11 +394,18 @@ func (w *xcWallet) checkPeersAndSyncStatus() error {
// flag to true, and validates the deposit address. Use Disconnect to cleanly
// shutdown the wallet.
func (w *xcWallet) Connect() error {
w.connectMtx.Lock()
defer w.connectMtx.Unlock()

// Disabled wallet cannot be connected to unless it is enabled.
if w.isDisabled() {
return fmt.Errorf(walletDisabledErrStr, strings.ToUpper(unbip(w.AssetID)))
}

if w.connected() {
return nil
}

// No parent context; use Disconnect instead. Also note that there's no
// reconnect loop for wallet like with the server Connectors, so we use
// ConnectOnce so that the ConnectionMaster's On method will report false.
Expand Down
Loading