Skip to content

Commit

Permalink
chore(coordinator): Reduce time holding PooledConnection
Browse files Browse the repository at this point in the history
It's good practice to hold these kind of resources for as little as
possible.
  • Loading branch information
luckysori committed Jan 23, 2024
1 parent e1e55fb commit 1395a8b
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions coordinator/src/collaborative_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ pub async fn propose_collaborative_revert(
trader_amount_sats: u64,
closing_price: Decimal,
) -> Result<()> {
let mut conn = pool.get().context("Could not acquire DB lock")?;

let channel_id_hex = channel_id.to_hex();

let dlc_channels = node
Expand Down Expand Up @@ -104,21 +102,23 @@ pub async fn propose_collaborative_revert(
"Proposing collaborative revert"
);

db::collaborative_reverts::insert(
&mut conn,
position::models::CollaborativeRevert {
channel_id,
trader_pubkey: peer_id,
coordinator_address: coordinator_address.clone(),
coordinator_amount_sats: coordinator_amount,
trader_amount_sats: trader_amount,
timestamp: OffsetDateTime::now_utc(),
price: closing_price,
},
)
.context("Could not insert new collaborative revert")?;

// Send collaborative revert proposal to the counterpary.
{
let mut conn = pool.get().context("Could not acquire DB lock")?;
db::collaborative_reverts::insert(
&mut conn,
position::models::CollaborativeRevert {
channel_id,
trader_pubkey: peer_id,
coordinator_address: coordinator_address.clone(),
coordinator_amount_sats: coordinator_amount,
trader_amount_sats: trader_amount,
timestamp: OffsetDateTime::now_utc(),
price: closing_price,
},
)
.context("Could not insert new collaborative revert")?
};

sender
.send(OrderbookMessage::TraderMessage {
trader_id: peer_id,
Expand Down

0 comments on commit 1395a8b

Please sign in to comment.