(
"The http_request resulted into error. RejectionCode:
CanisterReject, Error: http_request request sent with
176_928_000 cycles,
but 20_933_203_200 cycles are required.",
)
its about 120times bigger cycles than i expect.
//https://internetcomputer.org/docs/current/developer-docs/gas-cost
pub fn calculate_cost(
node_num: u32,
send_bytes: u64,
receive_bytes: u64,
) -> u128 {
let base_fee_http_request_init =
(3_780_000 * node_num) as u128 * node_num as u128;
let request_cost = 400 * node_num as u128 * send_bytes as u128;
let response_cost = 800 * node_num as u128 * receive_bytes as u128;
base_fee_http_request_init + request_cost + response_cost
}
}
Questions:
If cycles can not be too determined, then Can i just send with 1T cycles and after http_request it return rest of cycles for me ?
Also i found out if i exec http_request in local dfx enviroment. even 1 cycle can excute a big http_request . so wired. Which cause me a bug if i want to make http_request on ic-main-net.
And also i guess some of cycle cost can be a part of sdk lib to auto generate for developers ?
You’re most likely running your local replica in system subnet mode, where nothing costs anything. It’s either configured like that in dfx.json or in the place where dfx info networks-json-path points you to
But even if you run in application subnet mode (what you’re probably looking for), then the local costs won’t be the same as on mainnet since your local subnet then only contains 1 node instead of 13. Here’s the gas cost table if you want more on that
We decided against that because we can’t offer something that works completely. IMO overpaying is the easiest way to do it for now
Could you please confirm that overpaid cycles are returned?
How is this handled?..
I’m battling cycle leakage and so far it’s down to https outcalls, I already specify Some(1) in max_response_bytes, because I absolutely don’t care about response.
I just need to fire and forget with best effort delivery(hitting an idempotent proxy server)
Is it feasible to specify max_response_bytes as Some(1) or even Some(0)?
Anything I should be aware about when doing so?
I do not care about response, I just need fire and forget mechanic and request to eventually make it through(best effort)
What I care about is cycle consumption…
The same page says a common error message is max_response_bytes expected to be in the range [0..2000000], so yes, using Some(0) is perfectly valid. I would suggest that in that case you also add a transformation function that discards the response and just returns an empty response. If you don’t transform the response the call happened, but you will probably get back an error that there was no consensus on the response
Yea, transformation afaik involves some extra costs and I don’t really care about consensus
The only 2 concerns is getting request delivered at the best effort eventually and that the cycles consumption is reduced as low as possible
Problem I’m facing is I glued my dapp with performance_counters calls everywhere and I don’t see numbers that are even close to the observed cycle consumption(~8TC per day). DApp not even got that many users and we’ve just released
We got some timers, that trigger about every 3 mins and some https outcalls, otherwise logic itself doesn’t eat that much https://social.insaneclownprotocol.com/
What’s worse is than performance_counter(1) doesn’t even properly report on consumption of cycles, it’s ALWAYS low… never once I saw 26bil per call reported
wtf
performance_counter shows how many wasm instructions were run in a certain context. It does not provide a number of cycles that were consumed. For example it doesn’t include the fixed cost that is charged for every update call
We don’t have much tooling for that. To profile individual functions I would suggest canbench. Anything else is a matter of reviewing where you make calls with attached cycles