Fix account restoration batch upsert collapsing same-PK public keys - #64
Open
sausagee wants to merge 2 commits into
Open
Fix account restoration batch upsert collapsing same-PK public keys#64sausagee wants to merge 2 commits into
sausagee wants to merge 2 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
public_key_auth_keysbatch 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 sharedlast_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 timeThis 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_modelssorted thendedup_byon(public_key, public_key_type, auth_key, last_transaction_version). Distinct versions of the same key survived intoinsert_public_key_auth_keys_query.Fix
Dedup
public_key_auth_keyson the diesel PK across versions: keep the latestlast_transaction_version/ metadata, and ORis_public_key_used(once a key has signed for an auth key it cannot become unused).auth_key_account_addressesstill keeps the latest row only —is_auth_key_usedcan 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