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

Fixed output batching #1615

Open
wants to merge 54 commits into
base: dev_2-0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
dbf7ea0
added sync status test
Oscar-Pepper Dec 23, 2024
83be516
added sync status with test
Oscar-Pepper Dec 23, 2024
09f28e1
Merge branch 'sync_integration_pt1' into sync_status
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
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
0d37159
get block range returns a stream
Oscar-Pepper Jan 2, 2025
0b6f68b
implemented batcher
Oscar-Pepper Jan 3, 2025
182eb2f
added fixed output batching
Oscar-Pepper Jan 7, 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
1a1233c
Merge branch 'fix_reorg_and_improve_continuity_checks' into fixed_out…
Oscar-Pepper Jan 7, 2025
69fe10f
start work on setting scanned ranges correctly in post-scan processing
Oscar-Pepper Jan 7, 2025
24aa381
improve scan task split
Oscar-Pepper Jan 7, 2025
59dfbef
complete batcher with linear scanning continuity checks
Oscar-Pepper Jan 7, 2025
7b9ddc4
fix clippy warnings
Oscar-Pepper Jan 7, 2025
790f417
added outputs to initial sync state
Oscar-Pepper Jan 15, 2025
b8b2aca
updated sync status to include outputs
Oscar-Pepper Jan 16, 2025
a18ec66
format
Oscar-Pepper Jan 16, 2025
f792789
solve merge conflicts with sync_status branch changes
Oscar-Pepper Jan 16, 2025
312f5c8
solve merge conflicts with shard_ranges branch changes
Oscar-Pepper Jan 16, 2025
ce51a0d
solve merge conflicts and update to changes in sync_status branch
Oscar-Pepper Jan 16, 2025
23f4442
retain all scanned ranges boundary blocks in the wallet
Oscar-Pepper Jan 16, 2025
c9b898b
Merge branch 'fix_reorg_and_improve_continuity_checks' into fixed_out…
Oscar-Pepper Jan 16, 2025
45c95e6
fix overflow bugs
Oscar-Pepper Jan 16, 2025
fb2685a
Merge branch 'sync_status' into shard_ranges
Oscar-Pepper Jan 16, 2025
5c34d84
Merge branch 'shard_ranges' into fix_reorg_and_improve_continuity_checks
Oscar-Pepper Jan 16, 2025
4f42071
Merge branch 'fix_reorg_and_improve_continuity_checks' into fixed_out…
Oscar-Pepper Jan 16, 2025
20c0eb4
fix case where block height is lower than activation height when dete…
Oscar-Pepper Jan 17, 2025
acfd0af
Merge branch 'shard_ranges' into fix_reorg_and_improve_continuity_checks
Oscar-Pepper Jan 17, 2025
1372b69
solve merge conflicts with changes to shard_ranges branch
Oscar-Pepper Jan 17, 2025
9339488
small cleanup
Oscar-Pepper Jan 17, 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
3 changes: 1 addition & 2 deletions libtonode-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ edition = "2021"
[features]
chain_generic_tests = []
ci = ["zingolib/ci"]
sync = ["dep:zingo-sync"]

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

bip0039.workspace = true
Expand Down
55 changes: 53 additions & 2 deletions libtonode-tests/tests/sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::time::Duration;

use tempfile::TempDir;
use testvectors::seeds::HOSPITAL_MUSEUM_SEED;
use zingo_netutils::GrpcConnector;
use zingo_sync::sync::sync;
use zingo_sync::sync::{self, sync};
use zingolib::{
config::{construct_lightwalletd_uri, load_clientconfig, DEFAULT_LIGHTWALLETD_SERVER},
get_base_address_macro,
Expand All @@ -10,7 +12,7 @@ use zingolib::{
wallet::WalletBase,
};

#[ignore = "too slow, and flakey"]
#[ignore = "temporary mainnet test for sync development"]
#[tokio::test]
async fn sync_mainnet_test() {
rustls::crypto::ring::default_provider()
Expand Down Expand Up @@ -49,6 +51,55 @@ async fn sync_mainnet_test() {
dbg!(&wallet.sync_state);
}

#[ignore = "mainnet test for large chain"]
#[tokio::test]
async fn sync_status() {
rustls::crypto::ring::default_provider()
.install_default()
.expect("Ring to work as a default");
tracing_subscriber::fmt().init();

let uri = construct_lightwalletd_uri(Some(DEFAULT_LIGHTWALLETD_SERVER.to_string()));
let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path().to_path_buf();
let config = load_clientconfig(
uri.clone(),
Some(temp_path),
zingolib::config::ChainType::Mainnet,
true,
)
.unwrap();
let lightclient = LightClient::create_from_wallet_base_async(
WalletBase::from_string(HOSPITAL_MUSEUM_SEED.to_string()),
&config,
2_750_000,
// 2_670_000,
true,
)
.await
.unwrap();

let client = GrpcConnector::new(uri).get_client().await.unwrap();

let wallet = lightclient.wallet.clone();
let sync_handle = tokio::spawn(async move {
sync(client, &config.chain, wallet).await.unwrap();
});

let wallet = lightclient.wallet.clone();
tokio::spawn(async move {
loop {
let wallet = wallet.clone();
let sync_status = sync::sync_status(wallet).await;
dbg!(sync_status);
tokio::time::sleep(Duration::from_secs(1)).await;
}
});

sync_handle.await.unwrap();
}

// temporary test for sync development
#[tokio::test]
async fn sync_test() {
tracing_subscriber::fmt().init();
Expand Down
24 changes: 16 additions & 8 deletions zingo-sync/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ pub enum FetchRequest {
/// Gets the height of the blockchain from the server.
ChainTip(oneshot::Sender<BlockId>),
/// Gets the specified range of compact blocks from the server (end exclusive).
CompactBlockRange(oneshot::Sender<Vec<CompactBlock>>, Range<BlockHeight>),
CompactBlockRange(
oneshot::Sender<tonic::Streaming<CompactBlock>>,
Range<BlockHeight>,
),
/// Gets the tree states for a specified block height.
TreeState(oneshot::Sender<TreeState>, BlockHeight),
/// Get a full transaction by txid.
Expand Down Expand Up @@ -74,14 +77,14 @@ pub async fn get_chain_height(
pub async fn get_compact_block_range(
fetch_request_sender: UnboundedSender<FetchRequest>,
block_range: Range<BlockHeight>,
) -> Result<Vec<CompactBlock>, ()> {
) -> Result<tonic::Streaming<CompactBlock>, ()> {
let (reply_sender, reply_receiver) = oneshot::channel();
fetch_request_sender
.send(FetchRequest::CompactBlockRange(reply_sender, block_range))
.unwrap();
let compact_blocks = reply_receiver.await.unwrap();
let block_stream = reply_receiver.await.unwrap();

Ok(compact_blocks)
Ok(block_stream)
}

/// Gets the stream of shards (subtree roots)
Expand All @@ -93,7 +96,7 @@ pub async fn get_subtree_roots(
start_index: u32,
shielded_protocol: i32,
max_entries: u32,
) -> Result<tonic::Streaming<SubtreeRoot>, ()> {
) -> Result<Vec<SubtreeRoot>, ()> {
let (reply_sender, reply_receiver) = oneshot::channel();
fetch_request_sender
.send(FetchRequest::GetSubtreeRoots(
Expand All @@ -103,8 +106,13 @@ pub async fn get_subtree_roots(
max_entries,
))
.unwrap();
let shards = reply_receiver.await.unwrap();
Ok(shards)
let mut subtree_root_stream = reply_receiver.await.unwrap();
let mut subtree_roots = Vec::new();
while let Some(subtree_root) = subtree_root_stream.message().await.unwrap() {
subtree_roots.push(subtree_root);
}

Ok(subtree_roots)
}

/// Gets the frontiers for a specified block height.
Expand Down Expand Up @@ -188,7 +196,7 @@ pub async fn get_transparent_address_transactions(
pub async fn get_mempool_transaction_stream(
client: &mut CompactTxStreamerClient<zingo_netutils::UnderlyingService>,
) -> Result<tonic::Streaming<RawTransaction>, ()> {
tracing::info!("Fetching mempool stream");
tracing::debug!("Fetching mempool stream");
let mempool_stream = fetch::get_mempool_stream(client).await.unwrap();

Ok(mempool_stream)
Expand Down
33 changes: 14 additions & 19 deletions zingo-sync/src/client/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ async fn fetch_from_server(
) -> Result<(), ()> {
match fetch_request {
FetchRequest::ChainTip(sender) => {
tracing::info!("Fetching chain tip.");
tracing::debug!("Fetching chain tip.");
let block_id = get_latest_block(client).await.unwrap();
sender.send(block_id).unwrap();
}
FetchRequest::CompactBlockRange(sender, block_range) => {
tracing::info!("Fetching compact blocks. {:?}", &block_range);
let compact_blocks = get_block_range(client, block_range).await.unwrap();
sender.send(compact_blocks).unwrap();
tracing::debug!("Fetching compact blocks. {:?}", &block_range);
let block_stream = get_block_range(client, block_range).await.unwrap();
sender.send(block_stream).unwrap();
}
FetchRequest::GetSubtreeRoots(sender, start_index, shielded_protocol, max_entries) => {
tracing::info!(
tracing::debug!(
"Fetching subtree roots. start index: {}. shielded protocol: {}",
start_index,
shielded_protocol
Expand All @@ -124,19 +124,19 @@ async fn fetch_from_server(
sender.send(shards).unwrap();
}
FetchRequest::TreeState(sender, block_height) => {
tracing::info!("Fetching tree state. {:?}", &block_height);
tracing::debug!("Fetching tree state. {:?}", &block_height);
let tree_state = get_tree_state(client, block_height).await.unwrap();
sender.send(tree_state).unwrap();
}
FetchRequest::Transaction(sender, txid) => {
tracing::info!("Fetching transaction. {:?}", txid);
tracing::debug!("Fetching transaction. {:?}", txid);
let transaction = get_transaction(client, consensus_parameters, txid)
.await
.unwrap();
sender.send(transaction).unwrap();
}
FetchRequest::UtxoMetadata(sender, (addresses, start_height)) => {
tracing::info!(
tracing::debug!(
"Fetching unspent transparent output metadata from {:?} for addresses:\n{:?}",
&start_height,
&addresses
Expand All @@ -147,7 +147,7 @@ async fn fetch_from_server(
sender.send(utxo_metadata).unwrap();
}
FetchRequest::TransparentAddressTxs(sender, (address, block_range)) => {
tracing::info!(
tracing::debug!(
"Fetching raw transactions in block range {:?} for address {:?}",
&block_range,
&address
Expand All @@ -169,13 +169,11 @@ async fn get_latest_block(

Ok(client.get_latest_block(request).await.unwrap().into_inner())
}

async fn get_block_range(
client: &mut CompactTxStreamerClient<zingo_netutils::UnderlyingService>,
block_range: Range<BlockHeight>,
) -> Result<Vec<CompactBlock>, ()> {
let mut compact_blocks: Vec<CompactBlock> =
Vec::with_capacity(u64::from(block_range.end - block_range.start) as usize);

) -> Result<tonic::Streaming<CompactBlock>, ()> {
let request = tonic::Request::new(BlockRange {
start: Some(BlockId {
height: u64::from(block_range.start),
Expand All @@ -186,13 +184,8 @@ async fn get_block_range(
hash: vec![],
}),
});
let mut block_stream = client.get_block_range(request).await.unwrap().into_inner();

while let Some(compact_block) = block_stream.message().await.unwrap() {
compact_blocks.push(compact_block);
}

Ok(compact_blocks)
Ok(client.get_block_range(request).await.unwrap().into_inner())
}

async fn get_subtree_roots(
Expand All @@ -206,12 +199,14 @@ async fn get_subtree_roots(
shielded_protocol,
max_entries,
};

Ok(client
.get_subtree_roots(request)
.await
.unwrap()
.into_inner())
}

async fn get_tree_state(
client: &mut CompactTxStreamerClient<zingo_netutils::UnderlyingService>,
block_height: BlockHeight,
Expand Down
Loading
Loading