Skip to content

Add support for channel closure (based on new upstream rust-bitcoin) #17

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

Merged
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lightning"
version = "0.0.1"
version = "0.0.2"
authors = ["Matt Corallo"]
license = "Apache-2.0"
repository = "https://github.com/TheBlueMatt/rust-lightning/"
Expand All @@ -15,7 +15,7 @@ non_bitcoin_chain_hash_routing = []
fuzztarget = ["secp256k1/fuzztarget", "bitcoin/fuzztarget"]

[dependencies]
bitcoin = "0.12"
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin" }
rust-crypto = "0.2"
rand = "0.4"
secp256k1 = "0.9"
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ honggfuzz_fuzz = ["honggfuzz"]

[dependencies]
lightning = { path = "..", features = ["fuzztarget"] }
bitcoin = { version = "0.12", features = ["fuzztarget"] }
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", features = ["fuzztarget"] }
secp256k1 = { version = "0.9", features = ["fuzztarget"] }
honggfuzz = { version = "0.5", optional = true }
afl = { version = "0.3", optional = true }
Expand Down
10 changes: 9 additions & 1 deletion fuzz/fuzz_targets/channel_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn do_test(data: &[u8]) {

let their_pubkey = get_pubkey!();

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

let mut channel = if get_slice!(1)[0] != 0 {
Expand Down Expand Up @@ -248,6 +248,14 @@ pub fn do_test(data: &[u8]) {
let update_fee = decode_msg!(msgs::UpdateFee, 32+4);
return_err!(channel.update_fee(&fee_est, &update_fee));
},
9 => {
let shutdown = decode_msg_with_len16!(msgs::Shutdown, 32, 1);
return_err!(channel.shutdown(&fee_est, &shutdown));
},
10 => {
let closing_signed = decode_msg!(msgs::ClosingSigned, 32+8+64);
return_err!(channel.closing_signed(&fee_est, &closing_signed));
},
_ => return,
}
}
Expand Down
11 changes: 9 additions & 2 deletions fuzz/fuzz_targets/full_stack_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ extern crate bitcoin;
extern crate lightning;
extern crate secp256k1;

use bitcoin::blockdata::transaction::Transaction;
use bitcoin::network::constants::Network;
use bitcoin::util::hash::Sha256dHash;

use lightning::chain::chaininterface::{ConfirmationTarget,FeeEstimator,ChainWatchInterfaceUtil};
use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,FeeEstimator,ChainWatchInterfaceUtil};
use lightning::ln::{channelmonitor,msgs};
use lightning::ln::channelmanager::ChannelManager;
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
Expand Down Expand Up @@ -73,6 +74,11 @@ impl channelmonitor::ManyChannelMonitor for TestChannelMonitor {
}
}

struct TestBroadcaster {}
impl BroadcasterInterface for TestBroadcaster {
fn broadcast_transaction(&self, _tx: &Transaction) {}
}

#[derive(Clone, PartialEq, Eq, Hash)]
struct Peer {
id: u8,
Expand Down Expand Up @@ -120,8 +126,9 @@ pub fn do_test(data: &[u8]) {

let monitor = Arc::new(TestChannelMonitor{});
let watch = Arc::new(ChainWatchInterfaceUtil::new());
let broadcast = Arc::new(TestBroadcaster{});

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();
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();
let router = Arc::new(Router::new(PublicKey::from_secret_key(&secp_ctx, &our_network_key).unwrap()));

let handler = PeerManager::new(MessageHandler {
Expand Down
Loading