Http_request cannot achieve consensus

I have a canister function that performs a http_request and returns the response.body.

When I run it in a local canister it works fine, but on the IC it cannot achieve consensus. There is nothing in the response body that can vary. I can run it as many times as I like locally and it always returns the same value. There are no dates or any other variable content. Here’s the value that is always (correctly) returned locally. The balance figure cannot vary.

("{"rows":[{"balance":"321.5278 XPR"}],"more":false,"next_key":""}. See more info of the request sent at: https://api-xprnetwork-main.saltant.io/v1/chain/get_table_rows/inspect")

I’ve tried sending an Idempotency-Key in the request headers but that didn’t work.

I would appreciate any tips that would allow me to examine the responses from each of the nodes. Is that possible? Or any tips for resolving this situation?

Are any headers part of the response as well?

I can have a look but my understanding is that consensus is achieved on the result that is returned by the function. I might be wrong though. Does consensus take account of the whole http response, or just the value that I am stripping out and returning?

If it is the whole response then I can try to use a transform function.

[Edit - I’ve since learned that consensus is based on the whole HttpResponse, not the return value of the function. That changes things. I will use a transform function on the response]

Thanks @Severin - I used a transform function to remove all response headers, some of which were varying on each call. I tried a targeted approach at first, removing certain response headers, but something was still varying, so I removed all headers, seeing as I’m only interested in the response body. Here is the transform function in Rust:

#[ic_cdk::query]
fn clean_dynamic_content(args: TransformArgs) -> HttpResponse {
    let mut response = args.response;

    //response.headers.retain(|header| header.name != "Date" && header.name != "CF-RAY" && header.name != "Report-To");
    response.headers.clear();
    
    // Return the cleaned response
    response
}
1 Like