Skip to content

Commit

Permalink
refactor: Remove unnecessary pool argument
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed Jun 17, 2024
1 parent 49afd95 commit d42783f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions coordinator/src/bin/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,10 @@ async fn main() -> Result<()> {
node.inner.oracle_pubkey,
);
let _handle = rollover::monitor(
pool.clone(),
node.clone(),
node_event_handler.subscribe(),
notification_service.get_sender(),
network,
node.clone(),
);
let _handle = collaborative_revert::monitor(
pool.clone(),
Expand Down
17 changes: 8 additions & 9 deletions coordinator/src/node/rollover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use anyhow::Result;
use bitcoin::secp256k1::PublicKey;
use bitcoin::Network;
use diesel::r2d2::ConnectionManager;
use diesel::r2d2::Pool;
use diesel::r2d2::PooledConnection;
use diesel::PgConnection;
use dlc_manager::contract::contract_input::ContractInput;
Expand All @@ -39,11 +38,10 @@ use xxi_node::node::event::NodeEvent;
use xxi_node::node::ProtocolId;

pub fn monitor(
pool: Pool<ConnectionManager<PgConnection>>,
node: Node,
mut receiver: broadcast::Receiver<NodeEvent>,
notifier: mpsc::Sender<Notification>,
network: Network,
node: Node,
) -> RemoteHandle<()> {
let (fut, remote_handle) = async move {
loop {
Expand All @@ -52,10 +50,9 @@ pub fn monitor(
tokio::spawn({
let notifier = notifier.clone();
let node = node.clone();
let pool = pool.clone();
async move {
if let Err(e) = node
.check_if_eligible_for_rollover(pool, notifier, peer, network)
.check_if_eligible_for_rollover(notifier, peer, network)
.await
{
tracing::error!(
Expand Down Expand Up @@ -87,14 +84,16 @@ pub fn monitor(
impl Node {
async fn check_if_eligible_for_rollover(
&self,
pool: Pool<ConnectionManager<PgConnection>>,
notifier: mpsc::Sender<Notification>,
trader_id: PublicKey,
network: Network,
) -> Result<()> {
let mut conn = spawn_blocking(move || pool.get())
.await
.expect("task to complete")?;
let mut conn = spawn_blocking({
let pool = self.pool.clone();
move || pool.get()
})
.await
.expect("task to complete")?;

tracing::debug!(%trader_id, "Checking if the user's position is eligible for rollover");

Expand Down

0 comments on commit d42783f

Please sign in to comment.