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

Commit

Permalink
Problem (Fix #1881): wallet sync logic adapt to new tendermint-rs lig…
Browse files Browse the repository at this point in the history
…ht client design

Solution:
- running light client superivsor, and sync wallet to recent
  trusted block
- rpc call_batch ignore the first failed request and return the
  successed ones.
- run ra-sp-server before prepare env, and gen fresh keypackage when prepare test env
- fix tendermint-rs deserialization issues
  • Loading branch information
yihuang committed Jul 21, 2020
1 parent e0527f7 commit e1dc79e
Show file tree
Hide file tree
Showing 33 changed files with 758 additions and 412 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ id_ecdsa

# integration tests temparary artifacts
/integration-tests/*.so
/integration-tests/bot/.venv
/integration-tests/.venv

**/chain-abci/Enclave_u.*

Expand Down
109 changes: 103 additions & 6 deletions Cargo.lock

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

6 changes: 1 addition & 5 deletions chain-tx-enclave-next/enclave-ra/ra-enclave/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cmac = "0.3"
crypto-mac = { version = "0.8", features = ["std"] }
log = "0.4"
rcgen = "0.8"
ring = "0.16"
ring = "0.16.15"
rustls = "0.18"
serde_json = "1.0"
sgx-isa = { version = "0.3", features = ["sgxstd"] }
Expand All @@ -23,7 +23,3 @@ thiserror = "1.0"

ra-common = { path = "../ra-common" }
ra-sp-client = { path = "../ra-sp-client" }

# Add these lines in workpace Cargo.toml
# [patch.crates-io]
# ring = { git = "https://github.com/crypto-com/ring.git", rev = "4e1862fb0df9efaf2d2c1ec8cacb1e53104f3daa" }
2 changes: 1 addition & 1 deletion chain-tx-enclave-next/mls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ readme = "../../README.md"
edition = "2018"

[dependencies]
ring = "0.16"
ring = "0.16.15"
thiserror = "1.0"
rustls = "0.18"
x509-parser = "0.8.0-beta4"
Expand Down
3 changes: 0 additions & 3 deletions chain-tx-enclave-next/tx-query-next/enclave-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ chain-core = { path = "../../../chain-core", default-features = false, features
enclave-protocol = { path = "../../../enclave-protocol", features = ["edp"] }
enclave-utils = { path = "../../../chain-tx-enclave-next/enclave-utils", features = ["sgxstd"] }
ra-enclave = { path = "../../../chain-tx-enclave-next/enclave-ra/ra-enclave" }

# [patch.crates-io]
# ring = { git = "https://github.com/crypto-com/ring.git", rev = "4e1862fb0df9efaf2d2c1ec8cacb1e53104f3daa" }
22 changes: 17 additions & 5 deletions client-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use client_core::signer::WalletSignerManager;
use client_core::transaction_builder::DefaultWalletTransactionBuilder;
use client_core::types::BalanceChange;
use client_core::wallet::syncer::{
ObfuscationSyncerConfig, ProgressReport, SyncerOptions, WalletSyncer,
spawn_light_client_supervisor, Handle, ObfuscationSyncerConfig, ProgressReport, SyncerOptions,
WalletSyncer,
};
use client_core::wallet::{DefaultWalletClient, WalletClient};
use client_network::network_ops::{DefaultNetworkOpsClient, NetworkOpsClient};
Expand Down Expand Up @@ -385,10 +386,17 @@ impl Command {
block_height_ensure,
} => {
let enckey = ask_seckey(None)?;
let tendermint_client = WebsocketRpcClient::new(&tendermint_url())?;
let rpc_url = tendermint_url();
let tendermint_client = WebsocketRpcClient::new(&rpc_url)?;
let tx_obfuscation = get_tx_query(tendermint_client.clone())?;

let storage = SledStorage::new(storage_path())?;
let db_path = storage_path();
let storage = SledStorage::new(&db_path)?;
let handle = spawn_light_client_supervisor(
db_path.as_ref(),
&rpc_url,
tendermint_client.genesis()?.trusting_period(),
)?;
let config = ObfuscationSyncerConfig::new(
storage.clone(),
tendermint_client,
Expand All @@ -399,8 +407,12 @@ impl Command {
batch_size: *batch_size,
block_height_ensure: *block_height_ensure,
},
handle.clone(),
);
Self::resync(config, name.clone(), enckey, *force, storage)?;
handle
.terminate()
.expect("terminate light client supervisor in client-cli");
Ok(())
}
Command::MultiSig { multisig_command } => {
Expand Down Expand Up @@ -637,8 +649,8 @@ impl Command {
Ok(())
}

fn resync<S: Storage, C: Client, O: TransactionObfuscation>(
config: ObfuscationSyncerConfig<S, C, O>,
fn resync<S: Storage, C: Client, O: TransactionObfuscation, L: Handle + Send + Sync + Clone>(
config: ObfuscationSyncerConfig<S, C, O, L>,
name: String,
enckey: SecKey,
force: bool,
Expand Down
5 changes: 3 additions & 2 deletions client-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ secstr = { version = "0.4.0", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sled = { version = "0.33.0", optional = true }
tendermint = { git = "https://github.com/crypto-com/tendermint-rs.git", default-features = false, rev = "ceca4219d6ae4e4ce906a6579e865af15458fdd6" }
tendermint = "0.15"
tendermint-rpc = "0.15"
tokio = { version = "0.2", features = ["rt-threaded", "sync", "time", "tcp"], optional = true }
tokio-tungstenite = { version = "0.10", features = ["tls"], optional = true }
uuid = { version = "0.8.1", features = ["v4"] }
Expand All @@ -51,4 +52,4 @@ quickcheck = "0.9"
default = ["sled", "websocket-rpc"]
websocket-rpc = ["futures-util", "tokio", "tokio-tungstenite"]
mock-enclave = []
experimental = []
experimental = []
16 changes: 2 additions & 14 deletions client-common/src/cipher/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ where
.collect::<Result<Vec<_>>>()
.expect("abci_query failed");

let sealed_logs = rsps
.into_iter()
.map(|rsp| rsp.value.expect("sealed log query failed"))
.collect::<Vec<_>>();
let sealed_logs = rsps.into_iter().map(|rsp| rsp.value).collect::<Vec<_>>();

let txs = sealed_logs
.into_iter()
Expand Down Expand Up @@ -95,7 +92,6 @@ fn checked_unseal(payload: &[u8], _private_key: &PrivateKey) -> Option<TxWithOut
mod tests {
use super::*;

use crate::tendermint::lite;
use crate::tendermint::types::*;
use crate::PrivateKey;
use chain_core::state::ChainState;
Expand Down Expand Up @@ -135,14 +131,6 @@ mod tests {
unreachable!()
}

fn block_batch_verified<'a, T: Clone + Iterator<Item = &'a u64>>(
&self,
_state: lite::TrustedState,
_heights: T,
) -> Result<(Vec<Block>, lite::TrustedState)> {
unreachable!()
}

fn broadcast_transaction(&self, _transaction: &[u8]) -> Result<BroadcastTxResponse> {
unreachable!()
}
Expand All @@ -155,7 +143,7 @@ mod tests {
_prove: bool,
) -> Result<AbciQuery> {
Ok(AbciQuery {
value: Some(seal(&TxWithOutputs::Transfer(Tx::default()))),
value: seal(&TxWithOutputs::Transfer(Tx::default())),
..Default::default()
})
}
Expand Down
8 changes: 0 additions & 8 deletions client-common/src/tendermint/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::tendermint::lite;
use crate::tendermint::types::*;
use crate::Result;
use chain_core::state::ChainState;
Expand Down Expand Up @@ -26,13 +25,6 @@ pub trait Client: Send + Sync + Clone {
heights: T,
) -> Result<Vec<BlockResultsResponse>>;

/// Fetch continuous blocks and verify them.
fn block_batch_verified<'a, T: Clone + Iterator<Item = &'a u64>>(
&self,
state: lite::TrustedState,
heights: T,
) -> Result<(Vec<Block>, lite::TrustedState)>;

/// Makes `broadcast_tx_sync` call to tendermint
fn broadcast_transaction(&self, transaction: &[u8]) -> Result<BroadcastTxResponse>;

Expand Down
Loading

0 comments on commit e1dc79e

Please sign in to comment.