Skip to content

Fix account restoration batch upsert collapsing same-PK public keys - #64

Open
sausagee wants to merge 2 commits into
mainfrom
cursor/fix-account-restoration-batch-conflict-6c6c
Open

Fix account restoration batch upsert collapsing same-PK public keys#64
sausagee wants to merge 2 commits into
mainfrom
cursor/fix-account-restoration-batch-conflict-6c6c

Conversation

@sausagee

@sausagee sausagee commented Sep 6, 2026

Copy link
Copy Markdown

Bug

public_key_auth_keys batch upsert crashes when a multi-key account has two or more transactions in the same processor batch.

Diesel insert uses ON CONFLICT (auth_key, public_key, public_key_type). The extractor only deduped rows that also shared last_transaction_version. A MultiEd25519 / MultiKey account that sends two txs in one batch therefore produced two rows with the same PK and different versions. Postgres rejects that with:

ON CONFLICT DO UPDATE command cannot affect row a second time

This is the same production failure upstream fixed in aptos-labs/aptos-indexer-processors-v2#132 (Momentum Safe / multi-ed accounts). It is not covered by open PRs #16#63 (#51 is the MultiEd25519 threshold-byte key-rotation parser; #53 is capability-rotation Account skip).

Root cause

parse_account_restoration_models sorted then dedup_by on (public_key, public_key_type, auth_key, last_transaction_version). Distinct versions of the same key survived into insert_public_key_auth_keys_query.

Fix

Dedup public_key_auth_keys on the diesel PK across versions: keep the latest last_transaction_version / metadata, and OR is_public_key_used (once a key has signed for an auth key it cannot become unused). auth_key_account_addresses still keeps the latest row only — is_auth_key_used can go true→false on an unverified rotation.

Tests

  • cargo test -p processor --lib account_restoration_processor_helpers — pass (3 tests)
  • cargo clippy -p processor --lib --tests -- -D warnings — pass
Open in Web Open in Cursor 

public_key_auth_keys only deduped rows that shared last_transaction_version.
A multi-key account with two txs in one batch produced duplicate
(auth_key, public_key, public_key_type) rows and crashed diesel ON CONFLICT
upsert. Dedup across versions, keep latest metadata, and OR is_public_key_used.

Co-authored-by: Young Yang Liauw <sausagee@users.noreply.github.com>
@sausagee
sausagee marked this pull request as ready for review September 6, 2026 16:34
@sausagee
sausagee changed the base branch from main to fix/lint-stable-xclippy September 7, 2026 22:19
@sausagee
sausagee changed the base branch from fix/lint-stable-xclippy to main September 7, 2026 22:31
Stack the CI unblocker files from PR #70 (stable cargo xclippy, bookworm Dockerfiles with make) onto this bugfix branch so CI can go green while #70 awaits review. Merge target remains main; this does not merge #70.
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