fix: align Sophia epoch settlement guard#6757
Conversation
|
@Scottcjn This PR is ready for maintainer review. Validation evidence is listed in the PR body. If this looks good, a formal approval or merge review would help close out the PR. |
Ishant5436
left a comment
There was a problem hiding this comment.
LGTM!
- The schema migration is idempotent and correctly backfills legacy finalized epochs.
- The use of
BEGIN IMMEDIATEcorrectly prevents concurrent races on epoch settlement. - The
rowcountcheck ensures atomic application of the settlement marker. - Good test coverage verifying the schema and settlement logic.
This securely resolves the divergence between Sophia's local settlement state and the integrated implementation.
|
Thanks — this is the right instinct (it advances #6749), but tri-brain (Codex+Grok) flags BLOCKING issues that make it unsafe to merge as-is, and they're the exact reason #6749 calls for a coordinated fix rather than per-path patches:
Let's converge this with #6760 (which fixes the same |
+ #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>
|
@Scottcjn Thanks for reviewing this. GitHub currently shows this as a comment-only review rather than a formal approval. Could you re-review when you have a chance? If this looks good, a formal approval would help close out the review. |
|
Superseded by #6769 (merged synthesis) — your settlement fix + test suite are in it, co-credited to you, with the tri-brain BLOCKINGs resolved (NULL consistency, busy_timeout, one-time backfill, atomic-tx rollback). 18 RTC sent to |
… + #6760) (#6769) * fix: align Sophia epoch settlement guard * security(consensus): atomic Sophia epoch settlement — synthesis of #6757 + #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> --------- Co-authored-by: SR <ssr@SRdeMacBook-Pro.local> Co-authored-by: Scott Boudreaux <scottbphone12@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
✅ Paid 25 RTC — settlement-guard, synthesized & mergedYour settlement-guard alignment was synthesized with Ishant5436's vintage-miner guide and my atomic-claim hardening into #6769, which merged (commit 5a969b7) after a tri-brain consensus review. 25 RTC (Medium consensus-correctness tier) to Thanks for the contribution. 🌸 |
|
✅ Verified eligible — pending payout. Per Bounty #73: you were the first reviewer of PR #6757 and left a substantive review (assessed the idempotent schema migration + legacy-epoch backfill correctness). Eligible even though the PR itself was later closed — the bounty pays for the review. Eligible: 1 substantive first-review → 5 RTC (current $0.15 reference rate). Marked for payout. |
BCOS Checklist (Required For Non-Doc PRs)
BCOS-L2What Changed
node/sophia_elya_service.pyso itsepoch_stateschema includes the sharedsettledandsettled_tscolumns used by the other settlement paths.finalized=1Sophia epochs assettled=1.finalize_epoch()acquireBEGIN IMMEDIATEand claimsettled=1before crediting balances, so an epoch already settled by another path is not credited again.node/tests/test_sophia_elya_service_money_units.pyfor legacy schema migration, second-settlement blocking, and respecting an existing settled marker.Why It Matters
This addresses the bounded Sophia service slice of #6749. The main integrated settlement path and RIP-200/anti-double-mining paths already use
epoch_state.settled; Sophia still had a divergent schema and only checkedfinalized, which could bypass the shared settlement marker in mixed deployments.Validation
.venv-bounty-validation/bin/python -m pytest -q node/tests/test_sophia_elya_service_money_units.py node/tests/test_sophia_elya_service.py --tb=short->15 passed.venv-bounty-validation/bin/python -m py_compile node/sophia_elya_service.py node/tests/test_sophia_elya_service_money_units.py-> passedgit diff --check origin/main...HEAD-> passedorigin/main...HEAD-> passed, 2 changed files scanned, no findingsTouched Files / Subsystems
node/sophia_elya_service.py: Sophia epoch-state schema migration and atomic settlement claim.node/tests/test_sophia_elya_service_money_units.py: focused regression tests for the Sophia settlement guard.Scope / Risk Boundary
epoch_state.settledguard.Refs #6749 and #305.
wallet: RTC47bc28896a1a4bf240d1fd780f4559b242bcd945