feat: restore tx pool after reboot (#5665)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Nil Medvedev
2024-01-02 14:11:41 +00:00
committed by GitHub
parent 4cd30bdc9b
commit 7fa4cddc72
6 changed files with 259 additions and 10 deletions

View File

@ -536,6 +536,7 @@ impl NodeConfig {
blockchain_db: &BlockchainProvider<DB, Tree>,
head: Head,
executor: &TaskExecutor,
data_dir: &ChainPath<DataDirPath>,
) -> eyre::Result<EthTransactionPool<BlockchainProvider<DB, Tree>, InMemoryBlobStore>>
where
DB: Database + Unpin + Clone + 'static,
@ -555,12 +556,28 @@ impl NodeConfig {
let transaction_pool =
reth_transaction_pool::Pool::eth_pool(validator, blob_store, self.txpool.pool_config());
info!(target: "reth::cli", "Transaction pool initialized");
let transactions_path = data_dir.txpool_transactions_path();
// spawn txpool maintenance task
{
let pool = transaction_pool.clone();
let chain_events = blockchain_db.canonical_state_stream();
let client = blockchain_db.clone();
let transactions_backup_config =
reth_transaction_pool::maintain::LocalTransactionBackupConfig::with_local_txs_backup(transactions_path);
executor.spawn_critical_with_graceful_shutdown_signal(
"local transactions backup task",
|shutdown| {
reth_transaction_pool::maintain::backup_local_transactions_task(
shutdown,
pool.clone(),
transactions_backup_config,
)
},
);
// spawn the maintenance task
executor.spawn_critical(
"txpool maintenance task",
reth_transaction_pool::maintain::maintain_transaction_pool_future(
@ -1055,7 +1072,7 @@ impl<DB: Database + DatabaseMetrics + DatabaseMetadata + 'static> NodeBuilderWit
// build transaction pool
let transaction_pool =
self.config.build_and_spawn_txpool(&blockchain_db, head, &executor)?;
self.config.build_and_spawn_txpool(&blockchain_db, head, &executor, &self.data_dir)?;
// build network
let (network_client, mut network_builder) = self

View File

@ -312,6 +312,13 @@ impl<D> ChainPath<D> {
self.0.join("blobstore").into()
}
/// Returns the path to the local transactions backup file
///
/// `<DIR>/<CHAIN_ID>/txpool-transactions-backup.rlp`
pub fn txpool_transactions_path(&self) -> PathBuf {
self.0.join("txpool-transactions-backup.rlp").into()
}
/// Returns the path to the config file for this chain.
///
/// `<DIR>/<CHAIN_ID>/reth.toml`