Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions prdoc/pr_8897.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: '[pallet-revive-rpc] fix sqlite in-memory connection pool issue'
doc:
- audience: Runtime Dev
description: |-
Fix in-memory sqlite connection pool issue
see https://github.com/launchbadge/sqlx/issues/2510
crates:
- name: pallet-revive-eth-rpc
bump: patch
16 changes: 12 additions & 4 deletions substrate/frame/revive/rpc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use sc_service::{
config::{PrometheusConfig, RpcConfiguration},
start_rpc_servers, TaskManager,
};
use sqlx::sqlite::SqlitePoolOptions;

// Default port if --prometheus-port is not specified
const DEFAULT_PROMETHEUS_PORT: u16 = 9616;
Expand Down Expand Up @@ -110,19 +111,26 @@ fn build_client(
let (api, rpc_client, rpc) = connect(node_rpc_url).await?;
let block_provider = SubxtBlockInfoProvider::new( api.clone(), rpc.clone()).await?;

let keep_latest_n_blocks = if database_url == IN_MEMORY_DB {
let (pool, keep_latest_n_blocks) = if database_url == IN_MEMORY_DB {
log::warn!( target: LOG_TARGET, "💾 Using in-memory database, keeping only {cache_size} blocks in memory");
Some(cache_size)
// see sqlite in-memory issue: https://github.com/launchbadge/sqlx/issues/2510
let pool = SqlitePoolOptions::new()
.max_connections(1)
.idle_timeout(None)
.max_lifetime(None)
.connect(database_url).await?;

(pool, Some(cache_size))
} else {
None
(SqlitePoolOptions::new().connect(database_url).await?, None)
};

let receipt_extractor = ReceiptExtractor::new(
api.clone(),
earliest_receipt_block).await?;

let receipt_provider = ReceiptProvider::new(
database_url,
pool,
block_provider.clone(),
receipt_extractor.clone(),
keep_latest_n_blocks,
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/revive/rpc/src/receipt_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ impl BlockInfo for SubstrateBlock {
impl<B: BlockInfoProvider> ReceiptProvider<B> {
/// Create a new `ReceiptProvider` with the given database URL and block provider.
pub async fn new(
database_url: &str,
pool: SqlitePool,
block_provider: B,
receipt_extractor: ReceiptExtractor,
keep_latest_n_blocks: Option<usize>,
) -> Result<Self, sqlx::Error> {
let pool = SqlitePool::connect(database_url).await?;
sqlx::migrate!().run(&pool).await?;
Ok(Self {
pool,
Expand Down