Skip to content

Commit 962f259

Browse files
authored
feat(bens): add read replica (#1660)
* refactor(launcher): split postgres connect and SeaORM migrations * fix(launcher): propagate read replica connect failure from maybe_connect_replica_repo * feat(bens): add optional replica_database settings and env examples * refactor(bens): hold Arc<ReadWriteRepo> in SubgraphReader Drop ReadPoolSource; resolve read/write pools via read_db()/main_db() each call. Add blockscout-service-launcher dep; adjust tests, benchmark, and server wiring. * fix(bens): align subgraph error diagnostics with read vs write pool * fix tests * set blockscout-launcher-server version to branch * fix tests
1 parent cd7ea83 commit 962f259

20 files changed

Lines changed: 375 additions & 192 deletions

File tree

blockscout-ens/Cargo.lock

Lines changed: 70 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blockscout-ens/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ anyhow = { version = "1" }
1717
async-trait = { version = "0.1" }
1818
bigdecimal = { version = "0.4" }
1919
blockscout-display-bytes = { version = "1.0" }
20-
blockscout-service-launcher = { version = "0.21.0" }
20+
blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs", branch = "ll/bens/read-replica" }
2121
cached = { version = "0.54.0", default-features = false }
2222
chrono = "0.4"
2323
config = { version = "0.14" }
@@ -41,7 +41,8 @@ sea-query = { version = "0.32" }
4141
serde = { version = "1" }
4242
serde_json = { version = "1", default-features = false }
4343
serde_with = { version = "3.11" }
44-
sqlx = { version = "0.8", default-features = false }
44+
# Pin to the same sqlx minor as sea-orm / blockscout-service-launcher to avoid duplicate sqlx.
45+
sqlx = { version = "0.8.6", default-features = false }
4546
tera = { version = "1.19" }
4647
thiserror = { version = "2" }
4748
tokio = { version = "1.23", default-features = false }

blockscout-ens/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Service is **multi-chain**, meaning that only one instance of `graph-node`, `pos
4040
| `BENS__TRACING__ENABLED` | | | `true` |
4141
| `BENS__TRACING__FORMAT` | | | `default` |
4242
| `BENS__SUBGRAPHS_READER__REFRESH_CACHE_DISABLED` | | | `false` |
43+
| `BENS__REPLICA_DATABASE__CONNECT__URL` | true | e.g. `postgresql://postgres:postgres@localhost:5433/postgres` | |
44+
| `BENS__REPLICA_DATABASE__HEALTH_CHECK_INTERVAL` | | | `10` |
45+
| `BENS__REPLICA_DATABASE__MAX_LAG` | | | `300` |
4346

4447
[anchor]: <> (anchors.envs.end.envs_main)
4548

blockscout-ens/bens-logic/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ alloy-ccip-read = { workspace = true }
1111
anyhow = { workspace = true }
1212
async-trait = { workspace = true }
1313
bigdecimal = { workspace = true }
14+
blockscout-service-launcher = { workspace = true, features = ["database-1"] }
1415
cached = { workspace = true, features = [
1516
"proc_macro",
1617
"tokio",
@@ -52,6 +53,7 @@ ens-normalize-rs = { workspace = true }
5253
pretty_assertions = { workspace = true }
5354
rstest = { workspace = true }
5455
tracing-subscriber = { workspace = true, features = ["env-filter"] }
56+
wiremock = { workspace = true }
5557

5658
[[example]]
5759
name = "resolve_benchmark"

blockscout-ens/bens-logic/examples/resolve_benchmark.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use bens_logic::{
55
protocols::{Network, ProtocolInfo, Tld},
66
subgraph::{BatchResolveAddressNamesInput, SubgraphReader},
77
};
8+
use blockscout_service_launcher::database::{
9+
DatabaseConnectSettings, DatabaseSettings, ReadWriteRepo,
10+
};
811
use nonempty::nonempty;
9-
use sqlx::postgres::PgPoolOptions;
1012
use std::{collections::HashMap, sync::Arc, time::Instant};
1113
use tracing_subscriber::fmt::format::FmtSpan;
1214

@@ -23,12 +25,13 @@ async fn main() -> Result<(), anyhow::Error> {
2325
.init();
2426

2527
let url = std::env::var("DATABASE_URL").expect("no database url");
26-
let pool = Arc::new(
27-
PgPoolOptions::new()
28-
.max_connections(40)
29-
.connect(&url)
30-
.await?,
31-
);
28+
let settings = DatabaseSettings {
29+
connect: DatabaseConnectSettings::Url(url),
30+
connect_options: Default::default(),
31+
create_database: false,
32+
run_migrations: false,
33+
};
34+
let db = Arc::new(ReadWriteRepo::new_no_migrations(&settings, None).await?);
3235
let eth_client = BlockscoutClient::new("https://eth.blockscout.com".parse().unwrap(), 5, 30);
3336
let rootstock_client =
3437
BlockscoutClient::new("https://rootstock.blockscout.com".parse().unwrap(), 5, 30);
@@ -72,7 +75,7 @@ async fn main() -> Result<(), anyhow::Error> {
7275
},
7376
),
7477
]);
75-
let reader = SubgraphReader::initialize(pool.clone(), networks, protocol_infos).await?;
78+
let reader = SubgraphReader::initialize(db, networks, protocol_infos).await?;
7679

7780
let addresses = vec![
7881
"0x0292f204513eeafe8c032ffc4cb4c7e10eca908c",

blockscout-ens/bens-logic/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod metrics;
55
pub mod migrations;
66
pub mod protocols;
77
pub mod subgraph;
8-
#[cfg(feature = "test-utils")]
8+
#[cfg(any(test, feature = "test-utils"))]
99
pub mod test_utils;
1010

1111
pub use protocols::hash_name::hex;

0 commit comments

Comments
 (0)