Skip to content

Commit f27dde8

Browse files
committed
makes tx-pool hold a Client reference for reuse
1 parent 8300f03 commit f27dde8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/tasks/bundler.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pub use crate::config::BuilderConfig;
33
use crate::tasks::oauth::Authenticator;
44
use oauth2::TokenResponse;
5-
use reqwest::Url;
5+
use reqwest::{Client, Url};
66
use serde::{Deserialize, Serialize};
77
use signet_bundle::SignetEthBundle;
88
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel};
@@ -32,6 +32,8 @@ pub struct BundlePoller {
3232
pub config: BuilderConfig,
3333
/// Authentication module that periodically fetches and stores auth tokens.
3434
pub authenticator: Authenticator,
35+
/// Holds a Reqwest client
36+
pub client: Client,
3537
/// Defines the interval at which the bundler polls the tx-pool for bundles.
3638
pub poll_interval_ms: u64,
3739
}
@@ -40,7 +42,12 @@ pub struct BundlePoller {
4042
impl BundlePoller {
4143
/// Creates a new BundlePoller from the provided builder config.
4244
pub fn new(config: &BuilderConfig, authenticator: Authenticator) -> Self {
43-
Self { config: config.clone(), authenticator, poll_interval_ms: 1000 }
45+
Self {
46+
config: config.clone(),
47+
authenticator,
48+
client: Client::new(),
49+
poll_interval_ms: 1000,
50+
}
4451
}
4552

4653
/// Creates a new BundlePoller from the provided builder config and with the specified poll interval in ms.
@@ -49,15 +56,16 @@ impl BundlePoller {
4956
authenticator: Authenticator,
5057
poll_interval_ms: u64,
5158
) -> Self {
52-
Self { config: config.clone(), authenticator, poll_interval_ms }
59+
Self { config: config.clone(), authenticator, client: Client::new(), poll_interval_ms }
5360
}
5461

5562
/// Fetches bundles from the transaction cache and returns them.
5663
pub async fn check_bundle_cache(&mut self) -> eyre::Result<Vec<Bundle>> {
5764
let bundle_url: Url = Url::parse(&self.config.tx_pool_url)?.join("bundles")?;
5865
let token = self.authenticator.fetch_oauth_token().await?;
5966

60-
let result = reqwest::Client::new()
67+
let result = self
68+
.client
6169
.get(bundle_url)
6270
.bearer_auth(token.access_token().secret())
6371
.send()

0 commit comments

Comments
 (0)