Skip to content

Commit

Permalink
[4.0.x] api fix for spent height and bump to 4.0.2 (#3402)
Browse files Browse the repository at this point in the history
* include height even for spent outputs in get_outputs api (#3400)

* bump to 4.0.2
  • Loading branch information
antiochp authored Jul 22, 2020
1 parent c0ff4b9 commit 12936be
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 86 deletions.
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand Down Expand Up @@ -32,14 +32,14 @@ term = "0.6"
failure = "0.1"
failure_derive = "0.1"

grin_api = { path = "./api", version = "4.0.1" }
grin_config = { path = "./config", version = "4.0.1" }
grin_chain = { path = "./chain", version = "4.0.1" }
grin_core = { path = "./core", version = "4.0.1" }
grin_keychain = { path = "./keychain", version = "4.0.1" }
grin_p2p = { path = "./p2p", version = "4.0.1" }
grin_servers = { path = "./servers", version = "4.0.1" }
grin_util = { path = "./util", version = "4.0.1" }
grin_api = { path = "./api", version = "4.0.2" }
grin_config = { path = "./config", version = "4.0.2" }
grin_chain = { path = "./chain", version = "4.0.2" }
grin_core = { path = "./core", version = "4.0.2" }
grin_keychain = { path = "./keychain", version = "4.0.2" }
grin_p2p = { path = "./p2p", version = "4.0.2" }
grin_servers = { path = "./servers", version = "4.0.2" }
grin_util = { path = "./util", version = "4.0.2" }

[dependencies.cursive]
version = "0.15"
Expand All @@ -50,5 +50,5 @@ features = ["pancurses-backend"]
built = { version = "0.4", features = ["git2"]}

[dev-dependencies]
grin_chain = { path = "./chain", version = "4.0.1" }
grin_store = { path = "./store", version = "4.0.1" }
grin_chain = { path = "./chain", version = "4.0.2" }
grin_store = { path = "./store", version = "4.0.2" }
14 changes: 7 additions & 7 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_api"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "APIs for grin, a simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand Down Expand Up @@ -31,9 +31,9 @@ rustls = "0.17"
url = "2.1"
bytes = "0.5"

grin_core = { path = "../core", version = "4.0.1" }
grin_chain = { path = "../chain", version = "4.0.1" }
grin_p2p = { path = "../p2p", version = "4.0.1" }
grin_pool = { path = "../pool", version = "4.0.1" }
grin_store = { path = "../store", version = "4.0.1" }
grin_util = { path = "../util", version = "4.0.1" }
grin_core = { path = "../core", version = "4.0.2" }
grin_chain = { path = "../chain", version = "4.0.2" }
grin_p2p = { path = "../p2p", version = "4.0.2" }
grin_pool = { path = "../pool", version = "4.0.2" }
grin_store = { path = "../store", version = "4.0.2" }
grin_util = { path = "../util", version = "4.0.2" }
26 changes: 14 additions & 12 deletions api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,18 @@ impl OutputPrintable {
};

let out_id = core::OutputIdentifier::from(output);
let res = chain.get_unspent(&out_id)?;
let (spent, block_height) = if let Some(output_pos) = res {
(false, Some(output_pos.height))
} else {
(true, None)
};
let pos = chain.get_unspent(&out_id)?;

let spent = pos.is_none();

// If output is unspent then we know its pos and height from the output_pos index.
// We use the header height directly for spent pos.
// Note: There is an interesting edge case here and we need to consider if the
// api is currently doing the right thing here:
// An output can be spent and then subsequently reused and the new instance unspent.
// This would result in a height that differs from the provided block height.
let output_pos = pos.map(|x| x.pos).unwrap_or(0);
let block_height = pos.map(|x| x.height).or(block_header.map(|x| x.height));

let proof = if include_proof {
Some(output.proof_bytes().to_hex())
Expand All @@ -317,8 +323,6 @@ impl OutputPrintable {
}
};

let output_pos = chain.get_output_pos(&output.commit).unwrap_or(0);

Ok(OutputPrintable {
output_type,
commit: output.commit,
Expand Down Expand Up @@ -743,8 +747,7 @@ mod test {

#[test]
fn serialize_output_printable() {
let hex_output =
"{\
let hex_output = "{\
\"output_type\":\"Coinbase\",\
\"commit\":\"083eafae5d61a85ab07b12e1a51b3918d8e6de11fc6cde641d54af53608aa77b9f\",\
\"spent\":false,\
Expand All @@ -761,8 +764,7 @@ mod test {

#[test]
fn serialize_output() {
let hex_commit =
"{\
let hex_commit = "{\
\"commit\":\"083eafae5d61a85ab07b12e1a51b3918d8e6de11fc6cde641d54af53608aa77b9f\",\
\"height\":0,\
\"mmr_index\":0\
Expand Down
10 changes: 5 additions & 5 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_chain"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand All @@ -24,10 +24,10 @@ chrono = "0.4.11"
lru-cache = "0.1"
lazy_static = "1"

grin_core = { path = "../core", version = "4.0.1" }
grin_keychain = { path = "../keychain", version = "4.0.1" }
grin_store = { path = "../store", version = "4.0.1" }
grin_util = { path = "../util", version = "4.0.1" }
grin_core = { path = "../core", version = "4.0.2" }
grin_keychain = { path = "../keychain", version = "4.0.2" }
grin_store = { path = "../store", version = "4.0.2" }
grin_util = { path = "../util", version = "4.0.2" }

[dev-dependencies]
env_logger = "0.7"
Expand Down
9 changes: 3 additions & 6 deletions chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,9 @@ impl Chain {
}
}

/// TODO - where do we call this from? And do we need a rewind first?
/// For the given commitment find the unspent output and return the
/// associated Return an error if the output does not exist or has been
/// spent. This querying is done in a way that is consistent with the
/// current chain state, specifically the current winning (valid, most
/// work) fork.
/// Returns Ok(Some(pos)) if output is unspent.
/// Returns Ok(None) if output is spent.
/// Returns Err if something went wrong beyond not finding the output.
pub fn get_unspent(&self, output_ref: &OutputIdentifier) -> Result<Option<CommitPos>, Error> {
self.txhashset.read().get_unspent(output_ref)
}
Expand Down
10 changes: 5 additions & 5 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_config"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Configuration for grin, a simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand All @@ -16,10 +16,10 @@ serde_derive = "1"
toml = "0.5"
dirs = "2.0"

grin_core = { path = "../core", version = "4.0.1" }
grin_servers = { path = "../servers", version = "4.0.1" }
grin_p2p = { path = "../p2p", version = "4.0.1" }
grin_util = { path = "../util", version = "4.0.1" }
grin_core = { path = "../core", version = "4.0.2" }
grin_servers = { path = "../servers", version = "4.0.2" }
grin_p2p = { path = "../p2p", version = "4.0.2" }
grin_util = { path = "../util", version = "4.0.2" }

[dev-dependencies]
pretty_assertions = "0.6.1"
6 changes: 3 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_core"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand Down Expand Up @@ -28,8 +28,8 @@ log = "0.4"
chrono = { version = "0.4.11", features = ["serde"] }
zeroize = { version = "1.1", features =["zeroize_derive"] }

keychain = { package = "grin_keychain", path = "../keychain", version = "4.0.1" }
util = { package = "grin_util", path = "../util", version = "4.0.1" }
keychain = { package = "grin_keychain", path = "../keychain", version = "4.0.2" }
util = { package = "grin_util", path = "../util", version = "4.0.2" }

[dev-dependencies]
serde_json = "1"
4 changes: 2 additions & 2 deletions keychain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_keychain"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand All @@ -26,4 +26,4 @@ ripemd160 = "0.7"
sha2 = "0.7"
pbkdf2 = "0.2"

grin_util = { path = "../util", version = "4.0.1" }
grin_util = { path = "../util", version = "4.0.2" }
12 changes: 6 additions & 6 deletions p2p/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_p2p"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand All @@ -21,10 +21,10 @@ tempfile = "3.1"
log = "0.4"
chrono = { version = "0.4.11", features = ["serde"] }

grin_core = { path = "../core", version = "4.0.1" }
grin_store = { path = "../store", version = "4.0.1" }
grin_util = { path = "../util", version = "4.0.1" }
grin_chain = { path = "../chain", version = "4.0.1" }
grin_core = { path = "../core", version = "4.0.2" }
grin_store = { path = "../store", version = "4.0.2" }
grin_util = { path = "../util", version = "4.0.2" }
grin_chain = { path = "../chain", version = "4.0.2" }

[dev-dependencies]
grin_pool = { path = "../pool", version = "4.0.1" }
grin_pool = { path = "../pool", version = "4.0.2" }
10 changes: 5 additions & 5 deletions pool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_pool"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Chain implementation for grin, a simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand All @@ -19,9 +19,9 @@ chrono = "0.4.11"
failure = "0.1"
failure_derive = "0.1"

grin_core = { path = "../core", version = "4.0.1" }
grin_keychain = { path = "../keychain", version = "4.0.1" }
grin_util = { path = "../util", version = "4.0.1" }
grin_core = { path = "../core", version = "4.0.2" }
grin_keychain = { path = "../keychain", version = "4.0.2" }
grin_util = { path = "../util", version = "4.0.2" }

[dev-dependencies]
grin_chain = { path = "../chain", version = "4.0.1" }
grin_chain = { path = "../chain", version = "4.0.2" }
18 changes: 9 additions & 9 deletions servers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grin_servers"
version = "4.0.1"
version = "4.0.2"
authors = ["Grin Developers <[email protected]>"]
description = "Simple, private and scalable cryptocurrency implementation based on the Mimblewimble chain format."
license = "Apache-2.0"
Expand All @@ -26,11 +26,11 @@ tokio = {version = "0.2", features = ["full"] }
tokio-util = { version = "0.2", features = ["codec"] }
walkdir = "2.3.1"

grin_api = { path = "../api", version = "4.0.1" }
grin_chain = { path = "../chain", version = "4.0.1" }
grin_core = { path = "../core", version = "4.0.1" }
grin_keychain = { path = "../keychain", version = "4.0.1" }
grin_p2p = { path = "../p2p", version = "4.0.1" }
grin_pool = { path = "../pool", version = "4.0.1" }
grin_store = { path = "../store", version = "4.0.1" }
grin_util = { path = "../util", version = "4.0.1" }
grin_api = { path = "../api", version = "4.0.2" }
grin_chain = { path = "../chain", version = "4.0.2" }
grin_core = { path = "../core", version = "4.0.2" }
grin_keychain = { path = "../keychain", version = "4.0.2" }
grin_p2p = { path = "../p2p", version = "4.0.2" }
grin_pool = { path = "../pool", version = "4.0.2" }
grin_store = { path = "../store", version = "4.0.2" }
grin_util = { path = "../util", version = "4.0.2" }
Loading

0 comments on commit 12936be

Please sign in to comment.