core/keystore/aptos: wrap duplicate-key Import error with ErrKeyExists sentinel - #23267
Draft
cawthorne wants to merge 1 commit into
Draft
core/keystore/aptos: wrap duplicate-key Import error with ErrKeyExists sentinel#23267cawthorne wants to merge 1 commit into
cawthorne wants to merge 1 commit into
Conversation
Contributor
|
✅ No conflicts with other open PRs targeting |
Contributor
|
I see you updated files related to
|
|
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.




Summary
AptosKeyStore.Importreturned the duplicate-key conflict as a free-standingfmt.Errorf("key with ID %s already exists", ...). The boot path incore/cmd/shell_local.godoeserrors.Is(err2, keystore.ErrKeyExists)to recognize and skip the dup case (so a node can re-import its already-present keys on restart), but that check returnedfalsefor the bare-string error — different pointer values, no wrap. The control flow fell through tos.errorOut(...)andos.Exit(1).One-line fix: wrap with the existing
ErrKeyExistssentinel viafmt.Errorf("%w: ...", ErrKeyExists, ...)soerrors.Iscorrectly identifies the duplicate path, which the boot caller already handles by logging and continuing.return aptoskey.Key{}, fmt.Errorf("key with ID %s already exists", key.ID()) +return aptoskey.Key{}, fmt.Errorf("%w: key with ID %s already exists", ErrKeyExists, key.ID())The user-visible error string is unchanged (
"Key already exists: key with ID <id> already exists"), so existing log lines, assertion paths, and tests are unaffected.Symptom
Production operators with hand-imported keys via in-TOML
[Aptos.Keys]blocks (e.g. CRE local env, fixtures, or staging clusters that pre-seed deterministic keystores) hitExit 1on any node that restarts while the key is already present in the DB. The dev-build fire-drill in chainlink-data-feeds specifically demonstrates this:This is the textbook "CRE Aptos key-import collision" the local-cre health check warns about. Other production paths — including the typical
chainlink admin keys apt createflow — do not pre-seed[Aptos.Keys]so they aren't affected; the bug is silent there.Out of scope
The same pattern exists in cosmos, solana, stellar, p2p, etc. — those keystores'
Importmethods also return bare-string duplicates. They are not on the boot codepath (onlyEnsureKeyis called, which is idempotent), so this PR is intentionally minimal. A follow-up can sweep them in a separate change if warranted.The data-feeds
apply-local-cre-settings-profile.shregression (docker restartreuses container env, soCL_CRE_SETTINGS_DEFAULTupdates don't actually apply withoutdocker rm+docker run) is a separate issue affecting only that repo.Tests
core/services/keystore/aptos_test.goline-78 existingassertions.Equal(t, ..., err2.Error())continue to pass — the rendered string is unchanged.errors.Is(err, keystore.ErrKeyExists)now returnstruefor the duplicate-error path; this is the only new behavioral contract added.