Skip to content

Conversation

buck54321
Copy link
Member

Starts resolving #1492 . Just sketching this out for now. I can add other wallets here, or that can be followup work. The btc changes are in anticipation of changes coming in #1657.

Our current scheme for configuration changes requires killing the
existing wallet and creating a new one. Unfortunately, even though
we allow reconfiguration with active matches/orders, we've made
no accommodations for re-establishing locked coins on the new wallet.

client/asset:
Introduce the LiveReconfigurer interface with a single
method, Reconfigure(WalletConfig) (restartRequired bool, err error).
If a wallet implements LiverReconfigurer,

client/core:
Core will call Reconfigure early in (*Core).ReconfigureWallet, and
if there is no error and restartRequired is false, then the
reconfiguration is considered complete and no new wallet is created.
If, on the other hand, the LiveReconfigurer indicates that a restart
is required, we use our existing ReconfigureWallet code without
modification, but add a step at the end to re-reserve funding coin
and refund/redeem reserves. This new method (*Core).reReserveFunding
is modeled closely after resumeTrades, but optimized for only 1 asset
an no audits.

client/asset/btc:
Implement Reconfigure. Puts user-configurable baseWallet configuration
in a seperate struct, stored as an atomic.Value baseWallet field, with
the settings themselves readable through new getters. rpcWallet does
something similar with its an atomic.Value for its requester
RawRequesterWithContext field. The only thing that requires a restart
now is a wallet type change, though an error is generated if there is
an attempt to reduce the spv wallet birthday with special:activelyUsed set.

@chappjc
Copy link
Member

chappjc commented Jul 4, 2022

Looks like you're building on #1657, in spirit. I'm fine with that one so wanna merge that so this can get rebased?

@buck54321
Copy link
Member Author

I'm opening this up for review. I can add other assets here, but following up is good too.

@buck54321 buck54321 marked this pull request as ready for review July 5, 2022 01:07
Copy link
Collaborator

@martonp martonp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well. I just see two minor UI issues:

  1. If I try to switch wallet types while I have an active order, it fails with an error message as it should, but on the UI the wallet is shown as locked and unsynced. This fixes itself after refreshing the screen.

  2. If I'm trying to switch from the SPV wallet to the external wallet while I have a trade running, it fails as it should, but if I navigate away to the markets page, then come back to the reconfigure screen, the RPC wallet settings are still showing even though I'm not using an SPV wallet. When I'm using the RPC wallet and I fail at switching to the SPV wallet, then I navigate away and come back to the reconfigure screen, the RPC wallet configs are still showing as they are supposed to. The issue only happens when attempting to switch from SPV to RPC.

// Check the RPC configuration.
newCfg := &parsedCfg.RPCConfig
if err := dexbtc.CheckRPCConfig(&newCfg.RPCConfig, wc.cloneParams.WalletInfo.Name, wc.cloneParams.Network, wc.cloneParams.Ports); err != nil {
return false, err
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just do return here as you did earlier in the function.

@chappjc chappjc added this to the 0.5 milestone Jul 12, 2022
Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine and tests well.

Comment on lines 391 to 399
if err := w.updateDBBirthday(newBday); err != nil {
return false, fmt.Errorf("error storing new birthday")
}
w.birthdayV.Store(newBday)
if rescanRequired {
if err = w.rescanWalletAsync(); err != nil {
return false, fmt.Errorf("error initiating rescan after birthday adjustment")
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could include the error in these two.

Comment on lines +2357 to +2363
c.log.Warnf("Error getting balance for wallet %s: %v", unbip(assetID), err)
// Do not fail in case this requires an unlocked wallet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this would also fail if the wallet was rescanning because the birthday was set lower?

return nil
}

clearTickGovernors := func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't figure out why it is necessary to clear these tick blocking timers. Why do we do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tick governor meters attempts at swapping when there is repeating error. A new wallet might fix the issue, so we allow a tick to occur immediately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I didn't realize this method is expected to be used if something was erroring. No problem.

fromID = tracker.Base()
}

denom, marketMult, limitMult := lcm(uint64(len(tracker.matches)), trade.Quantity)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chappjc changes this up in #1653

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. May not go that way for a while if things are OK for now. Can rebase it in the future.

However, there are a number of bug fixes and simplifications I listed that we should probably get eyes on and extract: #1653 (review)

Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @JoeGruffins please circle back on your review when convenient. Thx.

@JoeGruffins
Copy link
Member

Switching wallet types, rpc to spv looks fine, but spv to rpc will say I have no peers and not let me trade until I restart dexc.

Our current scheme for configuration changes requires killing the
existing wallet and creating a new one. Unfortunately, even though
we allow reconfiguration with active matches/orders, we've made
no accomodations for re-establishing locked coins on the new wallet.

client/asset:
Introduce the LiveReconfigurer interface with a single
method, Reconfigure(WalletConfig) (restartRequired bool, err error).
If a wallet implements LiverReconfigurer,

client/core:
Core will call Reconfigure early in (*Core).ReconfigureWallet, and
if there is no error and restartRequired is false, then the
reconfiguration is considered complete and no new wallet is created.
If, on the other hand, the LiveReconfigurer indicates that a restart
is required, we use our existing ReconfigureWallet code without
modification, but add a step at the end to re-reserve funding coin
and refund/redeem reserves. This new method (*Core).reReserveFunding
is modeled closely after resumeTrades, but optimized for only 1 asset
an no audits.

client/asset/btc:
Implement Reconfigure. Puts user-configurable baseWallet configuration
in a seperate struct, stored as an atomic.Value baseWallet field, with
the settings themselves readable through new getters. rpcWallet does
something similar with its an atomic.Value for its requester
RawRequesterWithContext field. The only thing that requires a restart
now is a wallet type change, though an error is generated if there is
an attempt to reduce the spv wallet birthday with special:activelyUsed set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants