Skip to content

Commit

Permalink
SubChannelManager implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibo-lg committed Mar 1, 2023
1 parent a495f6b commit b467ed8
Show file tree
Hide file tree
Showing 54 changed files with 5,869 additions and 533 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
key: test-cache-${{ github.run_id }}-${{ github.run_number }}
- uses: actions/checkout@v2
- id: set-matrix
run: cargo test --no-run && echo "::set-output name=matrix::$(scripts/get_test_list.sh execution manager channel_execution)"
run: cargo test --no-run && echo "::set-output name=matrix::$(scripts/get_test_list.sh manager channel_execution ln_dlc)"
integration_tests:
name: integration-tests
needs: integration_tests_prepare
Expand Down
2 changes: 1 addition & 1 deletion bitcoin-rpc-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bitcoin = {version = "0.29.2"}
bitcoincore-rpc = {version = "0.16.0"}
bitcoincore-rpc-json = {version = "0.16.0"}
dlc-manager = {path = "../dlc-manager"}
lightning = {version = "0.0.113"}
lightning = {version = "0.0.113", git = "https://github.com/p2pderivatives/rust-lightning/", branch = "split-tx-experiment"}
log = "0.4.14"
rust-bitcoin-coin-selection = {version = "0.1.0", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", features = ["rand"]}
simple-wallet = {path = "../simple-wallet"}
5 changes: 4 additions & 1 deletion dlc-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ bitcoin = {version = "0.29.2"}
dlc = {version = "0.4.0", path = "../dlc"}
dlc-messages = {version = "0.4.0", path = "../dlc-messages"}
dlc-trie = {version = "0.4.0", path = "../dlc-trie"}
lightning = {version = "0.0.113"}
lightning = {version = "0.0.113", git = "https://github.com/p2pderivatives/rust-lightning/", branch = "split-tx-experiment"}
log = "0.4.14"
rand_chacha = {version = "0.3.1", optional = true}
secp256k1-zkp = {version = "0.7.0", features = ["bitcoin_hashes", "rand", "rand-std"]}
serde = {version = "1.0", optional = true}

[dev-dependencies]
bitcoin-bech32 = "0.12.1"
bitcoin-rpc-provider = {path = "../bitcoin-rpc-provider"}
bitcoin-test-utils = {path = "../bitcoin-test-utils"}
bitcoincore-rpc = {version = "0.16.0"}
bitcoincore-rpc-json = {version = "0.16.0"}
criterion = "0.4.0"
chrono = "0.4"
dlc-manager = {path = ".", features = ["use-serde"]}
dlc-messages = {path = "../dlc-messages", features = ["serde"]}
electrs-blockchain-provider = {path = "../electrs-blockchain-provider"}
env_logger = "0.9.1"
lightning-persister = {version = "0.0.113", git = "https://github.com/p2pderivatives/rust-lightning/", branch = "split-tx-experiment"}
mocks = {path = "../mocks"}
secp256k1-zkp = {version = "0.7.0", features = ["bitcoin_hashes", "rand", "rand-std", "global-context", "use-serde"]}
serde = "1.0"
Expand Down
6 changes: 4 additions & 2 deletions dlc-manager/src/chain_monitor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//!
//! This module includes the [`ChainMonitor`] struct that helps watching the blockchain for
//! transactions of interest in the context of DLC.
use std::collections::HashMap;

Expand Down Expand Up @@ -60,9 +61,10 @@ impl_dlc_writeable_enum!(TxType,;
pub(crate) enum RevokedTxType {
Buffer,
Settle,
Split,
}

impl_dlc_writeable_enum!(RevokedTxType,;;;(0, Buffer), (1, Settle));
impl_dlc_writeable_enum!(RevokedTxType,;;;(0, Buffer), (1, Settle), (2, Split));

impl ChainMonitor {
/// Returns a new [`ChainMonitor`] with fields properly initialized.
Expand Down
16 changes: 9 additions & 7 deletions dlc-manager/src/channel/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ impl_dlc_writeable!(SignedChannel, {
(roll_back_state, option),
(own_per_update_seed, writeable),
(counter_party_commitment_secrets, writeable),
(fee_rate_per_vb, writeable)
(fee_rate_per_vb, writeable),
(is_sub_channel, writeable)
});

impl_dlc_writeable_enum!(
SignedChannelState,;
(0, Established, {(signed_contract_id, writeable), (own_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (counter_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (buffer_transaction, writeable), (is_offer, writeable)}),
(0, Established, {(signed_contract_id, writeable), (own_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (counter_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (buffer_transaction, writeable), (is_offer, writeable), (total_collateral, writeable)}),
(1, SettledOffered, {(counter_payout, writeable), (next_per_update_point, writeable), (timeout, writeable)}),
(2, SettledReceived, {(own_payout, writeable), (counter_next_per_update_point, writeable)}),
(3, SettledAccepted, {(counter_next_per_update_point, writeable), (own_next_per_update_point, writeable), (settle_tx, writeable), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable)}),
(4, SettledConfirmed, {(settle_tx, writeable), (counter_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (counter_next_per_update_point, writeable), (own_next_per_update_point, writeable), (timeout, writeable), (own_payout, writeable) }),
(5, Settled, {(settle_tx, writeable), (counter_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature})}),
(2, SettledReceived, {(own_payout, writeable), (counter_next_per_update_point, writeable), (counter_payout, writeable)}),
(3, SettledAccepted, {(counter_next_per_update_point, writeable), (own_next_per_update_point, writeable), (settle_tx, writeable), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable), (counter_payout, writeable)}),
(4, SettledConfirmed, {(settle_tx, writeable), (counter_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (counter_next_per_update_point, writeable), (own_next_per_update_point, writeable), (timeout, writeable), (own_payout, writeable), (counter_payout, writeable) }),
(5, Settled, {(settle_tx, writeable), (counter_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_settle_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (own_payout, writeable), (counter_payout, writeable)}),
(6, RenewOffered, {(offered_contract_id, writeable), (counter_payout, writeable), (is_offer, writeable), (offer_next_per_update_point, writeable), (timeout, writeable)}),
(7, RenewAccepted, {(contract_id, writeable), (offer_per_update_point, writeable), (accept_per_update_point, writeable), (buffer_transaction, writeable), (buffer_script_pubkey, writeable), (accept_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable)}),
(8, RenewConfirmed, {(contract_id, writeable), (offer_per_update_point, writeable), (accept_per_update_point, writeable), (buffer_transaction, writeable), (buffer_script_pubkey, writeable), (offer_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (accept_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable)}),
(8, RenewConfirmed, {(contract_id, writeable), (offer_per_update_point, writeable), (accept_per_update_point, writeable), (buffer_transaction, writeable), (buffer_script_pubkey, writeable), (offer_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (accept_buffer_adaptor_signature, {cb_writeable, write_ecdsa_adaptor_signature, read_ecdsa_adaptor_signature}), (timeout, writeable), (own_payout, writeable), (total_collateral, writeable)}),
(9, Closing, {(buffer_transaction, writeable), (signed_cet, writeable), (contract_id, writeable), (attestations, vec)}),
(10, ClosedPunished, { (punishment_txid, writeable) }),
(11, CollaborativeCloseOffered, { (counter_payout, writeable), (offer_signature, writeable), (close_tx, writeable), (timeout, writeable) })
Expand All @@ -67,3 +68,4 @@ impl_dlc_writeable_enum!(

impl_dlc_writeable!(FailedAccept, {(temporary_channel_id, writeable), (error_message, {cb_writeable, write_string, read_string}), (accept_message, writeable), (counter_party, writeable)});
impl_dlc_writeable!(FailedSign, {(channel_id, writeable), (error_message, {cb_writeable, write_string, read_string}), (sign_message, writeable), (counter_party, writeable)});

16 changes: 16 additions & 0 deletions dlc-manager/src/channel/signed_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ typed_enum!(
/// Whether the local party is the one that initiated the latest channel
/// state change.
is_offer: bool,
/// The total amount of collateral in the channel
total_collateral: u64,
},
/// A [`SignedChannel`] is in `SettledOffered` state when the local party
/// has sent a [`dlc_messages::channel::SettleOffer`] message.
Expand All @@ -126,6 +128,8 @@ typed_enum!(
SettledReceived {
/// The payout that was proposed to the local party to settle the channel.
own_payout: u64,
/// The payout that was proposed to the counter party.
counter_payout: u64,
/// The per update point to be used by the counter party for the setup
/// of the next channel state.
counter_next_per_update_point: PublicKey,
Expand All @@ -149,6 +153,8 @@ typed_enum!(
timeout: u64,
/// The payout to the local party after settling the channel.
own_payout: u64,
/// The payout that was proposed to the counter party.
counter_payout: u64,
},
/// A [`SignedChannel`] is in `SettledConfirmed` state when the local party
/// has sent a [`dlc_messages::channel::SettleConfirm`] message.
Expand All @@ -172,6 +178,8 @@ typed_enum!(
timeout: u64,
/// The payout to the local party after settling the channel.
own_payout: u64,
/// The payout that was proposed to the counter party.
counter_payout: u64,
},
/// A [`SignedChannel`] is in `Settled` state when the local party
/// has all the necessary information to close the channel with the last
Expand All @@ -185,6 +193,10 @@ typed_enum!(
/// The adaptor signature for the settle transaction generated by the
/// local party.
own_settle_adaptor_signature: EcdsaAdaptorSignature,
/// The amount the local party holds in the channel.
own_payout: u64,
/// The amount the counter party holds in the channel.
counter_payout: u64,
},
/// A [`SignedChannel`] is in `RenewOffered` state when the local party
/// has sent or received a [`dlc_messages::channel::RenewOffer`] message.
Expand Down Expand Up @@ -252,6 +264,8 @@ typed_enum!(
timeout: u64,
/// The payout to the local party attributed for closing the previous state.
own_payout: u64,
/// The total amount of collateral in the channel.
total_collateral: u64,
},
/// A [`SignedChannel`] is in `Closing` state when the local party
/// has broadcast a buffer transaction and is waiting to finalize the
Expand Down Expand Up @@ -364,4 +378,6 @@ pub struct SignedChannel {
pub counter_party_commitment_secrets: CounterpartyCommitmentSecrets,
/// The current fee rate to be used to create transactions.
pub fee_rate_per_vb: u64,
/// Whether this channel is embedded within a Lightning Network channel.
pub is_sub_channel: bool,
}
Loading

0 comments on commit b467ed8

Please sign in to comment.