From e9f1e351659f4d7905dd3ff0799baa107b2e87d1 Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:54:53 -0800 Subject: [PATCH] Address PR comments - Add new index before removing old index to be safer - Change MaxLogsKept & LogsPerBlock from big.Int to uint64 --- core/chains/evm/logpoller/log_poller.go | 4 ++-- core/chains/evm/logpoller/orm_test.go | 4 ++-- core/chains/evm/logpoller/query.go | 4 ++-- ...log_poller_filters_add_topics_logs_per_block.sql | 13 +++++++++---- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/chains/evm/logpoller/log_poller.go b/core/chains/evm/logpoller/log_poller.go index 9a0565edc32..a2c35bec59f 100644 --- a/core/chains/evm/logpoller/log_poller.go +++ b/core/chains/evm/logpoller/log_poller.go @@ -160,8 +160,8 @@ type Filter struct { Topic3 evmtypes.HashArray // list of possible values for topic3 Topic4 evmtypes.HashArray // list of possible values for topic4 Retention time.Duration // maximum amount of time to retain logs - MaxLogsKept *ubig.Big // maximum number of logs to retain - LogsPerBlock *ubig.Big // rate limit ( maximum # of logs per block to save to db ) + MaxLogsKept uint64 // maximum number of logs to retain ( 0 = unlimited ) + LogsPerBlock uint64 // rate limit ( maximum # of logs per block, 0 = unlimited ) } // FilterName is a suggested convenience function for clients to construct unique filter names diff --git a/core/chains/evm/logpoller/orm_test.go b/core/chains/evm/logpoller/orm_test.go index ff4a15046b7..9824d0e9426 100644 --- a/core/chains/evm/logpoller/orm_test.go +++ b/core/chains/evm/logpoller/orm_test.go @@ -502,8 +502,8 @@ func TestLogPollerFilters(t *testing.T) { Name: "10 lpb rate limit, 1M max logs", Addresses: types.AddressArray{address}, EventSigs: types.HashArray{event1}, - MaxLogsKept: ubig.NewI(1000000), - LogsPerBlock: ubig.NewI(10), + MaxLogsKept: 1000000, + LogsPerBlock: 10, }, { // ensure that the UNIQUE CONSTRAINT isn't too strict (should only error if all fields are identical) Name: "duplicate of filter by topic4", Addresses: types.AddressArray{address}, diff --git a/core/chains/evm/logpoller/query.go b/core/chains/evm/logpoller/query.go index 097c8c049fa..d8112459743 100644 --- a/core/chains/evm/logpoller/query.go +++ b/core/chains/evm/logpoller/query.go @@ -142,11 +142,11 @@ func (q *queryArgs) withRetention(retention time.Duration) *queryArgs { return q.withCustomArg("retention", retention) } -func (q *queryArgs) withLogsPerBlock(logsPerBlock *ubig.Big) *queryArgs { +func (q *queryArgs) withLogsPerBlock(logsPerBlock uint64) *queryArgs { return q.withCustomArg("logs_per_block", logsPerBlock) } -func (q *queryArgs) withMaxLogsKept(maxLogsKept *ubig.Big) *queryArgs { +func (q *queryArgs) withMaxLogsKept(maxLogsKept uint64) *queryArgs { return q.withCustomArg("max_logs_kept", maxLogsKept) } diff --git a/core/store/migrate/migrations/0223_log_poller_filters_add_topics_logs_per_block.sql b/core/store/migrate/migrations/0223_log_poller_filters_add_topics_logs_per_block.sql index f16313b7d49..77e3d5fbd51 100644 --- a/core/store/migrate/migrations/0223_log_poller_filters_add_topics_logs_per_block.sql +++ b/core/store/migrate/migrations/0223_log_poller_filters_add_topics_logs_per_block.sql @@ -4,19 +4,24 @@ ALTER TABLE evm.log_poller_filters ADD COLUMN topic2 BYTEA CHECK (octet_length(topic2) = 32), ADD COLUMN topic3 BYTEA CHECK (octet_length(topic3) = 32), ADD COLUMN topic4 BYTEA CHECK (octet_length(topic4) = 32), - ADD COLUMN max_logs_kept NUMERIC(78,0), - ADD COLUMN logs_per_block NUMERIC(78,0), - DROP CONSTRAINT evm_log_poller_filters_name_evm_chain_id_address_event_key; + ADD COLUMN max_logs_kept BIGINT, + ADD COLUMN logs_per_block BIGINT; + -- Ordinary UNIQUE CONSTRAINT can't work for topics because they can be NULL. Any row with any column being NULL automatically satisfies the unique constraint (NULL != NULL) -- Using a hash of all the columns treats NULL's as the same as any other field. If we ever get to a point where we can require postgresql >= 15 then this can -- be fixed by using UNIQUE CONSTRAINT NULLS NOT DISTINCT which treats NULL's as if they were ordinary values (NULL == NULL) CREATE UNIQUE INDEX evm_log_poller_filters_name_chain_address_event_topics_key ON evm.log_poller_filters (hash_record_extended((name, evm_chain_id, address, event, topic2, topic3, topic4), 0)); +ALTER TABLE evm.log_poller_filters + DROP CONSTRAINT evm_log_poller_filters_name_evm_chain_id_address_event_key; + -- +goose Down +ALTER TABLE evm.log_poller_filters + ADD CONSTRAINT evm_log_poller_filters_name_evm_chain_id_address_event_key UNIQUE (name, evm_chain_id, address, event); DROP INDEX IF EXISTS evm_log_poller_filters_name_chain_address_event_topics_key; + ALTER TABLE evm.log_poller_filters - ADD CONSTRAINT evm_log_poller_filters_name_evm_chain_id_address_event_key UNIQUE (name, evm_chain_id, address, event), DROP COLUMN topic2, DROP COLUMN topic3, DROP COLUMN topic4,