dfinity / dfinity/sdk

PocketIC does not check for http outcalls reaching consensus

Open
#4,325 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
Rust
Stars
204
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Problem

The following code runs perfectly on local network dfx start but fails on mainnet:

const JWK_URL: &str =
    "https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com";

pub async fn fetch_public_keys() -> Result<JwkKeys, FetchPublicKeysError> {
    let response =
        ic_cdk::management_canister::http_request(&ic_cdk::management_canister::HttpRequestArgs {
            url: JWK_URL.to_string(),
            max_response_bytes: None,
            method: ic_cdk::management_canister::HttpMethod::GET,
            headers: vec![],
            body: None,
            transform: None,
        })
        .await
        .map_err(FetchPublicKeysError::CouldntFetchPublicKeys)?;
// ...
}

The error: No consensus could be reached. Replicas had different responses.

I'm almost certain that the reason for this error is that HTTP response is different for each call to this URL (max-age header value changes). There's no way for such errors to be caught in development

Potential solution

PocketIC should try to make more than one HTTP call and compare response results, to better simulate the production environment. Just two calls would've caught the error for the aforementioned URL

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating PocketIC's handling of HTTP outcalls and review how a single response is currently returned. Reproduce the JWK URL scenario with repeated calls, then verify that differing responses are detected so local testing exposes the consensus failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.