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")