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

Add viewkey only benchmark #411

Merged
merged 24 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c3b709c
prefer PathBuf to String where appropriate
zancas Jul 6, 2023
df68910
fix annotation storage location
zancas Jul 6, 2023
2ee9097
make DurationAnnotation fields pub
zancas Jul 6, 2023
8ea59f9
move build_fvk_client_capability to zingo-testutils
zancas Jul 10, 2023
b183949
migrate viewkey builder to utils
zancas Jul 10, 2023
fb35c83
start on unsynced view client fixture
zancas Jul 10, 2023
cdd6563
finish layout of fixture
zancas Jul 10, 2023
26d0da9
generalize enough to permit new scenarios
zancas Jul 11, 2023
51e10a0
basic view-only benchmark complete
zancas Jul 11, 2023
26cbed7
write down annotations in a single location
zancas Jul 11, 2023
cdfdc42
update such that funded wallet provides the capability
zancas Jul 11, 2023
2622568
factor fvk builder into capability parameterized fn
zancas Jul 11, 2023
b28af6b
remove redundant test helper
zancas Jul 11, 2023
853165d
finish removing redundant impl
zancas Jul 11, 2023
50d7be7
remove/move uninteresting test, and unused helper
zancas Jul 11, 2023
17ad505
update public constructor names
zancas Jul 11, 2023
d4dc53a
remove integration_test feature, combine all LightClient constructors…
zancas Jul 11, 2023
119c98a
alphabetize contructors
zancas Jul 11, 2023
35db3ed
alphabetize non-constructors
zancas Jul 11, 2023
295e89a
apply clippy comment
zancas Jul 11, 2023
fe5699e
viewonly client has orchard, sapling, and transparent view keys
zancas Jul 11, 2023
5ad42ba
rename ClientManager -> ClientBuilder
zancas Jul 11, 2023
01d5f65
make argument to timing_run correct for fullview
zancas Jul 11, 2023
e52cb9f
ClientManager -> ClientBuilder in darkside
zancas Jul 12, 2023
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions zingo-testutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ edition = "2021"
zingoconfig = { path = "../zingoconfig" }
zingolib = { path = "../zingolib" }
zcash_primitives = { workspace = true }
zcash_address = { workspace = true }
orchard = { workspace = true }
portpicker = { workspace = true}
tempdir = { workspace = true }
json = "0.12.4"
Expand Down
117 changes: 97 additions & 20 deletions zingo-testutils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub mod data;
pub use incrementalmerkletree;
use zcash_address::unified::{Fvk, Ufvk};
use zingolib::wallet::keys::unified::WalletCapability;
use zingolib::wallet::WalletBase;
pub mod regtest;
use std::fs::OpenOptions;
use std::io::Read;
Expand All @@ -17,12 +20,53 @@ use zingolib::lightclient::LightClient;

use crate::scenarios::setup::TestEnvironmentGenerator;

pub fn build_fvks_from_wallet_capability(wallet_capability: &WalletCapability) -> [Fvk; 3] {
let o_fvk = Fvk::Orchard(
orchard::keys::FullViewingKey::try_from(wallet_capability)
.unwrap()
.to_bytes(),
);
let s_fvk = Fvk::Sapling(
zcash_primitives::zip32::sapling::DiversifiableFullViewingKey::try_from(wallet_capability)
.unwrap()
.to_bytes(),
);
let mut t_fvk_bytes = [0u8; 65];
let t_ext_pk: zingolib::wallet::keys::extended_transparent::ExtendedPubKey =
(wallet_capability).try_into().unwrap();
t_fvk_bytes[0..32].copy_from_slice(&t_ext_pk.chain_code[..]);
t_fvk_bytes[32..65].copy_from_slice(&t_ext_pk.public_key.serialize()[..]);
let t_fvk = Fvk::P2pkh(t_fvk_bytes);
[o_fvk, s_fvk, t_fvk]
}
pub async fn build_fvk_client_and_capability(
fvks: &[&Fvk],
zingoconfig: &ZingoConfig,
) -> (LightClient, WalletCapability) {
let ufvk = zcash_address::unified::Encoding::encode(
&<Ufvk as zcash_address::unified::Encoding>::try_from_items(
fvks.iter().copied().cloned().collect(),
)
.unwrap(),
&zcash_address::Network::Regtest,
);
let viewkey_client =
LightClient::create_unconnected(zingoconfig, WalletBase::Ufvk(ufvk), 0).unwrap();
let watch_wc = viewkey_client
.wallet
.wallet_capability()
.read()
.await
.clone();
(viewkey_client, watch_wc)
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct DurationAnnotation {
timestamp: u64,
git_description: String,
test_name: String,
duration: Duration,
pub timestamp: u64,
pub git_description: String,
pub test_name: String,
pub duration: Duration,
}
impl DurationAnnotation {
pub fn new(test_name: String, duration: Duration) -> Self {
Expand Down Expand Up @@ -66,8 +110,7 @@ fn timestamp() -> u64 {
.unwrap()
.as_secs()
}
fn path_to_times(basename: String) -> PathBuf {
let file_name = PathBuf::from(basename);
fn path_to_times(file_name: PathBuf) -> PathBuf {
let timing_dir = PathBuf::from(
std::env::var("CARGO_MANIFEST_DIR").expect("To be inside a manifested space."),
)
Expand All @@ -82,18 +125,20 @@ pub fn read_duration_annotation_file(target: PathBuf) -> Vec<DurationAnnotation>
};
data_set
}
pub fn get_duration_annotations(storage_file: PathBuf) -> Vec<DurationAnnotation> {
read_duration_annotation_file(storage_file)
}
pub fn record_time(annotation: &DurationAnnotation) {
let basename = format!("{}.json", annotation.test_name);
let data_store = path_to_times(basename);

let mut data_set = read_duration_annotation_file(data_store.clone());
let storage_location =
path_to_times(PathBuf::from("sync_duration_annotation.json".to_string()));
let mut data_set = get_duration_annotations(storage_location.clone());
data_set.push(annotation.clone());

//let json_dataset = array!(data_set);
let mut time_file = OpenOptions::new()
.create(true)
.write(true)
.open(data_store)
.open(storage_location)
.expect("to access a data_store file");
std::io::Write::write_all(
&mut time_file,
Expand Down Expand Up @@ -269,7 +314,7 @@ pub mod scenarios {
use super::regtest::{ChildProcessHandler, RegtestManager};
use zingolib::{get_base_address, lightclient::LightClient};

use self::setup::ClientManager;
use self::setup::ClientBuilder;

use super::increase_height_and_sync_client;
pub mod setup {
Expand All @@ -282,7 +327,7 @@ pub mod scenarios {
pub struct ScenarioBuilder {
pub test_env: TestEnvironmentGenerator,
pub regtest_manager: RegtestManager,
pub client_builder: ClientManager,
pub client_builder: ClientBuilder,
pub child_process_handler: Option<ChildProcessHandler>,
}
impl ScenarioBuilder {
Expand All @@ -300,7 +345,7 @@ pub mod scenarios {
} else {
regtest_manager.zingo_datadir.clone()
};
let client_builder = ClientManager::new(
let client_builder = ClientBuilder::new(
test_env.get_lightwalletd_uri(),
data_dir,
data::seeds::ABANDON_ART_SEED,
Expand Down Expand Up @@ -371,17 +416,17 @@ pub mod scenarios {

/// Internally (and perhaps in wider scopes) we say "Sprout" to mean
/// take a seed, and generate a client from the seed (planted in the chain).
pub struct ClientManager {
pub struct ClientBuilder {
pub server_id: http::Uri,
pub zingo_datadir: PathBuf,
seed: String,
client_number: u8,
}
impl ClientManager {
impl ClientBuilder {
pub fn new(server_id: http::Uri, zingo_datadir: PathBuf, seed: &str) -> Self {
let seed = seed.to_string();
let client_number = 0;
ClientManager {
ClientBuilder {
server_id,
zingo_datadir,
seed,
Expand Down Expand Up @@ -416,7 +461,7 @@ pub mod scenarios {
) -> LightClient {
//! A "faucet" is a lightclient that receives mining rewards
let zingo_config = self.make_unique_data_dir_and_load_config();
LightClient::new_from_wallet_base_async(
LightClient::create_from_wallet_base_async(
WalletBase::MnemonicPhrase(self.seed.clone()),
&zingo_config,
birthday,
Expand All @@ -432,7 +477,7 @@ pub mod scenarios {
overwrite: bool,
) -> LightClient {
let zingo_config = self.make_unique_data_dir_and_load_config();
LightClient::new_from_wallet_base_async(
LightClient::create_from_wallet_base_async(
WalletBase::MnemonicPhrase(mnemonic_phrase),
&zingo_config,
birthday,
Expand Down Expand Up @@ -515,7 +560,7 @@ pub mod scenarios {
}
}
}
pub fn custom_clients() -> (RegtestManager, ChildProcessHandler, ClientManager) {
pub fn custom_clients() -> (RegtestManager, ChildProcessHandler, ClientBuilder) {
let sb = setup::ScenarioBuilder::build_configure_launch(
Some(REGSAP_ADDR_FROM_ABANDONART.to_string()),
None,
Expand Down Expand Up @@ -620,13 +665,45 @@ pub mod scenarios {
)
}
pub mod chainload {
use crate::{build_fvk_client_and_capability, build_fvks_from_wallet_capability};

use super::*;

pub async fn unsynced_basic() -> ChildProcessHandler {
setup::ScenarioBuilder::new_load_1153_saplingcb_regtest_chain()
.child_process_handler
.unwrap()
}
pub async fn unsynced_viewonlyclient_1153(
) -> (RegtestManager, ChildProcessHandler, LightClient) {
let mut sb = setup::ScenarioBuilder::new_load_1153_saplingcb_regtest_chain();
let zingo_config = zingolib::load_clientconfig(
sb.client_builder.server_id.clone(),
Some(sb.client_builder.zingo_datadir.clone()),
zingoconfig::ChainType::Regtest,
)
.unwrap();
// Create a lightclient to extract a capability from.
let original_recipient = sb.client_builder.build_new_faucet(0, false).await;
// Extract viewing keys
let wallet_capability = original_recipient
.wallet
.wallet_capability()
.read()
.await
.clone();
// Delete the client after getting the capability.
drop(original_recipient);
// Extract the orchard fvk
let [o_fvk, s_fvk, t_fvk] = build_fvks_from_wallet_capability(&wallet_capability);
let (viewing_client, _) =
build_fvk_client_and_capability(&[&o_fvk, &s_fvk, &t_fvk], &zingo_config).await;
(
sb.regtest_manager,
sb.child_process_handler.unwrap(),
viewing_client,
)
}
pub async fn faucet_recipient_1153() -> (
RegtestManager,
ChildProcessHandler,
Expand Down
2 changes: 1 addition & 1 deletion zingocli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ zcash_primitives = { workspace = true }
tempdir = { workspace = true }
portpicker = { workspace = true }
env_logger = "0.10.0"
zingolib = { path = "../zingolib/", features = ["integration_test"] }
zingolib = { path = "../zingolib/" }
bech32 = "0.9.0"
rand = "0.8.5"
hex = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions zingocli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,13 @@ pub fn startup(
"Cannot initiate a wallet with a seed and a viewing key simultaneously",
));
}
(Some(phrase), None) => Arc::new(LightClient::new_from_wallet_base(
(Some(phrase), None) => Arc::new(LightClient::create_from_wallet_base(
WalletBase::MnemonicPhrase(phrase),
&config,
filled_template.birthday,
false,
)?),
(None, Some(ufvk)) => Arc::new(LightClient::new_from_wallet_base(
(None, Some(ufvk)) => Arc::new(LightClient::create_from_wallet_base(
WalletBase::Ufvk(ufvk),
&config,
filled_template.birthday,
Expand Down
8 changes: 4 additions & 4 deletions zingocli/tests/darkside/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::darkside::{
use json::JsonValue;

use tokio::time::sleep;
use zingo_testutils::scenarios::setup::ClientManager;
use zingo_testutils::scenarios::setup::ClientBuilder;
use zingolib::{get_base_address, lightclient::LightClient};

use std::sync::Arc;
Expand Down Expand Up @@ -216,7 +216,7 @@ async fn simple_sync() {
.await
.unwrap();

let light_client = ClientManager::new(
let light_client = ClientBuilder::new(
server_id,
darkside_handler.darkside_dir.clone(),
DARKSIDE_SEED,
Expand Down Expand Up @@ -267,7 +267,7 @@ async fn reorg_away_receipt() {
.await
.unwrap();

let light_client = ClientManager::new(
let light_client = ClientBuilder::new(
server_id.clone(),
darkside_handler.darkside_dir.clone(),
DARKSIDE_SEED,
Expand Down Expand Up @@ -332,7 +332,7 @@ async fn sent_transaction_reorged_into_mempool() {
.await
.unwrap();

let mut client_manager = ClientManager::new(
let mut client_manager = ClientBuilder::new(
server_id.clone(),
darkside_handler.darkside_dir.clone(),
DARKSIDE_SEED,
Expand Down
Loading