Skip to content

Commit 3e70d93

Browse files
authored
fix: misc fixes + logging (#27)
* fix: connecting to rds pg cluster * add error logging * add additional logging * add logging * persist to db
1 parent b4e2927 commit 3e70d93

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed

crates/ingress-rpc/src/validation.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloy_consensus::private::alloy_eips::{BlockId, BlockNumberOrTag};
12
use alloy_consensus::{Transaction, Typed2718, constants::KECCAK_EMPTY, transaction::Recovered};
23
use alloy_primitives::{Address, B256, U256};
34
use alloy_provider::{Provider, RootProvider};
@@ -49,24 +50,29 @@ pub trait L1BlockInfoLookup: Send + Sync {
4950
#[async_trait]
5051
impl L1BlockInfoLookup for RootProvider<Optimism> {
5152
async fn fetch_l1_block_info(&self) -> RpcResult<L1BlockInfo> {
52-
let block_number = self
53-
.get_block_number()
54-
.await
55-
.map_err(|_| EthApiError::InternalEthError.into_rpc_err())?;
5653
let block = self
57-
.get_block_by_number(block_number.into())
54+
.get_block(BlockId::Number(BlockNumberOrTag::Latest))
5855
.full()
5956
.await
60-
.map_err(|_| EthApiError::InternalEthError.into_rpc_err())?
61-
.ok_or_else(|| EthApiError::HeaderNotFound(block_number.into()).into_rpc_err())?;
57+
.map_err(|e| {
58+
warn!(message = "failed to fetch latest block", err = %e);
59+
EthApiError::InternalEthError.into_rpc_err()
60+
})?
61+
.ok_or_else(|| {
62+
warn!(message = "empty latest block returned");
63+
EthApiError::InternalEthError.into_rpc_err()
64+
})?;
6265

6366
let txs = block.transactions.clone();
64-
let first_tx = txs
65-
.first_transaction()
66-
.ok_or_else(|| EthApiError::InternalEthError.into_rpc_err())?;
67-
68-
Ok(extract_l1_info_from_tx(&first_tx.clone())
69-
.map_err(|_| EthApiError::InternalEthError.into_rpc_err())?)
67+
let first_tx = txs.first_transaction().ok_or_else(|| {
68+
warn!(message = "block contains no transactions");
69+
EthApiError::InternalEthError.into_rpc_err()
70+
})?;
71+
72+
Ok(extract_l1_info_from_tx(&first_tx.clone()).map_err(|e| {
73+
warn!(message = "failed to extract l1_info from tx", err = %e);
74+
EthApiError::InternalEthError.into_rpc_err()
75+
})?)
7076
}
7177
}
7278

crates/maintenance/src/job.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use std::collections::HashSet;
1616
use std::time::Duration;
1717
use tips_audit::{BundleEvent, BundleEventPublisher, DropReason};
1818
use tips_datastore::BundleDatastore;
19-
use tips_datastore::postgres::{BundleFilter, BundleState, BundleWithMetadata};
19+
use tips_datastore::postgres::{BlockInfoUpdate, BundleFilter, BundleState, BundleWithMetadata};
2020
use tokio::sync::mpsc;
21-
use tracing::{error, info, warn};
21+
use tracing::{debug, error, info, warn};
2222
use uuid::Uuid;
2323

2424
pub struct MaintenanceJob<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> {
@@ -54,6 +54,11 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
5454
.await?
5555
.ok_or_else(|| anyhow::anyhow!("Failed to get latest block"))?;
5656

57+
debug!(
58+
message = "Executing up to latest block",
59+
block_number = latest_block.number()
60+
);
61+
5762
let block_info = self.store.get_current_block_info().await?;
5863

5964
if let Some(current_block_info) = block_info {
@@ -62,6 +67,8 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
6267
for block_num in
6368
(current_block_info.latest_block_number + 1)..=latest_block.header.number
6469
{
70+
debug!(message = "Fetching block number", ?latest_block);
71+
6572
let block = self
6673
.node
6774
.get_block(BlockId::Number(alloy_rpc_types::BlockNumberOrTag::Number(
@@ -71,12 +78,19 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
7178
.await?
7279
.ok_or_else(|| anyhow::anyhow!("Failed to get block {}", block_num))?;
7380

81+
let hash = block.hash();
7482
self.on_new_block(block).await?;
83+
self.store
84+
.commit_block_info(vec![BlockInfoUpdate {
85+
block_number: block_num,
86+
block_hash: hash,
87+
}])
88+
.await?;
7589
}
7690
}
7791
} else {
7892
warn!("No block info found in database, initializing with latest block as finalized");
79-
let block_update = tips_datastore::postgres::BlockInfoUpdate {
93+
let block_update = BlockInfoUpdate {
8094
block_number: latest_block.header.number,
8195
block_hash: latest_block.header.hash,
8296
};
@@ -142,33 +156,36 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
142156
loop {
143157
tokio::select! {
144158
_ = maintenance_interval.tick() => {
159+
info!(message = "starting maintenance");
145160
match self.periodic_maintenance().await {
146161
Ok(_) => {
147-
info!("Periodic maintenance completed");
162+
info!(message = "Periodic maintenance completed");
148163
},
149164
Err(err) => {
150-
error!("Error in periodic maintenance: {:?}", err);
165+
error!(message = "Error in periodic maintenance", error = %err);
151166
}
152167

153168
}
154169
}
155170
_ = execution_interval.tick() => {
171+
info!(message = "starting execution run");
156172
match self.execute().await {
157173
Ok(_) => {
158-
info!("Successfully executed maintenance run");
174+
info!(message = "Successfully executed maintenance run");
159175
}
160176
Err(e) => {
161-
error!("Error executing maintenance run: {:?}", e);
177+
error!(message = "Error executing maintenance run", error = %e);
162178
}
163179
}
164180
}
165181
Some(flashblock) = fb_rx.recv() => {
182+
info!(message = "starting flashblock processing");
166183
match self.process_flashblock(flashblock).await {
167184
Ok(_) => {
168-
info!("Successfully processed flashblock");
185+
info!(message = "Successfully processed flashblock");
169186
}
170187
Err(e) => {
171-
error!("Error processing flashblock: {:?}", e);
188+
error!(message = "Error processing flashblock", error = %e);
172189
}
173190
}
174191
}

ui/src/db/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import * as schema from "./schema";
44

55
const pool = new Pool({
66
connectionString: process.env.TIPS_DATABASE_URL,
7+
ssl: {
8+
requestCert: false,
9+
rejectUnauthorized: false,
10+
},
711
});
812

913
export const db = drizzle(pool, { schema });

0 commit comments

Comments
 (0)