-
Notifications
You must be signed in to change notification settings - Fork 137
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
V2 slate versioning enablement #85
V2 slate versioning enablement #85
Conversation
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.
Higher level question: If slates can always be converted from V0 format, why don't we always use V0 for network communications?
libwallet/src/slate_versions/mod.rs
Outdated
match *self { | ||
VersionedSlate::V2(_) => SlateVersion::V2, | ||
VersionedSlate::V1(_) => SlateVersion::V1, | ||
_ => SlateVersion::V0, |
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.
Why match on a wildcard here? Matching on VersionedSlate::V0(_)
instead would serve as a reminder to update the function when V3 comes around.
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.
Good point, changed
libwallet/src/slate_versions/mod.rs
Outdated
V2(SlateV2), | ||
/// V1 Grin 1.0.1 - 1.0.3) | ||
V1(SlateV1), | ||
/// V2 Grin 1.0.0 |
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.
V2?
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.
👍
|
||
//use grin_wallet_libwallet::slate_versions::v1::SlateV1; | ||
//use grin_wallet_libwallet::slate_versions::v2::SlateV2; | ||
|
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.
I suggest running similar tests for every slate version.
Most importantly, test that always request_slate.version() == response_slate.version()
.
Something like this would work:
// easy-jsonrpc generates typesafe client stubs.
// try adding `pub use crate::foreign_rpc::foreign_rpc as foreign_rpc_client;`
// to `api/src/lib.rs` then running `cargo doc --open`
use grin_wallet_api::foreign_rpc_client;
/// call ForeignRpc::receive_tx on vs and return the result
fn receive_tx(vs: VersionedSlate) -> VersionedSlate {
let dir = tempdir().map_err(|e| format!("{:#?}", e)).unwrap();
let dir = dir
.path()
.to_str()
.ok_or("Failed to convert tmpdir path to string.".to_owned())
.unwrap();
let bound_method = foreign_rpc_client::receive_tx(
vs,
None,
Some("Thanks for saving my dog from that tree, bddap.".into()),
)
.unwrap();
let (call, tracker) = bound_method.call();
let json_response = run_doctest_foreign(call.as_request(), dir, 5, false)
.unwrap()
.unwrap();
let mut response = easy_jsonrpc::Response::from_json_response(json_response).unwrap();
tracker.get_return(&mut response).unwrap().unwrap()
}
#[test]
fn version_unchanged() {
let req: Value = serde_json::from_str(include_str!("slates/v1_req.slate")).unwrap();
let slate: VersionedSlate = serde_json::from_value(req["params"][0].clone()).unwrap();
let slate_req: Slate = slate.into();
assert_eq!(
receive_tx(VersionedSlate::into_version(
slate_req.clone(),
SlateVersion::V0
))
.version(),
SlateVersion::V0
);
assert_eq!(
receive_tx(VersionedSlate::into_version(
slate_req.clone(),
SlateVersion::V1
))
.version(),
SlateVersion::V1
);
assert_eq!(
receive_tx(VersionedSlate::into_version(
slate_req.clone(),
SlateVersion::V2
))
.version(),
SlateVersion::V2
);
// compile time test will remind us to update these tests when updating slate format
fn _all_versions_tested(vs: VersionedSlate) {
match vs {
VersionedSlate::V0(_) => (),
VersionedSlate::V1(_) => (),
VersionedSlate::V2(_) => (),
}
}
}
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.
Thanks for putting this together, I've included this in the last push
We're eventually going to drop support for earlier slate versions, and want to be able to make breaking but managed changes to the slate format, so while converting everything to v0 is an option now, it won't be in future. There will also be more consumers of the slate than just us, and V0 is very annoying to work with due to the way fields were serialized as byte arrays. |
* V2 slate versioning enablement (mimblewimble#85) * fix for command line listener port override * reduce parameter query size * Add slate versioning * rustfmt * bump version number * Add tests for slate version conversion * rustfmt * Updates and test addition based on bdap's review * rustfmt * fix mimblewimble#88 (mimblewimble#89) * Add `check_version` function to Foreign API (mimblewimble#87) * move api deser types into separate types mod * rustfmt * missing types file * make all exports from libwallet more explicit * rustfmt * add version check function to foreign api * rustfmt * change check_version return value to result, for consistency * fix the merge missed parts * rustfmt
* V2 slate versioning enablement (mimblewimble#85) * fix for command line listener port override * reduce parameter query size * Add slate versioning * rustfmt * bump version number * Add tests for slate version conversion * rustfmt * Updates and test addition based on bdap's review * rustfmt * fix mimblewimble#88 (mimblewimble#89) * Add `check_version` function to Foreign API (mimblewimble#87) * move api deser types into separate types mod * rustfmt * missing types file * make all exports from libwallet more explicit * rustfmt * add version check function to foreign api * rustfmt * change check_version return value to result, for consistency * Revert "Merge branch 'master' into master" This reverts commit a63f2c7, reversing changes made to d774272. * [WIP] Invoiced Transactions API Support (mimblewimble#90) * basic invoiced tx working * rustfmt * teardown * rustfmt * rename, new struct for invoice args, begin to add new functions to RPC apis * rustfmt * add fns to rpc api * rustfmt * owner api functions RPC documentation in place * rustfmt * doctests for new invoicing functions * rustfmt * test fixes * update documentation and doctests * rustfmt * invoice testing verification of tx log output * rustfmt * Add Azure Pipelines to grin-wallet * Remove cursive and fix task names * Do not crash on empty terminal * Add LLVM * Possible MSFT pipeline bug with . task * Change connection name * Command line implementation of invoice commands (mimblewimble#96) * add issue_invoice_tx command * rustfmt * add first pass at process_invoice command * start of process_invoice fn * rustfmt * rename issue invoice and process invoice to invoice and pay * add prompting and display information to pay invoice command * rustfmt * support invoice transactions in finalize command * rustfmt * Add Azure Pipelines badge * Remove duplicate LMDB wallet backend code (mimblewimble#101) * remove leftover wallet lmdb code * rustfmt * Simplify slate (de)serialization (mimblewimble#103) * Simplify slate (de)serialization * rustfmt * Cleanup * Fix slate version tests * Another fix for tests * Fix slate deser in http adapter * docstring update and provide a bit of a readme (mimblewimble#104) * Updates for 1.1.0-beta.3 release (mimblewimble#106) * bump version number and build from tag for beta 3 release * update for latest grin tag * Fix keybase adapter (mimblewimble#107) * fix version string in yml (mimblewimble#113) * fix: invoice transaction pay need update the slate height (mimblewimble#115) * Remove double json encoding on http response (mimblewimble#114) * Add participant ID as part of key to stored private transaction context data (mimblewimble#117) * add participant_id to saved tranasction context data * rustfmt? * change participant id for command line pay command * change the api repository to grin-wallet instead of grin (mimblewimble#118) * rustfmt * fix the test * fix controller and api test
* V2 slate versioning enablement (mimblewimble#85) * fix for command line listener port override * reduce parameter query size * Add slate versioning * rustfmt * bump version number * Add tests for slate version conversion * rustfmt * Updates and test addition based on bdap's review * rustfmt * fix mimblewimble#88 (mimblewimble#89) * Add `check_version` function to Foreign API (mimblewimble#87) * move api deser types into separate types mod * rustfmt * missing types file * make all exports from libwallet more explicit * rustfmt * add version check function to foreign api * rustfmt * change check_version return value to result, for consistency * Revert "Merge branch 'master' into master" This reverts commit a63f2c7, reversing changes made to d774272. * [WIP] Invoiced Transactions API Support (mimblewimble#90) * basic invoiced tx working * rustfmt * teardown * rustfmt * rename, new struct for invoice args, begin to add new functions to RPC apis * rustfmt * add fns to rpc api * rustfmt * owner api functions RPC documentation in place * rustfmt * doctests for new invoicing functions * rustfmt * test fixes * update documentation and doctests * rustfmt * invoice testing verification of tx log output * rustfmt * Add Azure Pipelines to grin-wallet * Remove cursive and fix task names * Do not crash on empty terminal * Add LLVM * Possible MSFT pipeline bug with . task * Change connection name * Command line implementation of invoice commands (mimblewimble#96) * add issue_invoice_tx command * rustfmt * add first pass at process_invoice command * start of process_invoice fn * rustfmt * rename issue invoice and process invoice to invoice and pay * add prompting and display information to pay invoice command * rustfmt * support invoice transactions in finalize command * rustfmt * Add Azure Pipelines badge * Remove duplicate LMDB wallet backend code (mimblewimble#101) * remove leftover wallet lmdb code * rustfmt * Simplify slate (de)serialization (mimblewimble#103) * Simplify slate (de)serialization * rustfmt * Cleanup * Fix slate version tests * Another fix for tests * Fix slate deser in http adapter * docstring update and provide a bit of a readme (mimblewimble#104) * Updates for 1.1.0-beta.3 release (mimblewimble#106) * bump version number and build from tag for beta 3 release * update for latest grin tag * Fix keybase adapter (mimblewimble#107) * fix version string in yml (mimblewimble#113) * fix: invoice transaction pay need update the slate height (mimblewimble#115) * Remove double json encoding on http response (mimblewimble#114) * Add participant ID as part of key to stored private transaction context data (mimblewimble#117) * add participant_id to saved tranasction context data * rustfmt? * change participant id for command line pay command * change the api repository to grin-wallet instead of grin (mimblewimble#118) * Test (mimblewimble#119) * Remove Travis.yml (mimblewimble#124) * Version Info API Function tweak, remove 'min_compat_version' from slate (mimblewimble#123) * change slate version function to return list of supported slate formats * rustfmt * remove min_compat_version * Changes for 1.1.0 -> 2.0.0 Deployment strategy decisions (mimblewimble#126) * make slate v0 the default for regular sends * add block_header_version to slate * update doc tests for latest grin version * rustfmt * HACF if HF height detected * rustfmt * version bump for beta.4 * cargo.lock crate version update, and remove 3 build warning from cargo 1.35.0 * Fix for API secret on node API startup (mimblewimble#131) * fix for api_secret when reading node height * rustfmt * remove macro export * trigger ci again * More helpful error message on recover when `wallet_data` dir doesn't exist (mimblewimble#134) * make recover error message when wallet doesn't exist more helpful * rustfmt * fixes and version update for final 1.0.0 build * fixes and version update for final 1.0.0 build * rustfmt * get back the travis-ci scripts * fix the test
* V2 slate versioning enablement (mimblewimble#85) * fix for command line listener port override * reduce parameter query size * Add slate versioning * rustfmt * bump version number * Add tests for slate version conversion * rustfmt * Updates and test addition based on bdap's review * rustfmt * fix mimblewimble#88 (mimblewimble#89) * Add `check_version` function to Foreign API (mimblewimble#87) * move api deser types into separate types mod * rustfmt * missing types file * make all exports from libwallet more explicit * rustfmt * add version check function to foreign api * rustfmt * change check_version return value to result, for consistency * Revert "Merge branch 'master' into master" This reverts commit a63f2c7, reversing changes made to d774272. * [WIP] Invoiced Transactions API Support (mimblewimble#90) * basic invoiced tx working * rustfmt * teardown * rustfmt * rename, new struct for invoice args, begin to add new functions to RPC apis * rustfmt * add fns to rpc api * rustfmt * owner api functions RPC documentation in place * rustfmt * doctests for new invoicing functions * rustfmt * test fixes * update documentation and doctests * rustfmt * invoice testing verification of tx log output * rustfmt * Add Azure Pipelines to grin-wallet * Remove cursive and fix task names * Do not crash on empty terminal * Add LLVM * Possible MSFT pipeline bug with . task * Change connection name * Command line implementation of invoice commands (mimblewimble#96) * add issue_invoice_tx command * rustfmt * add first pass at process_invoice command * start of process_invoice fn * rustfmt * rename issue invoice and process invoice to invoice and pay * add prompting and display information to pay invoice command * rustfmt * support invoice transactions in finalize command * rustfmt * Add Azure Pipelines badge * Remove duplicate LMDB wallet backend code (mimblewimble#101) * remove leftover wallet lmdb code * rustfmt * Simplify slate (de)serialization (mimblewimble#103) * Simplify slate (de)serialization * rustfmt * Cleanup * Fix slate version tests * Another fix for tests * Fix slate deser in http adapter * docstring update and provide a bit of a readme (mimblewimble#104) * Updates for 1.1.0-beta.3 release (mimblewimble#106) * bump version number and build from tag for beta 3 release * update for latest grin tag * Fix keybase adapter (mimblewimble#107) * fix version string in yml (mimblewimble#113) * fix: invoice transaction pay need update the slate height (mimblewimble#115) * Remove double json encoding on http response (mimblewimble#114) * Add participant ID as part of key to stored private transaction context data (mimblewimble#117) * add participant_id to saved tranasction context data * rustfmt? * change participant id for command line pay command * change the api repository to grin-wallet instead of grin (mimblewimble#118) * Test (mimblewimble#119) * Remove Travis.yml (mimblewimble#124) * Version Info API Function tweak, remove 'min_compat_version' from slate (mimblewimble#123) * change slate version function to return list of supported slate formats * rustfmt * remove min_compat_version * Changes for 1.1.0 -> 2.0.0 Deployment strategy decisions (mimblewimble#126) * make slate v0 the default for regular sends * add block_header_version to slate * update doc tests for latest grin version * rustfmt * HACF if HF height detected * rustfmt * version bump for beta.4 * cargo.lock crate version update, and remove 3 build warning from cargo 1.35.0 * Fix for API secret on node API startup (mimblewimble#131) * fix for api_secret when reading node height * rustfmt * remove macro export * trigger ci again * More helpful error message on recover when `wallet_data` dir doesn't exist (mimblewimble#134) * make recover error message when wallet doesn't exist more helpful * rustfmt * fixes and version update for final 1.0.0 build * fixes and version update for final 1.0.0 build * create 2.0.0 branch * V0/V1 Slate Removal + Grin Header Version Bump (mimblewimble#140) * Remove V0 and V1 Slates from Wallet * rustfmt * V1 API + V2 wallet to wallet impl (mimblewimble#144) * remove v1 API * rustfmt * convert http adapter to use V2 api * rustfmt * V2 API conversion Pt2 - Check version (mimblewimble#146) * call check_version on wallet before http send * rustfmt * Support new Bulletproof rewind scheme (mimblewimble#122) * Restore with LegacyProofBuilder * Switch to ProofBuilder at HF block * Switch proof builder for coinbase outputs at hard fork * Use valid_header_version to switch proof builder * Fix compilation errors * Use legacy proof builder for AutomatedTesting chain type * Add macro to avoid duplicate code * Read version info from server, react accordingly (mimblewimble#154) * read and parse version, bump hf * rustfmt * add foreign api middleware check * rustfmt * add middleware checks * rustfmt * add check for incoming pre-hf slates * api tests * Add double rewind period (mimblewimble#155) * Add double rewind period * Simplify restore * Fix comment * bump imported version for beta release
* fix for command line listener port override * reduce parameter query size * Add slate versioning * rustfmt * bump version number * Add tests for slate version conversion * rustfmt * Updates and test addition based on bdap's review * rustfmt
* fix for command line listener port override * reduce parameter query size * Add slate versioning * rustfmt * bump version number * Add tests for slate version conversion * rustfmt * Updates and test addition based on bdap's review * rustfmt
Implementation enabling the V2 api to accept differing versions of a Slate as suggested by @bddap in #84. (Would appreciate a bit of a review to see if there's anything here than can be made simpler)
receive_tx
function to use a versioned slateGlad to have this in before 1.1.0 release as knowing this is in place will make slate changes much easier going forward.
Also note this won't compile until a tiny PR is merged in Grin, being created right now.