Bounty
XE-13355 · Bounty

[DAO] sessions._submitted leaves Anchor rows unwritten until worker.job_sessions, causing false anchor_overdue health degradation and unbounded rescans

Closed · duplicate — xe#500 filed 2026-11-12 05:49 UTC by Khanhtnq

Report

Summary

In dao/services/sessions.py, _ended (L502-506) deletes an Anchor row inside the same transaction whenever an anchor session ends failed or cancelled. By contrast, _submitted (L394-401) — the single helper called by submit (L426), _refused (L448), rebuild (L295), and cancel (L494) whenever a session's block has landed on the state chain — sets SigningSession.status = "submitted", submitted_index, and submitted_hash without updating Anchor.statechain_index or Anchor.statechain_hash.

This produces two concrete defects:

  1. False anchor_overdue health degradation and stale public anchor surfaces after API submission:
    • Every member API path that lands an anchor block (POST /v1/members/sessions/{sid}/sign, /rebuild, /cancel) commits SigningSession.status = "submitted" while leaving Anchor.statechain_index = None and Anchor.statechain_hash = "".
    • In dao/worker.py:289-303 (Worker.scheduler), "health" is ordered before "sessions" in job_table. On any scheduler pass where both job_health and job_sessions are due after an overdue anchor has just been signed and submitted via the API (or when GET /v1/health / dao health runs before the next 120-second job_sessions tick, or while the worker is not yet caught up), records.health (dao/services/records.py:282) queries latest_anchor(db, written=True) (Anchor.statechain_index.isnot(None)), misses the already-landed anchor, sets anchor_overdue = True and ok = False, degrades 30-day uptime (HealthCheck(ok=False)), and appends a public health.degraded event to EventLog.
    • Over the same window, GET /v1/legal/anchors, GET /v1/log/head, and /records report statechain_index: null (pending) while /members already shows the anchor session Written at state-chain #N.
  2. Unbounded full-history anchor scan every 120 seconds in worker.job_sessions:
    • To compensate for _submitted not updating Anchor, dao/worker.py:195-197 runs select(SigningSession).where(SigningSession.status == "submitted", SigningSession.kind == "anchor") on every two-minute job_sessions pass with no Anchor.statechain_index.is_(None) filter, reloading every submitted anchor session since genesis and issuing SELECT ... FROM anchors + ORM updates for each one.

Impact

Submitting an overdue anchor via the member API still triggers false anchor_overdue health failure, permanent health.degraded log entries, 30-day uptime loss when job_health runs ahead of job_sessions, temporary disagreement between /members and /records + /v1/legal/anchors + /v1/log/head, and an O(total historical anchors) database scan every 120 seconds.

Thread

Khanhtnq2026-11-12 05:49 UTCgithub

Fix proposed in xeprotocol/dao#4.

Joseph Denneteam2026-11-15 10:27 UTCgithub

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-13355 and says what differs; it is read like any other.