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: Update server host #1605

Merged
merged 1 commit into from
Jun 20, 2022
Merged

client: Update server host #1605

merged 1 commit into from
Jun 20, 2022

Conversation

martonp
Copy link
Contributor

@martonp martonp commented May 5, 2022

DEX servers are able to advertise on multiple host names. This update gives users of the dex client the ability to switch between the different host names of the same dex.

  • client/core: Add UpdateDexHost method which takes
    a current dex host and a new host name, and if the dex
    at both host names use the same dex pub key, the host
    name is updated. Also, adding a dex with the same pub
    key as a dex which is already registered is now blocked.

  • ui: Adds a button on the dex settings page to allow updating
    the dex host. The DEXAddressForm is reused for this purpose.
    The DEXAddressPopup is also updated to not show known
    exchanges that the user is already registered for.

@martonp martonp force-pushed the updateHost branch 4 times, most recently from 24c6f8a to 301a141 Compare May 25, 2022 04:04
@martonp martonp marked this pull request as ready for review May 25, 2022 04:04
Comment on lines 253 to 260
atomic.StoreUint32(&newDc.reportingConnects, 1)
c.wg.Add(1)
go c.listen(newDc)
go newDc.subPriceFeed()

c.connMtx.Lock()
c.conns[newDc.acct.host] = newDc
c.connMtx.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

This section is a duplicate. Maybe a new upgradeConnection method?

Comment on lines 267 to 272
newHost string
feePending bool
expectError bool
newPubKey *secp256k1.PublicKey
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you don't need the newPubKey and newHost fields. They are always the same. Just use vars?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

newPubKey isn't always the same, but you're right about newHost.

@@ -418,6 +418,31 @@ func (s *WebServer) apiUpdateCert(w http.ResponseWriter, r *http.Request) {
writeJSON(w, simpleAck(), s.indent)
}

func (s *WebServer) apiUpdateDexHost(w http.ResponseWriter, r *http.Request) {
form := new(updateHostForm)
Copy link
Member

Choose a reason for hiding this comment

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

If updateHostForm is only used once here, how about an anonymous struct.

form := new(struct {
	Pass    encode.PassBytes `json:"pw"`
	OldHost string           `json:"oldHost"`
	NewHost string           `json:"newHost"`
	Cert    string           `json:"cert"`
})

I think it improves readability.

// UpdateDexHost updates the host for a connection to a dex. The dex at oldHost
// and newHost must be the same dex, which means that the dex at both hosts use
// the same public key.
func (c *Core) UpdateDexHost(oldHost, newHost string, appPW []byte, certI interface{}) (*Exchange, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Noting the difference of the capitalization of DEX between UpdateDexHost with GetDEXConfig.

Comment on lines 1127 to 1146
if (this.knownExchanges.length === 0) {
Doc.show(page.customBox)
Doc.hide(page.showCustom, page.knownXCs, page.pickServerMsg, page.addCustomMsg)
} else {
Doc.hide(page.customBox)
Doc.show(page.showCustom)
}
Copy link
Member

Choose a reason for hiding this comment

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

Something is off here and I can't submit the form. When bringing up the form to change the host, there is no button.

Compare that with the expanded custom dex form when going through the registration sequence, where the button is displayed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry about that, I think it must be because I forgot to update the cache buster. I've updated it now.

Copy link
Member

Choose a reason for hiding this comment

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

Still happening for me.

I see the problem. It's a pre-existing bug. The button won't be displayed when the password is cached, since we're hiding page.auth, which includes the submit button.

During the initial registration sequence, it doesn't matter, because we

Doc.bind(page.showCustom, 'click', () => {
  Doc.hide(page.showCustom)
  Doc.show(page.customBox, page.auth)
})

But when the custom form is displayed by default (because we already registered at the only DEX), we never hit that code.

I think the easiest solution is to

if (this.knownExchanges.length === 0) Doc.show(page.auth)

@chappjc chappjc added this to the 0.5 milestone May 25, 2022
Comment on lines 1127 to 1146
if (this.knownExchanges.length === 0) {
Doc.show(page.customBox)
Doc.hide(page.showCustom, page.knownXCs, page.pickServerMsg, page.addCustomMsg)
} else {
Doc.hide(page.customBox)
Doc.show(page.showCustom)
}
Copy link
Member

Choose a reason for hiding this comment

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

Still happening for me.

I see the problem. It's a pre-existing bug. The button won't be displayed when the password is cached, since we're hiding page.auth, which includes the submit button.

During the initial registration sequence, it doesn't matter, because we

Doc.bind(page.showCustom, 'click', () => {
  Doc.hide(page.showCustom)
  Doc.show(page.customBox, page.auth)
})

But when the custom form is displayed by default (because we already registered at the only DEX), we never hit that code.

I think the easiest solution is to

if (this.knownExchanges.length === 0) Doc.show(page.auth)

@martonp
Copy link
Contributor Author

martonp commented May 31, 2022

@buck54321 I see it now. I need to make a habit of testing with the password both cached and not cached.

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.

Testing well for me.

client/webserver/locales/en-us.go Outdated Show resolved Hide resolved
server/cmd/dcrdex/main.go Show resolved Hide resolved
client/webserver/api.go Outdated Show resolved Hide resolved
client/core/account.go Outdated Show resolved Hide resolved
client/core/core.go Outdated Show resolved Hide resolved
client/core/core.go Outdated Show resolved Hide resolved
client/core/core.go Outdated Show resolved Hide resolved
client/webserver/api.go Show resolved Hide resolved
client/webserver/api.go Outdated Show resolved Hide resolved
Comment on lines 267 to 282
err = c.AccountDisable(appPW, oldHost)
if err != nil {
return nil, fmt.Errorf("failed to disable old account: %w", err)
}

_, err = c.discoverAccount(newDc, crypter)
if err != nil {
return nil, err
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if the order of these AccountDisable and discoverAccount should be switched.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it so that it disconnects the dex first, then does discoverAccount, then finally removes the old dex from the db.

Comment on lines 98 to 100
// KnownUnregisteredExchanges returns all the known exchanges that
// the user has not registered for.
func (s *WebServer) KnownUnregisteredExchanges(registeredExchanges map[string]*core.Exchange) []string {
Copy link
Member

Choose a reason for hiding this comment

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

No need to export.

if (this.pwCache) this.pwCache.pw = pw
this.success(res.xc, cert)
}

makeDexUpdater (dexToUpdate: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Please comment here that this is a one way function. The changes made during makeDexUpdater are not reversed upon refresh. So the same DEXAddressForm can't do double duty for new registration and host name updates.

I would actually prefer that makeDexUpdater was used internally based on an argument to the constructor.

Copy link
Member

Choose a reason for hiding this comment

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

Remove makeDexUpdater now? I believe you have it done in if (dexToUpdate) { now.

@@ -22,6 +22,9 @@
<button id="updateCertBtn" class="bg2 selected">[[[Update TLS Certificate]]]</button>
Copy link
Member

Choose a reason for hiding this comment

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

Not from this PR, but from #1602 (comment), I think only part of solution made it into the final product.

Can you get rid of the <h4> up above and do something like

<div class="flex-center fs16 mb-2">
  <span class="me-2 connection ico-connection d-hide" id="connectedIcon"></span>
  <span class="me-2 disconnected ico-disconnected d-hide" id="disconnectedIcon"></span>
  <span id="connectionStatus"></span>
</div>

oldHost, newHost)
}

err = c.AccountDisable(appPW, oldHost)
Copy link
Member

Choose a reason for hiding this comment

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

If there are active orders, we'll fail here, but should we check that condition higher up to prevent making an unnecessary connection?

@chappjc chappjc self-requested a review June 13, 2022 16:07
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.

A few little things left, but seems g2g.

client/core/core.go Outdated Show resolved Hide resolved
client/core/account.go Outdated Show resolved Hide resolved
if (this.pwCache) this.pwCache.pw = pw
this.success(res.xc, cert)
}

makeDexUpdater (dexToUpdate: string) {
Copy link
Member

Choose a reason for hiding this comment

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

Remove makeDexUpdater now? I believe you have it done in if (dexToUpdate) { now.

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. Working very well.

Might as well rebase while waiting for @buck54321 to circle back since your merge base is quite old. I tested a rebased branch though.

Comment on lines +280 to +281
if err != nil {
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

This would be a weird place to end up, but I think the likelihood of getting here is virtually nil.

DEX servers are able to advertise on multiple host names.
This update gives users of the dex client the ability to
switch between the different host names of the same dex.

- client/core: Add `UpdateDexHost` method which takes
  a current dex host and a new host name, and if the dex
  at both host names use the same dex pub key, the host
  name is updated. Also, adding a dex with the same pub
  key as a dex which is already registered is now blocked.

- ui: Adds a button on the dex settings page to allow updating
  the dex host. The DEXAddressForm is reused for this purpose.
  The DEXAddressPopup is also updated to not show known exchanges
  that the user is already registered for.
@chappjc chappjc merged commit 1283356 into decred:master Jun 20, 2022
@martonp martonp deleted the updateHost branch January 20, 2024 13:16
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