Skip to content

Ready for Review : Handle resolution in case of channel going onchain, pass state backward offchain #198

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

Closed
wants to merge 13 commits into from
Closed
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
18 changes: 9 additions & 9 deletions fuzz/fuzz_targets/full_stack_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,C
use lightning::chain::transaction::OutPoint;
use lightning::chain::keysinterface::{ChannelKeys, KeysInterface};
use lightning::ln::channelmonitor;
use lightning::ln::channelmanager::{ChannelManager, PaymentFailReason};
use lightning::ln::channelmanager::{ChannelManager, PaymentFailReason, PaymentHash, PaymentPreimage};
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
use lightning::ln::router::Router;
use lightning::util::events::{EventsProvider,Event};
Expand Down Expand Up @@ -328,7 +328,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
}, our_network_key, Arc::clone(&logger)));

let mut should_forward = false;
let mut payments_received: Vec<[u8; 32]> = Vec::new();
let mut payments_received: Vec<PaymentHash> = Vec::new();
let mut payments_sent = 0;
let mut pending_funding_generation: Vec<([u8; 32], u64, Script)> = Vec::new();
let mut pending_funding_signatures = HashMap::new();
Expand Down Expand Up @@ -380,11 +380,11 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
Ok(route) => route,
Err(_) => return,
};
let mut payment_hash = [0; 32];
payment_hash[0..8].copy_from_slice(&be64_to_array(payments_sent));
let mut payment_hash = PaymentHash([0; 32]);
payment_hash.0[0..8].copy_from_slice(&be64_to_array(payments_sent));
let mut sha = Sha256::new();
sha.input(&payment_hash);
sha.result(&mut payment_hash);
sha.input(&payment_hash.0[..]);
sha.result(&mut payment_hash.0[..]);
payments_sent += 1;
match channelmanager.send_payment(route, payment_hash) {
Ok(_) => {},
Expand Down Expand Up @@ -418,11 +418,11 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
// for the remaining bytes. Thus, if not all remaining bytes are 0s we cannot
// fulfill this HTLC, but if they are, we can just take the first byte and
// place that anywhere in our preimage.
if &payment[1..] != &[0; 31] {
if &payment.0[1..] != &[0; 31] {
channelmanager.fail_htlc_backwards(&payment, PaymentFailReason::PreimageUnknown);
} else {
let mut payment_preimage = [0; 32];
payment_preimage[0] = payment[0];
let mut payment_preimage = PaymentPreimage([0; 32]);
payment_preimage.0[0] = payment.0[0];
channelmanager.claim_funds(payment_preimage);
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use bitcoin::blockdata::opcodes;
use bitcoin::blockdata::transaction::{TxIn,TxOut,OutPoint,Transaction};
use bitcoin::util::hash::{Hash160,Sha256dHash};

use ln::channelmanager::PaymentHash;

use secp256k1::key::{PublicKey,SecretKey};
use secp256k1::Secp256k1;
use secp256k1;
Expand Down Expand Up @@ -156,15 +158,15 @@ pub struct HTLCOutputInCommitment {
pub offered: bool,
pub amount_msat: u64,
pub cltv_expiry: u32,
pub payment_hash: [u8; 32],
pub payment_hash: PaymentHash,
pub transaction_output_index: u32,
}

#[inline]
pub fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, a_htlc_key: &PublicKey, b_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script {
let payment_hash160 = {
let mut ripemd = Ripemd160::new();
ripemd.input(&htlc.payment_hash);
ripemd.input(&htlc.payment_hash.0[..]);
let mut res = [0; 20];
ripemd.result(&mut res);
res
Expand Down
193 changes: 116 additions & 77 deletions src/ln/channel.rs

Large diffs are not rendered by default.

677 changes: 620 additions & 57 deletions src/ln/channelmanager.rs

Large diffs are not rendered by default.

Loading