Skip to content
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

[r2r] Zcoin native mode support integration & multi lightwalletd servers support #1438

Merged
merged 66 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
dc9839f
WIP init_native_client,RpcClient, ZcoinNativeClientInitError added
laruh Jul 14, 2022
b76ff67
WIP match added in current_block check
laruh Jul 15, 2022
ae6a842
WIP trying trait Client
laruh Jul 15, 2022
646126d
WIP serialized_block added
laruh Jul 15, 2022
ddcffdb
WIP remove BlockIDNative, BlockRangeNative
laruh Jul 15, 2022
f70493f
WIP use if let
laruh Jul 18, 2022
c68fcd9
Merge remote-tracking branch 'origin/dev' into native_mode_support
laruh Jul 18, 2022
7724cb7
WIP merge fix
laruh Jul 18, 2022
7f00005
WIP if let added in check_watch_for_tx_existence
laruh Jul 18, 2022
187bb7d
WIP client.clone() added
laruh Jul 19, 2022
10e9790
WIP match for get_raw_tx added
laruh Jul 19, 2022
df68b93
WIP
laruh Jul 19, 2022
3fc0ed9
[r2r] trait impl comment removed
laruh Jul 20, 2022
f7cb333
WIP
laruh Jul 26, 2022
3265803
WIP
laruh Jul 26, 2022
5d5ce17
WIP
laruh Jul 26, 2022
c200dab
WIP
laruh Jul 26, 2022
37e9e2f
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Jul 26, 2022
efbe95b
WIP no method named `to_bytes`jubjub
laruh Jul 27, 2022
e235c03
WIP group crate added
laruh Jul 27, 2022
4085046
WIP
laruh Jul 27, 2022
cf6cc09
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Jul 29, 2022
c08e3ff
WIP merge fixes
laruh Jul 29, 2022
a8cbc72
WIP log! added
laruh Aug 1, 2022
1e84019
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 1, 2022
fc78a13
WIP log
laruh Aug 1, 2022
82595c9
WIP verbose in getblockheader should be boolean
laruh Aug 1, 2022
3bc4b3b
WIP fee 0 for transparent inputs
laruh Aug 2, 2022
1754dc6
WIP Deafult added for CompactTxNative
laruh Aug 2, 2022
59b9b52
WIP custom structures were removed
laruh Aug 3, 2022
2195b0d
WIP z_coin_grpc compact structs
laruh Aug 3, 2022
a7b9c66
WIP
laruh Aug 3, 2022
52e16ac
WIP fix fmt
laruh Aug 3, 2022
87f6e19
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 3, 2022
e5a28d0
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 5, 2022
5a8d823
WIP
laruh Aug 5, 2022
c98ac4e
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 5, 2022
0eb2517
WIP empty header
laruh Aug 5, 2022
29af60c
r2r
laruh Aug 8, 2022
f35a072
r2r
laruh Aug 8, 2022
283f906
r2r ZcoinClientInitError
laruh Aug 8, 2022
601e06a
First review iteration
laruh Aug 8, 2022
08df23e
WIP trait added
laruh Aug 9, 2022
089f22e
WIP reference removed
laruh Aug 9, 2022
9dc0d78
remove rpc_client, impl additional method
laruh Aug 9, 2022
4006f9b
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 10, 2022
b4c50fd
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 10, 2022
581f674
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 11, 2022
1f46d98
fix errors
laruh Aug 11, 2022
8fb9060
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 16, 2022
45549b2
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Aug 18, 2022
83c450c
WIP LightwalletdImpl and LightwalletdConnection added
laruh Aug 26, 2022
1816d60
r2r native mode support for zcoin
laruh Sep 2, 2022
b80ea9b
WIP multi lightwalletd servers support
laruh Sep 2, 2022
2663a56
WIP use drop_mutability
laruh Sep 2, 2022
2b2b9ca
WIP added RpcClientInitErr, one cache paths, attempts fixed
laruh Sep 6, 2022
7f89dfa
WIP propagate the error instead of panic, mutable watch_for_tx remove…
laruh Sep 7, 2022
ea8f18f
WIP async_blocking added in create_wallet_db
laruh Sep 7, 2022
29f7bce
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Sep 7, 2022
c42fc8d
Merge remote-tracking branch 'origin/dev' into zcoin_native_mode_support
laruh Sep 7, 2022
610a2f4
remove some unnecessary code for multi servers
laruh Sep 8, 2022
e1f0add
remove unused code
laruh Sep 9, 2022
a3cfe1f
type OnCompactBlockFn added
laruh Sep 9, 2022
45ad18f
rename to check_tx_existence, add return bool, databases init moved t…
laruh Sep 9, 2022
da01b73
leave Vec of urls for init_light_client
laruh Sep 9, 2022
e61a4d5
fix clippy
laruh Sep 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ethkey = { git = "https://github.com/artemii235/parity-ethereum.git" }
futures01 = { version = "0.1", package = "futures" }
# using select macro requires the crate to be named futures, compilation failed with futures03 name
futures = { version = "0.3", package = "futures", features = ["compat", "async-await"] }
group = "0.8.0"
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
gstuff = { version = "0.7", features = ["nightly"] }
hex = "0.4.2"
http = "0.2"
Expand Down
6 changes: 3 additions & 3 deletions mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,14 @@ pub enum EstimateFeeMethod {
SmartFee,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum BlockNonce {
String(String),
U64(u64),
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Serialize)]
pub struct VerboseBlock {
/// Block hash
pub hash: H256Json,
Expand Down Expand Up @@ -1124,7 +1124,7 @@ impl NativeClientImpl {

/// https://developer.bitcoin.org/reference/rpc/getblockheader.html
pub fn get_block_header_bytes(&self, block_hash: H256Json) -> RpcRes<BytesJson> {
let verbose = 0;
let verbose = false;
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
rpc_func!(self, "getblockheader", block_hash, verbose)
}
}
Expand Down
44 changes: 27 additions & 17 deletions mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ use futures::compat::Future01CompatExt;
use futures::lock::Mutex as AsyncMutex;
use futures::{FutureExt, TryFutureExt};
use futures01::Future;
use http::Uri;
use keys::hash::H256;
use keys::{KeyPair, Message, Public};
use mm2_core::mm_ctx::MmArc;
use mm2_err_handle::prelude::*;
use mm2_number::{BigDecimal, MmNumber};
#[cfg(test)] use mocktopus::macros::*;
use parking_lot::Mutex;
use primitives::bytes::Bytes;
use rpc::v1::types::{Bytes as BytesJson, Transaction as RpcTransaction, H256 as H256Json};
use script::{Builder as ScriptBuilder, Opcode, Script, TransactionInputSigner};
use serde_json::Value as Json;
use serialization::CoinVariant;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use zcash_client_backend::data_api::WalletRead;
use zcash_client_backend::encoding::{decode_payment_address, encode_extended_spending_key, encode_payment_address};
Expand All @@ -70,9 +69,10 @@ use z_htlc::{z_p2sh_spend, z_send_dex_fee, z_send_htlc};

mod z_rpc;
pub use z_rpc::SyncStatus;
use z_rpc::{init_light_client, SaplingSyncConnector, SaplingSyncGuard, WalletDbShared};
use z_rpc::{init_light_client, init_native_client, SaplingSyncConnector, SaplingSyncGuard, WalletDbShared};

mod z_coin_errors;
use crate::z_coin::z_rpc::{create_wallet_db, BlockDb};
pub use z_coin_errors::*;

#[cfg(all(test, feature = "zhtlc-native-tests"))]
Expand Down Expand Up @@ -766,29 +766,39 @@ impl<'a> UtxoCoinWithIguanaPrivKeyBuilder for ZCoinBuilder<'a> {
);

let evk = ExtendedFullViewingKey::from(&self.z_spending_key);
let cache_db_path = self.db_dir_path.join(format!("{}_cache.db", self.ticker));
let wallet_db_path = self.db_dir_path.join(format!("{}_wallet.db", self.ticker));
let blocks_db =
async_blocking(|| BlockDb::for_path(cache_db_path).map_to_mm(ZcoinClientInitError::BlocksDbInitFailure))
.await?;
let wallet_db = create_wallet_db(
wallet_db_path,
self.protocol_info.consensus_params.clone(),
self.protocol_info.check_point_block.clone(),
evk,
)
.await?;
let wallet_db = Arc::new(Mutex::new(wallet_db));
let (sync_state_connector, light_wallet_db) = match &self.z_coin_params.mode {
ZcoinRpcMode::Native => {
return MmError::err(ZCoinBuildError::NativeModeIsNotSupportedYet);
let native_client = self.native_client()?;
init_native_client(
native_client,
blocks_db,
wallet_db,
self.protocol_info.consensus_params.clone(),
)
.await?
},
ZcoinRpcMode::Light {
light_wallet_d_servers, ..
} => {
let cache_db_path = self.db_dir_path.join(format!("{}_light_cache.db", self.ticker));
let wallet_db_path = self.db_dir_path.join(format!("{}_light_wallet.db", self.ticker));
// TODO multi lightwalletd servers support will be added on the next iteration
let uri = Uri::from_str(
light_wallet_d_servers
.first()
.or_mm_err(|| ZCoinBuildError::EmptyLightwalletdUris)?,
)?;

init_light_client(
uri,
cache_db_path,
wallet_db_path,
light_wallet_d_servers.clone(),
blocks_db,
wallet_db,
self.protocol_info.consensus_params.clone(),
self.protocol_info.check_point_block,
evk,
)
.await?
},
Expand Down
37 changes: 24 additions & 13 deletions mm2src/coins/z_coin/z_coin_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::utxo::rpc_clients::UtxoRpcError;
use crate::utxo::utxo_builder::UtxoCoinBuildError;
use crate::WithdrawError;
use crate::{NumConversError, PrivKeyNotAllowed};
use common::jsonrpc_client::JsonRpcError;
use db_common::sqlite::rusqlite::Error as SqliteError;
use db_common::sqlite::rusqlite::Error as SqlError;
use derive_more::Display;
Expand All @@ -19,6 +20,9 @@ pub enum UpdateBlocksCacheErr {
GrpcError(tonic::Status),
BlocksDbError(SqliteError),
ZcashSqliteError(ZcashClientError),
UtxoRpcError(UtxoRpcError),
InternalError(String),
JsonRpcError(JsonRpcError),
}

impl From<tonic::Status> for UpdateBlocksCacheErr {
Expand All @@ -33,18 +37,32 @@ impl From<ZcashClientError> for UpdateBlocksCacheErr {
fn from(err: ZcashClientError) -> Self { UpdateBlocksCacheErr::ZcashSqliteError(err) }
}

impl From<UtxoRpcError> for UpdateBlocksCacheErr {
fn from(err: UtxoRpcError) -> Self { UpdateBlocksCacheErr::UtxoRpcError(err) }
}

impl From<JsonRpcError> for UpdateBlocksCacheErr {
fn from(err: JsonRpcError) -> Self { UpdateBlocksCacheErr::JsonRpcError(err) }
}

#[derive(Debug, Display)]
#[non_exhaustive]
pub enum ZcoinLightClientInitError {
pub enum ZcoinClientInitError {
TlsConfigFailure(tonic::transport::Error),
ConnectionFailure(tonic::transport::Error),
BlocksDbInitFailure(SqliteError),
WalletDbInitFailure(SqliteError),
ZcashSqliteError(ZcashClientError),
EmptyLightwalletdUris,
InvalidUri(InvalidUri),
}

impl From<ZcashClientError> for ZcoinLightClientInitError {
fn from(err: ZcashClientError) -> Self { ZcoinLightClientInitError::ZcashSqliteError(err) }
impl From<ZcashClientError> for ZcoinClientInitError {
fn from(err: ZcashClientError) -> Self { ZcoinClientInitError::ZcashSqliteError(err) }
}

impl From<InvalidUri> for ZcoinClientInitError {
fn from(err: InvalidUri) -> Self { ZcoinClientInitError::InvalidUri(err) }
}

#[derive(Debug, Display)]
Expand Down Expand Up @@ -182,10 +200,7 @@ pub enum ZCoinBuildError {
path: String,
},
Io(std::io::Error),
EmptyLightwalletdUris,
NativeModeIsNotSupportedYet,
InvalidLightwalletdUri(InvalidUri),
LightClientInitErr(ZcoinLightClientInitError),
RpcClientInitErr(ZcoinClientInitError),
ZCashParamsNotFound,
}

Expand All @@ -205,12 +220,8 @@ impl From<std::io::Error> for ZCoinBuildError {
fn from(err: std::io::Error) -> ZCoinBuildError { ZCoinBuildError::Io(err) }
}

impl From<InvalidUri> for ZCoinBuildError {
fn from(err: InvalidUri) -> Self { ZCoinBuildError::InvalidLightwalletdUri(err) }
}

impl From<ZcoinLightClientInitError> for ZCoinBuildError {
fn from(err: ZcoinLightClientInitError) -> Self { ZCoinBuildError::LightClientInitErr(err) }
impl From<ZcoinClientInitError> for ZCoinBuildError {
fn from(err: ZcoinClientInitError) -> Self { ZCoinBuildError::RpcClientInitErr(err) }
}

pub(super) enum SqlTxHistoryError {
Expand Down
Loading