Skip to content

fix: size split coins to match operational requirements#1526

Merged
TheLastCicada merged 1 commit into
fix/parallel-store-creation-retryfrom
fix/coin-management-size
Mar 12, 2026
Merged

fix: size split coins to match operational requirements#1526
TheLastCicada merged 1 commit into
fix/parallel-store-creation-retryfrom
fix/coin-management-size

Conversation

@TheLastCicada

@TheLastCicada TheLastCicada commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • COIN_SIZE was hardcoded to 1,000,000 mojos while CADT operations require DEFAULT_COIN_AMOUNT + DEFAULT_FEE (typically 600,000,000 mojos on production configs). This caused a perpetual splitting loop where coins were created 600x too small to be "usable" by CADT's own criteria, wasting 300M mojo in fees every 6 hours and temporarily draining spendable balance.
  • Set COIN_SIZE = MIN_USABLE_COIN_SIZE (DEFAULT_COIN_AMOUNT + DEFAULT_FEE) so each split coin can independently fund one full DataLayer operation (mirror creation, store creation, etc.).
  • Added a splitInProgress flag exported from coin-management so checkWalletBalanceForMirror in persistance.js logs a warning (not an error) when balance is temporarily reduced during an active coin split, making logs actionable instead of alarming.
  • Consolidated three duplicate split-and-wait code paths into a single executeSplit() helper.

Root Cause

On a system with DEFAULT_COIN_AMOUNT=300000000 and DEFAULT_FEE=300000000:

  1. COIN_SIZE was 1M mojos but MIN_USABLE_COIN_SIZE was 600M mojos — split coins were never considered "usable"
  2. Coin management ran every 6 hours, found 0 usable coins, split the largest coin into 1M mojo pieces (burning 300M in fees), timed out waiting for 15 coins ≥ 600M, repeated forever
  3. During the ~10-minute split confirmation window, the source coin was locked and spendable_balance dropped, causing mirror-check to log "Insufficient funds" errors

Test plan

  • All 32 coin management unit tests updated and passing
  • Full v2 integration suite passes (1225 passing, 1 pre-existing failure unrelated to this change)
  • Deploy to testnet instance and verify coin management creates coins of the correct size
  • Verify mirror creation succeeds without "insufficient funds" errors after split completes

Note

Medium Risk
Changes coin-splitting amounts and transaction flow in the wallet maintenance task, which can affect spendable balances and DataLayer operation reliability if mis-sized or mis-triggered. The changes are localized but touch on-chain transaction behavior and retry timing.

Overview
Fixes the coin-management task to size split outputs at DEFAULT_COIN_AMOUNT + DEFAULT_FEE (instead of a hardcoded 1,000,000 mojos) so each resulting coin can independently fund a full DataLayer operation, avoiding repeated under-sized splits and wasted fees.

Refactors split logic into a single executeSplit() path and exports isSplitInProgress(); checkWalletBalanceForMirror now logs a warning and skips mirror creation when spendable balance is temporarily reduced by an in-flight split. Updates coin-management integration tests to match the new sizing and calculation expectations.

Written by Cursor Bugbot for commit 20baea7. This will update automatically on new commits. Configure here.

COIN_SIZE was hardcoded to 1,000,000 mojos while CADT operations
require DEFAULT_COIN_AMOUNT + DEFAULT_FEE (typically 600,000,000
mojos). This caused a perpetual splitting loop where coins were
created 600x too small to be usable, wasting fees and temporarily
draining spendable balance.

Set COIN_SIZE = DEFAULT_COIN_AMOUNT + DEFAULT_FEE so each split coin
can independently fund one full DataLayer operation. Add a
splitInProgress flag so mirror-check tasks log a warning instead of
an error when balance is temporarily reduced during a split.
@TheLastCicada TheLastCicada merged commit d0ebc8c into fix/parallel-store-creation-retry Mar 12, 2026
20 checks passed
@TheLastCicada TheLastCicada deleted the fix/coin-management-size branch March 12, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant