Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add coordinator and trader funding collateral to dlc channels #2299

Merged
merged 1 commit into from
Mar 22, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE "dlc_channels"
DROP COLUMN IF EXISTS coordinator_funding_sats,
DROP COLUMN IF EXISTS trader_funding_sats;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE "dlc_channels"
ADD COLUMN coordinator_funding_sats BIGINT NOT NULL DEFAULT 0,
ADD COLUMN trader_funding_sats BIGINT NOT NULL DEFAULT 0;
4 changes: 4 additions & 0 deletions coordinator/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ pub async fn migrate_dlc_channels(State(state): State<Arc<AppState>>) -> Result<
.inner
.get_dlc_channel_usable_balance_counterparty(&channel.channel_id)
.map_err(|e| AppError::InternalServerError(format!("{e:#}")))?;
let coordinator_funding = Amount::from_sat(channel.own_params.collateral);
let trader_funding = Amount::from_sat(channel.counter_params.collateral);

let protocol_id = match channel.reference_id {
Some(reference_id) => ProtocolId::try_from(reference_id)
Expand All @@ -592,6 +594,8 @@ pub async fn migrate_dlc_channels(State(state): State<Arc<AppState>>) -> Result<
to_txid_30(channel.fund_tx.txid()),
coordinator_reserve,
trader_reserve,
coordinator_funding,
trader_funding,
)
.map_err(|e| AppError::InternalServerError(format!("{e:#}")))?;

Expand Down
5 changes: 5 additions & 0 deletions coordinator/src/db/dlc_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ pub(crate) fn insert_pending_dlc_channel(
.execute(conn)
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn set_dlc_channel_open(
conn: &mut PgConnection,
open_protocol_id: &ProtocolId,
channel_id: &DlcChannelId,
funding_txid: Txid,
coordinator_reserve: Amount,
trader_reserve: Amount,
coordinator_funding: Amount,
trader_funding: Amount,
) -> QueryResult<usize> {
diesel::update(dlc_channels::table)
.set((
Expand All @@ -72,6 +75,8 @@ pub(crate) fn set_dlc_channel_open(
dlc_channels::updated_at.eq(OffsetDateTime::now_utc()),
dlc_channels::coordinator_reserve_sats.eq(coordinator_reserve.to_sat() as i64),
dlc_channels::trader_reserve_sats.eq(trader_reserve.to_sat() as i64),
dlc_channels::coordinator_funding_sats.eq(coordinator_funding.to_sat() as i64),
dlc_channels::trader_funding_sats.eq(trader_funding.to_sat() as i64),
))
.filter(dlc_channels::open_protocol_id.eq(open_protocol_id.to_uuid()))
.execute(conn)
Expand Down
6 changes: 6 additions & 0 deletions coordinator/src/node/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::node::Node;
use anyhow::bail;
use anyhow::Context;
use anyhow::Result;
use bitcoin::Amount;
use dlc_manager::channel::signed_channel::SignedChannel;
use dlc_manager::channel::signed_channel::SignedChannelState;
use dlc_manager::channel::Channel;
Expand Down Expand Up @@ -107,6 +108,9 @@ impl Node {
.inner
.get_dlc_channel_usable_balance(&signed_channel.channel_id)?;

let coordinator_funding = Amount::from_sat(signed_channel.own_params.collateral);
let trader_funding = Amount::from_sat(signed_channel.counter_params.collateral);

let protocol_id = ProtocolId::try_from(protocol_id)?;
let dlc_protocol = db::dlc_protocols::get_dlc_protocol(&mut conn, protocol_id)?;

Expand All @@ -119,6 +123,8 @@ impl Node {
to_txid_30(signed_channel.fund_tx.txid()),
coordinator_reserve,
trader_reserve,
coordinator_funding,
trader_funding,
)?;
}
DlcProtocolType::Renew { .. }
Expand Down
2 changes: 2 additions & 0 deletions coordinator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ diesel::table! {
punish_txid -> Nullable<Text>,
created_at -> Timestamptz,
updated_at -> Timestamptz,
coordinator_funding_sats -> Int8,
trader_funding_sats -> Int8,
}
}

Expand Down
Loading