Skip to content

Commit

Permalink
V0/V1 Slate Removal + Grin Header Version Bump (#140)
Browse files Browse the repository at this point in the history
* Remove V0 and V1 Slates from Wallet

* rustfmt
  • Loading branch information
yeastplume authored Jun 7, 2019
1 parent 5d001a0 commit 25d3ccf
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 3,031 deletions.
255 changes: 129 additions & 126 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ pub trait ForeignRpc {
"Ok": {
"foreign_api_version": 2,
"supported_slate_versions": [
"V0",
"V1",
"V2"
]
}
Expand Down Expand Up @@ -174,7 +172,7 @@ pub trait ForeignRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
]
Expand Down Expand Up @@ -212,7 +210,7 @@ pub trait ForeignRpc {
"version_info": {
"version": 2,
"orig_version": 2,
"block_header_version": 1
"block_header_version": 2
},
"num_participants": 2,
"id": "0436430c-2b02-624c-2032-570501212b00",
Expand Down Expand Up @@ -337,7 +335,7 @@ pub trait ForeignRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
}
Expand Down Expand Up @@ -370,7 +368,7 @@ pub trait ForeignRpc {
"version_info": {
"version": 2,
"orig_version": 2,
"block_header_version": 1
"block_header_version": 2
},
"num_participants": 2,
"id": "0436430c-2b02-624c-2032-570501212b00",
Expand Down Expand Up @@ -505,7 +503,7 @@ pub trait ForeignRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ pub trait OwnerRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
}
Expand Down Expand Up @@ -471,7 +471,7 @@ pub trait OwnerRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
}
Expand Down Expand Up @@ -535,7 +535,7 @@ pub trait OwnerRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
},
{
Expand Down Expand Up @@ -619,7 +619,7 @@ pub trait OwnerRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
}
Expand Down Expand Up @@ -688,7 +688,7 @@ pub trait OwnerRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
},
0
Expand Down Expand Up @@ -726,7 +726,7 @@ pub trait OwnerRpc {
"version_info": {
"version": 2,
"orig_version": 2,
"block_header_version": 1
"block_header_version": 2
},
"num_participants": 2,
"id": "0436430c-2b02-624c-2032-570501212b00",
Expand Down Expand Up @@ -862,7 +862,7 @@ pub trait OwnerRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
}
Expand Down Expand Up @@ -1121,7 +1121,7 @@ pub trait OwnerRpc {
"version_info": {
"orig_version": 2,
"version": 2,
"block_header_version": 1
"block_header_version": 2
}
}
]
Expand Down
13 changes: 8 additions & 5 deletions api/tests/slate_versioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
// limitations under the License.

//! core::libtx specific tests
use grin_wallet_api::foreign_rpc_client;
//use grin_wallet_api::foreign_rpc_client;
use grin_wallet_api::run_doctest_foreign;
use grin_wallet_libwallet::{Slate, SlateVersion, VersionedSlate};
//use grin_wallet_libwallet::VersionedSlate;
use serde_json;
use serde_json::Value;
use tempfile::tempdir;
//use grin_wallet_libwallet::slate_versions::v1::SlateV1;
//use grin_wallet_libwallet::slate_versions::v2::SlateV2;

// test all slate conversions
#[test]
fn receive_versioned_slate() {
//#[test]
fn _receive_versioned_slate() {
// as in doctests, except exercising versioning functionality
// by accepting and responding with a V1 slate

Expand Down Expand Up @@ -65,6 +65,9 @@ fn receive_versioned_slate() {
}
}

// TODO: Re-introduce on a new slate version

/*
/// 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();
Expand Down Expand Up @@ -128,4 +131,4 @@ fn version_unchanged() {
VersionedSlate::V2(_) => (),
}
}
}
}*/
24 changes: 7 additions & 17 deletions libwallet/src/slate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ use std::fmt;
use std::sync::Arc;
use uuid::Uuid;

use crate::slate_versions::v0::SlateV0;
use crate::slate_versions::v1::SlateV1;
use crate::slate_versions::v2::{
InputV2, OutputV2, ParticipantDataV2, SlateV2, TransactionBodyV2, TransactionV2, TxKernelV2,
VersionCompatInfoV2,
Expand Down Expand Up @@ -207,20 +205,15 @@ impl Slate {
/// Recieve a slate, upgrade it to the latest version internally
pub fn deserialize_upgrade(slate_json: &str) -> Result<Slate, Error> {
let version = Slate::parse_slate_version(slate_json)?;
let v2 = match version {
let v2: SlateV2 = match version {
2 => serde_json::from_str(slate_json).context(ErrorKind::SlateDeser)?,
1 => {
let mut v1: SlateV1 =
serde_json::from_str(slate_json).context(ErrorKind::SlateDeser)?;
v1.orig_version = 1;
SlateV2::from(v1)
}
0 => {
// left as a reminder
/*0 => {
let v0: SlateV0 =
serde_json::from_str(slate_json).context(ErrorKind::SlateDeser)?;
let v1 = SlateV1::from(v0);
SlateV2::from(v1)
}
}*/
_ => return Err(ErrorKind::SlateVersion(version).into()),
};
Ok(v2.into())
Expand Down Expand Up @@ -681,15 +674,12 @@ impl Serialize for Slate {
let v2 = SlateV2::from(self);
match self.version_info.orig_version {
2 => v2.serialize(serializer),
1 => {
let v1 = SlateV1::from(v2);
v1.serialize(serializer)
}
0 => {
// left as a reminder
/*0 => {
let v1 = SlateV1::from(v2);
let v0 = SlateV0::from(v1);
v0.serialize(serializer)
}
}*/
v => Err(S::Error::custom(format!("Unknown slate version {}", v))),
}
}
Expand Down
53 changes: 16 additions & 37 deletions libwallet/src/slate_versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,24 @@

//! This module contains old slate versions and conversions to the newest slate version
//! Used for serialization and deserialization of slates in a backwards compatible way.
//! Versions earlier than V2 are removed for the 2.0.0 release, but versioning code
//! remains for future needs
use crate::slate::Slate;
use crate::slate_versions::v0::SlateV0;
use crate::slate_versions::v1::SlateV1;
use crate::slate_versions::v2::SlateV2;

#[allow(missing_docs)]
pub mod v0;
#[allow(missing_docs)]
pub mod v1;
#[allow(missing_docs)]
pub mod v2;

/// The most recent version of the slate
pub const CURRENT_SLATE_VERSION: u16 = 2;

/// The grin block header this slate is intended to be compatible with
pub const GRIN_BLOCK_HEADER_VERSION: u16 = 1;
pub const GRIN_BLOCK_HEADER_VERSION: u16 = 2;

/// Existing versions of the slate
#[derive(EnumIter, Serialize, Deserialize, Clone, Debug, PartialEq, PartialOrd, Eq, Ord)]
pub enum SlateVersion {
/// V0
V0,
/// V1
V1,
/// V2 (most current)
V2,
}
Expand All @@ -48,39 +41,30 @@ pub enum SlateVersion {
/// Versions are ordered newest to oldest so serde attempts to
/// deserialize newer versions first, then falls back to older versions.
pub enum VersionedSlate {
/// Current
/// Current (Grin 1.1.0 - 2.x (current))
V2(SlateV2),
/// V1 - Grin 1.0.1 - 1.0.3)
V1(SlateV1),
/// V0 - Grin 1.0.0
V0(SlateV0),
}

impl VersionedSlate {
/// Return slate version
pub fn version(&self) -> SlateVersion {
match *self {
VersionedSlate::V2(_) => SlateVersion::V2,
VersionedSlate::V1(_) => SlateVersion::V1,
VersionedSlate::V0(_) => SlateVersion::V0,
}
}

/// convert this slate type to a specified older version
pub fn into_version(slate: Slate, version: SlateVersion) -> VersionedSlate {
match version {
SlateVersion::V2 => VersionedSlate::V2(slate.into()),
SlateVersion::V1 => {
let s = SlateV2::from(slate);
let s = SlateV1::from(s);
VersionedSlate::V1(s)
}
SlateVersion::V0 => {
// Left here as a reminder of what needs to be inserted on
// the release of a new slate
/*SlateVersion::V0 => {
let s = SlateV2::from(slate);
let s = SlateV1::from(s);
let s = SlateV0::from(s);
VersionedSlate::V0(s)
}
}*/
}
}
}
Expand All @@ -91,18 +75,13 @@ impl From<VersionedSlate> for Slate {
VersionedSlate::V2(s) => {
let s = SlateV2::from(s);
Slate::from(s)
}
VersionedSlate::V1(s) => {
let s = SlateV1::from(s);
let s = SlateV2::from(s);
Slate::from(s)
}
VersionedSlate::V0(s) => {
let s = SlateV0::from(s);
let s = SlateV1::from(s);
let s = SlateV2::from(s);
Slate::from(s)
}
} // Again, left in as a reminder
/*VersionedSlate::V0(s) => {
let s = SlateV0::from(s);
let s = SlateV1::from(s);
let s = SlateV2::from(s);
Slate::from(s)
}*/
}
}
}
Loading

0 comments on commit 25d3ccf

Please sign in to comment.