-
Notifications
You must be signed in to change notification settings - Fork 92
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
Conversation
898810c
to
a20e6b6
Compare
There was a problem hiding this 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.
c3ee8c7
to
b132cd5
Compare
b132cd5
to
751a29e
Compare
uri := parsedURL.Host // empty for urls without scheme | ||
if uri == "" { | ||
uri = parsedURL.String() |
There was a problem hiding this comment.
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.
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.
64ffbd5
to
b2e17e9
Compare
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. |
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. |
There was a problem hiding this 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.
client/core/types.go
Outdated
if privKey != nil { | ||
// no need to generate a new privKey, just decrypt. | ||
return privKey, a.unlock(crypter) | ||
} |
There was a problem hiding this comment.
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?
client/core/core.go
Outdated
|
||
// 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
b2e17e9
to
848b533
Compare
Done. |
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() |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Key changes:
core.PreRegister renamed to core.GetFee
core.Register
core.PreRegister
core.GetFee
.toFee paid
Fee payment in progress
. Though the notification subtext showsWaiting for N confirmations before trading at URL
, that might easily get missed because of the bolderFee paid
title.core.connectDEX
Check cert before attempting connection to return better error message for missing certs scenarios; currently returnsx509: certificate signed by unknown authority
Undone as per client/webserver,dexcctl: replace new wallet config file path with cfg text #346 (comment)