From 889d0fb3984c87e3bbe5ba6a6a5922245c318a8e Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Wed, 2 Oct 2024 08:30:50 +0300 Subject: [PATCH 1/8] feat: add PR test for coprocessor --- .github/workflows/coprocessor-test.yml | 37 +++++++++++++++++++ fhevm-engine/coprocessor/Makefile | 4 +- .../coprocessor/docker-compose.test.yml | 15 ++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/coprocessor-test.yml create mode 100644 fhevm-engine/coprocessor/docker-compose.test.yml diff --git a/.github/workflows/coprocessor-test.yml b/.github/workflows/coprocessor-test.yml new file mode 100644 index 00000000..2669da0d --- /dev/null +++ b/.github/workflows/coprocessor-test.yml @@ -0,0 +1,37 @@ +name: Run PR test + +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + coprocessor_test: + permissions: + contents: read + runs-on: "large_ubuntu_32" + if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }} + steps: + - name: Check out repo + uses: actions/checkout@v4 + + - name: Install protobuf compiler + run: sudo apt-get install -y protobuf-compiler + + - name: Install sqlx-cli from crates.io + uses: baptiste0928/cargo-install@v3 + with: + crate: sqlx-cli + version: '^0.8' + + - name: Setup database + working-directory: ./fhevm-engine/coprocessor + run: | + make init_db + # build with --release flag for faster tests + cargo build --release + cargo build --tests --release + COPROCESSOR_TEST_LOCAL_DB=true cargo test --release -- --nocapture + diff --git a/fhevm-engine/coprocessor/Makefile b/fhevm-engine/coprocessor/Makefile index 7b1d62fb..abb8790e 100644 --- a/fhevm-engine/coprocessor/Makefile +++ b/fhevm-engine/coprocessor/Makefile @@ -7,11 +7,11 @@ build: .PHONY: cleanup cleanup: - docker compose down -v + docker compose -f docker-compose.test.yml down -v .PHONY: init_db init_db: - docker compose up -d + docker compose -f docker-compose.test.yml up -d sleep 3 $(DB_URL) sqlx db create $(DB_URL) sqlx migrate run diff --git a/fhevm-engine/coprocessor/docker-compose.test.yml b/fhevm-engine/coprocessor/docker-compose.test.yml new file mode 100644 index 00000000..9f51f5dc --- /dev/null +++ b/fhevm-engine/coprocessor/docker-compose.test.yml @@ -0,0 +1,15 @@ +version: '3.8' +services: + db: + image: postgres:15.7 + restart: always + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + ports: + - '5432:5432' + volumes: + - db:/var/lib/postgresql/data +volumes: + db: + driver: local From 5f9f7ac2f39a9f49bc4cfecb24e1bff0813749d6 Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Thu, 3 Oct 2024 08:54:11 +0300 Subject: [PATCH 2/8] Fix ci tests --- .github/workflows/coprocessor-test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coprocessor-test.yml b/.github/workflows/coprocessor-test.yml index 2669da0d..c75c6472 100644 --- a/.github/workflows/coprocessor-test.yml +++ b/.github/workflows/coprocessor-test.yml @@ -33,5 +33,9 @@ jobs: # build with --release flag for faster tests cargo build --release cargo build --tests --release - COPROCESSOR_TEST_LOCAL_DB=true cargo test --release -- --nocapture + DATABASE_URL="postgres://postgres:postgres@localhost/coprocessor" cargo run --release -- --metrics-addr=127.0.0.1:9100 --run-server & + DATABASE_URL="postgres://postgres:postgres@localhost/coprocessor" cargo run --release -- --metrics-addr=127.0.0.1:9101 --run-bg-worker & + # give some time for ports to open etc + sleep 1 + COPROCESSOR_TEST_LOCALHOST=true cargo test --release -- --nocapture From 026ac85123f2ff86d7db869283066d6844d145be Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Thu, 3 Oct 2024 09:22:44 +0300 Subject: [PATCH 3/8] Print errors in waiting for computations --- fhevm-engine/coprocessor/src/tests/utils.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/fhevm-engine/coprocessor/src/tests/utils.rs b/fhevm-engine/coprocessor/src/tests/utils.rs index be92c82f..6132dc69 100644 --- a/fhevm-engine/coprocessor/src/tests/utils.rs +++ b/fhevm-engine/coprocessor/src/tests/utils.rs @@ -186,7 +186,15 @@ pub async fn wait_until_all_ciphertexts_computed( println!("All computations completed"); break; } else { - println!("{current_count} computations remaining, waiting..."); + let errors = sqlx::query!("SELECT output_handle, error_message FROM computations WHERE NOT is_error LIMIT 5") + .fetch_all(&pool) + .await?; + if !errors.is_empty() { + println!("errors found inside computations, breaking: {:?}", errors); + break; + } else { + println!("{current_count} computations remaining, waiting..."); + } } } From c0a2db133a6b656e208d01f7dd83997cdcc635e1 Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Thu, 3 Oct 2024 09:33:29 +0300 Subject: [PATCH 4/8] Correct error condition --- fhevm-engine/coprocessor/src/tests/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fhevm-engine/coprocessor/src/tests/utils.rs b/fhevm-engine/coprocessor/src/tests/utils.rs index 6132dc69..2192c35e 100644 --- a/fhevm-engine/coprocessor/src/tests/utils.rs +++ b/fhevm-engine/coprocessor/src/tests/utils.rs @@ -186,7 +186,7 @@ pub async fn wait_until_all_ciphertexts_computed( println!("All computations completed"); break; } else { - let errors = sqlx::query!("SELECT output_handle, error_message FROM computations WHERE NOT is_error LIMIT 5") + let errors = sqlx::query!("SELECT output_handle, error_message FROM computations WHERE is_error LIMIT 5") .fetch_all(&pool) .await?; if !errors.is_empty() { From 0752250855e50c4a6ad0f46d6da263062e9a3696 Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Mon, 14 Oct 2024 13:57:12 +0200 Subject: [PATCH 5/8] Try disabling randomness tests --- fhevm-engine/coprocessor/src/tests/random.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fhevm-engine/coprocessor/src/tests/random.rs b/fhevm-engine/coprocessor/src/tests/random.rs index aac4cbd4..7c131084 100644 --- a/fhevm-engine/coprocessor/src/tests/random.rs +++ b/fhevm-engine/coprocessor/src/tests/random.rs @@ -20,6 +20,7 @@ use crate::{ use super::operators::supported_types; #[tokio::test] +#[ignore] async fn test_fhe_random_basic() -> Result<(), Box> { let app = setup_test_app().await?; let pool = sqlx::postgres::PgPoolOptions::new() @@ -153,6 +154,7 @@ fn to_be_bytes(input: &str) -> Vec { } #[tokio::test] +#[ignore] async fn test_fhe_random_bounded() -> Result<(), Box> { let app = setup_test_app().await?; let pool = sqlx::postgres::PgPoolOptions::new() From c6a3cbffe44ffbd07d4f0f35a775d431c576b816 Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Thu, 24 Oct 2024 08:54:36 +0300 Subject: [PATCH 6/8] Reenable randomness tests --- fhevm-engine/coprocessor/src/tests/random.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/fhevm-engine/coprocessor/src/tests/random.rs b/fhevm-engine/coprocessor/src/tests/random.rs index f2f3f1fb..81430d94 100644 --- a/fhevm-engine/coprocessor/src/tests/random.rs +++ b/fhevm-engine/coprocessor/src/tests/random.rs @@ -20,7 +20,6 @@ use crate::{ use super::operators::supported_types; #[tokio::test] -#[ignore] async fn test_fhe_random_basic() -> Result<(), Box> { let app = setup_test_app().await?; let pool = sqlx::postgres::PgPoolOptions::new() @@ -154,7 +153,6 @@ fn to_be_bytes(input: &str) -> Vec { } #[tokio::test] -#[ignore] async fn test_fhe_random_bounded() -> Result<(), Box> { let app = setup_test_app().await?; let pool = sqlx::postgres::PgPoolOptions::new() From c0667b5a0e0fa841e3fc1b77756c02cd2a4c5ae7 Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Thu, 24 Oct 2024 09:05:01 +0300 Subject: [PATCH 7/8] Fix compilation --- fhevm-engine/fhevm-engine-common/Cargo.toml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fhevm-engine/fhevm-engine-common/Cargo.toml b/fhevm-engine/fhevm-engine-common/Cargo.toml index f0a2c911..8ca06cc7 100644 --- a/fhevm-engine/fhevm-engine-common/Cargo.toml +++ b/fhevm-engine/fhevm-engine-common/Cargo.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2021" [target.'cfg(target_arch = "x86_64")'.dependencies] -tfhe = { version = "0.8.3", features = ["boolean", "shortint", "integer", "x86_64-unix", "zk-pok", "experimental-force_fft_algo_dif4", "nightly-avx512"] } +tfhe = { version = "0.8.3", features = ["boolean", "shortint", "integer", "x86_64-unix", "zk-pok", "experimental-force_fft_algo_dif4"] } [target.'cfg(target_arch = "aarch64")'.dependencies] -tfhe = { version = "0.8.3", features = ["boolean", "shortint", "integer", "aarch64-unix", "zk-pok", "experimental-force_fft_algo_dif4", "nightly-avx512"] } +tfhe = { version = "0.8.3", features = ["boolean", "shortint", "integer", "aarch64-unix", "zk-pok", "experimental-force_fft_algo_dif4"] } [dependencies] sha3.workspace = true @@ -19,6 +19,9 @@ bigdecimal = "0.4.5" rand_chacha = "0.3.1" rand = "0.8.5" +[features] +nightly-avx512 = ["tfhe/nightly-avx512"] + [[bin]] name = "generate-keys" path = "src/bin/generate_keys.rs" From 160b188e1886449530bd28c41980ee355dbd5120 Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Thu, 24 Oct 2024 09:37:30 +0300 Subject: [PATCH 8/8] Print stuck computations --- fhevm-engine/Cargo.lock | 4 ++++ fhevm-engine/coprocessor/Cargo.toml | 2 +- fhevm-engine/coprocessor/src/tests/utils.rs | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/fhevm-engine/Cargo.lock b/fhevm-engine/Cargo.lock index 337cf6c3..58dad628 100644 --- a/fhevm-engine/Cargo.lock +++ b/fhevm-engine/Cargo.lock @@ -4800,6 +4800,7 @@ dependencies = [ "smallvec", "sqlformat", "thiserror", + "time", "tokio", "tokio-stream", "tracing", @@ -4885,6 +4886,7 @@ dependencies = [ "sqlx-core", "stringprep", "thiserror", + "time", "tracing", "uuid", "whoami", @@ -4924,6 +4926,7 @@ dependencies = [ "sqlx-core", "stringprep", "thiserror", + "time", "tracing", "uuid", "whoami", @@ -4947,6 +4950,7 @@ dependencies = [ "percent-encoding", "serde", "sqlx-core", + "time", "tracing", "url", "urlencoding", diff --git a/fhevm-engine/coprocessor/Cargo.toml b/fhevm-engine/coprocessor/Cargo.toml index d0cfe835..3a483bdd 100644 --- a/fhevm-engine/coprocessor/Cargo.toml +++ b/fhevm-engine/coprocessor/Cargo.toml @@ -18,7 +18,7 @@ tonic-web = "0.12" tonic-health = "0.12" tonic-types = "0.12" tokio-util = "0.7" -sqlx = { version = "0.7", features = ["runtime-tokio", "tls-rustls", "postgres", "uuid"] } +sqlx = { version = "0.7", features = ["runtime-tokio", "tls-rustls", "postgres", "uuid", "time"] } alloy = { version = "0.3.2", features = ["eip712", "sol-types", "signer-local"] } serde_json = "1.0" regex = "1.10.5" diff --git a/fhevm-engine/coprocessor/src/tests/utils.rs b/fhevm-engine/coprocessor/src/tests/utils.rs index a7b2217e..c9e1c329 100644 --- a/fhevm-engine/coprocessor/src/tests/utils.rs +++ b/fhevm-engine/coprocessor/src/tests/utils.rs @@ -194,6 +194,10 @@ pub async fn wait_until_all_ciphertexts_computed( break; } else { println!("{current_count} computations remaining, waiting..."); + let recs = sqlx::query!("SELECT * FROM computations WHERE NOT is_completed LIMIT 5") + .fetch_all(&pool) + .await?; + println!("{:#?}", recs); } } }