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

Instrument DB Txs - PRO-478 #19

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
18 changes: 18 additions & 0 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ethers::types::{Address, H256, U256};
use sqlx::migrate::{MigrateDatabase, Migrator};
use sqlx::types::{BigDecimal, Json};
use sqlx::{Pool, Postgres, Row};
use tracing::instrument;

use crate::broadcast_utils::gas_estimation::FeesEstimate;
use crate::config::DatabaseConfig;
Expand Down Expand Up @@ -39,6 +40,7 @@ impl Database {
Ok(Self { pool })
}

#[instrument(skip(self), level = "debug")]
pub async fn create_relayer(
&self,
id: &str,
Expand All @@ -64,6 +66,7 @@ impl Database {
Ok(())
}

#[instrument(skip(self), level = "debug")]
pub async fn update_relayer(
&self,
id: &str,
Expand Down Expand Up @@ -188,6 +191,7 @@ impl Database {
.await?)
}

#[instrument(skip(self), level = "debug")]
pub async fn create_transaction(
&self,
tx_id: &str,
Expand Down Expand Up @@ -257,6 +261,7 @@ impl Database {
.await?)
}

#[instrument(skip(self), level = "debug")]
pub async fn insert_tx_broadcast(
&self,
tx_id: &str,
Expand Down Expand Up @@ -402,6 +407,7 @@ impl Database {
Ok(row.try_get::<bool, _>(0)?)
}

#[instrument(skip(self), level = "debug")]
pub async fn save_block(
&self,
block_number: u64,
Expand Down Expand Up @@ -464,6 +470,7 @@ impl Database {
Ok(())
}

#[instrument(skip(self), level = "debug")]
pub async fn save_block_fees(
&self,
block_number: u64,
Expand All @@ -490,6 +497,7 @@ impl Database {
}

/// Returns a list of soft reorged txs
#[instrument(skip(self), level = "debug", ret)]
pub async fn handle_soft_reorgs(&self) -> eyre::Result<Vec<String>> {
let mut tx = self.pool.begin().await?;

Expand Down Expand Up @@ -532,6 +540,7 @@ impl Database {
}

/// Returns a list of hard reorged txs
#[instrument(skip(self), level = "debug", ret)]
pub async fn handle_hard_reorgs(&self) -> eyre::Result<Vec<String>> {
let mut tx = self.pool.begin().await?;

Expand Down Expand Up @@ -591,6 +600,7 @@ impl Database {
/// Marks txs as mined if the associated tx hash is present in a block
///
/// returns the tx ids and hashes for all mined txs
#[instrument(skip(self), level = "debug", ret)]
pub async fn mine_txs(
&self,
chain_id: u64,
Expand Down Expand Up @@ -630,6 +640,7 @@ impl Database {
.collect())
}

#[instrument(skip(self), level = "debug")]
pub async fn finalize_txs(
&self,
finalization_timestmap: DateTime<Utc>,
Expand Down Expand Up @@ -700,6 +711,7 @@ impl Database {
.await?)
}

#[instrument(skip(self), level = "debug")]
pub async fn escalate_tx(
&self,
tx_id: &str,
Expand Down Expand Up @@ -805,6 +817,7 @@ impl Database {
.await?)
}

#[instrument(skip(self), level = "debug")]
pub async fn update_relayer_nonce(
&self,
chain_id: u64,
Expand All @@ -829,6 +842,7 @@ impl Database {
Ok(())
}

#[instrument(skip(self), level = "debug")]
pub async fn prune_blocks(
&self,
timestamp: DateTime<Utc>,
Expand All @@ -846,6 +860,7 @@ impl Database {
Ok(())
}

#[instrument(skip(self), level = "debug")]
pub async fn prune_txs(
&self,
timestamp: DateTime<Utc>,
Expand All @@ -868,6 +883,7 @@ impl Database {
Ok(())
}

#[instrument(skip(self), level = "debug")]
pub async fn create_network(
&self,
chain_id: u64,
Expand Down Expand Up @@ -943,6 +959,7 @@ impl Database {
Ok(items.into_iter().map(|(x,)| x as u64).collect())
}

#[instrument(skip(self), level = "debug")]
pub async fn create_api_key(
&self,
relayer_id: &str,
Expand Down Expand Up @@ -1061,6 +1078,7 @@ impl Database {
})
}

#[instrument(skip(self), level = "debug")]
pub async fn purge_unsent_txs(&self, relayer_id: &str) -> eyre::Result<()> {
sqlx::query(
r#"
Expand Down