Skip to content

Commit

Permalink
Cascade delete to eth_txes when removing evm_key_state (smartcontract…
Browse files Browse the repository at this point in the history
  • Loading branch information
samsondav authored Oct 21, 2022
1 parent d6c5cc8 commit f20d288
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/services/keystore/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ func Test_EthKeyStore(t *testing.T) {
cltest.AssertCount(t, db, statesTableName, 0)
})

t.Run("Delete removes key even if eth_txes are present", func(t *testing.T) {
defer reset()
key, err := ethKeyStore.Create(&cltest.FixtureChainID)
require.NoError(t, err)
// ensure at least one state is present
cltest.AssertCount(t, db, statesTableName, 1)

// add one eth_tx
borm := cltest.NewTxmORM(t, db, cfg)
cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, borm, 0, 42, key.Address)

_, err = ethKeyStore.Delete(key.ID())
require.NoError(t, err)
retrievedKeys, err := ethKeyStore.GetAll()
require.NoError(t, err)
require.Equal(t, 0, len(retrievedKeys))
cltest.AssertCount(t, db, statesTableName, 0)
})

t.Run("EnsureKeys / EnabledKeysForChain", func(t *testing.T) {
defer reset()
err := ethKeyStore.EnsureKeys(&cltest.FixtureChainID)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- +goose Up
ALTER TABLE eth_txes DROP CONSTRAINT eth_txes_evm_chain_id_from_address_fkey, ADD CONSTRAINT eth_txes_evm_chain_id_from_address_fkey FOREIGN KEY (evm_chain_id, from_address) REFERENCES public.evm_key_states(evm_chain_id, address) ON DELETE CASCADE DEFERRABLE INITIALLY IMMEDIATE NOT VALID;
-- +goose Down
ALTER TABLE eth_txes DROP CONSTRAINT eth_txes_evm_chain_id_from_address_fkey, ADD CONSTRAINT eth_txes_evm_chain_id_from_address_fkey FOREIGN KEY (evm_chain_id, from_address) REFERENCES public.evm_key_states(evm_chain_id, address) DEFERRABLE INITIALLY IMMEDIATE NOT VALID;
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ If you want to change this, you can manually set `ETH_MAX_GAS_PRICE_WEI`.
### Fixed

- Fixed minor bug where Chainlink would attempt (and fail) to estimate a tip cap higher than the maximum configured gas price in EIP1559 mode. It now caps the tipcap to the max instead of erroring.
- Fixed bug whereby it was impossible to remove eth keys that had extant transactions. Now, removing an eth key will drop all associated data automatically including past transactions.

## 1.9.0 - 2022-10-12

Expand Down

0 comments on commit f20d288

Please sign in to comment.