maybe i didnt calcute right ?
(
"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 ?
my solution so far :
#[ic_cdk::update]
pub fn some_http_call(cycles:u128)->String{
...
}
by excute some_http_call(0)
. the call with response with how many cycles it inneeded. so make a new call some_http_call(x)