Merge parallel feature flag local certificate logic in cli ohttp#726
Merge parallel feature flag local certificate logic in cli ohttp#726spacebear21 merged 2 commits intopayjoin:masterfrom
Conversation
1c10ec6 to
f9151ba
Compare
Pull Request Test Coverage Report for Build 15476179133Details
💛 - Coveralls |
| } | ||
| } | ||
|
|
||
| ///Local relays are incapable of acting as proxies so we must opportunistically fetch keys from the config |
There was a problem hiding this comment.
This earlier comment was placed in an incorrect place based on my misunderstanding of where the logic was failing
This comment was marked as resolved.
This comment was marked as resolved.
857ae15 to
12b12d7
Compare
|
Ok resolved, as it turns out the problem was that the subsequent steps in the test when initializing were falling back to the default payjoin directory This was not a problem before as the ohttp-keys flag was overriding any checks and skipping this logic in the test. |
5245da8 to
bef6610
Compare
DanGould
left a comment
There was a problem hiding this comment.
The simplification is much greater than the diff count suggests. Great change.
3 things
- needs rebase
validate_relayandfetch_keysare almost exact now. Can they be deduplicated while you're rebase- It seems completely incorrect to require
--pj-directoryfor a sender. The BIP21 defines the directory. If we're always defaulting topayjo.inthat's a bug.
I think you're right that its actually a bug. The sender would just seemingly ignore the directory listed in the bip21 and use the |
2ed1621 to
7e1476b
Compare
|
I opted to keep the --pj-directory as a flag for the resume command. Is that ok or is there another place where I could access the directory from within the saved state as initialization is happening? |
c33b213 to
5c86251
Compare
f023303 to
028282d
Compare
|
It doesn't make much sense for |
59bf8ce to
bd364ac
Compare
|
Ok so I created a way for the directory to be correctly chosen across each payjoin-cli command.
|
An existing session should have its own pj_directory that overrides any configured payjoin directory. I can't think of any instance where application code should mutate the config once it is initialized. |
|
The issue I ran into is that the session isn't accessed until after the config defaults for that session are already written |
|
If I make a clone db at the config builder step how should I make sure that I am choosing the right session for the config with the |
c8fd1f0 to
315a4f5
Compare
|
you shouldn't need to edit the config or apply defaults even on resume. Each session should already have an associated pj_directory that can be used, no? The config should be irrelevant. |
|
Ok, I can just go direct for the session directory in the fetch function I wasn't sure if we wanted some consistency with he config but it makes sense to skip over it for this 👍 I definitely wasn't aware you could do this for anything beyond resume |
ba87a41 to
7f72302
Compare
| payjoin::io::fetch_ohttp_keys_with_cert( | ||
| selected_relay.clone(), | ||
| payjoin_directory.clone(), | ||
| cert_der, | ||
| ) |
There was a problem hiding this comment.
These clones are unnecessary and we can use references instead when calling fetch_ohttp_keys:
| payjoin::io::fetch_ohttp_keys_with_cert( | |
| selected_relay.clone(), | |
| payjoin_directory.clone(), | |
| cert_der, | |
| ) | |
| payjoin::io::fetch_ohttp_keys_with_cert( | |
| &selected_relay, | |
| &payjoin_directory, | |
| cert_der, | |
| ) |
payjoin-cli/src/app/v2/ohttp.rs
Outdated
| let config_keys = config.v2()?.ohttp_keys.clone(); | ||
| let mut fetched_keys = fetch_ohttp_keys(config, directory, relay_state).await?; | ||
|
|
||
| if let Some(keys) = config_keys { | ||
| fetched_keys.ohttp_keys = keys; |
There was a problem hiding this comment.
Minor optimization: we shouldn't have to fetch_ohttp_keys if the keys are going to be overridden by the config anyways.
There was a problem hiding this comment.
Also, isn't this error-prone if the config ohttp_keys doesn't correspond to the randomly selected relay in fetch_ohttp_keys?
There was a problem hiding this comment.
Ok, I guess that makes sense, I still need to return the relay but in those instances I think it is safe to just skip the fetching and use the first default relay
24874ef to
8e38602
Compare
These ohttp functions had parallel methods when running tests vs running in production. This made it difficult to read as there were two functions that appeared to do completely different things when a feature flag was present.
when merging the ohttp-key fetching and validation functions I found that there was some logic that was skipping the correct directory selection. By ensuring that the directory is chosen per session we can ensure that the correct directory is used no matter the initial config at intialization.
8e38602 to
6e03ab1
Compare
spacebear21
left a comment
There was a problem hiding this comment.
tACK 6e03ab1
Ran the cli receiver and sender and interrupted both sides to continue with the resume command. My v2 config only includes a single relay fwiw:
[v2]
ohttp_relays=["https://pj.bobspacebkk.com"]
These ohttp functions had parallel methods when running tests vs running in production. This made it difficult to read as there were two functions that appeared to do completely different things when a feature flag was present.
Because localhost relays are not actually able to be proxies here we still need to opportunistically select them from the config when running our tests instead of just allowing local cert validation.