From fd21e83135d9b6f610d8f95d9ad098f9c5fc281d Mon Sep 17 00:00:00 2001 From: Erwan Or Date: Fri, 27 Dec 2024 17:11:01 -0500 Subject: [PATCH] reindexer(events): capture full `TxResult` --- Cargo.lock | 5 ++++- Cargo.toml | 3 +++ src/indexer.rs | 30 +++++++++++++++++------------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff87cd7..205cbbb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -4306,6 +4306,7 @@ dependencies = [ "clap", "cnidarium 0.79.5", "cnidarium 0.80.11", + "digest 0.10.7", "directories", "hex", "ibc-types", @@ -4317,7 +4318,9 @@ dependencies = [ "penumbra-proto 0.80.6", "penumbra-sct 0.80.11", "penumbra-transaction 0.80.11", + "prost", "serde_json", + "sha2 0.10.8", "sqlx", "tendermint", "tendermint-proto", diff --git a/Cargo.toml b/Cargo.toml index 28d119e..e666a01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,9 @@ penumbra-governance-v0o80 = { package = "penumbra-governance", git = "https://gi penumbra-ibc-v0o80 = { package = "penumbra-ibc", git = "https://github.com/penumbra-zone/penumbra", tag = "v0.80.11" } penumbra-sct-v0o80 = { package = "penumbra-sct", git = "https://github.com/penumbra-zone/penumbra", tag = "v0.80.11" } penumbra-transaction-v0o80 = { package = "penumbra-transaction", git = "https://github.com/penumbra-zone/penumbra", tag = "v0.80.11" } +sha2 = { version = "0.10.8", default-features = false } +digest = { version = "0.10.7", default-features = false } +prost = "0.12.6" # In debug builds, nonetheless compile dependencies in release mode, for performance. diff --git a/src/indexer.rs b/src/indexer.rs index d3c2647..8133415 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -1,6 +1,9 @@ +use hex::ToHex; +use prost::bytes::Bytes; +use sha2::Digest; use sqlx::{PgPool, Postgres, Transaction}; use tendermint::abci::{response::DeliverTx, Event, EventAttribute}; -use tendermint_proto::Protobuf; +use tendermint_proto::v0_37::abci::{ResponseDeliverTx, TxResult}; struct Context { block_id: i64, @@ -108,19 +111,20 @@ impl Indexer { let block_id = context.block_id; let (pseudo_events, tx_id): (Vec, Option) = match tx { None => (Vec::new(), None), - Some((index, tx, tx_result)) => { - let tx_hash: String = { - let bytes = - ::digest( - &tx, - ); - hex::encode_upper(&bytes) + Some((index, raw_tx, exec_result)) => { + let tx_hash = sha2::Sha256::digest(raw_tx).encode_hex_upper(); + let exec_result_proto: ResponseDeliverTx = exec_result.into(); + let raw_tx_bytes: Bytes = raw_tx.to_vec().into(); + + let tx_result = TxResult { + height: i64::try_from(height)?, + index: index as u32, + tx: raw_tx_bytes, + result: Some(exec_result_proto), }; - let tx_result = - Protobuf::::encode_vec( - tx_result, - ); + use prost::Message; + let tx_result_bytes = tx_result.encode_to_vec(); let (tx_id,): (i64,) = sqlx::query_as( "INSERT INTO tx_results VALUES (DEFAULT, $1, $2, CURRENT_TIMESTAMP, $3, $4) RETURNING rowid", @@ -128,7 +132,7 @@ impl Indexer { .bind(block_id) .bind(i32::try_from(index)?) .bind(&tx_hash) - .bind(tx_result) + .bind(tx_result_bytes) .fetch_one(context.dbtx.as_mut()) .await?; let pseudo_events = vec![