Skip to content

Commit 4fbe0c9

Browse files
authored
Merge pull request #20 from TheBlueMatt/master
Rewrite parts of channel, cleanup a bunch of stuff
2 parents 69eb59b + 1ec9c3a commit 4fbe0c9

14 files changed

+1007
-512
lines changed

Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ description = """
88
A Bitcoin Lightning implementation in Rust.
99
Still super-early code-dump quality and is missing large chunks. See README in git repo for suggested projects if you want to contribute. Don't have to bother telling you not to use this for anything serious, because you'd have to finish building it to even try.
1010
"""
11+
build = "build.rs"
1112

1213
[features]
1314
# Supports tracking channels with a non-bitcoin chain hashes. Currently enables all kinds of fun DoS attacks.
1415
non_bitcoin_chain_hash_routing = []
1516
fuzztarget = ["secp256k1/fuzztarget", "bitcoin/fuzztarget"]
1617

1718
[dependencies]
18-
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin" }
19+
bitcoin = "0.13"
1920
rust-crypto = "0.2"
2021
rand = "0.4"
2122
secp256k1 = "0.9"
23+
24+
[build-dependencies]
25+
gcc = "0.3"
26+
27+
[dev-dependencies.bitcoin]
28+
version = "0.13"
29+
features = ["bitcoinconsensus"]

build.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extern crate gcc;
2+
3+
fn main() {
4+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")))]
5+
{
6+
let mut cfg = gcc::Build::new();
7+
cfg.file("src/util/rust_crypto_nonstd_arch.c");
8+
cfg.compile("lib_rust_crypto_nonstd_arch.a");
9+
}
10+
}

fuzz/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "lightning-fuzz"
33
version = "0.0.1"
44
authors = ["Automatically generated"]
55
publish = false
6+
# Because the function is unused it gets dropped before we link lightning, so
7+
# we have to duplicate build.rs here. Note that this is only required for
8+
# fuzztarget mode.
9+
build = "../build.rs"
610

711
[package.metadata]
812
cargo-fuzz = true
@@ -13,12 +17,15 @@ honggfuzz_fuzz = ["honggfuzz"]
1317

1418
[dependencies]
1519
lightning = { path = "..", features = ["fuzztarget"] }
16-
bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin", features = ["fuzztarget"] }
20+
bitcoin = { version = "0.13", features = ["fuzztarget"] }
1721
secp256k1 = { version = "0.9", features = ["fuzztarget"] }
1822
rust-crypto = "0.2"
1923
honggfuzz = { version = "0.5", optional = true }
2024
afl = { version = "0.3", optional = true }
2125

26+
[build-dependencies]
27+
gcc = "0.3"
28+
2229
# Prevent this from interfering with workspaces
2330
[workspace]
2431
members = ["."]

fuzz/fuzz_targets/channel_target.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use bitcoin::util::hash::Sha256dHash;
88
use bitcoin::network::serialize::{serialize, BitcoinHash};
99

1010
use lightning::ln::channel::Channel;
11-
use lightning::ln::channelmanager::PendingForwardHTLCInfo;
11+
use lightning::ln::channelmanager::{HTLCFailReason, PendingForwardHTLCInfo};
1212
use lightning::ln::msgs;
1313
use lightning::ln::msgs::MsgDecodable;
1414
use lightning::chain::chaininterface::{FeeEstimator, ConfirmationTarget};
@@ -241,11 +241,11 @@ pub fn do_test(data: &[u8]) {
241241
},
242242
4 => {
243243
let update_fail_htlc = decode_msg_with_len16!(msgs::UpdateFailHTLC, 32 + 8, 1);
244-
return_err!(channel.update_fail_htlc(&update_fail_htlc));
244+
return_err!(channel.update_fail_htlc(&update_fail_htlc, HTLCFailReason::dummy()));
245245
},
246246
5 => {
247247
let update_fail_malformed_htlc = decode_msg!(msgs::UpdateFailMalformedHTLC, 32+8+32+2);
248-
return_err!(channel.update_fail_malformed_htlc(&update_fail_malformed_htlc));
248+
return_err!(channel.update_fail_malformed_htlc(&update_fail_malformed_htlc, HTLCFailReason::dummy()));
249249
},
250250
6 => {
251251
let commitment_signed = decode_msg_with_len16!(msgs::CommitmentSigned, 32+64, 64);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../src/util/rust_crypto_nonstd_arch.c

src/ln/chan_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ pub struct HTLCOutputInCommitment {
157157
}
158158

159159
#[inline]
160-
pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey, offered: bool) -> Script {
160+
pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script {
161161
let payment_hash160 = {
162162
let mut ripemd = Ripemd160::new();
163163
ripemd.input(&htlc.payment_hash);
164164
let mut res = [0; 20];
165165
ripemd.result(&mut res);
166166
res
167167
};
168-
if offered {
168+
if htlc.offered {
169169
Builder::new().push_opcode(opcodes::All::OP_DUP)
170170
.push_opcode(opcodes::All::OP_HASH160)
171171
.push_slice(&Hash160::from_data(&revocation_key.serialize())[..])
@@ -231,5 +231,5 @@ pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a
231231
/// commitment secret. 'htlc' does *not* need to have its previous_output_index filled.
232232
#[inline]
233233
pub fn get_htlc_redeemscript(htlc: &HTLCOutputInCommitment, keys: &TxCreationKeys) -> Script {
234-
get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key, htlc.offered)
234+
get_htlc_redeemscript_with_explicit_keys(htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key)
235235
}

0 commit comments

Comments
 (0)