Skip to content

Commit

Permalink
fix(api): Healtcheck and api fixes (#360)
Browse files Browse the repository at this point in the history
# What ❔

<!-- What are the changes this PR brings about? -->
<!-- Example: This PR adds a PR template to the repo. -->
<!-- (For bigger PRs adding more context is appreciated) -->

## Why ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [ ] Code has been formatted via `cargo fmt`.

---------

Signed-off-by: Danil <[email protected]>
Co-authored-by: Fedor Sakharov <[email protected]>
  • Loading branch information
Deniallugo and montekki authored Jan 18, 2024
1 parent e6f8b0b commit 7f4a7e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ impl From<UserWithdrawal> for WithdrawalResponse {
pub async fn run_server(pool: PgPool) {
let app = Router::new()
.route("/withdrawals/:from", get(get_withdrawals))
.route("/health", get(health))
.with_state(pool);

// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}

async fn health(State(pool): State<PgPool>) -> Result<&'static str, StatusCode> {
pool.acquire()
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok("ok")
}

async fn get_withdrawals(
Path(from): Path<Address>,
State(pool): State<PgPool>,
Expand Down
10 changes: 8 additions & 2 deletions bin/withdrawal-finalizer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use ethers::{
types::U256,
};
use eyre::{anyhow, Result};
use sqlx::{postgres::PgConnectOptions, ConnectOptions, PgConnection, PgPool};
use sqlx::{
postgres::{PgConnectOptions, PgPoolOptions},
ConnectOptions, PgConnection,
};

use chain_events::{BlockEvents, L2EventsListener};
use client::{l1bridge::codegen::IL1Bridge, zksync_contract::codegen::IZkSync, ZksyncMiddleware};
Expand Down Expand Up @@ -177,7 +180,10 @@ async fn main() -> Result<()> {
let options =
PgConnectOptions::from_str(config.database_url.as_str())?.disable_statement_logging();

let pgpool = PgPool::connect_with(options).await?;
let pgpool = PgPoolOptions::new()
.acquire_timeout(Duration::from_secs(2))
.connect_with(options)
.await?;

let from_l2_block = start_from_l2_block(
client_l2.clone(),
Expand Down

0 comments on commit 7f4a7e9

Please sign in to comment.