Skip to content

Commit

Permalink
Update DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Jan 9, 2024
1 parent 8a5f5ee commit 385b5db
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
5 changes: 5 additions & 0 deletions db/migrations/002_relayers_table_update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE relayers
RENAME COLUMN gas_limits TO gas_price_limits;

ALTER TABLE relayers
ADD COLUMN enabled BOOL NOT NULL DEFAULT TRUE;
2 changes: 1 addition & 1 deletion manual_test_kms.nu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ echo "Creating relayer"
let relayer = http post -t application/json $"($txSitter)/1/admin/relayer" { "name": "My Relayer", "chainId": 11155111 }

http post -t application/json $"($txSitter)/1/admin/relayer/($relayer.relayerId)" {
gasLimits: [
gasPriceLimits: [
{ chainId: 11155111, value: "0x123" }
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/broadcast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn should_send_transaction(
) -> eyre::Result<bool> {
let relayer = app.db.get_relayer(relayer_id).await?;

for gas_limit in &relayer.gas_limits.0 {
for gas_limit in &relayer.gas_price_limits.0 {
let chain_fees = app
.db
.get_latest_block_fees_by_chain_id(relayer.chain_id)
Expand Down
20 changes: 10 additions & 10 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ impl Database {
.await?;
}

if let Some(gas_limits) = &update.gas_limits {
if let Some(gas_price_limits) = &update.gas_price_limits {
sqlx::query(
r#"
UPDATE relayers
SET gas_limits = $2
SET gas_price_limits = $2
WHERE id = $1
"#,
)
.bind(id)
.bind(Json(gas_limits))
.bind(Json(gas_price_limits))
.execute(tx.as_mut())
.await?;
}
Expand All @@ -132,7 +132,7 @@ impl Database {
nonce,
current_nonce,
max_inflight_txs,
gas_limits
gas_price_limits
FROM relayers
"#,
)
Expand All @@ -152,7 +152,7 @@ impl Database {
nonce,
current_nonce,
max_inflight_txs,
gas_limits
gas_price_limits
FROM relayers
WHERE id = $1
"#,
Expand Down Expand Up @@ -1090,7 +1090,7 @@ mod tests {

use super::*;
use crate::db::data::U256Wrapper;
use crate::types::RelayerGasLimit;
use crate::types::RelayerGasPriceLimit;

async fn setup_db() -> eyre::Result<(Database, DockerContainerGuard)> {
let db_container = postgres_docker_utils::setup().await?;
Expand Down Expand Up @@ -1230,14 +1230,14 @@ mod tests {
assert_eq!(relayer.nonce, 0);
assert_eq!(relayer.current_nonce, 0);
assert_eq!(relayer.max_inflight_txs, 5);
assert_eq!(relayer.gas_limits.0, vec![]);
assert_eq!(relayer.gas_price_limits.0, vec![]);

db.update_relayer(
relayer_id,
&RelayerUpdate {
relayer_name: None,
max_inflight_txs: Some(10),
gas_limits: Some(vec![RelayerGasLimit {
gas_price_limits: Some(vec![RelayerGasPriceLimit {
chain_id: 1,
value: U256Wrapper(U256::from(10_123u64)),
}]),
Expand All @@ -1256,8 +1256,8 @@ mod tests {
assert_eq!(relayer.current_nonce, 0);
assert_eq!(relayer.max_inflight_txs, 10);
assert_eq!(
relayer.gas_limits.0,
vec![RelayerGasLimit {
relayer.gas_price_limits.0,
vec![RelayerGasPriceLimit {
chain_id: 1,
value: U256Wrapper(U256::from(10_123u64)),
}]
Expand Down
10 changes: 5 additions & 5 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct RelayerInfo {
pub current_nonce: u64,
#[sqlx(try_from = "i64")]
pub max_inflight_txs: u64,
pub gas_limits: Json<Vec<RelayerGasLimit>>,
pub gas_price_limits: Json<Vec<RelayerGasPriceLimit>>,
}

#[derive(Deserialize, Serialize, Debug, Clone, Default)]
Expand All @@ -55,12 +55,12 @@ pub struct RelayerUpdate {
pub max_inflight_txs: Option<u64>,

#[serde(default)]
pub gas_limits: Option<Vec<RelayerGasLimit>>,
pub gas_price_limits: Option<Vec<RelayerGasPriceLimit>>,
}

#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct RelayerGasLimit {
pub struct RelayerGasPriceLimit {
pub value: U256Wrapper,
pub chain_id: i64,
}
Expand All @@ -82,7 +82,7 @@ mod tests {
nonce: 0,
current_nonce: 0,
max_inflight_txs: 0,
gas_limits: Json(vec![RelayerGasLimit {
gas_price_limits: Json(vec![RelayerGasPriceLimit {
value: U256Wrapper(U256::zero()),
chain_id: 1,
}]),
Expand All @@ -100,7 +100,7 @@ mod tests {
"nonce": 0,
"currentNonce": 0,
"maxInflightTxs": 0,
"gasLimits": [
"gasPriceLimits": [
{
"value": "0x0",
"chainId": 1
Expand Down

0 comments on commit 385b5db

Please sign in to comment.