security(consensus): atomic Sophia epoch settlement (synthesis of #6757 + #6760)#6769
Conversation
+ #6760 Combines @yyswhsccc's settlement-guard fix + tests (#6757) and @Ishant5436's same fix + the Mine-Your-Grandmas-Computer doc (#6760) into one PR, with the tri-brain BLOCKING issues fixed: - finalize_epoch: BEGIN IMMEDIATE + atomic claim (settled=1,finalized=1 WHERE COALESCE(settled,0)=0, rowcount-checked) — prevents double-settlement on the Sophia path. Post-claim payout wrapped in try/except -> rollback (no half-paid epoch). PRAGMA busy_timeout=5000 so concurrent block-ingest waits instead of erroring 'database is locked'. - epoch_state migration: adds settled/settled_ts, normalizes NULL->0 (so a legacy/shared row can't become permanently unpayable), backfills finalized. - inc_epoch_block: busy_timeout + guard so a late block can't inflate the count the reward was computed against. - get_epoch now exposes settled/settled_ts (DB contract was silently expanded). - 9 tests incl. idempotent-pays-once, NULL-settled-payable, inc-after-finalize. Co-authored-by: yyswhsccc <yyswhsccc@users.noreply.github.com> Co-authored-by: Ishant5436 <Ishant5436@users.noreply.github.com> SCOPE: fixes the Sophia path; the cross-module epoch_state schema/settlement coordination across rewards_implementation/anti_double_mining remains tracked in #6749. Tri-brain reviewed (Codex+Grok; GPT-OSS offline). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ BCOS v2 Scan Results
What does this mean?The BCOS (Beacon Certified Open Source) engine scans for:
BCOS v2 Engine - Free & Open Source (MIT) - Elyan Labs |
✅ Tri-brain review → MERGE (CHAOTIC-regime gate cleared)Ran the recurrent-depth dev loop (Brain 2 Codex 5.5 + Brain 4 Grok; Brain 3 GPT-OSS down — loop ran degraded/dual-brain). Both brains raised BLOCKING findings; Brain 1 (Coda) resolved them against the repo, which the sandboxed brains could not read (Grok: Codex BLOCKING — migration assumes Grok BLOCKING — Cross-path coordination is correct: main node and Sophia share the Residual (money-safe, cosmetic): on the live DB the column already exists, so the one-time backfill is skipped; legacy CI: the red Follow-ups filed under the #6749 cross-path-settlement design track: (1) main-node |
Atomic Sophia epoch settlement — synthesis of #6757 + #6760
@yyswhsccc (#6757) and @Ishant5436 (#6760) independently submitted the same
sophia_elya_service.pysettlement fix. This combines the best of both — yyswhsccc's fix + settlement test suite and Ishant5436's doc (MINE_YOUR_GRANDMAS_COMPUTER.md) — into one PR, with the tri-brain BLOCKINGs fixed.What it does
finalize_epoch:BEGIN IMMEDIATE+ atomic claim (settled=1, finalized=1 WHERE COALESCE(settled,0)=0, rowcount-checked) — closes the double-settlement window on the Sophia path. Post-claim payout intry/except → rollback(no half-paid epoch).PRAGMA busy_timeout=5000so concurrent block-ingest waits instead of erroring "database is locked".settled/settled_ts, normalizesNULL→0(so a legacy/shared row can't become permanently unpayable), and backfills finalized→settled once (only when the column is first added — never on later startups, which could suppress a two-phase settle).ALTERwrapped against concurrent-startup races.inc_epoch_block: guard + busy_timeout so a late block can't inflate the count the reward was computed against.get_epochnow exposessettled/settled_ts(additive).Tests (9, all green)
incl. idempotent-pays-once, NULL-
settled-payable, inc-after-finalize-frozen.Tri-brain (Codex + Grok; GPT-OSS offline) — 3 loops
Fixed: NULL consistency, busy_timeout, tx rollback, one-time backfill, ALTER TOCTOU.
This fixes the Sophia path. Cross-module
epoch_statecoordination (rewards_implementation / anti_double_mining schema + the rolling-deploy mixed-version window) is the broader #6749 work — deploy all settlement instances together. Complements the main-node fix in #6748.Co-authored-by: @yyswhsccc · @Ishant5436. Supersedes #6757 and #6760.
🤖 Generated with Claude Code