Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
- Add new index before removing old index to be safer
- Change MaxLogsKept & LogsPerBlock from big.Int to uint64
  • Loading branch information
reductionista committed Feb 22, 2024
1 parent 9ee23b2 commit e9f1e35
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/logpoller/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/logpoller/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e9f1e35

Please sign in to comment.