diff --git a/crates/bin/pindexer/src/stake/delegation_txs.rs b/crates/bin/pindexer/src/stake/delegation_txs.rs index a8da474a4c..c25dc63a4d 100644 --- a/crates/bin/pindexer/src/stake/delegation_txs.rs +++ b/crates/bin/pindexer/src/stake/delegation_txs.rs @@ -2,6 +2,7 @@ use anyhow::{anyhow, Result}; use cometindex::{async_trait, sqlx, AppView, ContextualizedEvent, PgPool, PgTransaction}; use penumbra_num::Amount; use penumbra_proto::{core::component::stake::v1 as pb, event::ProtoEvent}; +use penumbra_stake::IdentityKey; #[derive(Debug)] pub struct DelegationTxs {} @@ -17,7 +18,7 @@ impl AppView for DelegationTxs { sqlx::query( "CREATE TABLE stake_delegation_txs ( id SERIAL PRIMARY KEY, - validator_ik BYTEA NOT NULL, + ik TEXT NOT NULL, amount BIGINT NOT NULL, height BIGINT NOT NULL, tx_hash BYTEA NOT NULL @@ -26,8 +27,8 @@ impl AppView for DelegationTxs { .execute(dbtx.as_mut()) .await?; - // Create index on validator_ik - sqlx::query("CREATE INDEX idx_stake_delegation_txs_validator_ik ON stake_delegation_txs(validator_ik);") + // Create index on ik + sqlx::query("CREATE INDEX idx_stake_delegation_txs_ik ON stake_delegation_txs(ik);") .execute(dbtx.as_mut()) .await?; @@ -38,8 +39,8 @@ impl AppView for DelegationTxs { .execute(dbtx.as_mut()) .await?; - // Create composite index on validator_ik and height (descending) - sqlx::query("CREATE INDEX idx_stake_delegation_txs_validator_ik_height ON stake_delegation_txs(validator_ik, height DESC);") + // Create composite index on ik and height (descending) + sqlx::query("CREATE INDEX idx_stake_delegation_txs_validator_ik_height ON stake_delegation_txs(ik, height DESC);") .execute(dbtx.as_mut()) .await?; @@ -58,10 +59,10 @@ impl AppView for DelegationTxs { ) -> Result<()> { let pe = pb::EventDelegate::from_event(event.as_ref())?; - let ik_bytes = pe + let ik: IdentityKey = pe .identity_key .ok_or_else(|| anyhow::anyhow!("missing ik in event"))? - .ik; + .try_into()?; let amount = Amount::try_from( pe.amount @@ -69,9 +70,9 @@ impl AppView for DelegationTxs { )?; sqlx::query( - "INSERT INTO stake_delegation_txs (validator_ik, amount, height, tx_hash) VALUES ($1, $2, $3, $4)" + "INSERT INTO stake_delegation_txs (ik, amount, height, tx_hash) VALUES ($1, $2, $3, $4)" ) - .bind(&ik_bytes) + .bind(ik.to_string()) .bind(amount.value() as i64) .bind(event.block_height as i64) .bind(event.tx_hash.ok_or_else(|| anyhow!("missing tx hash in event"))?) diff --git a/crates/bin/pindexer/src/stake/missed_blocks.rs b/crates/bin/pindexer/src/stake/missed_blocks.rs index 7b5115792c..4516d619ac 100644 --- a/crates/bin/pindexer/src/stake/missed_blocks.rs +++ b/crates/bin/pindexer/src/stake/missed_blocks.rs @@ -2,6 +2,7 @@ use anyhow::Result; use cometindex::{async_trait, sqlx, AppView, ContextualizedEvent, PgPool, PgTransaction}; use penumbra_proto::{core::component::stake::v1 as pb, event::ProtoEvent}; +use penumbra_stake::IdentityKey; #[derive(Debug)] pub struct MissedBlocks {} @@ -18,7 +19,7 @@ impl AppView for MissedBlocks { "CREATE TABLE stake_missed_blocks ( id SERIAL PRIMARY KEY, height BIGINT NOT NULL, - ik BYTEA NOT NULL + ik TEXT NOT NULL );", ) .execute(dbtx.as_mut()) @@ -55,16 +56,16 @@ impl AppView for MissedBlocks { _src_db: &PgPool, ) -> Result<(), anyhow::Error> { let pe = pb::EventValidatorMissedBlock::from_event(event.as_ref())?; - let ik_bytes = pe + let ik: IdentityKey = pe .identity_key .ok_or_else(|| anyhow::anyhow!("missing ik in event"))? - .ik; + .try_into()?; let height = event.block_height; sqlx::query("INSERT INTO stake_missed_blocks (height, ik) VALUES ($1, $2)") .bind(height as i64) - .bind(ik_bytes) + .bind(ik.to_string()) .execute(dbtx.as_mut()) .await?; diff --git a/crates/bin/pindexer/src/stake/slashings.rs b/crates/bin/pindexer/src/stake/slashings.rs index 1be89b6944..bbc472171f 100644 --- a/crates/bin/pindexer/src/stake/slashings.rs +++ b/crates/bin/pindexer/src/stake/slashings.rs @@ -18,7 +18,7 @@ impl AppView for Slashings { "CREATE TABLE stake_slashings ( id SERIAL PRIMARY KEY, height BIGINT NOT NULL, - ik BYTEA NOT NULL, + ik TEXT NOT NULL, epoch_index BIGINT NOT NULL, penalty TEXT NOT NULL );", @@ -73,7 +73,7 @@ impl AppView for Slashings { VALUES ($1, $2, $3, $4)", ) .bind(height as i64) - .bind(ik.to_bytes()) + .bind(ik.to_string()) .bind(epoch_index as i64) .bind(penalty_json) .execute(dbtx.as_mut()) diff --git a/crates/bin/pindexer/src/stake/undelegation_txs.rs b/crates/bin/pindexer/src/stake/undelegation_txs.rs index d4f9da26e4..aeb9d90511 100644 --- a/crates/bin/pindexer/src/stake/undelegation_txs.rs +++ b/crates/bin/pindexer/src/stake/undelegation_txs.rs @@ -2,6 +2,7 @@ use anyhow::{anyhow, Result}; use cometindex::{async_trait, sqlx, AppView, ContextualizedEvent, PgPool, PgTransaction}; use penumbra_num::Amount; use penumbra_proto::{core::component::stake::v1 as pb, event::ProtoEvent}; +use penumbra_stake::IdentityKey; #[derive(Debug)] pub struct UndelegationTxs {} @@ -17,7 +18,7 @@ impl AppView for UndelegationTxs { sqlx::query( "CREATE TABLE stake_undelegation_txs ( id SERIAL PRIMARY KEY, - validator_ik BYTEA NOT NULL, + ik TEXT NOT NULL, amount BIGINT NOT NULL, height BIGINT NOT NULL, tx_hash BYTEA NOT NULL @@ -26,8 +27,8 @@ impl AppView for UndelegationTxs { .execute(dbtx.as_mut()) .await?; - // Create index on validator_ik - sqlx::query("CREATE INDEX idx_stake_undelegation_txs_validator_ik ON stake_undelegation_txs(validator_ik);") + // Create index on ik + sqlx::query("CREATE INDEX idx_stake_undelegation_txs_ik ON stake_undelegation_txs(ik);") .execute(dbtx.as_mut()) .await?; @@ -38,8 +39,8 @@ impl AppView for UndelegationTxs { .execute(dbtx.as_mut()) .await?; - // Create composite index on validator_ik and height (descending) - sqlx::query("CREATE INDEX idx_stake_undelegation_txs_validator_ik_height ON stake_undelegation_txs(validator_ik, height DESC);") + // Create composite index on ik and height (descending) + sqlx::query("CREATE INDEX idx_stake_undelegation_txs_ik_height ON stake_undelegation_txs(ik, height DESC);") .execute(dbtx.as_mut()) .await?; @@ -58,10 +59,10 @@ impl AppView for UndelegationTxs { ) -> Result<()> { let pe = pb::EventUndelegate::from_event(event.as_ref())?; - let ik_bytes = pe + let ik: IdentityKey = pe .identity_key .ok_or_else(|| anyhow::anyhow!("missing ik in event"))? - .ik; + .try_into()?; let amount = Amount::try_from( pe.amount @@ -69,9 +70,9 @@ impl AppView for UndelegationTxs { )?; sqlx::query( - "INSERT INTO stake_undelegation_txs (validator_ik, amount, height, tx_hash) VALUES ($1, $2, $3, $4)" + "INSERT INTO stake_undelegation_txs (ik, amount, height, tx_hash) VALUES ($1, $2, $3, $4)" ) - .bind(&ik_bytes) + .bind(ik.to_string()) .bind(amount.value() as i64) .bind(event.block_height as i64) .bind(event.tx_hash.ok_or_else(|| anyhow!("missing tx hash in event"))?)