I make calls to ICP query_blocks once in 20 seconds. From time to time I get this error.
`Err` value: "The replica returned a rejection error: reject code CanisterReject, reject message Fail to decode argument 0 from table0 to record { start : nat64; length : nat64 }, error code Some(\"IC0406\"): get_blocks ICRC1/2:ICP"
The error code IC0406
corresponds to the CanisterRejectedMessage: StatusCode 406
.
I failed to understand why the error occurs.
This is my code:
let now_utc = OffsetDateTime::now_utc();
let three_minutes = Duration::seconds(180);
let time = now_utc + three_minutes;
let response = agent.query(&ledger.id, "query_blocks")
.expire_at(time)
.with_arg(Encode!(&GetBlocksArgs { start, length }).unwrap())
.call_without_verification().await
.map_err(|e| format!("{}: get_blocks ICRC1/2:{}", e, ledger.name)).unwrap();
Two random guesses: are start
and length
actually u64
? And have you tried wrapping GetBlocksArgs
in a tuple?
The error means that the input and the expected input format don’t match
Arguments are correct, because it fails from time to time when I pass start = 1 and length = 1 as arguments just to get current chain length.
pub async fn get_blocks(agent: &Agent, ledger: &Ledger, start: u64, length: u64) -> (Option<QueryBlocksResponse>, Option<GetTransactionsResponse>) {
let now_utc = OffsetDateTime::now_utc();
let three_minutes = Duration::seconds(180);
let time = now_utc + three_minutes;
if ledger.standard == "ICRC3" {
let response = agent.query(&ledger.id, "get_transactions")
.expire_at(time)
.with_arg(Encode!(&GetBlocksRequest { start: Nat::from(start), length: Nat::from(length) }).unwrap())
.call_without_verification().await
.map_err(|e| format!("{}: get_blocks ICRC3:{}", e, ledger.name)).unwrap();
Error:
called Result::unwrap()
on an Err
value: “The replica returned an HTTP Error: Http Error: status 500 Internal Server Error, content type "text/plain; charset=utf-8", content: backend_timeout: get_blocks ICRC3:KINIC”
It happens with different ledgers. Perhaps, it is connected with ingress expiry issue?