Skip to content
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
13 changes: 13 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
POSTGRES_USER=dlcdevkit
POSTGRES_PASS=dlcdevkit

POSTGRES_HOST=localhost:5432
POSTGRES_DB=ddk
DATABASE_URL=postgres://dlcdevkit:dlcdevkit@localhost:5432/ddk

ESPLORA_HOST=http://localhost:30000

BITCOIND_USER=dlcdevkit
BITCOIND_PASS=dlcdevkit
BITCOIND_HOST=http://localhost:18443
RPC_WALLET=ddk
13 changes: 8 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ on:
pull_request:
env:
CARGO_TERM_COLOR: always
POSTGRES_USER: dlcdevkit
POSTGRES_PASS: dlcdevkit
DATABASE_URL: postgresql://dlcdevkit:dlcdevkit@localhost:5432/postgres
BITCOIND_HOST: http://localhost:18443
BITCOIND_USER: dlcdevkit
BITCOIND_PASS: dlcdevkit
ESPLORA_HOST: http://localhost:30000
RPC_WALLET: ddk

jobs:
clippy:
Expand Down Expand Up @@ -51,11 +59,6 @@ jobs:
unit-tests:
name: unit tests
runs-on: ubuntu-latest
env:
DATABASE_URL: postgresql://dlcdevkit:dlcdevkit@localhost:5433/postgres
BITCOIND_HOST: http://localhost:18443
ESPLORA_HOST: http://localhost:30000

steps:
- name: Install Protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
/ddk/.env
.env

/releases
/releases

logs

**/*/CLAUDE.md
/.claude
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 3 additions & 18 deletions ddk-manager/src/chain_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ impl ChainMonitor {
}

pub(crate) fn add_tx(&mut self, txid: Txid, channel_info: ChannelInfo) {
tracing::debug!("Watching transaction {txid}: {channel_info:?}");
self.watched_tx.insert(txid, WatchState::new(channel_info));

// When we watch a buffer transaction we also want to watch
Expand All @@ -103,14 +102,11 @@ impl ChainMonitor {
}

fn add_txo(&mut self, outpoint: OutPoint, channel_info: ChannelInfo) {
tracing::debug!("Watching transaction output {outpoint}: {channel_info:?}");
self.watched_txo
.insert(outpoint, WatchState::new(channel_info));
}

pub(crate) fn cleanup_channel(&mut self, channel_id: ChannelId) {
tracing::debug!("Cleaning up data related to channel {channel_id:?}");

self.watched_tx
.retain(|_, state| state.channel_id() != channel_id);

Expand All @@ -119,7 +115,6 @@ impl ChainMonitor {
}

pub(crate) fn remove_tx(&mut self, txid: &Txid) {
tracing::debug!("Stopped watching transaction {txid}");
self.watched_tx.remove(txid);
}

Expand Down Expand Up @@ -188,25 +183,15 @@ impl WatchState {
fn confirm(&mut self, transaction: Transaction) {
match self {
WatchState::Registered { ref channel_info } => {
tracing::info!(
"Transaction {} confirmed: {channel_info:?}",
transaction.compute_txid()
);

*self = WatchState::Confirmed {
channel_info: *channel_info,
transaction,
}
}
WatchState::Confirmed {
channel_info,
transaction,
} => {
tracing::error!(
"Transaction {} already confirmed: {channel_info:?}",
transaction.compute_txid()
);
}
channel_info: _,
transaction: _,
} => {}
}
}

Expand Down
29 changes: 25 additions & 4 deletions ddk-manager/src/channel_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ use ddk_messages::{
oracle_msgs::{OracleAnnouncement, OracleAttestation},
FundingSignatures,
};
use lightning::ln::chan_utils::{
build_commitment_secret, derive_private_key, CounterpartyCommitmentSecrets,
use lightning::{
ln::chan_utils::{build_commitment_secret, derive_private_key, CounterpartyCommitmentSecrets},
util::logger::Logger,
};
use secp256k1_zkp::{All, EcdsaAdaptorSignature, PublicKey, Secp256k1, SecretKey, Signing};

Expand Down Expand Up @@ -283,7 +284,13 @@ where
/// to a [`SignedChannel`] and [`SignedContract`], returning them as well as the
/// [`SignChannel`] to be sent to the counter party.
#[allow(clippy::too_many_arguments)]
pub async fn verify_and_sign_accepted_channel<W: Deref, SP: Deref, X: ContractSigner, S: Deref>(
pub async fn verify_and_sign_accepted_channel<
W: Deref,
SP: Deref,
X: ContractSigner,
S: Deref,
L: Deref,
>(
secp: &Secp256k1<All>,
offered_channel: &OfferedChannel,
offered_contract: &OfferedContract,
Expand All @@ -293,11 +300,13 @@ pub async fn verify_and_sign_accepted_channel<W: Deref, SP: Deref, X: ContractSi
signer_provider: &SP,
storage: &S,
chain_monitor: &Mutex<ChainMonitor>,
logger: &L,
) -> Result<(SignedChannel, SignedContract, SignChannel), Error>
where
W::Target: Wallet,
SP::Target: ContractSignerProvider<Signer = X>,
S::Target: Storage,
L::Target: Logger,
{
let (tx_input_infos, input_amount) =
crate::conversion_utils::get_tx_input_infos(&accept_channel.funding_inputs)?;
Expand Down Expand Up @@ -385,6 +394,7 @@ where
Some(channel_id),
storage,
signer_provider,
logger,
)
.await?;

Expand Down Expand Up @@ -467,7 +477,7 @@ where
/// given [`AcceptedChannel`] and [`AcceptedContract`], transforming them
/// to a [`SignedChannel`] and [`SignedContract`], and returning them.
#[allow(clippy::too_many_arguments)]
pub async fn verify_signed_channel<W: Deref, SP: Deref, S: Deref, X: ContractSigner>(
pub async fn verify_signed_channel<W: Deref, SP: Deref, S: Deref, X: ContractSigner, L: Deref>(
secp: &Secp256k1<All>,
accepted_channel: &AcceptedChannel,
accepted_contract: &AcceptedContract,
Expand All @@ -476,11 +486,13 @@ pub async fn verify_signed_channel<W: Deref, SP: Deref, S: Deref, X: ContractSig
chain_monitor: &Mutex<ChainMonitor>,
storage: &S,
signer_provider: &SP,
logger: &L,
) -> Result<(SignedChannel, SignedContract, Transaction), Error>
where
W::Target: Wallet,
SP::Target: ContractSignerProvider<Signer = X>,
S::Target: Storage,
L::Target: Logger,
{
let own_publish_pk = accepted_channel
.accept_base_points
Expand Down Expand Up @@ -514,6 +526,7 @@ where
Some(accepted_channel.channel_id),
storage,
signer_provider,
logger,
)
.await?;

Expand Down Expand Up @@ -1374,6 +1387,7 @@ pub async fn verify_renew_accept_and_confirm<
X: ContractSigner,
T: Deref,
S: Deref,
L: Deref,
>(
secp: &Secp256k1<All>,
renew_accept: &RenewAccept,
Expand All @@ -1385,12 +1399,14 @@ pub async fn verify_renew_accept_and_confirm<
signer_provider: &SP,
time: &T,
storage: &S,
logger: &L,
) -> Result<(SignedContract, RenewConfirm), Error>
where
W::Target: Wallet,
SP::Target: ContractSignerProvider<Signer = X>,
T::Target: Time,
S::Target: Storage,
L::Target: Logger,
{
let own_base_secret_key =
signer_provider.get_secret_key_for_pubkey(&signed_channel.own_points.own_basepoint)?;
Expand Down Expand Up @@ -1457,6 +1473,7 @@ where
Some(signed_channel.channel_id),
storage,
signer_provider,
logger,
)
.await?;

Expand Down Expand Up @@ -1505,6 +1522,7 @@ pub(crate) async fn verify_renew_confirm_and_finalize<
W: Deref,
SP: Deref,
X: ContractSigner,
L: Deref,
>(
secp: &Secp256k1<All>,
signed_channel: &mut SignedChannel,
Expand All @@ -1516,12 +1534,14 @@ pub(crate) async fn verify_renew_confirm_and_finalize<
signer: &SP,
chain_monitor: &Mutex<ChainMonitor>,
storage: &S,
logger: &L,
) -> Result<(SignedContract, RenewFinalize), Error>
where
T::Target: Time,
SP::Target: ContractSignerProvider<Signer = X>,
W::Target: Wallet,
S::Target: Storage,
L::Target: Logger,
{
let (
&offer_per_update_point,
Expand Down Expand Up @@ -1575,6 +1595,7 @@ where
Some(signed_channel.channel_id),
storage,
signer,
logger,
)
.await?;

Expand Down
Loading
Loading