Skip to content

Commit

Permalink
storage/consensus: Add index for transaction type
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jun 14, 2024
1 parent 98c1587 commit 1c78e00
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changelog/708.feature.md
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 11 additions & 28 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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/[email protected]/staking/api#pkg-variables).
example: *tx_body_1
success:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions storage/migrations/00_consensus.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down
5 changes: 5 additions & 0 deletions storage/migrations/16_consensus_tx_index.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

CREATE INDEX ix_transactions_method ON chain.transactions (method);

COMMIT;

0 comments on commit 1c78e00

Please sign in to comment.