Skip to content

Commit 3026c70

Browse files
committed
fix: sent_with_gas and sent_with_blob_gas saves in the db now
1 parent 603a029 commit 3026c70

File tree

6 files changed

+79
-22
lines changed

6 files changed

+79
-22
lines changed

crates/core/src/schema/v1_0_0.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub async fn apply_v1_0_0_schema(client: &PostgresClient) -> Result<(), Postgres
5151
gas_price NUMERIC NULL,
5252
sent_max_priority_fee_per_gas NUMERIC(80) NULL,
5353
sent_max_fee_per_gas NUMERIC(80) NULL,
54+
sent_with_gas JSONB NULL,
55+
sent_with_blob_gas JSONB NULL,
5456
gas_limit NUMERIC(80) NULL,
5557
block_hash BYTEA NULL,
5658
block_number BIGINT NULL,
@@ -89,6 +91,8 @@ pub async fn apply_v1_0_0_schema(client: &PostgresClient) -> Result<(), Postgres
8991
gas_price NUMERIC NULL,
9092
sent_max_priority_fee_per_gas NUMERIC(80) NULL,
9193
sent_max_fee_per_gas NUMERIC(80) NULL,
94+
sent_with_gas JSONB NULL,
95+
sent_with_blob_gas JSONB NULL,
9296
gas_limit NUMERIC(80) NULL,
9397
block_hash BYTEA NULL,
9498
block_number BIGINT NULL,
@@ -126,6 +130,12 @@ pub async fn apply_v1_0_0_schema(client: &PostgresClient) -> Result<(), Postgres
126130
CREATE INDEX IF NOT EXISTS idx_transaction_cancelled_by
127131
ON relayer.transaction(cancelled_by_transaction_id) WHERE cancelled_by_transaction_id IS NOT NULL;
128132
133+
CREATE INDEX IF NOT EXISTS idx_transaction_sent_with_gas
134+
ON relayer.transaction(sent_with_gas) WHERE sent_with_gas IS NOT NULL;
135+
136+
CREATE INDEX IF NOT EXISTS idx_transaction_sent_with_blob_gas
137+
ON relayer.transaction(sent_with_blob_gas) WHERE sent_with_blob_gas IS NOT NULL;
138+
129139
CREATE INDEX IF NOT EXISTS idx_relayer_chain_deleted
130140
ON relayer.record(chain_id, deleted);
131141

crates/core/src/transaction/db/builders.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use serde_json;
12
use tokio_postgres::Row;
23

34
use crate::{shared::common_types::EvmAddress, transaction::types::Transaction};
@@ -23,10 +24,12 @@ pub fn build_transaction_from_transaction_view(row: &Row) -> Transaction {
2324
expires_at: row.get("expires_at"),
2425
sent_at: row.get("sent_at"),
2526
confirmed_at: row.get("confirmed_at"),
26-
// TODO! load from db
27-
sent_with_gas: None,
28-
// TODO! load from db
29-
sent_with_blob_gas: None,
27+
sent_with_gas: row
28+
.get::<_, Option<serde_json::Value>>("sent_with_gas")
29+
.and_then(|v| serde_json::from_value(v).ok()),
30+
sent_with_blob_gas: row
31+
.get::<_, Option<serde_json::Value>>("sent_with_blob_gas")
32+
.and_then(|v| serde_json::from_value(v).ok()),
3033
mined_at: row.get("mined_at"),
3134
mined_at_block_number: row.get("block_number"),
3235
speed: row.get("speed"),

crates/core/src/transaction/db/write.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
common_types::EvmAddress,
3-
gas::{GasLimit, GasPriceResult},
3+
gas::{BlobGasPriceResult, GasLimit, GasPriceResult},
44
postgres::{PostgresClient, PostgresError},
55
relayer::RelayerId,
66
shared::{
@@ -13,6 +13,7 @@ use crate::{
1313
},
1414
};
1515
use alloy::network::AnyTransactionReceipt;
16+
use serde_json;
1617

1718
const TRANSACTION_TABLES: [&str; 2] = ["relayer.transaction", "relayer.transaction_audit_log"];
1819

@@ -63,6 +64,7 @@ impl PostgresClient {
6364
transaction_id: &TransactionId,
6465
transaction_hash: &TransactionHash,
6566
sent_with_gas: &GasPriceResult,
67+
sent_with_blob_gas: Option<&BlobGasPriceResult>,
6668
legacy_transaction: bool,
6769
) -> Result<(), PostgresError> {
6870
let mut conn = self.pool.get().await?;
@@ -73,6 +75,12 @@ impl PostgresClient {
7375
let max_fee_fee_option = option_if(!legacy_transaction, &sent_with_gas.max_fee);
7476
let legacy_gas_price = option_if(legacy_transaction, sent_with_gas.legacy_gas_price());
7577

78+
let sent_with_gas_json =
79+
serde_json::to_value(sent_with_gas).unwrap_or_else(|_| serde_json::Value::Null);
80+
81+
let sent_with_blob_gas_json = sent_with_blob_gas
82+
.map(|blob_gas| serde_json::to_value(blob_gas).unwrap_or(serde_json::Value::Null));
83+
7684
trans
7785
.execute(
7886
"
@@ -82,6 +90,8 @@ impl PostgresClient {
8290
sent_max_priority_fee_per_gas = $4,
8391
sent_max_fee_per_gas = $5,
8492
gas_price = $6,
93+
sent_with_gas = $7,
94+
sent_with_blob_gas = $8,
8595
sent_at = NOW()
8696
WHERE id = $1;
8797
",
@@ -92,6 +102,8 @@ impl PostgresClient {
92102
&max_priority_fee_option,
93103
&max_fee_fee_option,
94104
&legacy_gas_price,
105+
&sent_with_gas_json,
106+
&sent_with_blob_gas_json,
95107
],
96108
)
97109
.await?;
@@ -103,12 +115,12 @@ impl PostgresClient {
103115
id, relayer_id, \"to\", \"from\", nonce, chain_id, data, value, blobs, gas_limit,
104116
speed, status, expires_at, queued_at, sent_at, mined_at, confirmed_at,
105117
failed_at, failed_reason, hash, sent_max_priority_fee_per_gas,
106-
sent_max_fee_per_gas, gas_price, external_id
118+
sent_max_fee_per_gas, gas_price, sent_with_gas, sent_with_blob_gas, external_id
107119
)
108120
SELECT
109121
id, relayer_id, \"to\", \"from\", nonce, chain_id, data, value, blobs, gas_limit,
110122
speed, $2, expires_at, queued_at, NOW(), mined_at, confirmed_at,
111-
failed_at, failed_reason, $3, $4, $5, $6, external_id
123+
failed_at, failed_reason, $3, $4, $5, $6, $7, $8, external_id
112124
FROM relayer.transaction
113125
WHERE id = $1;
114126
",
@@ -119,6 +131,8 @@ impl PostgresClient {
119131
&max_priority_fee_option,
120132
&max_fee_fee_option,
121133
&legacy_gas_price,
134+
&sent_with_gas_json,
135+
&sent_with_blob_gas_json,
122136
],
123137
)
124138
.await?;
@@ -462,6 +476,16 @@ impl PostgresClient {
462476
let mut conn = self.pool.get().await?;
463477
let trans = conn.transaction().await.map_err(PostgresError::PgError)?;
464478

479+
let sent_with_gas_json = transaction
480+
.sent_with_gas
481+
.as_ref()
482+
.map(|gas| serde_json::to_value(gas).unwrap_or(serde_json::Value::Null));
483+
484+
let sent_with_blob_gas_json = transaction
485+
.sent_with_blob_gas
486+
.as_ref()
487+
.map(|blob_gas| serde_json::to_value(blob_gas).unwrap_or(serde_json::Value::Null));
488+
465489
trans
466490
.execute(
467491
"
@@ -484,8 +508,10 @@ impl PostgresClient {
484508
hash = $17,
485509
sent_max_fee_per_gas = $18,
486510
sent_max_priority_fee_per_gas = $19,
487-
external_id = $20,
488-
cancelled_by_transaction_id = $21
511+
sent_with_gas = $20,
512+
sent_with_blob_gas = $21,
513+
external_id = $22,
514+
cancelled_by_transaction_id = $23
489515
WHERE id = $1
490516
",
491517
&[
@@ -508,6 +534,8 @@ impl PostgresClient {
508534
&transaction.known_transaction_hash,
509535
&transaction.sent_with_max_fee_per_gas,
510536
&transaction.sent_with_max_priority_fee_per_gas,
537+
&sent_with_gas_json,
538+
&sent_with_blob_gas_json,
511539
&transaction.external_id,
512540
&transaction.cancelled_by_transaction_id,
513541
],
@@ -522,13 +550,15 @@ impl PostgresClient {
522550
id, relayer_id, \"to\", \"from\", nonce, chain_id, data, value, blobs, gas_limit,
523551
speed, status, expires_at, queued_at, sent_at, mined_at, confirmed_at,
524552
failed_at, failed_reason, hash, sent_max_priority_fee_per_gas,
525-
sent_max_fee_per_gas, gas_price, block_hash, block_number, expired_at, external_id
553+
sent_max_fee_per_gas, gas_price, sent_with_gas, sent_with_blob_gas,
554+
block_hash, block_number, expired_at, external_id
526555
)
527556
SELECT
528557
id, relayer_id, \"to\", \"from\", nonce, chain_id, data, value, blobs, gas_limit,
529558
speed, status, expires_at, queued_at, sent_at, mined_at, confirmed_at,
530559
failed_at, failed_reason, hash, sent_max_priority_fee_per_gas,
531-
sent_max_fee_per_gas, gas_price, block_hash, block_number, expired_at, external_id
560+
sent_max_fee_per_gas, gas_price, sent_with_gas, sent_with_blob_gas,
561+
block_hash, block_number, expired_at, external_id
532562
FROM relayer.transaction
533563
WHERE id = $1
534564
",

crates/core/src/transaction/queue_system/transactions_queue.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl TransactionsQueue {
191191
transaction_sent.sent_with_gas.max_priority_fee,
192192
),
193193
sent_with_gas: Some(transaction_sent.sent_with_gas.clone()),
194+
sent_with_blob_gas: transaction_sent.sent_with_blob_gas.clone(),
194195
sent_at: Some(Utc::now()),
195196
..transaction
196197
};
@@ -306,6 +307,7 @@ impl TransactionsQueue {
306307
comp_tx.original.sent_with_max_priority_fee_per_gas =
307308
Some(transaction_sent.sent_with_gas.max_priority_fee);
308309
comp_tx.original.sent_with_gas = Some(transaction_sent.sent_with_gas.clone());
310+
comp_tx.original.sent_with_blob_gas = transaction_sent.sent_with_blob_gas.clone();
309311
comp_tx.original.sent_at = Some(Utc::now());
310312
} else if let Some((ref mut competitor, _)) = comp_tx.competitive {
311313
if competitor.id == transaction_sent.id {
@@ -319,6 +321,7 @@ impl TransactionsQueue {
319321
competitor.sent_with_max_priority_fee_per_gas =
320322
Some(transaction_sent.sent_with_gas.max_priority_fee);
321323
competitor.sent_with_gas = Some(transaction_sent.sent_with_gas.clone());
324+
competitor.sent_with_blob_gas = transaction_sent.sent_with_blob_gas.clone();
322325
competitor.sent_at = Some(Utc::now());
323326
}
324327
}
@@ -377,7 +380,8 @@ impl TransactionsQueue {
377380
transaction.sent_at = replacement_transaction.sent_at;
378381
transaction.sent_with_gas =
379382
Some(transaction_sent_with_relayer.sent_with_gas.clone());
380-
transaction.sent_with_blob_gas = replacement_transaction.sent_with_blob_gas.clone();
383+
transaction.sent_with_blob_gas =
384+
transaction_sent_with_relayer.sent_with_blob_gas.clone();
381385
transaction.speed = replacement_transaction.speed.clone();
382386
transaction.sent_with_max_fee_per_gas =
383387
replacement_transaction.sent_with_max_fee_per_gas;
@@ -1021,43 +1025,49 @@ impl TransactionsQueue {
10211025
working_transaction.gas_limit = Some(estimated_gas_limit);
10221026
transaction.gas_limit = Some(estimated_gas_limit);
10231027

1024-
let transaction_request: TypedTransaction = if working_transaction.is_blob_transaction() {
1028+
let (transaction_request, sent_with_blob_gas): (
1029+
TypedTransaction,
1030+
Option<BlobGasPriceResult>,
1031+
) = if working_transaction.is_blob_transaction() {
10251032
info!("Creating final blob transaction for relayer: {}", self.relayer.name);
10261033
let blob_gas_price = self
10271034
.compute_blob_gas_price_for_transaction(
10281035
&working_transaction.speed,
10291036
&working_transaction.sent_with_blob_gas,
10301037
)
10311038
.await?;
1032-
working_transaction
1039+
let tx_request = working_transaction
10331040
.to_blob_typed_transaction_with_gas_limit(
10341041
Some(&gas_price),
10351042
Some(&blob_gas_price),
10361043
Some(estimated_gas_limit),
10371044
)
10381045
.map_err(|e| {
10391046
TransactionQueueSendTransactionError::TransactionConversionError(e.to_string())
1040-
})?
1047+
})?;
1048+
(tx_request, Some(blob_gas_price))
10411049
} else if self.is_legacy_transactions() {
10421050
info!("Creating final legacy transaction for relayer: {}", self.relayer.name);
1043-
working_transaction
1051+
let tx_request = working_transaction
10441052
.to_legacy_typed_transaction_with_gas_limit(
10451053
Some(&gas_price),
10461054
Some(estimated_gas_limit),
10471055
)
10481056
.map_err(|e| {
10491057
TransactionQueueSendTransactionError::TransactionConversionError(e.to_string())
1050-
})?
1058+
})?;
1059+
(tx_request, None)
10511060
} else {
10521061
info!("Creating final EIP-1559 transaction for relayer: {}", self.relayer.name);
1053-
working_transaction
1062+
let tx_request = working_transaction
10541063
.to_eip1559_typed_transaction_with_gas_limit(
10551064
Some(&gas_price),
10561065
Some(estimated_gas_limit),
10571066
)
10581067
.map_err(|e| {
10591068
TransactionQueueSendTransactionError::TransactionConversionError(e.to_string())
1060-
})?
1069+
})?;
1070+
(tx_request, None)
10611071
};
10621072
info!(
10631073
"Set gas limit {} for transaction {} on relayer: {}",
@@ -1080,6 +1090,7 @@ impl TransactionsQueue {
10801090
id: transaction.id,
10811091
hash: transaction_hash,
10821092
sent_with_gas: gas_price,
1093+
sent_with_blob_gas,
10831094
};
10841095

10851096
info!(
@@ -1097,6 +1108,7 @@ impl TransactionsQueue {
10971108
&transaction_sent.id,
10981109
&transaction_sent.hash,
10991110
&transaction_sent.sent_with_gas,
1111+
transaction_sent.sent_with_blob_gas.as_ref(),
11001112
self.is_legacy_transactions(),
11011113
)
11021114
.await?;
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
use core::fmt;
22
use std::fmt::{Display, Formatter};
33

4-
use crate::gas::GasPriceResult;
4+
use crate::gas::{BlobGasPriceResult, GasPriceResult};
55
use crate::transaction::types::{TransactionHash, TransactionId};
66

77
#[derive(Debug, Clone)]
88
pub struct TransactionSentWithRelayer {
99
pub id: TransactionId,
1010
pub hash: TransactionHash,
1111
pub sent_with_gas: GasPriceResult,
12+
pub sent_with_blob_gas: Option<BlobGasPriceResult>,
1213
}
1314

1415
impl Display for TransactionSentWithRelayer {
1516
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
1617
write!(
1718
f,
18-
"TransactionSentWithRelayer {{ id: {}, hash: {}, sent_with_gas: {:?} }}",
19-
self.id, self.hash, self.sent_with_gas
19+
"TransactionSentWithRelayer {{ id: {}, hash: {}, sent_with_gas: {:?}, sent_with_blob_gas: {:?} }}",
20+
self.id, self.hash, self.sent_with_gas, self.sent_with_blob_gas
2021
)
2122
}
2223
}

documentation/rrelayer/vocs.config.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,5 +713,6 @@ export default defineConfig({
713713
],
714714
},
715715
{ text: 'Changelog', link: '/changelog' },
716+
{ text: 'Shoutout', link: '/shoutout' },
716717
],
717718
});

0 commit comments

Comments
 (0)