cloud-engine-canisters
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud Engine Canisters
Cloud Engine Canister
What This Is
这是什么
A cloud engine is a user-owned slice of Internet Computer capacity, administered from a web console (see the skill for getting code onto one). Engines run on a dedicated subnet type with a free cycles cost schedule: nothing an engine canister does is metered in cycles — execution, storage, messaging, and HTTPS outcalls all cost zero — and engine canisters hold a 0 cycles balance by design.
deploy-to-cloud-engineCloudEngineThat model comes with protocol-enforced call rules. Code that works on a normal Application subnet can fail on an engine, and the failures look like cycles or consensus problems rather than what they are: code written for the wrong subnet type. The rules:
| Rule | On a cloud engine |
|---|---|
| 1 | Never attach cycles to any call — remove |
| 2 | Cross-subnet calls must be bounded-wait — |
| 3 | HTTPS outcalls: ordinary code, zero cost — keep the standard wrapper, transform on your own canister, never through the proxy |
| 4 | Cycle-bearing cross-subnet targets (XRC, threshold signing, vetKD, the Bitcoin API, EVM/SOL RPC) go through the console proxy canister. Ask the user for its id before writing that code |
| 5 | AI inference goes through the engine operator — call its |
Cloud engine 是用户拥有的 Internet Computer 容量切片,可通过 Web 控制台进行管理(有关将代码部署到引擎的信息,请参阅 skill)。引擎运行在专用的 subnet 类型上,并采用免费的 cycles 费用表:引擎 canister 执行的任何操作都不会按 cycles 计费——执行、存储、消息传递和 HTTPS outcall 的费用全部为零——而且引擎 canister 的 cycles 余额按设计就是 0 cycles。
deploy-to-cloud-engineCloudEngine该模型受到协议强制调用规则的约束。在普通 Application subnet 上可以正常工作的代码,在引擎上可能失败,而且这些失败看起来像是 cycles 或共识问题,实际上并非如此:代码是为错误的 subnet 类型编写的。规则如下:
| 规则 | 在 cloud engine 上 |
|---|---|
| 1 | 绝不要为任何调用附加 cycles——删除 |
| 2 | 跨子网调用必须使用 bounded-wait——Motoko 中使用 |
| 3 | HTTPS outcall:使用普通代码,费用为零——保留标准 wrapper,在自己的 canister 上执行 transform,绝不能通过 proxy |
| 4 | 需要 cycles 的跨子网目标(XRC、threshold signing、vetKD、Bitcoin API、EVM/SOL RPC)必须通过 console proxy canister。编写此类代码前,先向用户询问其 id |
| 5 | AI inference 通过 engine operator——调用其 |
Rule 1 — Never attach a cycles amount you computed yourself
规则 1——绝不要附加自行计算的 cycles 数量
Engine canisters hold 0 cycles and there is nothing to pay for: under the engine's free cost schedule every fee an Application-subnet canister would pay (execution, message transmission, HTTPS outcalls, threshold signing, vetKD, storage) is charged as zero.
-
Inter-canister calls you write: no cycles clause at all. There is nothing to buy — every fee on an engine is charged as zero — so a cycles attachment is never needed, independently of whether the protocol tolerates it. Write, never
await service.method(args). Verified on a live engine canister (await (with cycles = 1_000_000) service.method(args)): any non-zero amount fails withCycles: 0Canister <id> is out of cycles, error code Some("IC0504")Do not "fix" this by zeroing the amount. The platform team's guidance is simply not to mention cycles at all on an engine call, and aleft in place is noise that breaks again the moment the amount becomes non-zero (a computed fee, a copied constant). If you seecycles = 0from an engine canister, some call is attaching a non-zero amount.IC0504 -
Rust: the same rule — never callon a
.with_cycles(…)builder. (The platform team states the Motoko rule as "just don't mention cycles"; omittingCallis its Rust equivalent.).with_cycles -
Management-canister calls keep their standard wrapper.(Motoko,
Call.httpRequest) and the Rust outcall wrapper for your crate line (Rule 3) ask themo:icsystem API for the fee, and that API is cost-schedule aware: for an outcall it prices against your own subnet's cost schedule, which is free on an engine, so it returns 0, the wrapper attaches nothing, and the same source stays portable to an Application subnet. What breaks is substituting a hardcoded or hand-computed fee — never take a number from theic0.cost_*cost tables and attach it on an engine.https-outcalls -
Which subnet's schedule is consulted is the whole distinction. The chain-key cost APIs (and friends) price against the subnet that holds the key, not yours — that subnet charges normally, so they return a non-zero fee even when called from an engine, and the wrapper then attaches it. That is why a helper that signs cannot work here while the same crate's outcall builder can (Rules 3 and 4).
ic0.cost_sign_with_ecdsa -
The one exception: cycles that a cross-subnet target charges are placed insideof the console proxy (Rule 4), never attached to a call your canister sends.
ProxyArgs.cycles
引擎 canister 持有 0 cycles,而且没有任何需要付费的操作:在引擎的免费费用表下,Application-subnet canister 需要支付的所有费用(执行、消息传输、HTTPS outcall、threshold signing、vetKD、存储)都会被按零收费。
-
你编写的 canister 间调用:完全不要包含 cycles 子句。 这里没有任何需要购买的东西——引擎上的每项费用都按零收费——因此无论协议是否容忍,都绝不需要附加 cycles。编写,绝不要编写
await service.method(args)。在一个实际运行的引擎 canister 上已验证(await (with cycles = 1_000_000) service.method(args)):任何非零金额都会失败,并返回:Cycles: 0Canister <id> is out of cycles, error code Some("IC0504")不要通过将金额设为零来“修复”这个问题。平台团队的指导非常明确:在引擎调用中完全不要提及 cycles。保留只会制造噪声,并会在金额以后变为非零时再次引发问题(无论是计算出的费用还是复制来的常量)。如果引擎 canister 返回cycles = 0,说明某个调用附加了非零金额。IC0504 -
Rust: 规则相同——绝不要在builder 上调用
Call。(平台团队将 Motoko 规则表述为“完全不要提及 cycles”;省略.with_cycles(…)就是 Rust 中的等价做法。).with_cycles -
Management-canister 调用保留标准 wrapper。(Motoko、
Call.httpRequest)以及 Rust crate 对应版本中的 outcall wrapper(规则 3)会调用mo:icsystem API 查询费用。该 API 能够感知费用表:对于 outcall,它会根据你自己的 subnet 费用表定价,而引擎上的该费用表是免费的,因此会返回 0。Wrapper 不会附加任何 cycles,同一份源代码也能继续用于 Application subnet。真正有问题的是使用硬编码或手动计算的费用——绝不要从ic0.cost_*费用表中取一个数字并将其附加到引擎调用。https-outcalls -
查询哪个 subnet 的费用表正是关键区别。 Chain-key 费用 API(等)会根据持有密钥的 subnet 定价,而不是你的 subnet。该 subnet 正常收费,因此即使从引擎调用也会返回非零费用,随后 wrapper 就会附加这些费用。这正是签名 helper 无法在这里使用,而同一 crate 中的 outcall builder 可以使用的原因(规则 3 和规则 4)。
ic0.cost_sign_with_ecdsa -
唯一的例外是:跨子网目标收取的 cycles 要放入 console proxy 的中(规则 4),绝不能附加到你的 canister 发出的调用上。
ProxyArgs.cycles
Rule 2 — Cross-subnet calls must be bounded-wait
规则 2——跨子网调用必须使用 bounded-wait
The protocol rejects any cross-subnet (XNet) request from or to a CloudEngine subnet that is unbounded-wait (guaranteed-response) or carries cycles. The caller gets a reject with exactly this text:
Unbounded-wait calls and calls with cycles are not allowed to CloudEngine subnetsVerified live from an engine canister: a plain to a canister on another subnet comes back as that exact reject, while the same call with and no cycles clause succeeds.
await#system_fatal(with timeout = 30)Make every cross-subnet call bounded-wait and cycle-free:
motoko
// Motoko: `timeout : Nat32` is in seconds
let result = await (with timeout = 30) service.method(args);rust
// Rust, ic-cdk >= 0.18 — bounded_wait defaults to a 300-second timeout (the IC maximum)
let reply: T = Call::bounded_wait(canister_id, "method")
.with_arg(arg)
.await? // Err on reject / SYS_UNKNOWN — handle, do not unwrap
.candid()?; // decode the reply- Same-subnet calls are exempt: canisters on the same engine may call each other unbounded-wait. Bounded-wait is still the better default — an unbounded-wait call to an unresponsive callee blocks the caller's upgrades indefinitely (see the skill).
multi-canister - The restriction applies in both directions: a canister on a normal subnet calling into an engine canister must also use a bounded-wait, cycle-free call.
- A bounded-wait call can complete with (outcome unknown). Handle it — the
SYS_UNKNOWNskill covers the patterns.multi-canister
协议会拒绝任何从 CloudEngine subnet 发起或发往 CloudEngine subnet、且采用 unbounded-wait(guaranteed-response)或携带 cycles 的跨子网(XNet)请求。调用方会收到一条文本完全如下的 reject:
Unbounded-wait calls and calls with cycles are not allowed to CloudEngine subnets已从引擎 canister 实际验证:直接使用 调用另一个 subnet 上的 canister 会返回上述完全一致的 reject,而同一调用使用 且不包含 cycles 子句时则会成功。
await#system_fatal(with timeout = 30)所有跨子网调用都必须使用 bounded-wait,并且不能携带 cycles:
motoko
// Motoko: `timeout : Nat32` is in seconds
let result = await (with timeout = 30) service.method(args);rust
// Rust, ic-cdk >= 0.18 — bounded_wait defaults to a 300-second timeout (the IC maximum)
let reply: T = Call::bounded_wait(canister_id, "method")
.with_arg(arg)
.await? // Err on reject / SYS_UNKNOWN — handle, do not unwrap
.candid()?; // decode the reply- 同一 subnet 内的调用不受此限制: 同一引擎上的 canister 可以相互使用 unbounded-wait 调用。不过,bounded-wait 仍是更好的默认选择——对无响应的被调用方执行 unbounded-wait 调用,会无限期阻塞调用方的升级(参阅 skill)。
multi-canister - 该限制在两个方向上都适用:普通 subnet 上的 canister 调用引擎 canister 时,也必须使用 bounded-wait 且不携带 cycles。
- Bounded-wait 调用可能以 (结果未知)结束。必须处理这种情况——
SYS_UNKNOWNskill 介绍了相关模式。multi-canister
Rule 3 — HTTPS outcalls: ordinary code, zero cost
规则 3——HTTPS outcall:普通代码,零成本
HTTPS outcalls execute on the engine's own subnet, and the cost API reports them as free there, so the standard wrapper works unchanged — there is no engine-specific outcall code:
motoko
import IC "mo:ic/Types";
import Call "mo:ic/Call";
// Build `request : IC.HttpRequestArgs` exactly as in the https-outcalls skill,
// with the transform query on THIS canister. Call.httpRequest asks the cost API,
// which returns 0 on an engine, so nothing is attached.
let response = await Call.httpRequest(request);-
Keep the wrapper; never swap in a hardcoded fee (Rule 1). Letting the wrapper price the call is how outcalls are written in the Motoko engine apps running today.
-
In Rust, use the wrapper your crate line provides —from
HttpRequest::new(url)…send()0.2, the freeic-cdk-management-canisterin 0.1, oric_cdk_management_canister::http_requeston ic-cdk 0.19 (that module was removed in ic-cdk 0.20). All three behave identically here: each asksic_cdk::management_canister::http_request, which prices against your own subnet and so returns 0 on an engine, and each attaches that 0. Write for the line the project is actually on, and never bump crate versions to "fix" an engine outcall — there is nothing to fix.ic0.cost_*covers the differences between the three.https-outcalls -
's outcall builders are the supported path here — only its chain-key helpers are unusable on an engine (Rule 4). The crate is not off-limits; the target subnet is what decides.
ic-cdk-management-canister -
Pricing version 2 needs no tuning on an engine. The 0.2 builder always prices version 2 ("pay-as-you-go"), where the cycles attached double as each node's spending budget — so on a paying subnet an under-narrowedlets a call fail partway, after the remote server was contacted. On an engine that cannot happen: the free cost schedule never charges, so the budget never narrows anything — the round-trip timeout and the transform-instruction limit sit at the protocol maximum, and
with_expected_*is never raised. Treat theInsufficientCyclessetters as no-ops here: set them for portability if you like, but never tune them to fix an engine outcall, and never read an engine outcall failure as a budget problem. What still applies is your ownwith_expected_*— it bounds the response on an engine exactly as anywhere else, so an oversized reply is a real failure cause and the one outcall limit worth checking here.max_response_bytes -
Either pricing version works on an engine, so the version is not something to manage here. Version 2 is accepted only where the replica has pay-as-you-go enabled; where it does not, a requested version 2 is silently filtered back to version 1 with no error. That is a funding mismatch on a paying subnet, but harmless on an engine, because an outcall is charged zero under both versions. Do not add engine-specific version handling.
-
Everything else about outcalls is unchanged — transform function on your own canister,, idempotency. Engines support the full outcall feature set per the platform team, replicated or not, so
max_response_bytesis available for non-idempotent or rate-limited APIs — and for bulk workloads, where a replicated call multiplies every request by the replica count. Load theis_replicated = ?falseskill for those.https-outcalls -
Never route HTTPS outcalls through the console proxy canister. The platform team is explicit: all HTTP outcalls should be direct, and the proxy exists only for mainnet services that require cycles. The IC requires the transform function to live on the canister that issues— behind the proxy that is the proxy itself, and the proxy exposes no transform method (verified against its live interface, and the team confirms none is planned). Untransformed responses differ across replicas for most real APIs, and the call fails with:
http_requestSYS_TRANSIENT: No consensus could be reached. Replicas had different responsesA proxied outcall also pays. The proxy sits on a normal Application subnet, so it is charged the real outcall fee out of the balance you funded, while the same call issued from your engine canister is charged nothing. At migration scale — thousands of calls — that balance drains and every call starts failing with. That is a symptom of proxying outcalls, not of an under-funded engine.ProxyError::InsufficientCyclesBoth failures have the same fix: issue the outcall directly from your canister (free, works). Neither is fixed by retries or by topping the proxy up.
HTTPS outcall 会在引擎自己的 subnet 上执行,而费用 API 会报告它们在该 subnet 上免费,因此标准 wrapper 无需修改即可使用——不存在引擎专用的 outcall 代码:
motoko
import IC "mo:ic/Types";
import Call "mo:ic/Call";
// Build `request : IC.HttpRequestArgs` exactly as in the https-outcalls skill,
// with the transform query on THIS canister. Call.httpRequest asks the cost API,
// which returns 0 on an engine, so nothing is attached.
let response = await Call.httpRequest(request);-
保留 wrapper;绝不能替换成硬编码费用(规则 1)。让 wrapper 为调用定价,正是当前 Motoko 引擎应用编写 outcall 的方式。
-
在 Rust 中,使用项目所用 crate 版本提供的 wrapper——0.2 中的
ic-cdk-management-canister、0.1 中免费的HttpRequest::new(url)…send(),或 ic-cdk 0.19 中的ic_cdk_management_canister::http_request(该模块在 ic-cdk 0.20 中已移除)。三者在引擎上的行为完全相同:它们都会查询ic_cdk::management_canister::http_request,该 API 根据你自己的 subnet 定价,因此在引擎上返回 0,并附加 0。应针对项目实际使用的版本编写代码,绝不要为了“修复”引擎 outcall 而升级 crate 版本——这里没有任何问题需要修复。ic0.cost_*介绍了这三个版本之间的差异。https-outcalls -
的 outcall builder 是这里受支持的路径——只有它的 chain-key helper 无法在引擎上使用(规则 4)。这个 crate 并不是禁用对象;决定因素是目标 subnet。
ic-cdk-management-canister -
引擎无需调整 pricing version 2。 0.2 builder 始终使用 version 2(“pay-as-you-go”),其中附加的 cycles 同时也是每个节点的支出预算。因此,在付费 subnet 上,如果设置得过窄,调用可能在远程服务器已被联系后中途失败。在引擎上不会发生这种情况:免费费用表永远不会收费,因此预算不会产生任何收窄——往返超时和 transform 指令限制都处于协议最大值,并且绝不会抛出
with_expected_*。在这里应将InsufficientCyclessetter 视为无操作:为了可移植性可以设置它们,但绝不能通过调整它们来修复引擎 outcall,也绝不能将引擎 outcall 失败解读为预算问题。仍然适用的是你自己的with_expected_*——它与在其他任何环境中一样会限制引擎上的响应,因此响应过大仍然是真正的失败原因,也是这里唯一值得检查的 outcall 限制。max_response_bytes -
两种 pricing version 在引擎上都能使用,因此不需要管理 version。 只有在 replica 启用 pay-as-you-go 的位置才会接受 version 2;如果未启用,请求的 version 2 会在不报错的情况下被静默过滤回 version 1。在付费 subnet 上,这属于资金不匹配;但在引擎上无害,因为两种 version 下 outcall 的费用都是零。不要添加引擎专用的 version 处理逻辑。
-
Outcall 的其他所有行为均保持不变——在自己的 canister 上使用 transform function、使用、处理 idempotency。根据平台团队说明,无论是否启用 replication,引擎都支持完整的 outcall 功能集,因此可对非幂等或受速率限制的 API 使用
max_response_bytes;对于批量工作负载,replicated 调用会将每个请求乘以 replica 数量。请加载is_replicated = ?falseskill 了解相关内容。https-outcalls -
绝不能通过 console proxy canister 路由 HTTPS outcall。 平台团队明确说明:所有 HTTP outcall 都应直接发起,proxy 仅用于需要 cycles 的 mainnet 服务。IC 要求 transform function 必须位于发起的 canister 上——放在 proxy 后面时,它会位于 proxy 自身,而 proxy 不提供 transform method(已根据其实际 interface 验证,团队也确认没有提供此方法的计划)。对于大多数实际 API,未经 transform 的响应在各 replica 之间存在差异,调用会失败并返回:
http_requestSYS_TRANSIENT: No consensus could be reached. Replicas had different responses通过 proxy 发起 outcall 还会产生费用。Proxy 位于普通 Application subnet 上,因此会从你提供资金的余额中扣除真实的 outcall 费用,而同一调用从你的引擎 canister 发起时则不收取任何费用。在迁移规模下——数千次调用——该余额会被耗尽,随后每次调用都会开始失败并返回。这是通过 proxy 发起 outcall 所导致的症状,而不是引擎资金不足。ProxyError::InsufficientCycles两种失败具有相同的修复方式:直接从你的 canister 发起 outcall(免费且可用)。重试或为 proxy 充值都无法解决任何一种失败。
Rule 4 — Cross-subnet cycle-bearing calls via the console proxy
规则 4——通过 console proxy 执行需要 cycles 的跨子网调用
Two separate facts land in the same place. The Rule 2 restriction means an engine canister cannot send a cross-subnet message carrying cycles — and, per the platform team, cloud engines do not provide threshold signing at all, so those facilities have to be reached on mainnet. Either way the call cannot be made directly:
- threshold ECDSA / Schnorr signing (,
sign_with_ecdsa) and their public-key methods, and vetKD (sign_with_schnorr,vetkd_derive_key) — not available on an engine; use mainnet's via the proxy,vetkd_public_key - the exchange-rate canister (XRC) — a mainnet canister that charges cycles,
- the Bitcoin API (the management canister's methods) and the EVM RPC and SOL RPC canisters, which charge cycles per call.
bitcoin_*
A console proxy relays nothing else for your canisters (see "What a console proxy relays" below). This is the proxy's entire purpose: reaching mainnet services that require cycles. It is not for HTTPS outcalls (Rule 3).
The workaround is the console proxy canister: deployed on a normal Application subnet and kept funded out of the engine's balance. Your engine canister makes a cheap, cycle-less, bounded-wait call to the proxy, which re-issues it locally with the cycles attached and relays the raw reply back. Same-subnet or cycle-less calls do not need it — and neither do HTTPS outcalls (Rule 3).
两个彼此独立的事实最终汇聚到同一个解决方案。规则 2 的限制意味着引擎 canister 不能发送携带 cycles 的跨子网消息——而且根据平台团队的说明,cloud engine 根本不提供 threshold signing,因此必须通过 mainnet 访问这些功能。无论哪种情况,都不能直接发起调用:
- Threshold ECDSA / Schnorr 签名(、
sign_with_ecdsa)及其 public-key 方法,以及 vetKD(sign_with_schnorr、vetkd_derive_key)——引擎上不可用;应通过 proxy 使用 mainnet 上的这些功能;vetkd_public_key - Exchange-rate canister(XRC)——这是一个按 cycles 收费的 mainnet canister;
- Bitcoin API(management canister 的 方法),以及每次调用都会收取 cycles 的 EVM RPC 和 SOL RPC canister。
bitcoin_*
Console proxy 不会为你的 canister 中继其他任何内容(参阅下文的“What a console proxy relays”)。这正是 proxy 的唯一用途:访问需要 cycles 的 mainnet 服务。它不用于 HTTPS outcall(规则 3)。
解决方案是使用 console proxy canister:它部署在普通 Application subnet 上,并使用引擎余额中的资金维持运行。你的引擎 canister 向 proxy 发起一次廉价、无 cycles、bounded-wait 的调用;proxy 会在本地重新发起该调用并附加 cycles,然后将原始 reply 中继回来。同 subnet 调用或无需 cycles 的调用不需要 proxy——HTTPS outcall 也不需要(规则 3)。
Before writing the code: ask the user for the proxy
编写代码前:向用户询问 proxy
Neither your canister code nor you can create the console proxy: the engine's owner deploys it from the console, and the app only receives its canister id as configuration. So as soon as a task needs any target in the list above (a feature request, a plan, a port of existing code), raise it with the user before writing that code, not after the first call fails on the engine:
-
Say the app needs the engine's proxy canister, and why, in one sentence.
-
Ask whether the engine already has one:
- It does: ask for its canister id (engine → Integrations → Proxy canisters). If there are several and the app signs or derives keys, ask which one the app is to use: every derived key follows that choice (see "Threshold keys through the proxy"). Never pick one for them.
- It does not: ask the owner to deploy one: engine → Integrations → Proxy canisters → Deploy a proxy, then confirm. There is no card and no amount to choose: the proxy is paid for out of the engine's balance and tops itself up from it when it runs low. Then ask for the id it shows.
For example: "This app signs through your engine's proxy canister. If the engine has one, send me its id (engine → Integrations → Proxy canisters). If not, the engine owner can deploy one there with Deploy a proxy: it is paid from the engine's balance, no card. Then send me its id." -
Keep working meanwhile: read the id from a canister environment variable (, see
PROXY_CANISTER_ID), never a literal in source. The id is needed to deploy, not to write the code.deploy-to-cloud-engine -
When the id arrives, check it is a console proxy. This query is free and needs no project:bash
icp canister call <proxy-id> get_allowed_subnet '()' -n ic --query(the engine's subnet) is a console proxy, open to every canister on that subnet.opt principal "…", or an error that the canister has no such method, means it is not one (a self-deployed proxy, or not a proxy at all): ask again. Do not judge bynull: a console proxy answers it with an empty list.get_allowed_ranges(same form) also shows itsget_funding, andbalancebecause the engine tops it up.funding = opt record { engine_canister = …; … }
Never invent an id, reuse one from another engine or project, or deploy a self-deployed proxy as a stand-in while you wait: it rejects your engine canisters and derives different keys (see the table below).
无论是你的 canister 代码还是你本人,都无法创建 console proxy:引擎的所有者会从控制台部署它,应用只会将其 canister id 作为配置接收。因此,一旦任务需要上述任何目标(无论是功能请求、计划还是移植现有代码),都必须在编写相关代码之前向用户提出,而不是等引擎上的首次调用失败后再处理:
-
用一句话说明应用需要引擎的 proxy canister,以及需要它的原因。
-
询问引擎是否已经有一个:
- 已有: 询问其 canister id(engine → Integrations → Proxy canisters)。如果存在多个,而应用需要签名或派生密钥,则询问应用应使用哪一个:每个派生密钥都取决于该选择(参阅“Threshold keys through the proxy”)。绝不要替用户选择。
- 没有: 请所有者部署一个:engine → Integrations → Proxy canisters → Deploy a proxy,然后进行确认。这里没有卡片,也没有需要选择的金额:proxy 使用引擎余额付费,余额不足时会自行充值。然后询问它显示的 id。
例如:“此应用通过你引擎的 proxy canister 进行签名。如果引擎已有 proxy,请发送其 id(engine → Integrations → Proxy canisters)。如果没有,引擎所有者可以在该位置通过 Deploy a proxy 部署一个:费用从引擎余额扣除,不需要卡片。然后请发送其 id。” -
同时继续其他工作:从 canister 环境变量读取该 id(,参阅
PROXY_CANISTER_ID),绝不要在源代码中写死。该 id 是部署所必需的,而不是编写代码所必需的。deploy-to-cloud-engine -
收到 id 后,检查它是否为 console proxy。下面的查询免费且不需要项目:bash
icp canister call <proxy-id> get_allowed_subnet '()' -n ic --query(引擎的 subnet)表示它是 console proxy,并允许该 subnet 上的所有 canister 调用。返回opt principal "…",或出现该 canister 没有此类方法的错误,则表示它不是 console proxy(可能是自行部署的 proxy,也可能根本不是 proxy):请再次询问。不要通过null判断——console proxy 对此会返回空列表。get_allowed_ranges(使用相同形式)还会显示其get_funding,并且会得到balance,因为引擎会为它充值。funding = opt record { engine_canister = …; … }
绝不要虚构 id、复用另一个引擎或项目的 id,也不要在等待期间部署自行部署的 proxy 作为临时替代方案:它会拒绝你的引擎 canister,并且会派生不同的密钥(参阅下表)。
Getting a proxy
获取 proxy
Two different canisters can play the role, and they are not interchangeable:
| Console proxy (the engine's) | Self-deployed proxy ( | |
|---|---|---|
| Deployed by | The engine's owner, from the console | You, with |
| Who may call it | Every canister on the engine's subnet (checked with the NNS registry), plus its controller | Controllers only |
| Your engine canisters can call it | Yes, with no extra setup | Only if you add each of them as a controller |
| What it relays for them | Only the targets listed above | Anything |
| Threshold-key derivation | Caller-isolated (see below) | No isolation: raw pass-through |
| Funded with | The engine's balance: it tops itself up when low, no card | Cycles you already hold ( |
For engine canisters, use the console proxy. A self-deployed proxy is the right tool for calls you make from the CLI (, ), and the console proxy cannot serve that purpose, because it rejects ingress calls from any principal that is not one of its controllers, which your CLI identity is not.
icp canister call --proxyicp deploy --proxyDeploying and funding either one is not a canister-code task. It is covered in the skill; from here you need only the resulting proxy canister id. Take it from the user or from the app's configuration, never hardcode a guess, and read the derivation warning below before assuming one proxy id can be swapped for another.
deploy-to-cloud-engine两种不同的 canister 可以承担这一角色,但它们不可互换:
| Console proxy(引擎的) | Self-deployed proxy( | |
|---|---|---|
| 部署者 | 引擎的所有者,通过控制台部署 | 你,使用 |
| 谁可以调用 | 引擎 subnet 上的所有 canister(通过 NNS registry 检查),以及其 controller | 仅 Controller |
| 你的引擎 canister 能否调用 | 可以,无需额外设置 | 仅当将每个引擎 canister 都添加为 controller 时才可以 |
| 它会为这些调用方中继什么 | 仅限上述目标 | 任意目标 |
| Threshold-key 派生 | 按调用方隔离(见下文) | 不隔离:原始透传 |
| 资金来源 | 引擎余额:余额不足时自行充值,不需要卡片 | 你已经持有的 cycles( |
对于引擎 canister,请使用 console proxy。自行部署的 proxy 适用于你在 CLI 中发起的调用(、);console proxy 无法用于此目的,因为它会拒绝来自任何非 controller principal 的 ingress 调用,而你的 CLI identity 并不属于其 controller。
icp canister call --proxyicp deploy --proxy部署和资助任何一种 proxy 都不属于 canister 代码任务。这部分内容包含在 skill 中;在这里你只需要最终的 proxy canister id。应从用户或应用配置中获取该 id,绝不能硬编码一个猜测值,并且在假定一个 proxy id 可以替换为另一个之前,务必阅读下方的派生警告。
deploy-to-cloud-engineCall through the proxy from your canister
从你的 canister 通过 proxy 调用
Instead of calling the target canister directly, call the proxy's method with the target id, method name, candid-encoded argument bytes, and the cycles to attach. Its candid interface:
proxycandid
type ProxyArgs = record { canister_id : principal; method : text; args : blob; cycles : nat };
type ProxySucceed = record { result : blob };
type ProxyError = variant {
InsufficientCycles : record { available : nat; required : nat };
CallFailed : record { reason : text };
UnauthorizedUser;
};
type ProxyResult = variant { Ok : ProxySucceed; Err : ProxyError };
service : {
proxy : (ProxyArgs) -> (ProxyResult);
get_allowed_subnet : () -> (opt principal) query;
};- is the candid-encoded argument of the target method (you encode it);
argsis the target's raw reply bytes (you decode it).result - is what the proxy attaches to the relayed call — size it to what the target charges (e.g. the XRC or signing fee). The platform team confirms the caller chooses how much the proxy attaches, and the proxy receives
cyclesas an opaque blob, so it cannot size the amount for you: a constant you pass is exactly what it will require, and theargsfield ofrequiredechoes your own number back rather than reporting a proxy-side reservation. Do not attach cycles to the outerInsufficientCyclescall itself; the engine subnet forbids that and it is unnecessary.proxy - Handle :
ProxyErrormeans the proxy's balance is too low (a console proxy tops itself up from the engine's balance, so a lasting one means that balance is short: pitfall 8),InsufficientCyclesmeans the caller is not on the engine's subnet,UnauthorizedUsercarries the downstream reject reason, or says the console proxy does not relay that target (see "What a console proxy relays"), or that it could not yet check the caller's subnet with the NNS registry (CallFailed). That last one comes only while the proxy looks a caller up (typically a canister's first call after the proxy was installed or upgraded), and nothing was relayed: just retry.could not verify which subnet the caller … is on (…); retry - Over-attaching is safe; under-attaching is not. The callee refunds what it does not consume, and the refund goes back to the proxy (the proxy is the caller on that leg), so a generous figure costs nothing and survives a fee increase.
cyclesinavailableis the proxy's liquid balance (its freezing reserve is already excluded), so a proxy can reportInsufficientCycleswhile still showing a balance in the console.InsufficientCycles - A is not proof the call did not happen. The proxy relays with a bounded-wait call, so a downstream
CallFailedreaches you asSYS_UNKNOWNwith that reject code inCallFailed. The target may have executed and the cycles may already be spent. Treat it as "outcome unknown", not "failed": thereasonskill covers the patterns.multi-canister
Motoko sketch (Rust is analogous with / ):
candid::encode_onedecode_onemotoko
// `proxy` is an actor typed to the candid interface above.
let arg = to_candid (request); // encode the TARGET method's argument
let res = await (with timeout = 30) proxy.proxy({
canister_id = xrcPrincipal;
method = "get_exchange_rate";
args = arg;
cycles = 1_000_000_000; // the XRC fee the proxy forwards
});
switch (res) {
case (#Ok { result }) { let ?reply = from_candid (result) else return; /* … */ };
case (#Err e) { /* InsufficientCycles | CallFailed | UnauthorizedUser */ };
};不要直接调用目标 canister,而应调用 proxy 的 方法,并传入目标 id、方法名、Candid 编码后的参数字节以及要附加的 cycles。其 Candid interface 如下:
proxycandid
type ProxyArgs = record { canister_id : principal; method : text; args : blob; cycles : nat };
type ProxySucceed = record { result : blob };
type ProxyError = variant {
InsufficientCycles : record { available : nat; required : nat };
CallFailed : record { reason : text };
UnauthorizedUser;
};
type ProxyResult = variant { Ok : ProxySucceed; Err : ProxyError };
service : {
proxy : (ProxyArgs) -> (ProxyResult);
get_allowed_subnet : () -> (opt principal) query;
};- 是目标方法的 Candid 编码参数(由你编码);
args是目标的原始 reply 字节(由你解码)。result - 是 proxy 为中继调用所附加的 cycles——其数额应与目标所收取的费用匹配,例如 XRC 或签名费用。平台团队确认,调用方决定 proxy 附加多少 cycles,而 proxy 将
cycles视为不透明 blob,因此无法替你计算金额:你传入的常量就是它所需的数额,args中的InsufficientCycles字段只会原样返回你传入的数字,而不会报告 proxy 侧的预留额度。绝不要在外部required调用本身上附加 cycles;引擎 subnet 禁止这样做,而且也没有必要。proxy - 必须处理 :
ProxyError表示 proxy 余额过低(console proxy 会使用引擎余额自行充值,因此持续出现此错误意味着引擎余额不足:参见陷阱 8);InsufficientCycles表示调用方不在引擎 subnet 上;UnauthorizedUser会携带下游 reject 原因,或者说明 console proxy 不会中继该目标(参阅“What a console proxy relays”),也可能表示 proxy 暂时无法通过 NNS registry 检查调用方所在 subnet(CallFailed)。最后一种错误只会出现在 proxy 查找调用方期间,通常是 proxy 安装或升级后 canister 的首次调用;此时尚未发生任何中继,只需重试。could not verify which subnet the caller … is on (…); retry - 多附加是安全的;少附加则不安全。 被调用方会退还未消耗的部分,而退款会返回给 proxy(在中继这一段调用中,proxy 才是调用方),因此提供 generous 的 数额不会产生额外成本,并且能够承受费用上涨。
cycles中的InsufficientCycles是 proxy 的流动余额(已经排除了冻结准备金),因此 proxy 可能报告available,同时控制台中仍显示有余额。InsufficientCycles - 并不能证明调用没有发生。 Proxy 使用 bounded-wait 调用进行中继,因此下游的
CallFailed会以SYS_UNKNOWN的形式返回给你,并在CallFailed中包含该 reject code。目标可能已经执行,cycles 也可能已经消耗。必须将其视为“结果未知”,而不是“失败”——reasonskill 介绍了相关模式。multi-canister
Motoko 示例(Rust 可使用 / 实现类似逻辑):
candid::encode_onedecode_onemotoko
// `proxy` is an actor typed to the candid interface above.
let arg = to_candid (request); // encode the TARGET method's argument
let res = await (with timeout = 30) proxy.proxy({
canister_id = xrcPrincipal;
method = "get_exchange_rate";
args = arg;
cycles = 1_000_000_000; // the XRC fee the proxy forwards
});
switch (res) {
case (#Ok { result }) { let ?reply = from_candid (result) else return; /* … */ };
case (#Err e) { /* InsufficientCycles | CallFailed | UnauthorizedUser */ };
};What a console proxy relays
Console proxy 会中继什么
A console proxy pays out of the engine's balance, so for the engine's canisters it relays only what a proxy is for:
- the management canister ():
aaaaa-aa,sign_with_ecdsa,ecdsa_public_key,sign_with_schnorr,schnorr_public_key,vetkd_derive_key,vetkd_public_key, and thehttp_requestmethods (bitcoin_*,bitcoin_get_balance,bitcoin_get_utxos,bitcoin_send_transaction,bitcoin_get_current_fee_percentiles);bitcoin_get_block_headers - any method of these mainnet canisters: the exchange-rate canister , EVM RPC
uf6dk-hyaaa-aaaaq-qaaaq-cai, SOL RPC7hfb6-caaaa-aaaar-qadga-cai, Bitcoin mainnettghme-zyaaa-aaaar-qarca-caiand testnetghsi2-tqaaa-aaaan-aaaca-cai, and Dogecoing4xu7-jiaaa-aaaan-aaaaq-cai.gordg-fyaaa-aaaan-aaadq-cai
Anything else (another canister, , , the cycles ledger) comes back as with a reason starting . Topping up does not change that. is on the list, but Rule 3 still applies: make outcalls from your own canister. If the app genuinely has to pay a canister outside this list, that takes a self-deployed proxy with each calling canister added as a controller (see ), funded with cycles you hold.
deposit_cyclescreate_canisterCallFaileda proxy funded by its engine relays only to …http_requestdeploy-to-cloud-engineConsole proxy 使用引擎余额付费,因此对于引擎的 canister,它只中继 proxy 应当处理的内容:
- Management canister():
aaaaa-aa、sign_with_ecdsa、ecdsa_public_key、sign_with_schnorr、schnorr_public_key、vetkd_derive_key、vetkd_public_key,以及http_request方法(bitcoin_*、bitcoin_get_balance、bitcoin_get_utxos、bitcoin_send_transaction、bitcoin_get_current_fee_percentiles);bitcoin_get_block_headers - 以下 mainnet canister 的任意方法:exchange-rate canister 、EVM RPC
uf6dk-hyaaa-aaaaq-qaaaq-cai、SOL RPC7hfb6-caaaa-aaaar-qadga-cai、Bitcoin mainnettghme-zyaaa-aaaar-qarca-cai和 testnetghsi2-tqaaa-aaaan-aaaca-cai,以及 Dogecoing4xu7-jiaaa-aaaan-aaaaq-cai。gordg-fyaaa-aaaan-aaadq-cai
其他任何内容(另一个 canister、、、cycles ledger)都会以 返回,reason 以 开头。充值不会改变这一点。虽然 在列表中,但规则 3 仍然适用:应从你自己的 canister 发起 outcall。如果应用确实需要调用列表之外的 canister,则必须使用自行部署的 proxy,并将每个调用方 canister 添加为 controller(参阅 ),且使用你持有的 cycles 为其提供资金。
deposit_cyclescreate_canisterCallFaileda proxy funded by its engine relays only to …http_requestdeploy-to-cloud-engineThreshold keys through the proxy (read this before deriving keys)
通过 proxy 使用 threshold key(派生密钥前必读)
Threshold ECDSA, Schnorr, and vetKD are the proxy's main job on an engine, and the one place where getting the call wrong costs more than an error message: a key you cannot reproduce is a Bitcoin or Ethereum address whose funds you cannot move.
The chain-key helpers do not work here. , 's chain-key functions (, , and their public-key siblings), and Motoko's all call directly and attach the fee for you. Because the chain-key cost API prices against the key-holding subnet, that fee is non-zero even on an engine, and the helper issues an unbounded-wait call carrying it — a cross-subnet, cycle-bearing call, rejected twice over (Rules 1 and 2). Their convenience is exactly what you must give up: encode the management-canister argument yourself and send it through the proxy. The skill's code is written for a normal subnet and needs this rewrite before it will run on an engine.
ic-vetkeysic-cdk-management-canistersign_with_ecdsasign_with_schnorrvetkd_derive_keymo:ic-vetkeys/ManagementCanisteraaaaa-aavetkeysThis is scoped to the chain-key functions, not to the crates. also carries the HTTPS-outcall builders, and those are the supported way to make an outcall from an engine canister (Rule 3): they target your own subnet, price at 0, and must not be routed through the proxy. Reading "the helpers don't work on an engine" as "hand-encode outcalls through the proxy too" produces exactly the consensus and funding failures in pitfall 4. Split the crate by target subnet: local outcall ⇒ ordinary builder; remote chain-key ⇒ proxy.
ic-cdk-management-canisterWhat the proxy rewrites. For the six key methods (, , , , , ) the console proxy decodes your argument, isolates the derivation to you, and re-encodes it:
sign_with_ecdsaecdsa_public_keysign_with_schnorrschnorr_public_keyvetkd_derive_keyvetkd_public_key- ECDSA / Schnorr: your calling canister's principal is inserted as the first element of .
derivation_path - vetKD: your principal is prepended to , length-tagged: one byte holding the principal's length, then the principal bytes, then your context.
context - On the three methods,
*_public_keyis additionally forced tocanister_id.None
The principal comes from , so it cannot be forged and one engine canister can never reach another's keys. (Verified: , 10/10; , , .)
msg_caller()cargo test -p proxy-canister --libecdsa_sign_prepends_caller_and_preserves_the_restvetkd_prefixes_caller_into_context_length_taggeddistinct_callers_get_distinct_derivationsFees. , , and are free: pass . The paying methods are charged by the subnet that holds the key, not yours:
ecdsa_public_keyschnorr_public_keyvetkd_public_keycycles = 0| Key name | |
|---|---|
| 26_153_846_153 |
| 10_000_000_000 |
Round up rather than passing the exact figure: the unused remainder is refunded to the proxy.
Worked example: ECDSA, Motoko. Declare the management-canister types yourself; field names and variant tags must match the candid interface exactly, because the proxy decodes and re-encodes the blob; a missing or misnamed field, or an unknown variant tag, fails the decode (surfacing as , not a mis-derived key). A field the proxy does not model is not caught: candid's record subtyping skips it on decode and the re-encode drops it.
CallFailedmotoko
type EcdsaKeyId = { curve : { #secp256k1 }; name : Text };
type EcdsaPublicKeyArgs = { canister_id : ?Principal; derivation_path : [Blob]; key_id : EcdsaKeyId };
type EcdsaPublicKeyReply = { public_key : Blob; chain_code : Blob };
type SignWithEcdsaArgs = { message_hash : Blob; derivation_path : [Blob]; key_id : EcdsaKeyId };
type SignWithEcdsaReply = { signature : Blob };
let mgmt = Principal.fromText("aaaaa-aa");
let keyId : EcdsaKeyId = { curve = #secp256k1; name = "key_1" };
let signFee = 30_000_000_000; // >= 26_153_846_153; the excess comes back
// One helper for every proxied management call.
func viaProxy(method : Text, arg : Blob, cycles : Nat) : async Blob {
let res = await (with timeout = 30) proxy.proxy({
canister_id = mgmt; // the TARGET, not the proxy
method = method;
args = arg;
cycles = cycles; // 0 for the *_public_key methods
});
switch (res) {
case (#Ok { result }) { result };
case (#Err e) { Runtime.trap("proxy: " # debug_show e) }; // real code: return an error
};
};
// Address: free, no cycles.
let pkArg = to_candid ({
canister_id = null; // forced to null by the proxy anyway
derivation_path = [Text.encodeUtf8("user-42")]; // your own path; the proxy prefixes itself
key_id = keyId;
} : EcdsaPublicKeyArgs);
let ?pk : ?EcdsaPublicKeyReply = from_candid (await viaProxy("ecdsa_public_key", pkArg, 0))
else Runtime.trap("decode ecdsa_public_key");
// Signature: pays the fee. `message_hash` must be exactly 32 bytes.
let sigArg = to_candid ({
message_hash = messageHash;
derivation_path = [Text.encodeUtf8("user-42")]; // the SAME path as above
key_id = keyId;
} : SignWithEcdsaArgs);
let ?sig : ?SignWithEcdsaReply = from_candid (await viaProxy("sign_with_ecdsa", sigArg, signFee))
else Runtime.trap("decode sign_with_ecdsa");Note that has no field: the key it signs with is always the caller's, and behind the proxy the caller is the proxy. That is precisely why the public key you publish and the signature you produce must both come through the same proxy.
sign_with_ecdsacanister_idWorked example: vetKD, Motoko. Same shape, different types. is free; pays.
vetkd_public_keyvetkd_derive_keymotoko
type VetkdKeyId = { curve : { #bls12_381_g2 }; name : Text };
type VetkdPublicKeyArgs = { canister_id : ?Principal; context : Blob; key_id : VetkdKeyId };
type VetkdPublicKeyReply = { public_key : Blob };
type VetkdDeriveKeyArgs = {
input : Blob; context : Blob; transport_public_key : Blob; key_id : VetkdKeyId
};
type VetkdDeriveKeyReply = { encrypted_key : Blob };
let vetKeyId : VetkdKeyId = { curve = #bls12_381_g2; name = "key_1" };
let dkArg = to_candid ({
input = Text.encodeUtf8("note-7");
context = Text.encodeUtf8("my-app"); // the proxy length-tags its prefix onto this
transport_public_key = transportPk;
key_id = vetKeyId;
} : VetkdDeriveKeyArgs);
let ?dk : ?VetkdDeriveKeyReply = from_candid (await viaProxy("vetkd_derive_key", dkArg, 30_000_000_000))
else Runtime.trap("decode vetkd_derive_key");Rust is the same flow with / and a bounded-wait call, see the shape in the example under Rule 2.
candid::encode_onedecode_oneCall::bounded_wait(proxy_id, "proxy")The derived key belongs to the proxy, not to your app. The management canister derives from its caller, which is the proxy, so the key you get depends on which proxy canister id you went through:
- Point the app at a different proxy (a second one from the console's "Deploy another proxy", or a self-deployed one) and every address changes. The old address is not recoverable from the new proxy.
- Deleting a proxy destroys access to its keys. The console's delete button sends the unspent cycles back to the engine's balance; it cannot give back the derivation. Any Bitcoin or Ethereum funds held at an address derived through that proxy become permanently unspendable. Treat the proxy id of a signing app as permanent infrastructure, and never delete a proxy to "save cycles" without first moving every asset off the addresses derived through it.
- A self-deployed upstream proxy does no isolation at all (no principal prefix, no forced ), so its keys differ again from the console proxy's: the two are not substitutes even before the id changes.
canister_id = None - Anything reproducing a derivation off-chain (deriving the same public key in a frontend, say) must replicate the prefix the proxy injects, including vetKD's length tag.
Threshold ECDSA、Schnorr 和 vetKD 是 proxy 在引擎上的主要工作,也是将调用写错时后果最严重的地方:无法复现的密钥意味着对应的 Bitcoin 或 Ethereum 地址将无法转移其中的资金。
Chain-key helper 在这里无法使用。 、 的 chain-key 函数(、、 及其 public-key 对应函数),以及 Motoko 的 ,都会直接调用 并替你附加费用。由于 chain-key 费用 API 根据持有密钥的 subnet 定价,即使从引擎调用,该费用也非零;helper 还会发起携带费用的 unbounded-wait 调用——也就是同时违反规则 1 和规则 2 的跨子网、携带 cycles 的调用。你必须放弃的正是这些 helper 带来的便利:自行编码 management-canister 参数,并通过 proxy 发送。 skill 中的代码面向普通 subnet 编写,在引擎上运行前必须改写为上述形式。
ic-vetkeysic-cdk-management-canistersign_with_ecdsasign_with_schnorrvetkd_derive_keymo:ic-vetkeys/ManagementCanisteraaaaa-aavetkeys此限制仅针对 chain-key 函数,而不是整个 crate。 还包含 HTTPS-outcall builder,而它正是从引擎 canister 发起 outcall 的受支持方式(规则 3):这些 builder 面向你自己的 subnet,定价为 0,绝不能通过 proxy 路由。如果将“helper 在引擎上不可用”误解为“outcall 也必须手动编码并通过 proxy 发送”,就会直接触发陷阱 4 中描述的共识和资金问题。请根据目标 subnet 区分:本地 outcall 使用普通 builder;远程 chain-key 使用 proxy。
ic-cdk-management-canisterProxy 会改写什么。 对于六个密钥方法(、、、、、),console proxy 会解码你的参数,将派生隔离到你的调用方,然后重新编码:
sign_with_ecdsaecdsa_public_keysign_with_schnorrschnorr_public_keyvetkd_derive_keyvetkd_public_key- 对于 ECDSA / Schnorr:调用方 canister 的 principal 会作为 的第一个元素插入。
derivation_path - 对于 vetKD:调用方 principal 会添加到 前面,并进行长度标记:先写入一个保存 principal 长度的字节,然后写入 principal 字节,最后写入你的 context。
context - 对于三个 方法,还会强制将
*_public_key设置为canister_id。None
Principal 来自 ,因此无法伪造,一个引擎 canister 绝不可能访问另一个引擎 canister 的密钥。(已验证:,10/10;、、。)
msg_caller()cargo test -p proxy-canister --libecdsa_sign_prepends_caller_and_preserves_the_restvetkd_prefixes_caller_into_context_length_taggeddistinct_callers_get_distinct_derivations费用。 、 和 免费:传入 。付费方法按持有密钥的 subnet 收费,而不是按你的 subnet 收费:
ecdsa_public_keyschnorr_public_keyvetkd_public_keycycles = 0| 密钥名称 | |
|---|---|
| 26_153_846_153 |
| 10_000_000_000 |
应向上取整,不要传入完全相等的数值:未使用的余数会退还给 proxy。
示例:ECDSA,Motoko。 自行声明 management-canister 类型;字段名和 variant tag 必须与 Candid interface 完全匹配,因为 proxy 会解码并重新编码 blob。缺少字段、字段名错误或使用未知 variant tag 都会导致解码失败(表现为 ,而不是派生出了错误密钥)。Proxy 未建模的字段不会被检查:Candid 的 record subtyping 会在解码时跳过该字段,重新编码时将其丢弃。
CallFailedmotoko
type EcdsaKeyId = { curve : { #secp256k1 }; name : Text };
type EcdsaPublicKeyArgs = { canister_id : ?Principal; derivation_path : [Blob]; key_id : EcdsaKeyId };
type EcdsaPublicKeyReply = { public_key : Blob; chain_code : Blob };
type SignWithEcdsaArgs = { message_hash : Blob; derivation_path : [Blob]; key_id : EcdsaKeyId };
type SignWithEcdsaReply = { signature : Blob };
let mgmt = Principal.fromText("aaaaa-aa");
let keyId : EcdsaKeyId = { curve = #secp256k1; name = "key_1" };
let signFee = 30_000_000_000; // >= 26_153_846_153; the excess comes back
// One helper for every proxied management call.
func viaProxy(method : Text, arg : Blob, cycles : Nat) : async Blob {
let res = await (with timeout = 30) proxy.proxy({
canister_id = mgmt; // the TARGET, not the proxy
method = method;
args = arg;
cycles = cycles; // 0 for the *_public_key methods
});
switch (res) {
case (#Ok { result }) { result };
case (#Err e) { Runtime.trap("proxy: " # debug_show e) }; // real code: return an error
};
};
// Address: free, no cycles.
let pkArg = to_candid ({
canister_id = null; // forced to null by the proxy anyway
derivation_path = [Text.encodeUtf8("user-42")]; // your own path; the proxy prefixes itself
key_id = keyId;
} : EcdsaPublicKeyArgs);
let ?pk : ?EcdsaPublicKeyReply = from_candid (await viaProxy("ecdsa_public_key", pkArg, 0))
else Runtime.trap("decode ecdsa_public_key");
// Signature: pays the fee. `message_hash` must be exactly 32 bytes.
let sigArg = to_candid ({
message_hash = messageHash;
derivation_path = [Text.encodeUtf8("user-42")]; // the SAME path as above
key_id = keyId;
} : SignWithEcdsaArgs);
let ?sig : ?SignWithEcdsaReply = from_candid (await viaProxy("sign_with_ecdsa", sigArg, signFee))
else Runtime.trap("decode sign_with_ecdsa");注意, 没有 字段:它所签名的密钥始终属于调用方,而在 proxy 后面,调用方是 proxy。这正是你发布的 public key 和生成的 signature 必须来自同一个 proxy 的原因。
sign_with_ecdsacanister_id示例:vetKD,Motoko。 整体形式相同,但类型不同。 免费; 需要付费。
vetkd_public_keyvetkd_derive_keymotoko
type VetkdKeyId = { curve : { #bls12_381_g2 }; name : Text };
type VetkdPublicKeyArgs = { canister_id : ?Principal; context : Blob; key_id : VetkdKeyId };
type VetkdPublicKeyReply = { public_key : Blob };
type VetkdDeriveKeyArgs = {
input : Blob; context : Blob; transport_public_key : Blob; key_id : VetkdKeyId
};
type VetkdDeriveKeyReply = { encrypted_key : Blob };
let vetKeyId : VetkdKeyId = { curve = #bls12_381_g2; name = "key_1" };
let dkArg = to_candid ({
input = Text.encodeUtf8("note-7");
context = Text.encodeUtf8("my-app"); // the proxy length-tags its prefix onto this
transport_public_key = transportPk;
key_id = vetKeyId;
} : VetkdDeriveKeyArgs);
let ?dk : ?VetkdDeriveKeyReply = from_candid (await viaProxy("vetkd_derive_key", dkArg, 30_000_000_000))
else Runtime.trap("decode vetkd_derive_key");Rust 的流程相同,使用 / 和 bounded-wait 调用;可参阅规则 2 中 示例的代码结构。
candid::encode_onedecode_oneCall::bounded_wait(proxy_id, "proxy")派生密钥属于 proxy,而不属于你的应用。 Management canister 根据它的调用方派生密钥,而这里的调用方是 proxy,因此你获得的密钥取决于你通过哪个 proxy canister id 发起调用:
- 如果将应用指向另一个 proxy(控制台中的“Deploy another proxy”所创建的第二个 proxy,或自行部署的 proxy),所有地址都会改变。无法从新 proxy 恢复旧地址。
- 删除 proxy 会永久失去其密钥的访问权限。 控制台的删除按钮会将未使用的 cycles 退回引擎余额,但无法返还派生关系。通过该 proxy 派生地址所托管的任何 Bitcoin 或 Ethereum 资金都将永久无法支出。应将签名应用的 proxy id 视为永久基础设施,绝不能为了“节省 cycles”而删除 proxy,除非先将所有资产从通过它派生的地址中移走。
- 自行部署的 upstream proxy 完全不执行隔离(不添加 principal 前缀,也不会强制设置 ),因此其密钥又会不同:即使尚未更换 id,这两种 proxy 也不能互相替代。
canister_id = None - 任何需要在链下复现派生过程的操作(例如在前端派生相同的 public key)都必须复制 proxy 注入的前缀,包括 vetKD 的长度标记。
Rule 5 — Inference through the engine operator
规则 5——通过 engine operator 执行 inference
Every engine has an engine-operator canister, and it is the engine's route to AI inference. The operator holds a list of providers with their keys: today and . The engine's owner or an admin turns one on in the console (engine → Integrations → Inference) and can switch it at any time. A canister on the engine sends an OpenAI request to the operator's , and the operator adds the key of the provider that is on and makes the outcall.
iigcaffeineinference_request- No provider key in the canister (source, init args, environment variables) and no outcall to a provider's host. Such a canister spends credit from code anyone can read and ignores the owner's switch.
- Leave and
providerout. The provider that is on answers with its own default model, so the code keeps working when the owner switches. A named provider that is off answersmodel, and model ids differ per provider.BadRequest - No cycles, and a plain is allowed (same subnet, Rule 2). A bounded wait needs a timeout above the outcall's 30 second deadline (
await, or(with timeout = 60)'s 300 second default): a shorter one returnsCall::bounded_waitwhile the operator may still spend the credit.SYS_UNKNOWN
每个引擎都有一个 engine-operator canister,它是引擎访问 AI inference 的路径。Operator 持有一个 provider 列表及其密钥:目前为 和 。引擎的所有者或管理员可以在控制台中启用其中一个(engine → Integrations → Inference),并可随时切换。引擎上的 canister 向 operator 的 发送 OpenAI 请求,operator 会添加当前启用 provider 的密钥并发起 outcall。
iigcaffeineinference_request- Canister 中不能有 provider 密钥(源代码、init args 或环境变量中均不可有),也不能直接向 provider 主机发起 outcall。这种 canister 会从任何人都能读取的代码中消耗额度,并且会忽略所有者的切换设置。
- 不要设置 和
provider。 当前启用的 provider 会使用自己的默认 model 作出响应,因此所有者切换 provider 后,代码仍可继续工作。指定一个未启用的 provider 会返回model,而且各 provider 的 model id 也互不相同。BadRequest - 不能附加 cycles,并且允许使用普通 (同一 subnet,规则 2)。如果使用 bounded-wait,超时时间必须长于 outcall 的 30 秒截止时间(
await,或(with timeout = 60)默认的 300 秒):更短的等待会在 operator 仍可能消耗额度时返回Call::bounded_wait。SYS_UNKNOWN
Finding the operator
查找 operator
The operator's id is configuration, not a literal: read it from a canister environment variable (, see M6) or an init argument. The user finds it on the engine's Canisters page in the console, and the ICP MCP route reads it as from the engine registry ( M1). Ask for it as soon as the app needs inference.
OPERATOR_CANISTER_IDdeploy-to-cloud-engineengine_operator_iddeploy-to-cloud-engineCheck that a provider is on with the public query :
listInferenceProvidersbash
icp canister call <operator-id> listInferenceProviders '()' -n ic --querycandid
(record { providers = opt vec {
record { id = opt "iig"; name = opt "IIG"; base_url = opt "https://<iig-router>/v1"; enabled = opt true; ready = opt true };
record { id = opt "caffeine"; name = opt "Caffeine"; base_url = opt "https://inference.caffeine.ai/v1"; enabled = opt false; ready = opt true };
} })At most one provider is , and means the operator holds its key. With none on, or with a named one off or not ready, every call answers : the owner fixes that in the console, not in code.
enabledreadyBadRequestOperator 的 id 属于配置,不能写死:从 canister 环境变量(,参阅 M6)或 init argument 中读取。用户可以在控制台的引擎 Canisters 页面找到它,ICP MCP route 则从 engine registry 中将其读取为 ( M1)。应用需要 inference 时,应立即向用户询问该 id。
OPERATOR_CANISTER_IDdeploy-to-cloud-engineengine_operator_iddeploy-to-cloud-engine使用公共查询 检查是否已启用 provider:
listInferenceProvidersbash
icp canister call <operator-id> listInferenceProviders '()' -n ic --querycandid
(record { providers = opt vec {
record { id = opt "iig"; name = opt "IIG"; base_url = opt "https://<iig-router>/v1"; enabled = opt true; ready = opt true };
record { id = opt "caffeine"; name = opt "Caffeine"; base_url = opt "https://inference.caffeine.ai/v1"; enabled = opt false; ready = opt true };
} })最多只有一个 provider 处于 状态,而 表示 operator 持有其密钥。如果没有 provider 启用,或者指定的 provider 未启用或未就绪,每次调用都会返回 :所有者需要在控制台中解决,而不是修改代码。
enabledreadyBadRequestThe call
调用
candid
type HttpHeader = record { name : text; value : text };
type InferenceRequestArgs = record {
provider : opt text; // null: the provider that is on
method : opt variant { get; post }; // defaults to post with a body, get without
path : opt text; // required: "/chat/completions", "/embeddings", "/models"
headers : opt vec HttpHeader; // the operator sets Authorization itself
body : opt blob; // a JSON body with no "model" gets the provider's default
max_response_bytes : opt nat64;
};
type InferenceResponse = record { status : opt nat; headers : opt vec HttpHeader; body : opt blob; provider : opt text };
type Error = variant { Unauthorized; NotFound; BadRequest : text; Internal : text };
service : {
inference_request : (InferenceRequestArgs) -> (variant { ok : InferenceResponse; err : Error });
};motoko
type HttpHeader = { name : Text; value : Text };
type InferenceRequestArgs = {
provider : ?Text; method : ?{ #get; #post }; path : ?Text;
headers : ?[HttpHeader]; body : ?Blob; max_response_bytes : ?Nat64;
};
type InferenceResponse = { status : ?Nat; headers : ?[HttpHeader]; body : ?Blob; provider : ?Text };
type OperatorError = { #Unauthorized; #NotFound; #BadRequest : Text; #Internal : Text };
type Operator = actor {
inference_request : InferenceRequestArgs -> async { #ok : InferenceResponse; #err : OperatorError };
};
let operator : Operator = actor (Principal.toText(operatorId)); // from configuration
let request = "{\"max_tokens\":350,\"stream\":false,\"messages\":[{\"role\":\"user\",\"content\":\"What is a canister?\"}]}";
let res = await operator.inference_request({
provider = null; method = null; path = ?"/chat/completions";
headers = ?[{ name = "content-type"; value = "application/json" }];
body = ?Text.encodeUtf8(request);
max_response_bytes = ?200_000;
});
switch (res) {
case (#ok { status = ?200; body = ?bytes }) { /* OpenAI chat completion: choices[0].message.content */ };
case (#ok { status }) { /* the provider's own status: 401 key refused, 402 no credit */ };
case (#err (#BadRequest msg)) { /* no provider on, the named one off or not ready, or a bad path */ };
case (#err (#Unauthorized)) { /* the caller is not a canister on this engine */ };
case (#err (#Internal msg)) { /* the outcall failed, see "The deadline" */ };
case (#err (#NotFound)) { /* a named provider the engine does not list */ };
};In Rust, make the same call with and the types above as structs ( / on the result variant, for ), with the body built by .
Call::unbounded_wait(operator, "inference_request")CandidType#[serde(rename = "ok")]"err"Option<Nat>statusserde_json- Only canisters on the engine may call it. An ingress call from the CLI is ; to try it, deploy a small caller canister on the engine.
Unauthorized - The answer is the provider's HTTP response as it is, and names the one that answered. A 401 (key refused) or a 402 (no credit) is the owner's to fix, not yours: tell the user.
provider - Keep false. An outcall returns one whole response.
stream
candid
type HttpHeader = record { name : text; value : text };
type InferenceRequestArgs = record {
provider : opt text; // null: the provider that is on
method : opt variant { get; post }; // defaults to post with a body, get without
path : opt text; // required: "/chat/completions", "/embeddings", "/models"
headers : opt vec HttpHeader; // the operator sets Authorization itself
body : opt blob; // a JSON body with no "model" gets the provider's default
max_response_bytes : opt nat64;
};
type InferenceResponse = record { status : opt nat; headers : opt vec HttpHeader; body : opt blob; provider : opt text };
type Error = variant { Unauthorized; NotFound; BadRequest : text; Internal : text };
service : {
inference_request : (InferenceRequestArgs) -> (variant { ok : InferenceResponse; err : Error });
};motoko
type HttpHeader = { name : Text; value : Text };
type InferenceRequestArgs = {
provider : ?Text; method : ?{ #get; #post }; path : ?Text;
headers : ?[HttpHeader]; body : ?Blob; max_response_bytes : ?Nat64;
};
type InferenceResponse = { status : ?Nat; headers : ?[HttpHeader]; body : ?Blob; provider : ?Text };
type OperatorError = { #Unauthorized; #NotFound; #BadRequest : Text; #Internal : Text };
type Operator = actor {
inference_request : InferenceRequestArgs -> async { #ok : InferenceResponse; #err : OperatorError };
};
let operator : Operator = actor (Principal.toText(operatorId)); // from configuration
let request = "{\"max_tokens\":350,\"stream\":false,\"messages\":[{\"role\":\"user\",\"content\":\"What is a canister?\"}]}";
let res = await operator.inference_request({
provider = null; method = null; path = ?"/chat/completions";
headers = ?[{ name = "content-type"; value = "application/json" }];
body = ?Text.encodeUtf8(request);
max_response_bytes = ?200_000;
});
switch (res) {
case (#ok { status = ?200; body = ?bytes }) { /* OpenAI chat completion: choices[0].message.content */ };
case (#ok { status }) { /* the provider's own status: 401 key refused, 402 no credit */ };
case (#err (#BadRequest msg)) { /* no provider on, the named one off or not ready, or a bad path */ };
case (#err (#Unauthorized)) { /* the caller is not a canister on this engine */ };
case (#err (#Internal msg)) { /* the outcall failed, see "The deadline" */ };
case (#err (#NotFound)) { /* a named provider the engine does not list */ };
};在 Rust 中,使用上述类型作为 struct(result variant 使用 / , 使用 ),通过 发起相同调用,并使用 构建 body。
CandidType#[serde(rename = "ok")]"err"statusOption<Nat>Call::unbounded_wait(operator, "inference_request")serde_json- 只有引擎上的 canister 才能调用它。 来自 CLI 的 ingress 调用会返回 ;如需尝试,应在引擎上部署一个小型调用方 canister。
Unauthorized - 响应就是 provider 原始的 HTTP 响应。 标识实际作出响应的 provider。401(密钥被拒绝)或 402(没有额度)需要由所有者解决,而不是由代码解决:应告知用户。
provider - 保持 为 false。 Outcall 会返回完整响应。
stream
The deadline
截止时间
An outcall has a 30 second deadline. A completion that is still generating when it passes fails as
err = Internal("the outcall to <provider> failed: Canister http request timed out")and the provider may bill the reply anyway. Bound every completion: (350 took about 5 seconds end to end through Caffeine), short replies, a small conversation. A answers in seconds and spends no credit: it shows that the route works, not why a completion timed out.
max_tokensGET /modelsOutcall 的截止时间为 30 秒。如果生成内容在截止时间到达时仍未完成,则会失败并返回:
err = Internal("the outcall to <provider> failed: Canister http request timed out")而且 provider 仍可能对该回复计费。必须限制每次 completion:设置 (通过 Caffeine 生成 350 个 token 的内容,端到端大约耗时 5 秒)、保持回复简短,并控制对话长度。 通常会在数秒内响应且不消耗额度:它只能证明路由可用,无法解释 completion 为什么超时。
max_tokensGET /modelsWho may call your canister
谁可以调用你的 canister
The operator checks only that the caller is on the engine, so your canister decides who spends the engine's credit. A public method is a faucet, and a sign-in is not an authorization: anyone can make a keypair and call as a non-anonymous principal. Do one of these, and tell the user which:
chat- Restrict the method to the canister's controllers () or an allow-list the owner keeps.
is_controller - Meter an open service: a quota per principal and a total cap, both in stable state, besides per-call bounds (, message size).
max_tokens
Operator 只检查调用方是否位于引擎上,因此你的 canister 决定谁能够消耗引擎额度。公开的 方法会变成一个资金 faucet,而登录并不是授权:任何人都可以创建 keypair,并以非匿名 principal 的身份调用。请采用以下方式之一,并告知用户选择了哪一种:
chat- 限制该方法只允许 canister 的 controller()或所有者维护的 allow-list 调用。
is_controller - 对开放服务进行计量: 除每次调用的边界(、消息大小)外,还要在 stable state 中保存每个 principal 的配额和总量上限。
max_tokens
Common Pitfalls
常见陷阱
- Attaching a cycles amount to a call you write. A clause on an inter-canister call from an engine canister is never needed, and any non-zero
(with cycles = N)fails withN/IC0504(verified live). Remove the clause entirely rather than settingis out of cycles: a zero is accepted, so it hides the mistake instead of fixing the habit. Nothing an engine canister does needs cycles: outcall, signing, and messaging fees are all zero under the engine's free cost schedule.cycles = 0 - Unbounded-wait cross-subnet calls. A plain to a canister on another subnet is unbounded-wait and is rejected with "Unbounded-wait calls and calls with cycles are not allowed to CloudEngine subnets". Use
await service.method(args)in Motoko or(with timeout = N)in Rust — and handleCall::bounded_wait. Same-subnet (engine-local) calls are exempt.SYS_UNKNOWN - Rewriting outcall code for an engine — or hardcoding its fee. Outcalls need no engine-specific form: keep (Motoko) or, in Rust, whichever wrapper the project's crate line provides (
Call.httpRequestonHttpRequest::new(url)…send()0.2;ic-cdk-management-canisteronly up to ic-cdk 0.19, since 0.20 removed that module). Theic_cdk::management_canister::http_requestAPI they consult prices against your own subnet and returns 0 on an engine. The mistake is replacing that call with a hand-computed fee from an Application-subnet cost table, which attaches a non-zero amount against a 0 balance.ic0.cost_* - Routing HTTPS outcalls through the console proxy. Two different failures, one cause. Consensus: , because the transform must live on the calling canister — behind the proxy that is the proxy itself, and it exposes none (nor is one planned). Cost: the proxy is on a normal Application subnet, so it pays the real outcall fee out of its balance, which the engine's balance refills, and a bulk workload drains it into
SYS_TRANSIENT: No consensus could be reached. Replicas had different responses. Issue outcalls directly from your canister instead: on an engine they are free and unmetered, so no budget exists to exhaust.ProxyError::InsufficientCycles - Topping up an engine canister with cycles. Engine canisters hold 0 cycles by design; you cannot and need not send cycles to them. A "0 cycles" reading from an engine canister is normal, not an emergency — do not add top-up logic or cycles-balance alarms ported from Application-subnet apps.
- Calling the XRC / threshold signing / vetKD directly from an engine canister. Cloud engines do not provide threshold signing at all (platform team), so /
sign_with_ecdsa/ vetKD must be reached on mainnet — and a cross-subnet, cycle-bearing call is exactly what a CloudEngine-subnet canister cannot send. Route them through the funded console proxy (Rule 4). Plain same-subnet or cycle-less calls do not need the proxy.sign_with_schnorr - Attaching cycles to the outer call. The engine subnet forbids cycle-bearing cross-subnet messages — that is the whole reason for the proxy. Put the cycles inside
proxy(the proxy attaches them locally); neverProxyArgs.cycleson the call towith cyclesitself.proxy - Topping up the proxy without first asking what it was relaying. On , check the call type before treating it as a funding problem. An HTTPS outcall does not belong on the proxy at all (Rule 3, pitfall 4): move it onto your own canister, where it is free, rather than buying budget for work that should cost nothing; raising the balance only delays the same stall. A drained balance is a genuine funding problem only for the proxy's real jobs (XRC, threshold signing, vetKD, the Bitcoin API, EVM/SOL RPC). A console proxy tops itself up out of the engine's balance every few minutes, within an hourly cap, so a lasting
ProxyError::InsufficientCyclesmeans the engine's balance has nothing free to send (the owner adds funds to the engine) or the app spends faster than the cap refills. There is no top-up button for it. SeeInsufficientCyclesfor the balances.deploy-to-cloud-engine - Expecting a direct-call key through the proxy. Threshold-key derivation via the proxy is caller-isolated, so the derived key/address is not the same as a direct management-canister call. Fetch the public key and sign through the proxy consistently; do not mix direct and proxied key calls for the same identity.
- Using a chain-key helper library on an engine. ,
ic-vetkeys's chain-key functions, andic-cdk-management-canistercallmo:ic-vetkeys/ManagementCanisterdirectly and attach the fee themselves — non-zero even on an engine, because the chain-key cost API prices against the key-holding subnet — making it a cross-subnet, cycle-bearing call that the engine rejects under Rules 1 and 2. Their whole value proposition (correct types, automatic cycles) is what has to go: hand-encode the management-canister argument and relay it through the proxy. Code copied from theaaaaa-aaskill will not run on an engine unmodified.vetkeys - Over-reading that warning and proxying outcalls too. The warning above is about the chain-key functions, not the crates that contain them. is also what Rust outcall code should use (Rule 3), and its
ic-cdk-management-canisterbuilder is correct on an engine as written. Concluding "this crate doesn't work on an engine, so the outcall must be hand-encoded through the proxy" lands straight in pitfall 4 — a transform that cannot apply and a proxy balance that drains. Decide by target subnet, not by crate name:HttpRequestaaaaa-aais local and free; signing and vetKD are remote and paid.http_request - Tuning pricing-version-2 budgets for an engine. 0.2 always prices version 2, where the attached cycles are also each node's budget and a too-narrow
ic-cdk-management-canistercan fail a call partway. On an engine the free cost schedule never charges, so the budget narrows nothing: the timeout and transform-instruction limits sit at the protocol maximum andwith_expected_*cannot be raised. The setters therefore change nothing here — do not add them to fix an engine outcall, and do not diagnose an engine outcall failure as an exhausted budget. Your ownInsufficientCyclesis the exception: it still bounds the response, so an oversized reply remains a genuine cause. (Nor does the pricing version itself need managing: where the replica lacks pay-as-you-go, version 2 is silently filtered to version 1, and both cost zero on an engine.)max_response_bytes - Deleting or swapping the proxy of a signing app. The management canister derives keys from its caller (the proxy), so the proxy's canister id is part of every address the app owns. Deleting a proxy (the console sends its cycles back to the engine's balance) or repointing the app at another one silently produces different addresses and leaves any Bitcoin or Ethereum funds at the old ones permanently unspendable. A signing app's proxy id is permanent infrastructure, not a fungible resource.
- Reading as "it did not happen". The proxy relays with a bounded-wait call, so a downstream
CallFailedarrives asSYS_UNKNOWNwith that reject code inProxyError::CallFailed. The target may have run and the cycles may be gone. Retrying a signature is harmless; retrying a stateful call on this basis is not: treat it as an unknown outcome (seereason).multi-canister - Calling the console proxy from the CLI. fails: the console proxy admits only the canisters on the engine's subnet and its own controller (the platform canister that created it), and an ingress call from your CLI identity is neither (it is rejected by
icp canister call --proxy <console-proxy-id>before it reaches replicated state). For CLI-side proxying, deploy your own proxy (inspect_message) which authorizes controllers, i.e. you.icp new … --subfolder proxy - Writing proxy-dependent code without asking for the proxy. Signing, vetKD, XRC, Bitcoin API or EVM/SOL RPC code can be written and even deployed with no proxy behind it, and then fails on its first call: a placeholder or guessed id gets or reaches nothing, and an id copied from another engine or project signs with someone else's keys. You cannot create the console proxy yourself: there is no
UnauthorizedUsercommand for it, and only the engine's owner can deploy one, from the console. Ask as soon as the need is known ("Before writing the code" in Rule 4), read the id from configuration, and never substitute a self-deployed proxy for the engine's.icp - Relaying to a target the console proxy does not serve. A console proxy relays for the engine's canisters only the management canister's threshold-key, and
http_requestmethods and the XRC, EVM RPC, SOL RPC, Bitcoin and Dogecoin canisters. Anything else, a third-party canister that charges cycles included, comes back asbitcoin_*(CallFailed), whatever its balance. Do not top it up or retry: route such a call through a self-deployed proxy that has the calling canister as a controller, or drop the dependency.a proxy funded by its engine relays only to … - A provider key in the canister. On an engine, inference goes through the operator's (Rule 5). Drop the key and the outcall to the provider.
inference_request - A completion with no bound. from
Internal("… Canister http request timed out")is the 30 second outcall deadline. Setinference_requestfirst, then measure; a workingmax_tokensdoes not explain it.GET /models - Reading every from
BadRequestas a console problem, or every one as a code bug. Read the message. A message aboutinference_requestis yours: send a path that starts withpath. A message that a provider is off, has no key, or that none is on is the engine's state: leave/out ifprovidershows another one on and ready, and otherwise tell the user to pick a provider in the console.listInferenceProviders
- 为自行编写的调用附加 cycles 数量。 从引擎 canister 发出的 canister 间调用永远不需要 子句,任何非零
(with cycles = N)都会失败并返回N/IC0504(已实际验证)。应彻底删除该子句,而不是设置为is out of cycles:零值虽然能够通过,却会掩盖错误,而不是纠正习惯。在引擎的免费费用表下,引擎 canister 执行的任何操作都不需要 cycles:outcall、签名和消息传递费用全部为零。cycles = 0 - 在跨子网调用中使用 unbounded-wait。 直接使用 调用另一个 subnet 上的 canister 属于 unbounded-wait,会被拒绝并返回 “Unbounded-wait calls and calls with cycles are not allowed to CloudEngine subnets”。请在 Motoko 中使用
await service.method(args),或在 Rust 中使用(with timeout = N),并处理Call::bounded_wait。同一 subnet(引擎内部)的调用不受此限制。SYS_UNKNOWN - 为引擎重写 outcall 代码——或硬编码其费用。 Outcall 不需要引擎专用形式:保留 (Motoko),或在 Rust 中使用项目 crate 版本对应的 wrapper(
Call.httpRequest0.2 中的ic-cdk-management-canister;HttpRequest::new(url)…send()仅可用于 ic-cdk 0.19 及更早版本,因为 0.20 已移除该模块)。它们查询的ic_cdk::management_canister::http_requestAPI 会根据你自己的 subnet 定价,并在引擎上返回 0。错误做法是用 Application-subnet 费用表中的手动计算费用替换该调用,从而在零余额上附加非零金额。ic0.cost_* - 通过 console proxy 路由 HTTPS outcall。 两种不同的失败具有同一个原因。共识错误:,因为 transform 必须位于发起调用的 canister 上——放在 proxy 后面时,它会位于 proxy 自身,而 proxy 不提供 transform method(也没有提供此方法的计划)。成本问题:proxy 位于普通 Application subnet 上,因此会从其余额中支付真实 outcall 费用,而引擎余额会为 proxy 补充资金;批量工作负载会耗尽这些资金,并最终出现
SYS_TRANSIENT: No consensus could be reached. Replicas had different responses。应改为直接从你的 canister 发起 outcall:在引擎上它免费且不计量,因此不存在可被耗尽的预算。ProxyError::InsufficientCycles - 为引擎 canister 充值 cycles。 引擎 canister 按设计持有 0 cycles,你无法也不需要向其发送 cycles。引擎 canister 显示“0 cycles”是正常状态,并非紧急情况——不要添加充值逻辑,也不要移植来自 Application-subnet 应用的 cycles 余额告警。
- 直接从引擎 canister 调用 XRC / threshold signing / vetKD。 Cloud engine 根本不提供 threshold signing(平台团队说明),因此必须通过 mainnet 访问 /
sign_with_ecdsa/ vetKD——而携带 cycles 的跨子网调用恰恰是 CloudEngine-subnet canister 无法发送的调用。应通过已充资的 console proxy 路由这些调用(规则 4)。普通的同 subnet 或无需 cycles 的调用不需要 proxy。sign_with_schnorr - 为外部 调用附加 cycles。 引擎 subnet 禁止携带 cycles 的跨子网消息——这正是使用 proxy 的原因。将 cycles 放入
proxy(由 proxy 在本地附加);绝不要在调用ProxyArgs.cycles本身时使用proxy。with cycles - 未先确认 proxy 正在中继什么,就为其充值。 遇到 时,应先检查调用类型,再将其视为资金问题。HTTPS outcall 根本不应放在 proxy 上(规则 3、陷阱 4):应将其移到自己的 canister 上,在那里费用为零,而不是为本来无需付费的工作购买额度;增加余额只会延缓同一问题。只有在 proxy 承担实际工作(XRC、threshold signing、vetKD、Bitcoin API、EVM/SOL RPC)时,余额耗尽才是真正的资金问题。Console proxy 每隔几分钟会使用引擎余额自行充值,但受每小时上限约束,因此持续的
ProxyError::InsufficientCycles意味着引擎余额没有可用于发送的资金(所有者需要为引擎充值),或者应用的消耗速度超过了充值上限。Proxy 没有充值按钮。参阅InsufficientCycles了解余额详情。deploy-to-cloud-engine - 期望通过 proxy 获得与直接调用相同的密钥。 通过 proxy 进行 threshold-key 派生时,会按调用方隔离,因此派生出的密钥/地址与直接调用 management canister 时不同。应始终通过同一个 proxy 获取 public key 并签名;同一身份不要混用直接调用和 proxy 调用。
- 在引擎上使用 chain-key helper library。 、
ic-vetkeys的 chain-key 函数以及ic-cdk-management-canister会直接调用mo:ic-vetkeys/ManagementCanister并自动附加费用——即使在引擎上,该费用也非零,因为 chain-key 费用 API 根据持有密钥的 subnet 定价——从而形成引擎依据规则 1 和规则 2 拒绝的、携带 cycles 的跨子网调用。它们的核心价值(正确类型、自动附加 cycles)正是必须放弃的部分:应手动编码 management-canister 参数,并通过 proxy 中继。从aaaaa-aaskill 复制来的代码如果不修改,无法在引擎上运行。vetkeys - 过度解读上述警告,连 outcall 也通过 proxy 发送。 上述警告针对的是 chain-key 函数,而不是包含这些函数的整个 crate。同样是 Rust outcall 代码应使用的 crate(规则 3),其
ic-cdk-management-canisterbuilder 按原样即可在引擎上工作。得出“这个 crate 在引擎上不可用,因此 outcall 也必须手动编码并通过 proxy 发送”的结论,会直接落入陷阱 4:无法应用 transform,同时耗尽 proxy 余额。应根据目标 subnet,而不是 crate 名称作出决定:HttpRequest的aaaaa-aa是本地且免费的;签名和 vetKD 是远程且收费的。http_request - 为引擎调整 pricing-version-2 预算。 0.2 始终使用 version 2,其中附加的 cycles 同时也是每个节点的预算,设置过窄的
ic-cdk-management-canister可能导致调用中途失败。在引擎上,免费费用表永远不会收费,因此预算不会产生任何收窄:超时和 transform 指令限制都处于协议最大值,并且不会抛出with_expected_*。因此,这些 setter 在这里没有任何作用——不要添加它们来修复引擎 outcall,也不要将引擎 outcall 失败诊断为预算耗尽。自己的InsufficientCycles是例外:它仍会限制响应,因此响应过大仍然是真正的原因。(Pricing version 本身也不需要管理:如果 replica 不支持 pay-as-you-go,version 2 会被静默过滤回 version 1,而两种 version 在引擎上的费用都是零。)max_response_bytes - 删除或替换签名应用的 proxy。 Management canister 根据它的调用方(即 proxy)派生密钥,因此 proxy 的 canister id 是应用拥有的每个地址的一部分。删除 proxy(控制台会将其 cycles 退回引擎余额)或将应用重新指向另一个 proxy,都会悄无声息地产生不同的地址,并使旧地址中的任何 Bitcoin 或 Ethereum 资金永久无法支出。签名应用的 proxy id 是永久基础设施,而不是可随意替换的资源。
- 将 理解为“调用没有发生”。 Proxy 使用 bounded-wait 调用进行中继,因此下游的
CallFailed会以SYS_UNKNOWN的形式返回,并在ProxyError::CallFailed中包含该 reject code。目标可能已经运行,cycles 也可能已经消耗。重试签名是无害的;在此基础上重试有状态调用则不是:应将其视为结果未知(参阅reason)。multi-canister - 从 CLI 调用 console proxy。 会失败:console proxy 只允许引擎 subnet 上的 canister 和自身 controller(创建它的平台 canister)调用,而来自你的 CLI identity 的 ingress 调用两者都不是(它会在进入 replicated state 之前被
icp canister call --proxy <console-proxy-id>拒绝)。如需从 CLI 使用 proxy,请自行部署 proxy(inspect_message),它会授权 controller,也就是你。icp new … --subfolder proxy - 编写依赖 proxy 的代码,却不询问 proxy 信息。 签名、vetKD、XRC、Bitcoin API 或 EVM/SOL RPC 代码即使在没有 proxy 的情况下也可以编写和部署,随后却在首次调用时失败:使用占位符或猜测的 id 会得到 ,或者根本找不到目标;而从另一个引擎或项目复制来的 id 会使用其他人的密钥进行签名。你无法自行创建 console proxy:没有相应的
UnauthorizedUser命令,只有引擎所有者才能从控制台部署。一旦确定存在相关需求,就应立即询问(参阅规则 4中的“编写代码前”),从配置中读取 id,绝不能使用自行部署的 proxy 替代引擎的 proxy。icp - 中继到 console proxy 不提供服务的目标。 对于引擎的 canister,console proxy 只会中继 management canister 的 threshold-key、和
http_request方法,以及 XRC、EVM RPC、SOL RPC、Bitcoin 和 Dogecoin canister。其他任何目标,包括按 cycles 收费的第三方 canister,都会返回bitcoin_*(CallFailed),无论其余额多少。不要充值或重试:应通过自行部署的 proxy 路由此类调用,并将调用方 canister 设置为其 controller,或者移除该依赖。a proxy funded by its engine relays only to … - 在 canister 中存放 provider 密钥。 在引擎上,inference 必须通过 operator 的 (规则 5)。删除密钥以及直接调用 provider 的 outcall。
inference_request - 不限制 completion 的长度。 返回
inference_request表示已达到 30 秒的 outcall 截止时间。应先设置Internal("… Canister http request timed out"),然后再进行测量;能够成功执行max_tokens并不能解释 completion 为什么超时。GET /models - 将 返回的每个
inference_request都解读为控制台问题,或者都解读为代码错误。 应阅读消息内容。涉及BadRequest的消息属于你的问题:请发送以path开头的 path。涉及 provider 未启用、没有密钥或没有 provider 启用的消息则反映引擎状态:如果/显示另一个 provider 已启用并就绪,请不要设置listInferenceProviders;否则请告知用户在控制台中选择 provider。provider
Additional References
补充参考
- Load for getting the app onto the engine: which route to take (the ICP MCP connector from a sandboxed chat, or the icp CLI), CLI identity linking, subnet-targeted deploy, console app metadata, and for deploying and funding the proxy this skill's Rule 4 depends on: the console flow (the engine owner deploys it, paid from the engine's balance), which balance pays for what, and the self-deployed CLI alternative.
deploy-to-cloud-engine - Load for what vetKD is and how its keys are used (IBE, encrypted maps, transport keys). Its call code targets a normal subnet and attaches cycles through helper libraries: on an engine, keep the concepts and replace the calls with the proxied form above.
vetkeys - Load for everything about outcalls that is not engine-specific: transform functions,
https-outcalls, idempotency, debugging consensus failures.max_response_bytes - Load for inter-canister call design, bounded vs unbounded wait semantics, and
multi-canisterhandling.SYS_UNKNOWN
- 加载 ,了解如何将应用部署到引擎:应采用哪条路径(从沙箱聊天环境使用 ICP MCP connector,或使用 icp CLI)、CLI identity 关联、面向特定 subnet 的部署、控制台应用元数据,以及本 skill 规则 4 所依赖的 proxy 部署与资助流程:控制台操作方式(引擎所有者从控制台部署,使用引擎余额付费)、不同余额的用途,以及用于 CLI 的自行部署替代方案。
deploy-to-cloud-engine - 加载 ,了解 vetKD 及其密钥的用途(IBE、encrypted maps、transport keys)。其调用代码面向普通 subnet,并通过 helper library 附加 cycles:在引擎上应保留相关概念,并用上述 proxy 形式替换调用。
vetkeys - 加载 ,了解所有非引擎专用的 outcall 内容:transform function、
https-outcalls、idempotency,以及共识失败的调试方法。max_response_bytes - 加载 ,了解 canister 间调用设计、bounded 与 unbounded wait 语义,以及
multi-canister处理方式。SYS_UNKNOWN