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

Refactor - Split WalletCommAdapter into multiple traits #180

Merged
merged 12 commits into from
Jul 15, 2019

Conversation

bddap
Copy link
Contributor

@bddap bddap commented Jul 6, 2019

This is WIP, consider it experimental for now.

Edit: Ready for merge

@bddap bddap force-pushed the wallet-authentication branch from 03a9a57 to f52a8d2 Compare July 8, 2019 19:33
@bddap
Copy link
Contributor Author

bddap commented Jul 8, 2019

Did a bit of investigation on this and it looks like this feature warrants a new WalletCommAdapter.

WalletCommAdapter currently exposes a [https://deterministic.space/elegant-apis-in-rust.html#dont-stringly-type-your-api](stringly typed api) where the 'addr' argument is a string that represents a different type depending the Implementer.

I'm going to start by refactoring WalletCommAdapter, and refactoring implementors of WalletCommAdaptor to hold their address as struct fields. Not only will this make server authentication implementable, it will also be more strongly typed and will enable future efforts such as an i2p comm adaptor.

@bddap
Copy link
Contributor Author

bddap commented Jul 9, 2019

WalletCommAdapter declares a listen method, but listen() is not implementable for all implementers of WalletCommAdapter. For example, it doesn't make sense for the FileWalletCommAdapter to listen(). Splitting the WalletCommAdapter trait in twain, or a similar solution, is next on my list after the task mentioned in the previous comment.

@yeastplume
Copy link
Member

Yes, that trait definitely needs a re-think.

Slightly related, I'm going to propose that we make the grinbox spec a published open standard, and provide support for it in the default wallet. If you're able to look into that and have a think about it as part of all this work, I think it will be very valuable to help reduce the friction for the vast majority of transaction cases.

@bddap
Copy link
Contributor Author

bddap commented Jul 10, 2019

Definitely agree. From what I can tell, grinbox comms can be implemented as another WalletCommAdapter. I'll keep grinbox support as an explicit end goal of these refactors.

bddap added 5 commits July 10, 2019 12:41
…ntors,

visiting havok on automated tests, at least one of which is now out of date and failing
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used
Copy link
Contributor Author

@bddap bddap left a comment

Choose a reason for hiding this comment

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

Reviewing this myself. Read over the review for explanations of the changes.

api/src/owner.rs Show resolved Hide resolved
@@ -116,12 +113,6 @@ pub struct ListenArgs {
}

pub fn listen(config: &WalletConfig, args: &ListenArgs, g_args: &GlobalArgs) -> Result<(), Error> {
let mut params = HashMap::new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This object was only serving to hold variables local to the function. The http adapter has no listen implementation, and the keybase adapter never uses it's "params" argument.

"file" => FileWalletCommAdapter::new(),
"keybase" => KeybaseWalletCommAdapter::new(),
"self" => NullWalletCommAdapter::new(),
_ => NullWalletCommAdapter::new(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After the changes in the pr, this general case (when method is not http, file, keybase, or self) now results in an error. Apart from that, previous behavior is preserved.

api.tx_lock_outputs(&slate, 0)?;
if args.method == "self" {

match args.method.as_str() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With WalletCommAdapter split into several different traits, it makes sense to handle a different "methods" explicitly. Hopefully the new match statement is easier to read as well.

Reviewer, please read over this new match statement to double check that it is desired behavior.

@@ -346,8 +332,7 @@ pub fn receive(
g_args: &GlobalArgs,
args: ReceiveArgs,
) -> Result<(), Error> {
let adapter = FileWalletCommAdapter::new();
let mut slate = adapter.receive_tx_async(&args.input)?;
let mut slate = PathToSlate((&args.input).into()).get_tx()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(&args.input).into() creates a PathBuf from a String without taking ownership of said String.

// Send a slate to a keybase username then wait for a response for TTL seconds.
fn send_tx_sync(&self, addr: &str, slate: &Slate) -> Result<Slate, Error> {
// Limit only one recipient
if addr.matches(",").count() > 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check moved to constructor.

/// Start a listener, passing received messages to the wallet api directly
/// Takes a wallet config for now to avoid needing all sorts of awkward
/// type parameters on this trait
fn listen(
&self,
params: HashMap<String, String>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Params was a) loosely typed, and b) unused.

}

/// select a SlateSender based on method and dest fields from, e.g., SendArgs
pub fn create_sender(method: &str, dest: &str) -> Result<Box<dyn SlateSender>, Error> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this method does not work in the context of I2P or public key based server authentication, it won't be much trouble to simply delete it. It's only used in two places.

@@ -1,59 +0,0 @@
// Copyright 2018 The Grin Developers
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A null adapter is no longer needed and is never used.

@@ -344,55 +343,6 @@ impl LocalWalletClient {
}
}

impl WalletCommAdapter for LocalWalletClient {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This implementation was never used.

@bddap
Copy link
Contributor Author

bddap commented Jul 12, 2019

So far none of these changes have nothing to do with Public Key based server authentication. Instead the changes so far are general improvements paving the way for new comm adapters.

I'm going to rename this pr, limiting scope to the refactor only.

@bddap bddap changed the title [WIP] Public key Server authentication for https wallets without PKI Refactor - Split WalletCommAdapter into multiple traits Jul 12, 2019
@bddap
Copy link
Contributor Author

bddap commented Jul 12, 2019

Requesting merge.

Key changes:

  • Add typed fields to comm adapters to avoid passing of stringly typed arguments to WalletCommAdapter methods.
  • Split WalletCommAdapter into four separate traits, one for each behavior it previously tried to encompass.

New traits:

  • SlateSender - Sends transactions to a corresponding SlateReceiver
  • SlateReceiver - Listens for slates from SlateSender
  • SlatePutter - Asynchronous version of SlateSender; Posts slates to be read later by a corresponding SlateGetter
  • SlateGetter - Asynchronous version of SlateReceiver; Checks for a transactions from a corresponding SlatePutter, returns the transaction if it exists

Implementation matrix:

PathToSlate HttpSlateSender KeybaseAllChannels KeybaseChannel
SlateSender
SlateReceiver
SlatePutter
SlateGetter

@yeastplume
Copy link
Member

All looks really good, thanks for doing this refactor and yes, the previous trait didn't make a lot of sense, this is much more coherent.

I'm going to merge this into the milestone\2.1.0 branch (we're keeping master for any required fixes or changes to 2.0.0). This should give us plenty of time to test before the target release anyhow. Also need to merge these changes onto my own current refactor at #184, so we'll need a decent round of testing before 2.1.0 anyhow.

@yeastplume yeastplume changed the base branch from master to milestone/2.1.0 July 15, 2019 08:17
@yeastplume yeastplume merged commit 1e8359b into mimblewimble:milestone/2.1.0 Jul 15, 2019
yeastplume added a commit that referenced this pull request Jul 29, 2019
* version bump for next potential release

* Merge master into milestone/2.1.0 (#182)

* Derive --version output dynamically from cargo package version (#174)

* add --txid to the `wallet txs` command (#176)

* add --txid to the `wallet txs` command

* add test for `wallet txs` command with `--txid` parameter

* Refactor - Split WalletCommAdapter into multiple traits (#180)

* Derive --version output dynamically from cargo package version (#174)

* add server auth argument to http client

* Revert "add server auth argument to http client"

This reverts commit f52a8d2.

* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing

* Split WalletCommAdapter into four traits, one for each of its intended behaviors.

* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used

* Remove unused "params" argument from listen method.

* Re-add previously existing TODO comment

* Fix non-test build

* completely Fix non-test build

* Full Lifecycle API Support (#184)

* refactoring wallet lib traits

* rustfmt

* rustfmt

* add new files

* explicit lifetime specifiers on all wallet traits

* rustfmt

* modify apis to use new walletinst

* rustfmt

* converting controller crate

* rustfmt

* controller crate compiling

* rustfmt

* compilation

* rustfmt

* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl

* rustfmt

* full compilation, changing recovery + init to new model

* rustfmt

* wallet initialisation working, init command output and flow identical to v2.0.0 wallet

* rustfmt

* fix listener and owner api startup

* rustfmt

* rustfmt

* move encryption test

* rustfmt

* fix api doctests

* rustfmt

* fix for most tests in controller crate

* rustfmt

* fix for check tests in controller crate

* fix main wallet tests

* rustfmt

* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow

* rustfmt

* update keybase adapter to use new wallet format

* rustfmt

* test fix

* remove debug output
yyangli pushed a commit to mwcproject/mwc-wallet that referenced this pull request May 13, 2020
* version bump for next potential release

* Merge master into milestone/2.1.0 (mimblewimble#182)

* Derive --version output dynamically from cargo package version (mimblewimble#174)

* add --txid to the `wallet txs` command (mimblewimble#176)

* add --txid to the `wallet txs` command

* add test for `wallet txs` command with `--txid` parameter

* Refactor - Split WalletCommAdapter into multiple traits (mimblewimble#180)

* Derive --version output dynamically from cargo package version (mimblewimble#174)

* add server auth argument to http client

* Revert "add server auth argument to http client"

This reverts commit f52a8d2.

* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing

* Split WalletCommAdapter into four traits, one for each of its intended behaviors.

* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used

* Remove unused "params" argument from listen method.

* Re-add previously existing TODO comment

* Fix non-test build

* completely Fix non-test build

* Full Lifecycle API Support (mimblewimble#184)

* refactoring wallet lib traits

* rustfmt

* rustfmt

* add new files

* explicit lifetime specifiers on all wallet traits

* rustfmt

* modify apis to use new walletinst

* rustfmt

* converting controller crate

* rustfmt

* controller crate compiling

* rustfmt

* compilation

* rustfmt

* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl

* rustfmt

* full compilation, changing recovery + init to new model

* rustfmt

* wallet initialisation working, init command output and flow identical to v2.0.0 wallet

* rustfmt

* fix listener and owner api startup

* rustfmt

* rustfmt

* move encryption test

* rustfmt

* fix api doctests

* rustfmt

* fix for most tests in controller crate

* rustfmt

* fix for check tests in controller crate

* fix main wallet tests

* rustfmt

* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow

* rustfmt

* update keybase adapter to use new wallet format

* rustfmt

* test fix

* remove debug output
antiochp pushed a commit to antiochp/grin-wallet that referenced this pull request Aug 7, 2020
* version bump for next potential release

* Merge master into milestone/2.1.0 (mimblewimble#182)

* Derive --version output dynamically from cargo package version (mimblewimble#174)

* add --txid to the `wallet txs` command (mimblewimble#176)

* add --txid to the `wallet txs` command

* add test for `wallet txs` command with `--txid` parameter

* Refactor - Split WalletCommAdapter into multiple traits (mimblewimble#180)

* Derive --version output dynamically from cargo package version (mimblewimble#174)

* add server auth argument to http client

* Revert "add server auth argument to http client"

This reverts commit f52a8d2.

* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing

* Split WalletCommAdapter into four traits, one for each of its intended behaviors.

* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used

* Remove unused "params" argument from listen method.

* Re-add previously existing TODO comment

* Fix non-test build

* completely Fix non-test build

* Full Lifecycle API Support (mimblewimble#184)

* refactoring wallet lib traits

* rustfmt

* rustfmt

* add new files

* explicit lifetime specifiers on all wallet traits

* rustfmt

* modify apis to use new walletinst

* rustfmt

* converting controller crate

* rustfmt

* controller crate compiling

* rustfmt

* compilation

* rustfmt

* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl

* rustfmt

* full compilation, changing recovery + init to new model

* rustfmt

* wallet initialisation working, init command output and flow identical to v2.0.0 wallet

* rustfmt

* fix listener and owner api startup

* rustfmt

* rustfmt

* move encryption test

* rustfmt

* fix api doctests

* rustfmt

* fix for most tests in controller crate

* rustfmt

* fix for check tests in controller crate

* fix main wallet tests

* rustfmt

* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow

* rustfmt

* update keybase adapter to use new wallet format

* rustfmt

* test fix

* remove debug output
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.

2 participants