github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/internal/state/indexer/doc.go (about)

     1  /*
     2  Package indexer defines Tendermint's block and transaction event indexing logic.
     3  
     4  Tendermint supports two primary means of block and transaction event indexing:
     5  
     6  1. A key-value sink via an embedded database with a proprietary query language.
     7  2. A Postgres-based sink.
     8  
     9  An ABCI application can emit events during block and transaction execution in the form
    10  
    11     <abci.Event.Type>.<abci.EventAttributeKey>=<abci.EventAttributeValue>
    12  
    13  for example "transfer.amount=10000".
    14  
    15  An operator can enable one or both of the supported indexing sinks via the
    16  'tx-index.indexer' Tendermint configuration.
    17  
    18  Example:
    19  
    20  	[tx-index]
    21  	indexer = ["kv", "psql"]
    22  
    23  If an operator wants to completely disable indexing, they may simply just provide
    24  the "null" sink option in the configuration. All other sinks will be ignored if
    25  "null" is provided.
    26  
    27  If indexing is enabled, the indexer.Service will iterate over all enabled sinks
    28  and invoke block and transaction indexing via the appropriate IndexBlockEvents
    29  and IndexTxEvents methods.
    30  
    31  Note, the "kv" sink is considered deprecated and its query functionality is very
    32  limited, but does allow users to directly query for block and transaction events
    33  against Tendermint's RPC. Instead, operators are encouraged to use the "psql"
    34  indexing sink when more complex queries are required and for reliability purposes
    35  as PostgreSQL can scale.
    36  
    37  Prior to starting Tendermint with the "psql" indexing sink enabled, operators
    38  must ensure the following:
    39  
    40  1. The "psql" indexing sink is provided in Tendermint's configuration.
    41  2. A 'tx-index.psql-conn' value is provided that contains the PostgreSQL connection URI.
    42  3. The block and transaction event schemas have been created in the PostgreSQL database.
    43  
    44  Tendermint provides the block and transaction event schemas in the following
    45  path: state/indexer/sink/psql/schema.sql
    46  
    47  To create the schema in a PostgreSQL database, perform the schema query
    48  manually or invoke schema creation via the CLI:
    49  
    50  	$ psql <flags> -f state/indexer/sink/psql/schema.sql
    51  
    52  The "psql" indexing sink prohibits queries via RPC. When using a PostgreSQL sink,
    53  queries can and should be made directly against the database using SQL.
    54  
    55  The following are some example SQL queries against the database schema:
    56  
    57  * Query for all transaction events for a given transaction hash:
    58  
    59  	SELECT * FROM tx_events WHERE hash = '3E7D1F...';
    60  
    61  * Query for all transaction events for a given block height:
    62  
    63  	SELECT * FROM tx_events WHERE height = 25;
    64  
    65  * Query for transaction events that have a given type (i.e. value wildcard):
    66  
    67  	SELECT * FROM tx_events WHERE key LIKE '%transfer.recipient%';
    68  
    69  Note that if a complete abci.TxResult is needed, you will need to join "tx_events" with
    70  "tx_results" via a foreign key, to obtain contains the raw protobuf-encoded abci.TxResult.
    71  */
    72  package indexer