From a1d5e4102106c54ed75e2e9765666dbf9e901745 Mon Sep 17 00:00:00 2001 From: 0xZensh Date: Mon, 8 Jul 2024 19:13:09 +0800 Subject: [PATCH] chore: rename parallel_call_one_ok to parallel_call_any_ok; fix actions --- .github/workflows/build-canisters.yml | 20 +++++++++++-------- .../{build.yml => build-dockers.yml} | 2 +- .../{publish.yml => publish-crates.yml} | 5 +++-- .github/workflows/{ci.yml => test.yml} | 2 +- Cargo.toml | 4 ++-- examples/eth-canister-lite/src/jsonrpc.rs | 6 +++--- src/idempotent-proxy-canister/README.md | 4 ++-- .../idempotent-proxy-canister.did | 2 +- src/idempotent-proxy-canister/src/lib.rs | 2 +- 9 files changed, 26 insertions(+), 21 deletions(-) rename .github/workflows/{build.yml => build-dockers.yml} (98%) rename .github/workflows/{publish.yml => publish-crates.yml} (86%) rename .github/workflows/{ci.yml => test.yml} (97%) diff --git a/.github/workflows/build-canisters.yml b/.github/workflows/build-canisters.yml index cca6671..ef01d50 100644 --- a/.github/workflows/build-canisters.yml +++ b/.github/workflows/build-canisters.yml @@ -1,4 +1,4 @@ -name: CI +name: Canisters on: push: branches: [ "main" ] @@ -12,13 +12,17 @@ jobs: - name: Build canisters run: | dfx --version - dfx build idempotent-proxy-canister - cd target/wasm32-unknown-unknown/release - gzip idempotent_proxy_canister.wasm - sha256sum idempotent_proxy_canister.wasm.gz > idempotent_proxy_canister.wasm.gz.sha256.txt + cargo install ic-wasm + mkdir out + cargo build --target wasm32-unknown-unknown --release --locked -p idempotent-proxy-canister + cp target/wasm32-unknown-unknown/release/idempotent_proxy_canister.wasm out/ + cp src/idempotent-proxy-canister/idempotent-proxy-canister.did out/idempotent_proxy_canister.did + ic-wasm out/idempotent_proxy_canister.wasm -o out/idempotent_proxy_canister.wasm shrink + ic-wasm out/idempotent_proxy_canister.wasm -o out/idempotent_proxy_canister.wasm optimize O3 --inline-functions-with-loops + gzip out/idempotent_proxy_canister.wasm + SHA256="$(sha256sum < "out/idempotent_proxy_canister.wasm.gz" | sed 's/ .*$//g')" + echo $SHA256 > "out/idempotent_proxy_canister.wasm.gz.$SHA256.txt" - name: Release uses: softprops/action-gh-release@v2 with: - files: | - idempotent_proxy_canister.wasm.gz - idempotent_proxy_canister.wasm.gz.sha256.txt + files: out/* diff --git a/.github/workflows/build.yml b/.github/workflows/build-dockers.yml similarity index 98% rename from .github/workflows/build.yml rename to .github/workflows/build-dockers.yml index 31245b2..6757fb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build-dockers.yml @@ -1,4 +1,4 @@ -name: Docker +name: Dockers on: push: tags: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish-crates.yml similarity index 86% rename from .github/workflows/publish.yml rename to .github/workflows/publish-crates.yml index 34f5e44..04e3f2c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish-crates.yml @@ -1,7 +1,8 @@ -name: Publish +name: Crates on: push: - branches: [ "main" ] + tags: + - 'v*' jobs: publish: runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/test.yml similarity index 97% rename from .github/workflows/ci.yml rename to .github/workflows/test.yml index a1f1bcc..a76cb0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: CI +name: Test on: push: branches: [ "main" ] diff --git a/Cargo.toml b/Cargo.toml index 5bed0e1..e731221 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [workspace] members = [ - "src/idempotent-proxy-canister", - "src/idempotent-proxy-server", "src/idempotent-proxy-types", + "src/idempotent-proxy-server", + "src/idempotent-proxy-canister", "examples/eth-canister", "examples/eth-canister-lite", ] diff --git a/examples/eth-canister-lite/src/jsonrpc.rs b/examples/eth-canister-lite/src/jsonrpc.rs index bc98951..53214a5 100644 --- a/examples/eth-canister-lite/src/jsonrpc.rs +++ b/examples/eth-canister-lite/src/jsonrpc.rs @@ -34,7 +34,7 @@ pub struct RPCResponse { impl EthereumRPC { pub async fn eth_chain_id(&self, idempotency_key: String) -> Result { - self.call("parallel_call_one_ok", idempotency_key, "eth_chainId", &[]) + self.call("proxy_http_request", idempotency_key, "eth_chainId", &[]) .await } @@ -54,7 +54,7 @@ impl EthereumRPC { raw_tx: String, ) -> Result { self.call( - "proxy_http_request", + "parallel_call_any_ok", idempotency_key, "eth_sendTransaction", &[raw_tx.into()], @@ -66,7 +66,7 @@ impl EthereumRPC { pub async fn call( &self, - proxy_method: &str, // "proxy_http_request" | "parallel_call_one_ok" | "parallel_call_all_ok" + proxy_method: &str, // "proxy_http_request" | "parallel_call_any_ok" | "parallel_call_all_ok" idempotency_key: String, method: &str, params: &[Value], diff --git a/src/idempotent-proxy-canister/README.md b/src/idempotent-proxy-canister/README.md index 6ee84c7..7656684 100644 --- a/src/idempotent-proxy-canister/README.md +++ b/src/idempotent-proxy-canister/README.md @@ -5,7 +5,7 @@ The `idempotent-proxy-canister` is an ICP smart contract that can connect to 1 t The `idempotent-proxy-canister` automatically updates the proxy token periodically and offers the following three proxy interfaces to accommodate different business scenarios: 1. `proxy_http_request`: Prioritizes the first agent. If it fails (status code > 500), it attempts the next agent until it succeeds. -2. `parallel_call_one_ok`: Calls all agents in parallel. If any one succeeds, it returns the successful result; otherwise, it returns the last failed result. +2. `parallel_call_any_ok`: Calls all agents in parallel. If any one succeeds, it returns the successful result; otherwise, it returns the last failed result. 3. `parallel_call_all_ok`: Calls all agents in parallel. Only returns a successful result if all agents succeed and the results are identical; otherwise, it returns a 500 error with an array of all results. Note: If only one agent is configured, all three interfaces are equivalent. @@ -74,7 +74,7 @@ dfx canister call idempotent-proxy-canister proxy_http_request "(record { }; })" -dfx canister call idempotent-proxy-canister parallel_call_one_ok "(record { +dfx canister call idempotent-proxy-canister parallel_call_any_ok "(record { url = \"https://httpbin.org/get?api-key=abc123\"; method = variant{ \"get\" }; max_response_bytes = null; diff --git a/src/idempotent-proxy-canister/idempotent-proxy-canister.did b/src/idempotent-proxy-canister/idempotent-proxy-canister.did index 368f856..1a5e7e0 100644 --- a/src/idempotent-proxy-canister/idempotent-proxy-canister.did +++ b/src/idempotent-proxy-canister/idempotent-proxy-canister.did @@ -48,7 +48,7 @@ service : (opt ChainArgs) -> { admin_set_managers : (vec principal) -> (Result_1); get_state : () -> (Result_2) query; parallel_call_all_ok : (CanisterHttpRequestArgument) -> (HttpResponse); - parallel_call_one_ok : (CanisterHttpRequestArgument) -> (HttpResponse); + parallel_call_any_ok : (CanisterHttpRequestArgument) -> (HttpResponse); proxy_http_request : (CanisterHttpRequestArgument) -> (HttpResponse); validate_admin_set_managers : (vec principal) -> (Result_1) query; } diff --git a/src/idempotent-proxy-canister/src/lib.rs b/src/idempotent-proxy-canister/src/lib.rs index d093c14..4e128c9 100644 --- a/src/idempotent-proxy-canister/src/lib.rs +++ b/src/idempotent-proxy-canister/src/lib.rs @@ -140,7 +140,7 @@ async fn parallel_call_all_ok(req: CanisterHttpRequestArgument) -> HttpResponse /// Proxy HTTP request by all agents in parallel and return the first (status <= 500) result. #[ic_cdk::update] -async fn parallel_call_one_ok(req: CanisterHttpRequestArgument) -> HttpResponse { +async fn parallel_call_any_ok(req: CanisterHttpRequestArgument) -> HttpResponse { if !store::state::is_allowed(&ic_cdk::caller()) { return HttpResponse { status: Nat::from(403u64),