Skip to content

Commit

Permalink
Add max_queued_txs column
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Feb 27, 2024
1 parent 9be5bfb commit 94234d2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions db/migrations/003_relayers_tx_limits.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE relayers
ADD COLUMN max_queued_txs BIGINT NOT NULL DEFAULT 20,
ADD CONSTRAINT check_max_queued_txs CHECK (max_queued_txs > max_inflight_txs);

UPDATE relayers
SET max_queued_txs = GREATEST(max_inflight_txs, 20);
21 changes: 20 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ impl Database {
.await?;
}

if let Some(max_queued_txs) = update.max_queued_txs {
sqlx::query(
r#"
UPDATE relayers
SET max_queued_txs = $2
WHERE id = $1
"#,
)
.bind(id)
.bind(max_queued_txs as i64)
.execute(tx.as_mut())
.await?;
}

if let Some(gas_price_limits) = &update.gas_price_limits {
sqlx::query(
r#"
Expand Down Expand Up @@ -157,6 +171,7 @@ impl Database {
nonce,
current_nonce,
max_inflight_txs,
max_queued_txs,
gas_price_limits,
enabled
FROM relayers
Expand All @@ -180,6 +195,7 @@ impl Database {
nonce,
current_nonce,
max_inflight_txs,
max_queued_txs,
gas_price_limits,
enabled
FROM relayers
Expand Down Expand Up @@ -1128,7 +1144,8 @@ mod tests {
match Database::new(&DatabaseConfig::connection_string(&url)).await
{
Ok(db) => return Ok((db, db_container)),
Err(_) => {
Err(err) => {
eprintln!("Failed to connect to the database: {err:?}");
tokio::time::sleep(Duration::from_secs(1)).await;
}
}
Expand Down Expand Up @@ -1263,6 +1280,7 @@ mod tests {
&RelayerUpdate {
relayer_name: None,
max_inflight_txs: Some(10),
max_queued_txs: Some(20),
gas_price_limits: Some(vec![RelayerGasPriceLimit {
chain_id: 1,
value: U256Wrapper(U256::from(10_123u64)),
Expand All @@ -1282,6 +1300,7 @@ mod tests {
assert_eq!(relayer.nonce, 0);
assert_eq!(relayer.current_nonce, 0);
assert_eq!(relayer.max_inflight_txs, 10);
assert_eq!(relayer.max_queued_txs, 20);
assert_eq!(
relayer.gas_price_limits.0,
vec![RelayerGasPriceLimit {
Expand Down
6 changes: 6 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub struct RelayerInfo {
pub current_nonce: u64,
#[sqlx(try_from = "i64")]
pub max_inflight_txs: u64,
#[sqlx(try_from = "i64")]
pub max_queued_txs: u64,
pub gas_price_limits: Json<Vec<RelayerGasPriceLimit>>,
pub enabled: bool,
}
Expand All @@ -54,6 +56,8 @@ pub struct RelayerUpdate {
#[serde(default)]
pub max_inflight_txs: Option<u64>,
#[serde(default)]
pub max_queued_txs: Option<u64>,
#[serde(default)]
pub gas_price_limits: Option<Vec<RelayerGasPriceLimit>>,
#[serde(default)]
pub enabled: Option<bool>,
Expand Down Expand Up @@ -83,6 +87,7 @@ mod tests {
nonce: 0,
current_nonce: 0,
max_inflight_txs: 0,
max_queued_txs: 0,
gas_price_limits: Json(vec![RelayerGasPriceLimit {
value: U256Wrapper(U256::zero()),
chain_id: 1,
Expand All @@ -102,6 +107,7 @@ mod tests {
"nonce": 0,
"currentNonce": 0,
"maxInflightTxs": 0,
"maxQueuedTxs": 0,
"gasPriceLimits": [
{
"value": "0x0",
Expand Down

0 comments on commit 94234d2

Please sign in to comment.