Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge #694
Browse files Browse the repository at this point in the history
694: Problem: trusted_state serialization/deserailzation not symmetric r=tomtau a=yihuang

Solution:
- Fixed deserailzation code in tendermint-rs.
- Added unit test to verify.

Co-authored-by: yihuang <[email protected]>
  • Loading branch information
bors[bot] and yihuang authored Dec 17, 2019
2 parents 819881e + 9abf231 commit 361c7cf
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion client-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jsonrpc = { version = "0.11", optional = true }
serde_json = { version = "1.0", optional = true }
parity-scale-codec = { features = ["derive"], version = "1.1" }
websocket = { version = "0.24", default-features = false, features = ["sync"], optional = true }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "6fca043ec5ca48770fa9e7b95e207f7b0c88c97f" }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "a32cec297d80d240781c9ca2aaa71cace93e7510" }
itertools = "0.8"

[features]
Expand Down
2 changes: 1 addition & 1 deletion client-common/src/tendermint/lite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Encode for TrustedState {
impl Decode for TrustedState {
fn decode<I: Input>(value: &mut I) -> Result<Self, Error> {
serde_json::from_str(&String::decode(value)?)
.map_err(|_| "fail to encode trusted_state to json ".into())
.map_err(|_| "fail to decode trusted_state from json ".into())
}
}

Expand Down
2 changes: 1 addition & 1 deletion client-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tiny-bip39 = { version = "0.6", default-features = false }
unicase = "2.6.0"
lazy_static = "1.4.0"
ring = "0.16.9"
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "6fca043ec5ca48770fa9e7b95e207f7b0c88c97f" }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "a32cec297d80d240781c9ca2aaa71cace93e7510" }
thiserror = { version = "1.0", default-features = false }
non-empty-vec = "0.1"

Expand Down
20 changes: 20 additions & 0 deletions client-core/src/service/sync_state_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ where

#[cfg(test)]
mod tests {
use serde_json;

use super::*;
use client_common::storage::MemoryStorage;

Expand Down Expand Up @@ -153,4 +155,22 @@ mod tests {
.unwrap()
.is_none());
}

#[test]
fn check_sync_state_serialization() {
let trusted_state_json = r#"{"header":{"version":{"block":"10","app":"0"},"chain_id":"test-chain-y3m1e6-AB","height":"1","time":"2019-11-20T08:56:48.618137Z","num_txs":"0","total_txs":"0","last_block_id":null,"last_commit_hash":null,"data_hash":null,"validators_hash":"1D19568662F9A9167B338F98C860C4102AA0DE85600BF48A15B192DB53D030A1","next_validators_hash":"1D19568662F9A9167B338F98C860C4102AA0DE85600BF48A15B192DB53D030A1","consensus_hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","app_hash":"0F46E113C21F9EACB26D752F9523746CF8D47ECBEA492736D176005911F973A5","last_results_hash":null,"evidence_hash":null,"proposer_address":"A59B92278703DFECE52A40D9EF3AE9D1EDC6B949"},"validators":{"validators":[{"address":"A59B92278703DFECE52A40D9EF3AE9D1EDC6B949","pub_key":{"type":"tendermint/PubKeyEd25519","value":"oblY1MjCzNuYlr7A5cUsEY3yBxYBSRHzha16wbnWNx8="},"voting_power":"5000000000","proposer_priority":"0"}]}}"#;
let mut state = SyncState::genesis(vec![]);
state.last_block_height = 1;
state.last_app_hash =
"0F46E113C21F9EACB26D752F9523746CF8D47ECBEA492736D176005911F973A5".to_owned();
state.trusted_state = serde_json::from_str(trusted_state_json).unwrap();

let key = "Default";

let storage = MemoryStorage::default();
storage.save(KEYSPACE, key, &state).unwrap();
let state1: SyncState = storage.load(KEYSPACE, key).unwrap().unwrap();

assert_eq!(state.encode(), state1.encode());
}
}
2 changes: 1 addition & 1 deletion client-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ chrono = { version = "0.4", features = ["serde"] }
parity-scale-codec = { features = ["derive"], version = "1.1" }
hex = "0.4.0"
secp256k1zkp = { git = "https://github.com/crypto-com/rust-secp256k1-zkp.git", rev = "be445f29a96af31fe079611d26c07f1f596d1c5f", features = ["recovery"] }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "6fca043ec5ca48770fa9e7b95e207f7b0c88c97f" }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "a32cec297d80d240781c9ca2aaa71cace93e7510" }

[dev-dependencies]
secp256k1zkp = { git = "https://github.com/crypto-com/rust-secp256k1-zkp.git", rev = "be445f29a96af31fe079611d26c07f1f596d1c5f", features = ["serde", "zeroize", "rand", "recovery", "endomorphism"] }
2 changes: 1 addition & 1 deletion test-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ parity-scale-codec = { features = ["derive"], version = "1.1" }
base64 = "0.11"
hex = "0.4"

tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "6fca043ec5ca48770fa9e7b95e207f7b0c88c97f" }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "a32cec297d80d240781c9ca2aaa71cace93e7510" }
chain-core = { path = "../chain-core" }
chain-abci = { path = "../chain-abci" }
client-common = { path = "../client-common" }
Expand Down

0 comments on commit 361c7cf

Please sign in to comment.