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: refactor preregister and register methods #328

Merged
merged 10 commits into from
May 14, 2020

Conversation

itswisdomagain
Copy link
Member

@itswisdomagain itswisdomagain commented May 3, 2020

Key changes:

core.PreRegister renamed to core.GetFee

  • Close ws connections after retrieving fee, delete connection-caching code.

core.Register

  • Return error for registration attempts where a connection already exists for the url in the conns map. This tallies with the check made in core.PreRegistercore.GetFee.
  • Resolves first part of app: show better messaging when waiting for fee confirmations #306 by rewording the notification title displayed when fee is paid but not confirmed from Fee paid to Fee payment in progress. Though the notification subtext shows Waiting for N confirmations before trading at URL, that might easily get missed because of the bolder Fee paid title.

core.connectDEX

@itswisdomagain itswisdomagain changed the title client: refactor preregister and register ops in core and webserver client/core: refactor preregister and register methods May 3, 2020
Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

Lots of nice improvements here, but a couple of questions.

client/core/core.go Outdated Show resolved Hide resolved
client/core/core.go Outdated Show resolved Hide resolved
dex/runner.go Outdated Show resolved Hide resolved
client/db/bolt/db.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/core/core.go Outdated Show resolved Hide resolved
client/core/core.go Outdated Show resolved Hide resolved
client/core/core.go Show resolved Hide resolved
Comment on lines +1894 to +1913
uri := parsedURL.Host // empty for urls without scheme
if uri == "" {
uri = parsedURL.String()
Copy link
Member

Choose a reason for hiding this comment

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

Happy to see this, but I'd like to see a change at some point that stops calling it a URL at all, and requires only a host:port.

client/core/core.go Outdated Show resolved Hide resolved
client/core/core.go Outdated Show resolved Hide resolved
client/core/core.go Show resolved Hide resolved
@chappjc
Copy link
Member

chappjc commented May 8, 2020

Some conflicts too with the just-merged fee notification tweaks PR.

core.PreRegister
- Don't (re-)connect if there is a pending connection for same url,
only reset timer.
- Close pending connection if a new connection to a new url is established
and temporarily cache the new connection.
core.Register
- Return error for registration attempts where a connection already exists
for the url in the conns map.
- If there is no cached connection (either from a previous PreRegister call
or from a previous failed Register call), create a new connection and cache
it (in case Register fails and user wants to try again).
- Save new account info to db after registration to the dex server completes
successfully but before paying fees so that user will not need to re-register
with dex server if dexc is restarted.
core.connectDEX
- Attempt to connect to urls without scheme instead of using empty string.
- Check cert before attempting connection to return better error message for
missing certs scenarios.
@itswisdomagain itswisdomagain force-pushed the client-touchups branch 2 times, most recently from 64ffbd5 to b2e17e9 Compare May 9, 2020 16:10
@chappjc chappjc self-requested a review May 12, 2020 22:29
@chappjc
Copy link
Member

chappjc commented May 13, 2020

I know this PR is a "refactoring" job as stated by the title, but going forward let's try to be conservative with how many changes go into a PR. Part of it - and I feel like a complete hypocrite saying this - is large changes during review like the migration of code into dexconnection.go and routehandlers.go that make it difficult to follow diffs, and at a point when we had already reviewed most of the PR. Seems like everything was just copied over, but since the diff between two different files isn't shown it is hard to know. I did something like like this with server/market/epump.go in #287, but the motivation there was a deadlock bug that unfortunately necessitated significant changes to the types.

I support changes that solve bugs or make code less error prone, don't get me wrong. But we should try to keep the scope of the changes in check. Each notable change requires the tester to go back to their simnet harnesses and setup everything from scratch. That's where I'm at. I don't have any more specific comments, but I also just noticed the last commit and I still need to retest previous commits.

@chappjc
Copy link
Member

chappjc commented May 13, 2020

Actually, there are a ton of open client/core PRs right now and I'm pretty certain it's going to create a bunch of conflict headaches because the resolution involves a new file. Can you revert b2e17e9. except the dexConn->dc rename? Could also propose the core.authDEX(dc) to dc.auth() change in a separate commit since we've already discussed it a bit, but I more inclined to say let's just draw the line and consider that change in a follow up, with clear justification and a separate merge to track it.

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.

Retested and working. Ready to go after final commit is reworked without the new file creation. I generally support that move, but when there are far fewer conflicting PRs up.

Comment on lines 281 to 285
if privKey != nil {
// no need to generate a new privKey, just decrypt.
return privKey, a.unlock(crypter)
}
Copy link
Member

Choose a reason for hiding this comment

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

A properly initialized but locked dexAccount will still have a nil privKey. Did you mean to check dexAccount.encKey instead?


// signAndRequest signs and sends the request, unmarshaling the response into
// the provided interface.
func (dc *dexConnection) signAndRequest(signable msgjson.Signable, route string, result interface{}) error {
Copy link
Member

Choose a reason for hiding this comment

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

You've made this a standalone function, but are then passing the dexConnection as the first argument every time you use it. Why not leave it as a method then?

Copy link
Member Author

Choose a reason for hiding this comment

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

Weird. I think there was a case where I needed to sign and send a request but did not have a dexConnection instance. Looking at it now, ALL references to the standalone function pass a reference to a dexConnection object. Will revert this change.

@itswisdomagain
Copy link
Member Author

Retested and working. Ready to go after final commit is reworked without the new file creation. I generally support that move, but when there are far fewer conflicting PRs up.

Done.

Comment on lines -1995 to +1913
parsedURL, err := url.Parse(uri)
parsedURL, err := url.Parse(acctInfo.URL)
if err != nil {
return nil, fmt.Errorf("error parsing account URL %s: %v", uri, err)
return nil, fmt.Errorf("error parsing account URL %s: %v", acctInfo.URL, err)
}
uri := parsedURL.Host // empty for urls without scheme
if uri == "" {
uri = parsedURL.String()
Copy link
Member

@chappjc chappjc May 14, 2020

Choose a reason for hiding this comment

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

This only seems to help with ""//127.0.0.1:7232", which isn't much of an improvement over a random shceme. Doesn't seem to work. If you give it "127.0.0.1:7232" without the scheme, then url.Parse errors. Seems like you'd want to try net.SplitHostPort in the event that Parse fails. e.g. https://play.golang.org/p/_iJOLLmeyzV But let's address this later.

$   ./dexcctl -u u -P p getfee "http://127.0.0.1:7232" ~/.dcrdex/rpc.cert 
{
  "fee": 100000000
}
$   ./dexcctl -u u -P p getfee "127.0.0.1:7232" ~/.dcrdex/rpc.cert 
error parsing account URL 127.0.0.1:7232: parse "127.0.0.1:7232": first path segment in URL cannot contain colon
$   ./dexcctl -u u -P p getfee "//127.0.0.1:7232" ~/.dcrdex/rpc.cert 
{
  "fee": 100000000
}

Copy link
Member Author

Choose a reason for hiding this comment

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

iirc, I tried with localhost:35 and that worked.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I think's that's because with localhost:35 it interprets that in the format scheme:opaque?query#fragment so that URL.String is printing it as scheme+":"+opaque.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, it thinks localhost is the scheme in an opaque url that way https://play.golang.org/p/2KxZxqeMOTN

Let's fix this in another PR though.

@chappjc chappjc merged commit 7ec2b8c into decred:master May 14, 2020
@itswisdomagain itswisdomagain deleted the client-touchups branch May 15, 2020 01:54
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