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

Fix reorg and improve continuity checks #1604

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f3af157
add arc mutex to wallet struct
Oscar-Pepper Dec 16, 2024
5be6a3e
start sync integration
Oscar-Pepper Dec 17, 2024
e49c7f0
first part of zingo sync integration
Oscar-Pepper Dec 20, 2024
9ec9e19
Merge branch 'dev' into sync_status
Oscar-Pepper Dec 20, 2024
c6e986a
fix clippy
Oscar-Pepper Dec 20, 2024
abf54e4
remove --all-features from CI
Oscar-Pepper Dec 23, 2024
30c2f07
solve merge conflicts
Oscar-Pepper Dec 23, 2024
dbf7ea0
added sync status test
Oscar-Pepper Dec 23, 2024
83be516
added sync status with test
Oscar-Pepper Dec 23, 2024
f55d912
removed unecessary fields
Oscar-Pepper Dec 24, 2024
09f28e1
Merge branch 'sync_integration_pt1' into sync_status
Oscar-Pepper Dec 24, 2024
cbb977e
solve conflicts
Oscar-Pepper Dec 24, 2024
3768c5b
resolve conflicts and re-organise
Oscar-Pepper Dec 24, 2024
25ece4d
set new grpc method to debug level logging
Oscar-Pepper Dec 24, 2024
901ee9a
solve conflicts
Oscar-Pepper Dec 26, 2024
36aabd9
Merge branch 'sync_integration_pt1' into sync_status
Oscar-Pepper Dec 26, 2024
d4e2a9c
move forming of vec of subtree roots earlier to use for batching
Oscar-Pepper Dec 26, 2024
52c80ac
improve comments
Oscar-Pepper Dec 26, 2024
f72e996
fix clippy
Oscar-Pepper Dec 26, 2024
597caec
fix conflicts
Oscar-Pepper Dec 26, 2024
a0281c6
implemented batch by shards
Oscar-Pepper Dec 27, 2024
c23b617
fixed punch scan priority
Oscar-Pepper Dec 28, 2024
628f9b4
fix doc warnings
Oscar-Pepper Dec 28, 2024
4a44cdf
fix whitespace
Oscar-Pepper Dec 30, 2024
0d20cf1
implement logic for scanning sapling shard ranges on spend detection
Oscar-Pepper Dec 30, 2024
f74ba3a
set found note shard priorities
Oscar-Pepper Dec 30, 2024
2c4c522
add logic for shard boundaries
Oscar-Pepper Dec 30, 2024
072430c
fix clippy
Oscar-Pepper Dec 30, 2024
28c7c18
remove debug
Oscar-Pepper Dec 30, 2024
fec01ed
fix reorg bug and add end seam block for improved continuity checks
Oscar-Pepper Dec 31, 2024
627769a
fix clippy and combine located tree builds into one spawn blocking
Oscar-Pepper Dec 31, 2024
feb5d2a
revisit wallet data cleanup
Oscar-Pepper Dec 31, 2024
6d4daee
clear locators
Oscar-Pepper Dec 31, 2024
0a21d09
fix bug in
Oscar-Pepper Dec 31, 2024
6175ba0
add max re-org window
Oscar-Pepper Dec 31, 2024
03bbbc8
remove todo
Oscar-Pepper Dec 31, 2024
48b58cb
updated to divarge to a new dev 2 branch
Oscar-Pepper Jan 2, 2025
a264359
remove sync feature
Oscar-Pepper Jan 2, 2025
3391f3b
Merge pull request #1610 from Oscar-Pepper/sync_integration_pt1_revis…
AloeareV Jan 2, 2025
7eae9d6
solved conflicts with dev_2-0
Oscar-Pepper Jan 7, 2025
ac4d743
removed sync feature from libtonode
Oscar-Pepper Jan 7, 2025
9666f33
Merge branch 'sync_status' into shard_ranges
Oscar-Pepper Jan 7, 2025
b561545
Merge branch 'shard_ranges' into fix_reorg_and_improve_continuity_checks
Oscar-Pepper Jan 7, 2025
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: 1 addition & 1 deletion .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --all-features --verbose --workspace --avoid-cfg-tarpaulin --skip-clean --release --timeout 3000 --out xml
args: --verbose --workspace --avoid-cfg-tarpaulin --skip-clean --release --timeout 3000 --out xml

- name: Upload to codecov.io
uses: codecov/codecov-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: Swatinem/rust-cache@v2

- name: Build and archive tests
run: cargo nextest archive --verbose --workspace --all-features --archive-file nextest-archive.tar.zst
run: cargo nextest archive --verbose --workspace --archive-file nextest-archive.tar.zst

- name: Upload archive
uses: actions/upload-artifact@v4
Expand Down
220 changes: 105 additions & 115 deletions darkside-tests/tests/network_interruption_tests.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
use std::{
collections::HashMap,
sync::{
atomic::{AtomicBool, Ordering},
Arc, Mutex,
},
time::Duration,
sync::{atomic::AtomicBool, Arc, Mutex},
};

use darkside_tests::{
constants::DARKSIDE_SEED,
utils::{
create_chainbuild_file, load_chainbuild_file, prepare_darksidewalletd,
create_chainbuild_file, prepare_darksidewalletd,
scenarios::{DarksideEnvironment, DarksideSender},
DarksideHandler,
},
};
use tokio::time::sleep;

use zcash_client_backend::{PoolType, ShieldedProtocol};
use zingolib::config::RegtestNetwork;
use zingolib::get_base_address_macro;
use zingolib::testutils::{scenarios::setup::ClientBuilder, start_proxy_and_connect_lightclient};
use zingolib::{
lightclient::PoolBalances,
wallet::{
data::summaries::TransactionSummaryInterface as _,
transaction_record::{SendType, TransactionKind},
},
};

#[ignore]
#[tokio::test]
Expand Down Expand Up @@ -128,110 +117,111 @@ async fn shielded_note_marked_as_change_chainbuild() {
// json::stringify_pretty(scenario.get_lightclient(0).do_list_notes(true).await, 4)
// );
}
#[ignore]
#[tokio::test]
async fn shielded_note_marked_as_change_test() {
const BLOCKCHAIN_HEIGHT: u64 = 20_000;
let transaction_set = load_chainbuild_file("shielded_note_marked_as_change");
let mut scenario = DarksideEnvironment::default_faucet_recipient(PoolType::Shielded(
ShieldedProtocol::Sapling,
))
.await;
// // FIXME:
// #[ignore]
// #[tokio::test]
// async fn shielded_note_marked_as_change_test() {
// const BLOCKCHAIN_HEIGHT: u64 = 20_000;
// let transaction_set = load_chainbuild_file("shielded_note_marked_as_change");
// let mut scenario = DarksideEnvironment::default_faucet_recipient(PoolType::Shielded(
// ShieldedProtocol::Sapling,
// ))
// .await;

// stage a send to self every thousand blocks
for thousands_blocks_count in 1..BLOCKCHAIN_HEIGHT / 1000 {
scenario
.stage_and_apply_blocks(thousands_blocks_count * 1000 - 2, 0)
.await;
scenario.stage_next_transaction(&transaction_set).await;
scenario
.apply_blocks(thousands_blocks_count * 1000 - 1)
.await;
scenario.stage_next_transaction(&transaction_set).await;
}
// stage and apply final blocks
scenario.stage_and_apply_blocks(BLOCKCHAIN_HEIGHT, 0).await;
// // stage a send to self every thousand blocks
// for thousands_blocks_count in 1..BLOCKCHAIN_HEIGHT / 1000 {
// scenario
// .stage_and_apply_blocks(thousands_blocks_count * 1000 - 2, 0)
// .await;
// scenario.stage_next_transaction(&transaction_set).await;
// scenario
// .apply_blocks(thousands_blocks_count * 1000 - 1)
// .await;
// scenario.stage_next_transaction(&transaction_set).await;
// }
// // stage and apply final blocks
// scenario.stage_and_apply_blocks(BLOCKCHAIN_HEIGHT, 0).await;

// setup gRPC network interrupt conditions
let mut conditional_logic =
HashMap::<&'static str, Box<dyn Fn(Arc<AtomicBool>) + Send + Sync>>::new();
// conditional_logic.insert(
// "get_block_range",
// Box::new(|online: &Arc<AtomicBool>| {
// println!("Turning off, as we received get_block_range call");
// online.store(false, Ordering::Relaxed);
// }),
// );
conditional_logic.insert(
"get_tree_state",
Box::new(|online: Arc<AtomicBool>| {
println!("Turning off, as we received get_tree_state call");
online.store(false, Ordering::Relaxed);
}),
);
conditional_logic.insert(
"get_transaction",
Box::new(|online: Arc<AtomicBool>| {
println!("Turning off, as we received get_transaction call");
online.store(false, Ordering::Relaxed);
}),
);
// // setup gRPC network interrupt conditions
// let mut conditional_logic =
// HashMap::<&'static str, Box<dyn Fn(Arc<AtomicBool>) + Send + Sync>>::new();
// // conditional_logic.insert(
// // "get_block_range",
// // Box::new(|online: &Arc<AtomicBool>| {
// // println!("Turning off, as we received get_block_range call");
// // online.store(false, Ordering::Relaxed);
// // }),
// // );
// conditional_logic.insert(
// "get_tree_state",
// Box::new(|online: Arc<AtomicBool>| {
// println!("Turning off, as we received get_tree_state call");
// online.store(false, Ordering::Relaxed);
// }),
// );
// conditional_logic.insert(
// "get_transaction",
// Box::new(|online: Arc<AtomicBool>| {
// println!("Turning off, as we received get_transaction call");
// online.store(false, Ordering::Relaxed);
// }),
// );

let (_proxy_handle, proxy_status) =
start_proxy_and_connect_lightclient(scenario.get_lightclient(0), conditional_logic);
tokio::task::spawn(async move {
loop {
sleep(Duration::from_secs(5)).await;
proxy_status.store(true, std::sync::atomic::Ordering::Relaxed);
println!("Set proxy status to true");
}
});
// let (_proxy_handle, proxy_status) =
// start_proxy_and_connect_lightclient(scenario.get_lightclient(0), conditional_logic);
// tokio::task::spawn(async move {
// loop {
// sleep(Duration::from_secs(5)).await;
// proxy_status.store(true, std::sync::atomic::Ordering::Relaxed);
// println!("Set proxy status to true");
// }
// });

// start test
scenario.get_lightclient(0).do_sync(false).await.unwrap();
// // start test
// scenario.get_lightclient(0).do_sync(false).await.unwrap();

// debug info
println!("do list_notes:");
println!(
"{}",
json::stringify_pretty(scenario.get_lightclient(0).do_list_notes(true).await, 4)
);
println!("do list tx summaries:");
dbg!(
scenario
.get_lightclient(0)
.sorted_value_transfers(true)
.await
);
// // debug info
// println!("do list_notes:");
// println!(
// "{}",
// json::stringify_pretty(scenario.get_lightclient(0).do_list_notes(true).await, 4)
// );
// println!("do list tx summaries:");
// dbg!(
// scenario
// .get_lightclient(0)
// .sorted_value_transfers(true)
// .await
// );

// assert the balance is correct
assert_eq!(
scenario.get_lightclient(0).do_balance().await,
PoolBalances {
sapling_balance: Some(0),
verified_sapling_balance: Some(0),
spendable_sapling_balance: Some(0),
unverified_sapling_balance: Some(0),
orchard_balance: Some(760_000),
verified_orchard_balance: Some(760_000),
unverified_orchard_balance: Some(0),
spendable_orchard_balance: Some(760_000),
transparent_balance: Some(0),
}
);
// assert all fees are 10000 zats
let transaction_summaries = scenario.get_lightclient(0).transaction_summaries().await;
for summary in transaction_summaries.iter() {
if let Some(fee) = summary.fee() {
assert_eq!(fee, 10_000);
}
}
// assert the number of shields are correct
assert_eq!(
transaction_summaries
.iter()
.filter(|summary| summary.kind() == TransactionKind::Sent(SendType::Shield))
.count(),
(BLOCKCHAIN_HEIGHT / 1000 - 1) as usize
);
}
// // assert the balance is correct
// assert_eq!(
// scenario.get_lightclient(0).do_balance().await,
// PoolBalances {
// sapling_balance: Some(0),
// verified_sapling_balance: Some(0),
// spendable_sapling_balance: Some(0),
// unverified_sapling_balance: Some(0),
// orchard_balance: Some(760_000),
// verified_orchard_balance: Some(760_000),
// unverified_orchard_balance: Some(0),
// spendable_orchard_balance: Some(760_000),
// transparent_balance: Some(0),
// }
// );
// // assert all fees are 10000 zats
// let transaction_summaries = scenario.get_lightclient(0).transaction_summaries().await;
// for summary in transaction_summaries.iter() {
// if let Some(fee) = summary.fee() {
// assert_eq!(fee, 10_000);
// }
// }
// // assert the number of shields are correct
// assert_eq!(
// transaction_summaries
// .iter()
// .filter(|summary| summary.kind() == TransactionKind::Sent(SendType::Shield))
// .count(),
// (BLOCKCHAIN_HEIGHT / 1000 - 1) as usize
// );
// }
13 changes: 4 additions & 9 deletions darkside-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use darkside_tests::utils::update_tree_states_for_transaction;
use darkside_tests::utils::DarksideHandler;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use testvectors::seeds::DARKSIDE_SEED;
use tokio::time::sleep;
use zcash_client_backend::PoolType::Shielded;
Expand Down Expand Up @@ -59,11 +58,6 @@ async fn simple_sync() {
);
}

#[tokio::test]
async fn reorg_away_receipt_blaze() {
reorg_receipt_sync_generic(|lc| Box::pin(async { lc.do_sync(true).await.map(|_| ()) })).await;
}

#[ignore = "attempts to unwrap failed checked_sub on sapling output count"]
#[tokio::test]
async fn reorg_away_receipt_pepper() {
Expand All @@ -74,7 +68,7 @@ async fn reorg_away_receipt_pepper() {
.get_client()
.await
.unwrap();
zingo_sync::sync::sync(client, &lc.config().chain.clone(), &mut lc.wallet)
zingo_sync::sync::sync(client, &lc.config().chain.clone(), lc.wallet.clone())
.await
.map_err(|e| e.to_string())
})
Expand Down Expand Up @@ -331,6 +325,7 @@ async fn evicted_transaction_is_rebroadcast() {
);
});

let ref_primary: Arc<LightClient> = Arc::new(primary);
LightClient::start_mempool_monitor(ref_primary).unwrap();
// FIXME:
// let ref_primary: Arc<LightClient> = Arc::new(primary);
// LightClient::start_mempool_monitor(ref_primary).unwrap();
}
2 changes: 1 addition & 1 deletion libtonode-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ci = ["zingolib/ci"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
zingolib = { path = "../zingolib", features = ["deprecations", "test-elevation", "sync"] }
zingolib = { path = "../zingolib", features = [ "deprecations", "test-elevation" ] }
zingo-status = { path = "../zingo-status" }
zingo-netutils = { path = "../zingo-netutils" }
zingo-sync = { path = "../zingo-sync" }
Expand Down
Loading
Loading