Skip to content

Commit f7dd692

Browse files
authored
Merge pull request #17 from TheBlueMatt/2017-04-channel-close
Add support for channel closure (based on new upstream rust-bitcoin)
2 parents 2018782 + 187ca8c commit f7dd692

File tree

11 files changed

+632
-114
lines changed

11 files changed

+632
-114
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lightning"
3-
version = "0.0.1"
3+
version = "0.0.2"
44
authors = ["Matt Corallo"]
55
license = "Apache-2.0"
66
repository = "https://github.com/TheBlueMatt/rust-lightning/"
@@ -15,7 +15,7 @@ non_bitcoin_chain_hash_routing = []
1515
fuzztarget = ["secp256k1/fuzztarget", "bitcoin/fuzztarget"]
1616

1717
[dependencies]
18-
bitcoin = "0.12"
18+
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin" }
1919
rust-crypto = "0.2"
2020
rand = "0.4"
2121
secp256k1 = "0.9"

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ honggfuzz_fuzz = ["honggfuzz"]
1313

1414
[dependencies]
1515
lightning = { path = "..", features = ["fuzztarget"] }
16-
bitcoin = { version = "0.12", features = ["fuzztarget"] }
16+
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", features = ["fuzztarget"] }
1717
secp256k1 = { version = "0.9", features = ["fuzztarget"] }
1818
honggfuzz = { version = "0.5", optional = true }
1919
afl = { version = "0.3", optional = true }

fuzz/fuzz_targets/channel_target.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn do_test(data: &[u8]) {
163163

164164
let their_pubkey = get_pubkey!();
165165

166-
let tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new(), witness: Vec::new() };
166+
let tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: Vec::new() };
167167
let funding_output = (Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
168168

169169
let mut channel = if get_slice!(1)[0] != 0 {
@@ -248,6 +248,14 @@ pub fn do_test(data: &[u8]) {
248248
let update_fee = decode_msg!(msgs::UpdateFee, 32+4);
249249
return_err!(channel.update_fee(&fee_est, &update_fee));
250250
},
251+
9 => {
252+
let shutdown = decode_msg_with_len16!(msgs::Shutdown, 32, 1);
253+
return_err!(channel.shutdown(&fee_est, &shutdown));
254+
},
255+
10 => {
256+
let closing_signed = decode_msg!(msgs::ClosingSigned, 32+8+64);
257+
return_err!(channel.closing_signed(&fee_est, &closing_signed));
258+
},
251259
_ => return,
252260
}
253261
}

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ extern crate bitcoin;
22
extern crate lightning;
33
extern crate secp256k1;
44

5+
use bitcoin::blockdata::transaction::Transaction;
56
use bitcoin::network::constants::Network;
67
use bitcoin::util::hash::Sha256dHash;
78

8-
use lightning::chain::chaininterface::{ConfirmationTarget,FeeEstimator,ChainWatchInterfaceUtil};
9+
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,FeeEstimator,ChainWatchInterfaceUtil};
910
use lightning::ln::{channelmonitor,msgs};
1011
use lightning::ln::channelmanager::ChannelManager;
1112
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
@@ -73,6 +74,11 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
7374
}
7475
}
7576

77+
struct TestBroadcaster {}
78+
impl BroadcasterInterface for TestBroadcaster {
79+
fn broadcast_transaction(&self, _tx: &Transaction) {}
80+
}
81+
7682
#[derive(Clone, PartialEq, Eq, Hash)]
7783
struct Peer {
7884
id: u8,
@@ -120,8 +126,9 @@ pub fn do_test(data: &[u8]) {
120126

121127
let monitor = Arc::new(TestChannelMonitor{});
122128
let watch = Arc::new(ChainWatchInterfaceUtil::new());
129+
let broadcast = Arc::new(TestBroadcaster{});
123130

124-
let channelmanager = ChannelManager::new(our_network_key, slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone()).unwrap();
131+
let channelmanager = ChannelManager::new(our_network_key, slice_to_be32(get_slice!(4)), get_slice!(1)[0] != 0, Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone()).unwrap();
125132
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key).unwrap()));
126133

127134
let handler = PeerManager::new(MessageHandler {

0 commit comments

Comments
 (0)