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

Feature/ln dlc channels #97

Draft
wants to merge 102 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
3186b7b
Add ln/dlc messages
Tibo-lg Feb 7, 2023
a54d097
Add ln/dlc tx utilities to dlc crate
Tibo-lg Feb 7, 2023
16dd995
SubChannelManager implementation
Tibo-lg Mar 1, 2023
2d64a56
Patch lightning dependency at workspace level
Tibo-lg Mar 9, 2023
836c26c
Refactor sub dlc channel ids
Tibo-lg Mar 15, 2023
4636ad7
Fix contract state and chain monitor
Tibo-lg Mar 20, 2023
a2cc6f2
Add possibility to reject sub channel offer and close
Tibo-lg Mar 22, 2023
6d47783
Rebase on c35600e
Tibo-lg Mar 22, 2023
dfbd7bc
Fix sled storage prefix bug
Tibo-lg Mar 23, 2023
a402492
Add confirmed state for sub channel
Tibo-lg Mar 27, 2023
a4096ed
Prevent floating point arithmetic from triggering payout computation …
Tibo-lg Mar 27, 2023
41528a1
Fix pnl computation
Tibo-lg Apr 11, 2023
adc7cef
Fix channel reestablishment issue
Tibo-lg Apr 19, 2023
438350b
Fix sled storage when getting empty actions
Tibo-lg Apr 21, 2023
f66c922
Add offchain close open close integration test
Tibo-lg Apr 21, 2023
f552950
Ensure that we only run one integration test at a time on CI
luckysori Apr 22, 2023
e3492c7
Activate multiple DLCs path in test that should execute them
luckysori Apr 22, 2023
1af70e2
Build per_split_secret key correctly on sub-channel CloseConfirm
luckysori Apr 22, 2023
c826584
Appease Clippy
luckysori Apr 24, 2023
d916229
Merge pull request #107 from get10101/feature/ln-dlc-channels_debug
Tibo-lg Apr 24, 2023
053b9a0
Flush sled tree on upsert channel and sub_channel
luckysori Apr 24, 2023
bb4bb2c
Merge pull request #110 from get10101/flush-on-upsert
Tibo-lg Apr 24, 2023
1723807
Fix reconnect on off chain closing
Tibo-lg Apr 27, 2023
abdbf76
Fix clippy warning
Tibo-lg Apr 27, 2023
ac6aaaf
0.0.114 update
Tibo-lg May 1, 2023
65aa0ab
Fix clippy
Tibo-lg May 1, 2023
4385cb7
Update ldk ref + fix log in electrs provider
Tibo-lg May 9, 2023
d7c1ec5
Update LDK to use channel lock
Tibo-lg May 11, 2023
8ba5aae
Add check to ensure commitment transaction is spent
Tibo-lg May 18, 2023
7f975a7
Retry channel close automatically + use tx sync for lndlc tests
Tibo-lg Jun 6, 2023
2e8e963
Update LDK dependency to fix lock issue
Tibo-lg Jun 12, 2023
7a0afdd
Lock channel monitor when checking for watched transactions
Tibo-lg Jun 15, 2023
de6390b
Fix channel monitor lock when checking for watched transactions
luckysori Jun 15, 2023
9b5dd04
Appease Clippy
luckysori Jun 15, 2023
f8d834e
Merge pull request #112 from get10101/feature/ln-dlc-channels-114
Tibo-lg Jun 15, 2023
66b1570
Fix off chain close reconnect issue
Tibo-lg Jun 19, 2023
34f7334
Don't check channel state on force close
Tibo-lg Jun 20, 2023
7560cad
Fix protocol of channel renew and sub channel establish
Tibo-lg Jun 29, 2023
572afbb
Merge pull request #116 from p2pderivatives/fix/channel-renew-ln-dlc-…
Tibo-lg Jul 10, 2023
b32cc98
fix: Clear certain unprocessed messages after peer disconnect
luckysori Jul 17, 2023
06d3d93
Add more trait bounds to dlc_manager::Error::WalletError
luckysori Jul 17, 2023
20a2bbd
Allow building P2pderivatives oracle client without HTTP requests
luckysori May 23, 2023
943c873
Allow CET broadcast after CET_NSEQUENCE confirmations
luckysori Jun 3, 2023
37e5f70
Merge pull request #123 from p2pderivatives/fix/drop-msgs-on-disconnect
luckysori Jul 19, 2023
ecfbdd0
Merge pull request #124 from p2pderivatives/misc
luckysori Jul 19, 2023
e7e3967
chore: Update rust-lightning dependency
luckysori Jul 19, 2023
2af64a9
chore: Remove unnecessary mut modifier
luckysori Jul 19, 2023
6c01267
Log deser errors when getting all channels/contracts
luckysori Jun 15, 2023
1fbaeb1
Merge pull request #125 from p2pderivatives/update-rust-lightning
luckysori Jul 19, 2023
6a65cf6
Merge pull request #126 from p2pderivatives/log-deser-errors-when-get…
luckysori Jul 19, 2023
2013ad4
Allow force closing in any state
Tibo-lg Jul 20, 2023
e4a1083
Fix sporadic overflow in test
Tibo-lg Jul 24, 2023
5f899ab
Merge pull request #128 from p2pderivatives/feature/ln-dlc/close-in-a…
Tibo-lg Jul 26, 2023
86118ee
fix: Handle new Revoke message in CustomMessageHandler impl
luckysori Jul 27, 2023
049388b
Merge pull request #131 from p2pderivatives/fix/handle-revoke-msg
luckysori Jul 27, 2023
3b519f2
Refactor ln-dlc channels tests
Tibo-lg Aug 2, 2023
c00f338
fixup! Refactor ln-dlc channels tests
Tibo-lg Aug 2, 2023
8515435
chore: Update dlc-sled-storage-provider readme
luckysori Aug 4, 2023
3ca9dd3
fix: Avoid serialisation breaking changes when possible
luckysori Aug 4, 2023
78a8b46
Merge pull request #134 from p2pderivatives/fix/avoid-ser-breaking-ch…
luckysori Aug 4, 2023
94f2495
fixup! fixup! Refactor ln-dlc channels tests
luckysori Aug 4, 2023
5c92ecc
fixup! fixup! fixup! Refactor ln-dlc channels tests
luckysori Aug 4, 2023
4ab7e08
fixup! fixup! fixup! fixup! Refactor ln-dlc channels tests
Tibo-lg Aug 4, 2023
afce6e0
chore: Update rust-lightning
luckysori Aug 10, 2023
89106aa
Merge pull request #135 from p2pderivatives/update-ldk
luckysori Aug 14, 2023
ac5ac98
Merge pull request #133 from p2pderivatives/chore/ln-dlc/test-refactors
Tibo-lg Aug 15, 2023
f8716ae
Handle auto close from LDK
Tibo-lg Aug 15, 2023
0e13bbe
fix: Add missing renew revoke dlc message
holzeis Aug 17, 2023
c46bd5a
Merge pull request #139 from p2pderivatives/fix/revoke-renew-type-map…
Tibo-lg Aug 18, 2023
22b7052
feat(message_handler): Add has_pending_messages_to_process API
luckysori Aug 21, 2023
a765a59
Merge pull request #140 from p2pderivatives/feat/check-pending-msgs
luckysori Aug 24, 2023
6ec92ae
fixup! Handle auto close from LDK
Tibo-lg Aug 24, 2023
9885d40
fixup! fixup! Handle auto close from LDK
Tibo-lg Aug 24, 2023
19d4d99
fixup! fixup! fixup! Handle auto close from LDK
Tibo-lg Aug 28, 2023
2e9c5c6
Merge pull request #138 from p2pderivatives/feature/ln-dlc/handle-ldk…
Tibo-lg Aug 31, 2023
31588a7
Fix broken coin selection dependency
Tibo-lg Aug 28, 2023
d82a2aa
Merge pull request #147 from p2pderivatives/fix/broken-coin-selection
Tibo-lg Sep 6, 2023
6af6c49
Increase rust-lightning PING_TIMER to 20 seconds
luckysori Sep 6, 2023
695cec5
Merge pull request #144 from p2pderivatives/increase-ping-timer-ldk
luckysori Sep 6, 2023
f38cb39
chore(chain_monitor)!: Remove list of last block hashes
luckysori Jul 11, 2023
c938b00
feat(chain_monitor)!: Split block process from confirmation report
luckysori Sep 16, 2023
549073a
Appease Clippy
luckysori Sep 16, 2023
0d23ce3
Use Cargo feature resolver version 2
luckysori Sep 16, 2023
44d888e
Add secp256k1_zkp/global-context feature to mocks Cargo.toml
luckysori Sep 16, 2023
724f598
Merge pull request #122 from p2pderivatives/feat/split-block-processi…
luckysori Sep 21, 2023
0590022
Update to ldk v0.0.116
Tibo-lg Aug 22, 2023
8608049
fixup! Update to ldk v0.0.116
Tibo-lg Oct 4, 2023
456e494
Fix settle after disconnect during open bug
Tibo-lg Aug 28, 2023
49c0c20
Merge pull request #143 from p2pderivatives/fix/ln-dlc/renew-after-di…
Tibo-lg Oct 11, 2023
fa25bf7
Merge pull request #141 from p2pderivatives/chore/ln-dlc/update-to-116
Tibo-lg Oct 11, 2023
d761e63
Use commit tx number to reject stale messages.
Tibo-lg Aug 28, 2023
05f97b4
fixup! Use commit tx number to reject stale messages.
Tibo-lg Oct 4, 2023
56e35f7
Merge pull request #154 from p2pderivatives/fix/ln-dlc/stale-message-fix
Tibo-lg Oct 11, 2023
c5893d5
Do not panic on attempting to force-close a subchannel
luckysori Oct 24, 2023
f318fee
Appease Clippy 1.73.0
luckysori Oct 24, 2023
39882fe
Merge pull request #159 from p2pderivatives/fix/do-not-panic-on-subch…
luckysori Oct 24, 2023
e42cfcf
fix: overflow bug in payout curve
bonomat Nov 1, 2023
6801d17
Merge pull request #162 from p2pderivatives/fix/overflow-bug-in-payou…
bonomat Nov 1, 2023
9656c8e
Load ChainMonitor in (DLC) Manager constructor if possible
luckysori Nov 2, 2023
dda16c3
Merge pull request #166 from p2pderivatives/byo-chain-monitor
luckysori Nov 3, 2023
d335349
Fix bug in rust-lightning upgrade to 0.0.116
luckysori Nov 1, 2023
0f9ce7c
Merge pull request #164 from p2pderivatives/fix/ldk-116-upgrade-and-c…
luckysori Nov 20, 2023
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
4 changes: 2 additions & 2 deletions .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 All @@ -58,6 +58,6 @@ jobs:
- name: Wait for electrs to be ready
run: ./scripts/wait_for_electrs.sh
- name: Run test
run: RUST_BACKTRACE=1 ${{ matrix.tests }} --ignored
run: RUST_MIN_STACK=104857600 RUST_BACKTRACE=1 ${{ matrix.tests }} --ignored --exact
- name: Stop bitcoin node
run: ./scripts/stop_node.sh
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[workspace]

members = [
"bitcoin-test-utils",
"bitcoin-rpc-provider",
Expand All @@ -14,3 +13,9 @@ members = [
"dlc-sled-storage-provider",
"electrs-blockchain-provider",
]
resolver = "2"

[patch.crates-io]
lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "a57281b" }
lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "a57281b" }
lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "a57281b" }
4 changes: 2 additions & 2 deletions 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.116"}
log = "0.4.14"
rust-bitcoin-coin-selection = {version = "0.1.0", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", features = ["rand"]}
rust-bitcoin-coin-selection = { rev = "23a6bf85", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", features = ["rand"]}
simple-wallet = {path = "../simple-wallet"}
54 changes: 17 additions & 37 deletions bitcoin-rpc-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,11 @@ use rust_bitcoin_coin_selection::select_coins;
/// The minimum feerate we are allowed to send, as specify by LDK.
const MIN_FEERATE: u32 = 253;

#[derive(Clone, Eq, Hash, PartialEq)]
pub enum Target {
Background,
Normal,
HighPriority,
}

pub struct BitcoinCoreProvider {
client: Arc<Mutex<Client>>,
// Used to implement the FeeEstimator interface, heavily inspired by
// https://github.com/lightningdevkit/ldk-sample/blob/main/src/bitcoind_client.rs#L26
fees: Arc<HashMap<Target, AtomicU32>>,
fees: Arc<HashMap<ConfirmationTarget, AtomicU32>>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -107,10 +100,10 @@ impl BitcoinCoreProvider {

pub fn new_from_rpc_client(rpc_client: Client) -> Self {
let client = Arc::new(Mutex::new(rpc_client));
let mut fees: HashMap<Target, AtomicU32> = HashMap::new();
fees.insert(Target::Background, AtomicU32::new(MIN_FEERATE));
fees.insert(Target::Normal, AtomicU32::new(2000));
fees.insert(Target::HighPriority, AtomicU32::new(5000));
let mut fees: HashMap<ConfirmationTarget, AtomicU32> = HashMap::new();
fees.insert(ConfirmationTarget::Background, AtomicU32::new(MIN_FEERATE));
fees.insert(ConfirmationTarget::Normal, AtomicU32::new(2000));
fees.insert(ConfirmationTarget::HighPriority, AtomicU32::new(5000));
let fees = Arc::new(fees);
poll_for_fee_estimates(client.clone(), fees.clone());
BitcoinCoreProvider { client, fees }
Expand Down Expand Up @@ -372,35 +365,22 @@ impl Blockchain for BitcoinCoreProvider {
}

impl FeeEstimator for BitcoinCoreProvider {
fn get_est_sat_per_1000_weight(
&self,
confirmation_target: lightning::chain::chaininterface::ConfirmationTarget,
) -> u32 {
match confirmation_target {
ConfirmationTarget::Background => self
.fees
.get(&Target::Background)
.unwrap()
.load(Ordering::Acquire),
ConfirmationTarget::Normal => self
.fees
.get(&Target::Normal)
.unwrap()
.load(Ordering::Acquire),
ConfirmationTarget::HighPriority => self
.fees
.get(&Target::HighPriority)
.unwrap()
.load(Ordering::Acquire),
}
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
self.fees
.get(&confirmation_target)
.unwrap()
.load(Ordering::Acquire)
}
}

fn poll_for_fee_estimates(client: Arc<Mutex<Client>>, fees: Arc<HashMap<Target, AtomicU32>>) {
fn poll_for_fee_estimates(
client: Arc<Mutex<Client>>,
fees: Arc<HashMap<ConfirmationTarget, AtomicU32>>,
) {
std::thread::spawn(move || loop {
match query_fee_estimate(&client, 144, EstimateMode::Economical) {
Ok(fee_rate) => {
fees.get(&Target::Background)
fees.get(&ConfirmationTarget::Background)
.unwrap()
.store(fee_rate, Ordering::Release);
}
Expand All @@ -410,7 +390,7 @@ fn poll_for_fee_estimates(client: Arc<Mutex<Client>>, fees: Arc<HashMap<Target,
};
match query_fee_estimate(&client, 18, EstimateMode::Conservative) {
Ok(fee_rate) => {
fees.get(&Target::Normal)
fees.get(&ConfirmationTarget::Normal)
.unwrap()
.store(fee_rate, Ordering::Release);
}
Expand All @@ -420,7 +400,7 @@ fn poll_for_fee_estimates(client: Arc<Mutex<Client>>, fees: Arc<HashMap<Target,
};
match query_fee_estimate(&client, 6, EstimateMode::Conservative) {
Ok(fee_rate) => {
fees.get(&Target::HighPriority)
fees.get(&ConfirmationTarget::HighPriority)
.unwrap()
.store(fee_rate, Ordering::Release);
}
Expand Down
3 changes: 1 addition & 2 deletions bitcoin-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ pub fn from_hex(hex: &str, target: &mut [u8]) -> Result<usize, ()> {
/// Transforms an hex string to a Vec<u8>.
/// Panics if the string is not valid hex.
pub fn str_to_hex(hex_str: &str) -> Vec<u8> {
let mut hex = Vec::<u8>::new();
hex.resize(hex_str.len() / 2, 0);
let mut hex = vec![0; hex_str.len() / 2];
from_hex(hex_str, &mut hex).unwrap();
hex
}
Expand Down
6 changes: 5 additions & 1 deletion dlc-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@ 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.116"}
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.116"}
lightning-transaction-sync = {version = "0.0.116", features=["esplora-blocking"]}
mocks = {path = "../mocks"}
secp256k1-zkp = {version = "0.7.0", features = ["bitcoin_hashes", "rand", "rand-std", "global-context", "use-serde"]}
serde = "1.0"
Expand Down
Loading
Loading