From 01379783be86898a222461f5b55c496b7baad3f9 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 25 Oct 2026 16:49:10 -0500 Subject: [PATCH] fix(tkad): a replay that appends nothing must not publish dssend set the dirty flag after every successful tkacommit, including a retained or empty AUM replay where tkastageone finds the hash already in the pool and stages nothing. dsrequest then treated the daemon as changed, bumped Revision, and rewrote the snapshot for an operation that altered no logical state. Observed as Revision 10 -> 11 and 11 -> 12 on a second send of the same AUM, with identical head and node set. Capture tkacget 0 before staging and set the dirty flag only when the commit appended a node. The chain head is a pure function of the retained set, so an unchanged set also leaves dsputhead's reply and the stored bytes identical. smoke.py now pins this: it replays an already-retained AUM, then requires the same Revision and byte-identical snapshot, plus the exact reply. --- cmd/tkad/rpc.om | 7 +++++++ cmd/tkad/test/smoke.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/cmd/tkad/rpc.om b/cmd/tkad/rpc.om index 08111c4..318deda 100644 --- a/cmd/tkad/rpc.om +++ b/cmd/tkad/rpc.om @@ -340,6 +340,9 @@ end if ne tkabegin 0 ret 500 end +note Retained nodes before staging: a replay of an AUM we already have stages +note nothing, and must not be published as a durable change below. +rb = tkacget 0 b = new uchar 65536 0 if eq dskind t r 2 j = add r 1 @@ -361,7 +364,11 @@ end p = dslit out 0 10 p = dsputhead out p put ds_ctl 6 dslit out p 5 +note Publish only when the commit appended a node. A retained or empty AUM +note replay leaves the head, revision and stored bytes unchanged. +if gt tkacget 0 rb put ds_ctl 5 1 +end ret 200 end fn dsdisable t view ulong 32768 d view uchar 65536 out edit uchar 65536 to int diff --git a/cmd/tkad/test/smoke.py b/cmd/tkad/test/smoke.py index eb3f2ee..4d2f76f 100755 --- a/cmd/tkad/test/smoke.py +++ b/cmd/tkad/test/smoke.py @@ -178,6 +178,24 @@ with tempfile.TemporaryDirectory(prefix="omnet-tkad-") as top: affected = d.rpc(8, d.req(KeyID=FIX["keyID"])) check(affected["Signatures"] == FIX["signatures"], "affected raw signature array") d.rpc(5, d.req(Head=FIX["updatedHead"], MissingAUMs=[FIX["emptyMeta"]], Interactive=True)) + # A replay of an already-retained AUM appends nothing, so it must not + # persist: the snapshot bytes and Revision stay identical. The daemon + # rewrote the snapshot here with Revision+1 before this was pinned. + # File layout: 16-byte store magic, 40-byte record frame, then the + # 16-word daemon header (word 6 Revision, word 15 the complete marker). + def snapshot_state(): + raw = (state / "snapshot").read_bytes() + check(raw[:16] == b"OMNETSNAP0000001", "snapshot store magic") + header = struct.unpack_from("<16Q", raw, 56) + check(header[15] == 1, "snapshot complete marker") + return header[6], raw + head_after = d.map()["TKAInfo"]["Head"] + revision, before_bytes = snapshot_state() + replay = d.rpc(5, d.req(Head=head_after, MissingAUMs=[FIX["emptyMeta"]], Interactive=True)) + after_revision, after_bytes = snapshot_state() + check(replay == {"Head": head_after}, f"retained replay reply: {replay}") + check(after_revision == revision, f"retained replay must not advance Revision: {revision} -> {after_revision}") + check(after_bytes == before_bytes, "retained replay must not rewrite the snapshot") snapshot_map = d.map() d.stop(); d = Daemon(state) check(d.map() == snapshot_map, "typed empty metadata replay and signatures")