Skip to content

[FEAT] Add postCommitmentsSafe — idempotent variant#64

Merged
roeezolantz merged 2 commits into
masterfrom
feat/post-commitments-safe
Apr 28, 2026
Merged

[FEAT] Add postCommitmentsSafe — idempotent variant#64
roeezolantz merged 2 commits into
masterfrom
feat/post-commitments-safe

Conversation

@roeezolantz
Copy link
Copy Markdown
Contributor

Summary

Adds postCommitmentsSafe to CommitmentRegistry — an idempotent counterpart to postCommitments that silently skips handles already committed under the given version, instead of reverting the entire batch with CommitmentAlreadyExists.

postCommitments (strict) is unchanged; this is purely additive.

Why

Callers like blockchain-poster (CoFHE) batch many handles into one tx. The same handle can appear across batches because:

  • FHE outputs are deterministic — repeated operations on the same input produce the same handle
  • RabbitMQ redeliveries (after relayer/network failures) can re-batch the same messages

Under postCommitments, the first duplicate reverts the whole batch → nack-requeue → retry → revert again → eventually DLQ. Slim-listener's block tracker stalls. With postCommitmentsSafe, already-committed handles are skipped, the batch progresses, and the on-chain end state is identical.

Tracks PRO-300.

What's reverted/preserved

  • Reverts in postCommitmentsSafe:
    • EmptyBatch, LengthMismatch, VersionNotActive, OnlyPosterAllowed — caller bugs / lifecycle violations
    • ZeroCommitHash — indicates upstream bug producing invalid input
  • Skipped silently: a handle already mapped under (version, handle) in storage

Observability

New event:

event CommitmentsPostedSafe(bytes32 indexed version, uint256 newlyPosted, uint256 skipped);

newlyPosted + skipped == handles.length. Lets dashboards distinguish "real" commitments from idempotent re-posts.

Tests

13 new tests in CommitmentRegistry.behavior.ts covering:

  • Fresh batch — all written, skipped=0
  • Re-post identical handle — kept original, newlyPosted=0, skipped=N
  • Mixed batch (some new, some existing) — only new ones written
  • Within-batch duplicates — first wins, rest skipped
  • All four "still revert" cases (zero hash, empty batch, length mismatch, inactive version, non-poster)
  • handlesByVersion doesn't double-count on re-posts

All 87 tests pass (pnpm hardhat test).

Test plan

  • CI green
  • Coordinated rollout with cofhe (blockchain-poster) PR that flips its ABI call to postCommitmentsSafe

Follow-up

Once merged + redeployed, the consuming PR in cofhe (PR #676 — feat/blockchain-poster-event-completion) bumps the submodule SHA and switches blockchain-poster/src/abi.rs to call postCommitmentsSafe.

…y-posted handles

Reverts on duplicates (CommitmentAlreadyExists) break callers like
blockchain-poster whose batches can re-post the same handle (deterministic
FHE outputs, RabbitMQ redeliveries). The Safe variant silently skips and
emits CommitmentsPostedSafe(version, newlyPosted, skipped) so observability
isn't lost.

ZeroCommitHash, EmptyBatch, LengthMismatch, VersionNotActive, OnlyPosterAllowed
still revert — those indicate caller bugs.

Tracks PRO-300.
@roeezolantz roeezolantz force-pushed the feat/post-commitments-safe branch from c70de08 to 73a38ab Compare April 26, 2026 18:56
Pairs with the genesis allocation + keystore in the parent repo. The previous
default 0x3f1Eae… is the test wallet and races with Hardhat-driven txs for
the same nonce sequence — see PRO-300 / PR-#676 deployment requirements.
@roeezolantz roeezolantz marked this pull request as ready for review April 26, 2026 20:21
@roeezolantz roeezolantz requested a review from a team as a code owner April 26, 2026 20:21
@roeezolantz roeezolantz merged commit c1c1c3a into master Apr 28, 2026
7 checks passed
@roeezolantz roeezolantz deleted the feat/post-commitments-safe branch April 28, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants