Skip to content

Commit

Permalink
Merge pull request #181 from idky137/critical_errors
Browse files Browse the repository at this point in the history
Handle critical errors
  • Loading branch information
AloeareV authored Feb 18, 2025
2 parents dc3cbc1 + 745cd85 commit 091b8c0
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 265 deletions.
1 change: 1 addition & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[profile.default]
test-threads = 4
fail-fast = false
89 changes: 69 additions & 20 deletions integration-tests/tests/wallet_to_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ mod wallet_basic {

if validator == "zebrad" {
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
};

Expand All @@ -77,6 +79,7 @@ mod wallet_basic {
.await
.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.recipient.do_sync(true).await.unwrap();

assert_eq!(
Expand Down Expand Up @@ -115,9 +118,11 @@ mod wallet_basic {

if validator == "zebrad" {
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
};

Expand All @@ -132,6 +137,7 @@ mod wallet_basic {
.await
.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.recipient.do_sync(true).await.unwrap();

assert_eq!(
Expand Down Expand Up @@ -171,9 +177,11 @@ mod wallet_basic {

if validator == "zebrad" {
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
};

Expand All @@ -189,6 +197,7 @@ mod wallet_basic {
.unwrap();

test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;

let fetch_service = zaino_fetch::jsonrpc::connector::JsonRpcConnector::new_with_basic_auth(
test_node_and_return_url(
Expand Down Expand Up @@ -222,7 +231,17 @@ mod wallet_basic {

dbg!(unfinalised_transactions.clone());

test_manager.local_net.generate_blocks(99).await.unwrap();
// Generate blocks
//
// NOTE: Generating blocks with zcashd blocks the tokio main thread???, stopping background processes from running,
// for this reason we generate blocks 1 at a time and sleep to let other tasks run.
for height in 1..=99 {
dbg!("Generating block at height: {}", height);
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

tokio::time::sleep(std::time::Duration::from_millis(500)).await;

println!("\n\nFetching Tx From Finalized Chain!\n");

Expand Down Expand Up @@ -275,20 +294,25 @@ mod wallet_basic {
.expect("Clients are not initialized");

test_manager.local_net.generate_blocks(2).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();

// "Create" 3 orchard notes in faucet.
if validator == "zebrad" {
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
};

Expand Down Expand Up @@ -323,7 +347,17 @@ mod wallet_basic {
.await
.unwrap();

test_manager.local_net.generate_blocks(100).await.unwrap();
// Generate blocks
//
// NOTE: Generating blocks with zcashd blocks the tokio main thread???, stopping background processes from running,
// for this reason we generate blocks 1 at a time and sleep to let other tasks run.
for height in 1..=100 {
dbg!("Generating block at height: {}", height);
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.recipient.do_sync(true).await.unwrap();

assert_eq!(
Expand Down Expand Up @@ -380,9 +414,11 @@ mod wallet_basic {

if validator == "zebrad" {
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
};

Expand All @@ -397,7 +433,17 @@ mod wallet_basic {
.await
.unwrap();

test_manager.local_net.generate_blocks(100).await.unwrap();
// Generate blocks
//
// NOTE: Generating blocks with zcashd blocks the tokio main thread???, stopping background processes from running,
// for this reason we generate blocks 1 at a time and sleep to let other tasks run.
for height in 1..=100 {
dbg!("Generating block at height: {}", height);
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
}

tokio::time::sleep(std::time::Duration::from_secs(1)).await;
clients.recipient.do_sync(true).await.unwrap();

assert_eq!(
Expand All @@ -412,6 +458,7 @@ mod wallet_basic {

clients.recipient.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.recipient.do_sync(true).await.unwrap();

assert_eq!(
Expand Down Expand Up @@ -449,16 +496,20 @@ mod wallet_basic {
let recipient_client = Arc::new(clients.recipient);

test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();

if validator == "zebrad" {
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(100).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
clients.faucet.quick_shield().await.unwrap();
test_manager.local_net.generate_blocks(1).await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
clients.faucet.do_sync(true).await.unwrap();
};

Expand Down Expand Up @@ -528,22 +579,6 @@ mod wallet_basic {
.await
);

test_manager.local_net.generate_blocks(1).await.unwrap();

println!("\n\nFetching Mined Tx 1!\n");
let _transaction_1 = dbg!(
fetch_service
.get_raw_transaction(mempool_txids.transactions[0].clone(), Some(1))
.await
);

println!("\n\nFetching Mined Tx 2!\n");
let _transaction_2 = dbg!(
fetch_service
.get_raw_transaction(mempool_txids.transactions[1].clone(), Some(1))
.await
);

assert_eq!(
recipient_client
.do_balance()
Expand All @@ -562,7 +597,21 @@ mod wallet_basic {
);

test_manager.local_net.generate_blocks(1).await.unwrap();
recipient_client.do_rescan().await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(500)).await;

println!("\n\nFetching Mined Tx 1!\n");
let _transaction_1 = dbg!(
fetch_service
.get_raw_transaction(mempool_txids.transactions[0].clone(), Some(1))
.await
);

println!("\n\nFetching Mined Tx 2!\n");
let _transaction_2 = dbg!(
fetch_service
.get_raw_transaction(mempool_txids.transactions[1].clone(), Some(1))
.await
);

assert_eq!(
recipient_client
Expand Down
5 changes: 2 additions & 3 deletions zaino-serve/src/server/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ impl TonicServer {
pub async fn spawn(
service_subscriber: IndexerSubscriber<FetchServiceSubscriber>,
server_config: GrpcConfig,
status: AtomicStatus,
) -> Result<Self, ServerError> {
status.store(StatusType::Spawning as usize);
let status = AtomicStatus::new(StatusType::Spawning.into());

let svc = CompactTxStreamerServer::new(GrpcClient {
service_subscriber: service_subscriber.clone(),
Expand Down Expand Up @@ -78,7 +77,7 @@ impl TonicServer {
}

/// Sets the servers to close gracefully.
pub async fn shutdown(&mut self) {
pub async fn close(&mut self) {
self.status.store(StatusType::Closing as usize);

if let Some(handle) = self.server_handle.take() {
Expand Down
Loading

0 comments on commit 091b8c0

Please sign in to comment.