From d700441bc3576ab10bb5e7e1901cf5a603de22fd Mon Sep 17 00:00:00 2001 From: Sergey Timoshin Date: Mon, 28 Oct 2024 12:53:07 +0000 Subject: [PATCH] refactor: update health check timeout in spawn_prover function, rewrite prove_batch_append test Change CI runner to buildjet-8vcpu-ubuntu-2204 for rust tests run rust.yml on buildjet-16vcpu-ubuntu-2204 debug rust.yml workflow Add step to download proving keys for big batches Remove redundant setup steps and update test configurations Update ProverConfig to use test-specific circuits --- .github/actionlint.yaml | 1 + .../light-prover-client/src/gnark/helpers.rs | 2 +- .../light-prover-client/tests/gnark.rs | 99 ++++++++----------- cli/src/utils/process.ts | 2 +- .../src/state/batched_merkle_tree.rs | 6 +- .../tests/batched_merkle_tree_test.rs | 2 +- 6 files changed, 46 insertions(+), 66 deletions(-) diff --git a/.github/actionlint.yaml b/.github/actionlint.yaml index 42e31983f4..3f55237582 100644 --- a/.github/actionlint.yaml +++ b/.github/actionlint.yaml @@ -4,6 +4,7 @@ self-hosted-runner: - buildjet-2vcpu-ubuntu-2204 - buildjet-4vcpu-ubuntu-2204 - buildjet-8vcpu-ubuntu-2204 + - buildjet-16vcpu-ubuntu-2204 # Configuration variables in array of strings defined in your repository or # organization. `null` means disabling configuration variables check. # Empty array means no configuration variable is allowed. diff --git a/circuit-lib/light-prover-client/src/gnark/helpers.rs b/circuit-lib/light-prover-client/src/gnark/helpers.rs index 7a3336ffd6..915b291900 100644 --- a/circuit-lib/light-prover-client/src/gnark/helpers.rs +++ b/circuit-lib/light-prover-client/src/gnark/helpers.rs @@ -111,7 +111,7 @@ pub async fn spawn_prover(restart: bool, config: ProverConfig) { let _ = command.spawn().expect("Failed to start prover process"); - let health_result = health_check(20, 5).await; + let health_result = health_check(20, 30).await; if health_result { info!("Prover started successfully"); } else { diff --git a/circuit-lib/light-prover-client/tests/gnark.rs b/circuit-lib/light-prover-client/tests/gnark.rs index 4f2318045d..e918e8ce4d 100644 --- a/circuit-lib/light-prover-client/tests/gnark.rs +++ b/circuit-lib/light-prover-client/tests/gnark.rs @@ -73,7 +73,7 @@ async fn prove_inclusion() { false, ProverConfig { run_mode: None, - circuits: vec![ProofType::BatchUpdate], + circuits: vec![ProofType::BatchUpdateTest], }, ) .await; @@ -169,7 +169,7 @@ async fn prove_batch_update() { false, ProverConfig { run_mode: None, - circuits: vec![ProofType::BatchUpdate], + circuits: vec![ProofType::BatchUpdateTest], }, ) .await; @@ -221,7 +221,15 @@ async fn prove_batch_update() { .send() .await .expect("Failed to execute request."); - assert!(response_result.status().is_success()); + + let status = response_result.status(); + let body = response_result.text().await.unwrap(); + assert!( + status.is_success(), + "Batch append proof generation failed. Status: {}, Body: {}", + status, + body + ); } } @@ -229,55 +237,50 @@ async fn prove_batch_update() { #[tokio::test] async fn prove_batch_append() { init_logger(); + println!("spawning prover"); spawn_prover( true, ProverConfig { run_mode: None, - circuits: vec![ProofType::BatchAppend], + circuits: vec![ProofType::BatchAppendTest], }, ) .await; + println!("prover spawned"); + const HEIGHT: usize = 26; const CANOPY: usize = 0; let num_insertions = 10; - let tx_hash = [0u8; 32]; - info!("initializing merkle tree for update."); - let mut merkle_tree = MerkleTree::::new(HEIGHT, CANOPY); + // Do multiple rounds of batch appends for _ in 0..2 { + info!("initializing merkle tree for append."); + let merkle_tree = MerkleTree::::new(HEIGHT, CANOPY); + + let old_subtrees = merkle_tree.get_subtrees(); let mut leaves = vec![]; - let mut nullifiers = vec![]; + + // Create leaves for this batch append for i in 0..num_insertions { let mut bn: [u8; 32] = [0; 32]; bn[31] = i as u8; let leaf: [u8; 32] = Poseidon::hash(&bn).unwrap(); leaves.push(leaf); - merkle_tree.append(&leaf).unwrap(); - let nullifier = Poseidon::hashv(&[&leaf, &tx_hash]).unwrap(); - nullifiers.push(nullifier); } - let mut merkle_proofs = vec![]; - let mut path_indices = vec![]; - for index in 0..leaves.len() { - let proof = merkle_tree.get_proof_of_leaf(index, true).unwrap(); - merkle_proofs.push(proof.to_vec()); - path_indices.push(index as u32); - } - let root = merkle_tree.root(); - let leaves_hashchain = calculate_hash_chain(&nullifiers); - let inputs = get_batch_update_inputs::( - root, - vec![tx_hash; num_insertions], + let leaves_hashchain = calculate_hash_chain(&leaves); + + // Generate inputs for batch append operation + let inputs = get_batch_append_inputs::( + merkle_tree.layers[0].len(), + old_subtrees.try_into().unwrap(), leaves, leaves_hashchain, - merkle_proofs, - path_indices, - num_insertions as u32, ); - let client = Client::new(); - let inputs = update_inputs_string(&inputs); + // Send proof request to the server + let client = Client::new(); + let inputs = append_inputs_string(&inputs); let response_result = client .post(&format!("{}{}", SERVER_ADDRESS, PROVE_PATH)) .header("Content-Type", "text/plain; charset=utf-8") @@ -285,38 +288,14 @@ async fn prove_batch_append() { .send() .await .expect("Failed to execute request."); - assert!(response_result.status().is_success()); - } - - let num_insertions = 10; - - info!("initializing merkle tree for append."); - let merkle_tree = MerkleTree::::new(HEIGHT, CANOPY); - let old_subtrees = merkle_tree.get_subtrees(); - let mut leaves = vec![]; - for i in 0..num_insertions { - let mut bn: [u8; 32] = [0; 32]; - bn[31] = i as u8; - let leaf: [u8; 32] = Poseidon::hash(&bn).unwrap(); - leaves.push(leaf); + let status = response_result.status(); + let body = response_result.text().await.unwrap(); + assert!( + status.is_success(), + "Batch append proof generation failed. Status: {}, Body: {}", + status, + body + ); } - - let leaves_hashchain = calculate_hash_chain(&leaves); - let inputs = get_batch_append_inputs::( - merkle_tree.layers[0].len(), - old_subtrees.try_into().unwrap(), - leaves, - leaves_hashchain, - ); - let client = Client::new(); - let inputs = append_inputs_string(&inputs); - let response_result = client - .post(&format!("{}{}", SERVER_ADDRESS, PROVE_PATH)) - .header("Content-Type", "text/plain; charset=utf-8") - .body(inputs) - .send() - .await - .expect("Failed to execute request."); - assert!(response_result.status().is_success()); } diff --git a/cli/src/utils/process.ts b/cli/src/utils/process.ts index 22490f2313..996601531e 100644 --- a/cli/src/utils/process.ts +++ b/cli/src/utils/process.ts @@ -198,7 +198,7 @@ export async function waitForServers( ({ port, path }) => `http-get://127.0.0.1:${port}${path}`, ), delay: 1000, - timeout: 25000, + timeout: 360_000, interval: 300, simultaneous: 2, validateStatus: function (status: number) { diff --git a/programs/account-compression/src/state/batched_merkle_tree.rs b/programs/account-compression/src/state/batched_merkle_tree.rs index d10dfe5486..5432865011 100644 --- a/programs/account-compression/src/state/batched_merkle_tree.rs +++ b/programs/account-compression/src/state/batched_merkle_tree.rs @@ -885,7 +885,7 @@ mod tests { true, ProverConfig { run_mode: None, - circuits: vec![ProofType::BatchAppend, ProofType::BatchUpdate], + circuits: vec![ProofType::BatchAppendTest, ProofType::BatchUpdateTest], }, ) .await; @@ -1301,7 +1301,7 @@ mod tests { false, ProverConfig { run_mode: None, - circuits: vec![ProofType::BatchAppend, ProofType::BatchUpdate], + circuits: vec![ProofType::BatchAppendTest, ProofType::BatchUpdateTest], }, ) .await; @@ -1801,7 +1801,7 @@ mod tests { false, ProverConfig { run_mode: None, - circuits: vec![ProofType::BatchAppend, ProofType::BatchUpdate], + circuits: vec![ProofType::BatchAppendTest, ProofType::BatchUpdateTest], }, ) .await; diff --git a/test-programs/account-compression-test/tests/batched_merkle_tree_test.rs b/test-programs/account-compression-test/tests/batched_merkle_tree_test.rs index a29a8ded3f..2a83004adb 100644 --- a/test-programs/account-compression-test/tests/batched_merkle_tree_test.rs +++ b/test-programs/account-compression-test/tests/batched_merkle_tree_test.rs @@ -208,7 +208,7 @@ async fn test_init_state_merkle_tree() { false, ProverConfig { run_mode: None, - circuits: vec![ProofType::BatchAppend, ProofType::BatchUpdate], + circuits: vec![ProofType::BatchAppendTest, ProofType::BatchUpdateTest], }, ) .await;