Gas pool sizing¶
How many gas coins the relayer needs for a given load, how large each one must be, and what happens to a coin during a run.
You will learn / You need
You will learn: the sizing rules, how BATCH_SIZE changes the budget of every coin, the
lifecycle of a coin in the pool, and how to re-split the account's balance.
You need: the one-time setup finished up to the funding step, and the
Configuration rows for the variables below.
An IOTA coin serves one transaction at a time, so sustained throughput needs roughly rate x hold_time
coins. The pool is set by EVENT_HANDLER_GAS_COINS, the
parallelism by EVENT_HANDLER_CONCURRENCY and the
bundling by BATCH_SIZE, all in
stealth_name_service/backend/.env_sample.
Calculator¶
Sizing the gas pool¶
A coin serves one transaction at a time, so throughput needs about rate × hold time coins. The
BridgeAA is a shared object, so each call goes through consensus and holds its coin for a second or
more: about 660 coins at 330 req/s. EVENT_HANDLER_GAS_COINS defaults to 1000 and is the number of
coins the handler claims for each sender at startup. The pool is silently smaller if the account holds
fewer coins.
- Keep coins uniform. One coin below
LOADTEST_GAS_BUDGET_BRIDGEis a dead slot. - Size each coin for the whole run. A destination call costs about 1,000,000 nanos, so 100k requests over 1000 coins need about 0.1 IOTA per coin, plus headroom.
- Reclaim dust by paying one trivial transaction with all the small coins as gas; IOTA merges them.
- With
BRIDGE_PROTOCOL_PHASES=3, the acknowledgement sender on the source chain needs a comparable pool too. See Three phases.
Batching and gas¶
BATCH_SIZE (default 100, minimum 1) is the number of events the handler bundles into one
destination transaction. It is ignored in static mode. The handler takes whatever is queued, up to
BATCH_SIZE, without waiting for the batch to fill, so light load keeps its latency and batches fill
only under backlog.
The gas consequence is the one to plan for. A gas budget is a per-transaction reservation, and one coin must cover all of it:
| Leg | Budget of one transaction |
|---|---|
| Destination | LOADTEST_GAS_BUDGET_BRIDGE x events in the batch (at most BATCH_SIZE) |
| Acknowledgement | BRIDGE_ACK_GAS_BUDGET x requests in the batch (at most BATCH_SIZE) |
With BATCH_SIZE=100 and LOADTEST_GAS_BUDGET_BRIDGE=3000000 that is 300,000,000 nanos, 0.3 IOTA,
reserved per full-batch transaction. The budget is a reservation; the charge is the gas used. Only about EVENT_HANDLER_CONCURRENCY
transactions are in flight and each holds one coin, so the pool should shrink as the budget grows: a few
dozen rich coins, not 1000 poor ones.
A poor pool retires itself
A coin that cannot cover a full batch budget is retired for the rest of the run. An under-funded
pool retires itself within the first few batches, and every row of bridge_results.csv then
carries failure_stage no_gas. A source comment (event_handler.rs:693) says max_auth_gas
caps a BridgeAA batch at 2 intents. The code enforces no cap, but in practice batches of more
than 2 intents have failed on max gas. The limit likely depends on the IOTA network and on the
transaction type. Start with BATCH_SIZE=2, and raise it only after a test run succeeds.
Lifecycle of a coin¶
The pool is GasPool in stealth_name_service/backend/testing_backend/src/bin/event_handler.rs. A
coin keeps its index for the whole run; it is retired by a flag, never deleted.
stateDiagram-v2
[*] --> Fresh: preloaded at startup
Fresh --> Retired: startup pre-screen: below one full batch
Fresh --> Claimed: claim() takes its lock
Claimed --> Fresh: released, reference refreshed
Claimed --> Retired: node reports a balance below one full batch
Retired --> [*]: skipped until restart
| State | What it means in the code |
|---|---|
| Fresh | Read by GasPool::preload, up to EVENT_HANDLER_GAS_COINS coins, and not in use. The pre-screen retire_underfunded runs once before the first batch and retires every coin below min_balance, one full batch. It logs destination coins below one full batch retired with retired, live and min_balance. |
| Claimed | claim() picks the next live coin round-robin and takes that coin's lock, which is held across signing and submission. It is released before the acknowledgement leg, so a coin is not pinned for two cross-chain round trips. |
| Released | After the transaction the coin's reference comes from the transaction's effects. After a failed submit that does not retire the coin, the reference is re-read from the chain. |
| Retired | A coin that cannot cover the budget. Re-reading cannot fix an empty coin, so the slot is skipped for the rest of the run. The log line is gas coin drained below budget -- retiring it for the rest of the run. |
A gas failure retires the coin only when the node reports a balance below one full batch budget. If
the coin is healthy but one batch asked for more than it held, the log says batch budget exceeds the
gas coin's balance -- lower BATCH_SIZE or re-split the pool into fewer, richer coins, and the coin
stays live. When every coin is retired the batch fails with Every gas coin for … has been drained
below the budget and a no_gas row.
Re-splitting the pool¶
bridge_aa_coins merges every coin the BridgeAA owns into one, then splits it into --count equal
coins of --amount nanos and sends them back to the account. The account has no key, so each
transaction passes the authenticator with an anchor call to bridge_target::record; that is why it
reads BRIDGE_TARGET_PACKAGE. Flags and defaults are in
bridge_aa_coins.
cd stealth_name_service/backend/testing_backend
cargo run --release --bin bridge_aa_coins -- --count 2000 --amount 347000000 --dry-run
cargo run --release --bin bridge_aa_coins -- --count 2000 --amount 347000000
Stop the relayer first: it holds these coins and a merge deletes them. Afterwards restart it so
GasPool reloads the new coins, with EVENT_HANDLER_GAS_COINS at least --count. A re-run after a
failure is safe, because it merges everything again and converges on the same pool.
Check it worked¶
- The handler log shows
gas pool readywithcoinsequal to what you expect and nofewer gas coins than concurrent workerswarning. destination coins below one full batch retiredreportsretired=0, or a number you can account for.bridge_results.csvhas nono_gasrows.
Next¶
- Three phases and the AA acknowledgement: the second pool, on the source chain.
- Sending cross-chain requests: what one request costs and how failures appear.