From 1c78e0027ac6d1e6afd8d77d0fa4cdd8b11b129f Mon Sep 17 00:00:00 2001 From: ptrus Date: Thu, 13 Jun 2024 14:37:47 +0200 Subject: [PATCH] storage/consensus: Add index for transaction type --- .changelog/708.feature.md | 5 +++ api/spec/v1.yaml | 39 ++++++------------- storage/client/client.go | 3 -- storage/client/queries/queries.go | 11 ++---- storage/migrations/00_consensus.up.sql | 1 + .../migrations/16_consensus_tx_index.up.sql | 5 +++ 6 files changed, 26 insertions(+), 38 deletions(-) create mode 100644 .changelog/708.feature.md create mode 100644 storage/migrations/16_consensus_tx_index.up.sql diff --git a/.changelog/708.feature.md b/.changelog/708.feature.md new file mode 100644 index 000000000..1779acc6b --- /dev/null +++ b/.changelog/708.feature.md @@ -0,0 +1,5 @@ +/consensus/transactions: Add index for transaction type + +Additionally remove `minFee`, `maxFee` and `code` query filters. These +were not all that useful, and also don't have the necessary indexes +set to be usable in practice. diff --git a/api/spec/v1.yaml b/api/spec/v1.yaml index 22cf756e8..bdbbac6c8 100644 --- a/api/spec/v1.yaml +++ b/api/spec/v1.yaml @@ -238,23 +238,6 @@ paths: type: string description: A filter on related accounts. example: *staking_address_1 - - in: query - name: minFee - schema: - allOf: [$ref: '#/components/schemas/TextBigInt'] - description: A filter on minimum transaction fee, inclusive. - example: "1000" - - in: query - name: maxFee - schema: - allOf: [$ref: '#/components/schemas/TextBigInt'] - description: A filter on maximum transaction fee, inclusive. - example: "100000000000000000000000" - - in: query - name: code - schema: - type: integer - description: A filter on transaction status code. - in: query name: after schema: @@ -1128,7 +1111,7 @@ paths: - in: path name: address required: true - schema: + schema: allOf: [$ref: '#/components/schemas/EthOrOasisAddress'] description: The staking address of the account to return. responses: @@ -1530,8 +1513,8 @@ components: type: object description: The method call body. This spec does not encode the many possible types; instead, see [the Go API](https://pkg.go.dev/github.com/oasisprotocol/oasis-core/go) of oasis-core. - This object will conform to one of the types passed to variable instantiations using `NewMethodName` - two levels down the hierarchy, e.g. `MethodTransfer` from `oasis-core/go/staking/api` seen + This object will conform to one of the types passed to variable instantiations using `NewMethodName` + two levels down the hierarchy, e.g. `MethodTransfer` from `oasis-core/go/staking/api` seen [here](https://pkg.go.dev/github.com/oasisprotocol/oasis-core/go@v0.2300.10/staking/api#pkg-variables). example: *tx_body_1 success: @@ -1561,9 +1544,9 @@ components: This field, like `code` and `module`, can represent an error that originated anywhere in the paratime, i.e. either inside or outside a smart contract. - A common special case worth calling out: When the paratime is - EVM-compatible (e.g. Emerald or Sapphire) and the error originates - inside a smart contract (using `revert` in solidity), the following + A common special case worth calling out: When the paratime is + EVM-compatible (e.g. Emerald or Sapphire) and the error originates + inside a smart contract (using `revert` in solidity), the following will be true: - `module` will be "evm" and `code` will be 8; see [here](https://github.com/oasisprotocol/oasis-sdk/blob/runtime-sdk/v0.8.3/runtime-sdk/modules/evm/src/lib.rs#L128) for other possible errors in the `evm` module. - `message` will contain the best-effort human-readable revert reason. @@ -1573,12 +1556,12 @@ components: allOf: [$ref: '#/components/schemas/EvmAbiParam'] description: | The error parameters, as decoded using the contract abi. Present only when - - the error originated from within a smart contract (e.g. via `revert` in Solidity), and + - the error originated from within a smart contract (e.g. via `revert` in Solidity), and - the contract is verified or the revert reason is a plain String. If this field is present, `message` will include the name of the error, e.g. 'InsufficentBalance'. Note that users should be cautious when evaluating error data since the data origin is not tracked and error information can be faked. - + ConsensusEventType: type: string enum: @@ -2424,13 +2407,13 @@ components: This object will conform to one of the `*Event` types two levels down the hierarchy (e.g. `MintEvent` from `accounts > Event > MintEvent`), OR `evm > Event`. For object fields that specify an oasis-style address, Nexus - will add a field specifying the corresponding Ethereum address, if known. Currently, + will add a field specifying the corresponding Ethereum address, if known. Currently, the only such possible fields are `from_eth`, `to_eth`, and `owner_eth`. evm_log_name: type: string description: | - If the event type is `evm.log`, this field describes the human-readable type of - evm event, e.g. `Transfer`. + If the event type is `evm.log`, this field describes the human-readable type of + evm event, e.g. `Transfer`. Absent if the event type is not `evm.log`. example: 'Transfer' evm_log_params: diff --git a/storage/client/client.go b/storage/client/client.go index b62554653..322db2d26 100644 --- a/storage/client/client.go +++ b/storage/client/client.go @@ -364,9 +364,6 @@ func (c *StorageClient) Transactions(ctx context.Context, p apiTypes.GetConsensu p.Method, p.Sender, p.Rel, - toString(p.MinFee), - toString(p.MaxFee), - p.Code, p.After, p.Before, p.Limit, diff --git a/storage/client/queries/queries.go b/storage/client/queries/queries.go index f26e129a7..7c4ab1be9 100644 --- a/storage/client/queries/queries.go +++ b/storage/client/queries/queries.go @@ -65,14 +65,11 @@ const ( ($2::text IS NULL OR chain.transactions.method = $2::text) AND ($3::text IS NULL OR chain.transactions.sender = $3::text) AND ($4::text IS NULL OR chain.accounts_related_transactions.account_address = $4::text) AND - ($5::numeric IS NULL OR chain.transactions.fee_amount >= $5::numeric) AND - ($6::numeric IS NULL OR chain.transactions.fee_amount <= $6::numeric) AND - ($7::bigint IS NULL OR chain.transactions.code = $7::bigint) AND - ($8::timestamptz IS NULL OR chain.blocks.time >= $8::timestamptz) AND - ($9::timestamptz IS NULL OR chain.blocks.time < $9::timestamptz) + ($5::timestamptz IS NULL OR chain.blocks.time >= $5::timestamptz) AND + ($6::timestamptz IS NULL OR chain.blocks.time < $6::timestamptz) ORDER BY chain.transactions.block DESC, chain.transactions.tx_index - LIMIT $10::bigint - OFFSET $11::bigint` + LIMIT $7::bigint + OFFSET $8::bigint` Transaction = ` SELECT block, tx_index, tx_hash, sender, nonce, fee_amount, method, body, code, module, message, chain.blocks.time diff --git a/storage/migrations/00_consensus.up.sql b/storage/migrations/00_consensus.up.sql index dad4ff3e4..83656cfbe 100644 --- a/storage/migrations/00_consensus.up.sql +++ b/storage/migrations/00_consensus.up.sql @@ -66,6 +66,7 @@ CREATE TABLE chain.transactions -- Queries by sender and/or tx_hash are available via the API. CREATE INDEX ix_transactions_sender ON chain.transactions (sender); CREATE INDEX ix_transactions_tx_hash ON chain.transactions (tx_hash); +-- CREATE INDEX ix_transactions_method ON chain.transactions (method); -- added in 16_consensus_tx_idxs.up.sql CREATE TABLE chain.events ( diff --git a/storage/migrations/16_consensus_tx_index.up.sql b/storage/migrations/16_consensus_tx_index.up.sql new file mode 100644 index 000000000..dfa0c3919 --- /dev/null +++ b/storage/migrations/16_consensus_tx_index.up.sql @@ -0,0 +1,5 @@ +BEGIN; + +CREATE INDEX ix_transactions_method ON chain.transactions (method); + +COMMIT;