diff --git a/.github/workflows/coprocessor-test.yml b/.github/workflows/coprocessor-test.yml new file mode 100644 index 00000000..c75c6472 --- /dev/null +++ b/.github/workflows/coprocessor-test.yml @@ -0,0 +1,41 @@ +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 + 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 + 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/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 diff --git a/fhevm-engine/coprocessor/src/tests/utils.rs b/fhevm-engine/coprocessor/src/tests/utils.rs index ca1b0c01..c9e1c329 100644 --- a/fhevm-engine/coprocessor/src/tests/utils.rs +++ b/fhevm-engine/coprocessor/src/tests/utils.rs @@ -186,7 +186,19 @@ 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 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..."); + let recs = sqlx::query!("SELECT * FROM computations WHERE NOT is_completed LIMIT 5") + .fetch_all(&pool) + .await?; + println!("{:#?}", recs); + } } } 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"