Skip to content

Commit

Permalink
chore: rename parallel_call_one_ok to parallel_call_any_ok; fix actions
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jul 8, 2024
1 parent 8eeeadc commit a1d5e41
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 21 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/build-canisters.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Canisters
on:
push:
branches: [ "main" ]
Expand All @@ -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/*
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker
name: Dockers
on:
push:
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Publish
name: Crates
on:
push:
branches: [ "main" ]
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Test
on:
push:
branches: [ "main" ]
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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",
]
Expand Down
6 changes: 3 additions & 3 deletions examples/eth-canister-lite/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct RPCResponse<T> {

impl EthereumRPC {
pub async fn eth_chain_id(&self, idempotency_key: String) -> Result<String, String> {
self.call("parallel_call_one_ok", idempotency_key, "eth_chainId", &[])
self.call("proxy_http_request", idempotency_key, "eth_chainId", &[])
.await
}

Expand All @@ -54,7 +54,7 @@ impl EthereumRPC {
raw_tx: String,
) -> Result<String, String> {
self.call(
"proxy_http_request",
"parallel_call_any_ok",
idempotency_key,
"eth_sendTransaction",
&[raw_tx.into()],
Expand All @@ -66,7 +66,7 @@ impl EthereumRPC {

pub async fn call<T: DeserializeOwned>(
&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],
Expand Down
4 changes: 2 additions & 2 deletions src/idempotent-proxy-canister/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/idempotent-proxy-canister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit a1d5e41

Please sign in to comment.