Skip to content

core/keystore: wrap duplicate-key Import error with ErrKeyExists for Solana and Stellar - #23718

Open
Dev-next-gen wants to merge 1 commit into
smartcontractkit:developfrom
Dev-next-gen:fix/keystore-solana-stellar-errkeyexists
Open

core/keystore: wrap duplicate-key Import error with ErrKeyExists for Solana and Stellar#23718
Dev-next-gen wants to merge 1 commit into
smartcontractkit:developfrom
Dev-next-gen:fix/keystore-solana-stellar-errkeyexists

Conversation

@Dev-next-gen

Copy link
Copy Markdown

I was reading #23267, which fixed Aptos Import so the boot path in core/cmd/shell_local.go recognises a duplicate key through errors.Is(err2, keystore.ErrKeyExists) and continues instead of calling s.errorOut. That PR left the other keystores out on the grounds that they are not on the boot path, where only EnsureKey is called. For Solana and Stellar that is not the case: runNode loops over s.Config.ImportedSolKeys() and s.Config.ImportedStellarKeys(), calls Import, and relies on the exact same errors.Is(err2, keystore.ErrKeyExists) check. Both Import methods still return a bare fmt.Errorf("key with ID %s already exists", ...), so the check is false and a node with imported Solana or Stellar keys fails on the second boot, once the key is already in the keyring.

The fix is the same one-liner as the Aptos one, applied to solana.go and stellar.go. The rendered message becomes Key already exists: key with ID <id> already exists, identical in shape to Aptos and DKG recipient. No existing test compares the Solana or Stellar string.

To lock it in, I tightened the duplicate Import assertion in Test_SolanaKeyStore_E2E and Test_StellarKeyStore_E2E from require.Error to require.ErrorIs(t, err, keystore.ErrKeyExists). Against a local Postgres 16 prepared with make testdb, both tests fail without the change (Target error should be in err chain: expected: "Key already exists") and pass with it. The rest of the Aptos, DKG recipient, P2P and Stellar keystore tests still pass. I only exercised the keystore level, not a full node restart with [[Solana.Keys]] secrets. The boot code uses the same errors.Is check the test now asserts.

A few other keystores (Cosmos, StarkNet, Sui, TON, Tron, OCR, OCR2, VRF, CSA, Workflow) have the same bare error. They are not imported at boot, and some of their tests compare the exact string, so I left them out to keep this change minimal.

Requires

None.

Supports

None.

AI tools used

…Solana and Stellar

The boot path in core/cmd/shell_local.go imports ImportedSolKeys and
ImportedStellarKeys and skips duplicates with
errors.Is(err2, keystore.ErrKeyExists). Both Import methods returned a
bare error, so the check was false and a node restarting with an already
present key exited. Same fix as smartcontractkit#23267 for Aptos.
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.

1 participant