Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reindexer(events): capture full TxResult #18

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 17 additions & 13 deletions src/indexer.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -108,27 +111,28 @@ impl Indexer {
let block_id = context.block_id;
let (pseudo_events, tx_id): (Vec<Event>, Option<i64>) = match tx {
None => (Vec::new(), None),
Some((index, tx, tx_result)) => {
let tx_hash: String = {
let bytes =
<tendermint::crypto::default::Sha256 as tendermint::crypto::Sha256>::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::<tendermint_proto::v0_34::abci::ResponseDeliverTx>::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",
)
.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![
Expand Down
Loading