Skip to content

Commit 81ba452

Browse files
Antoine RiardTheBlueMatt
authored andcommitted
Generate Events from ChannelMonitor to indicate spendable ouputs
Extend KeyStorage with delayed_payment_base_key and per_commitment_point to derive local_delayed private key
1 parent 70b026c commit 81ba452

File tree

6 files changed

+248
-67
lines changed

6 files changed

+248
-67
lines changed

src/chain/keysinterface.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! keysinterface provides keys into rust-lightning and defines some useful enums which describe
2+
//! spendable on-chain outputs which the user owns and is responsible for using just as any other
3+
//! on-chain output which is theirs.
4+
5+
use bitcoin::blockdata::transaction::{OutPoint, TxOut};
6+
use bitcoin::blockdata::script::Script;
7+
8+
use secp256k1::key::SecretKey;
9+
10+
/// When on-chain outputs are created by rust-lightning an event is generated which informs the
11+
/// user thereof. This enum descibes the format of the output and provides the OutPoint.
12+
pub enum SpendableOutputDescriptor {
13+
/// Outpoint with an output to a script which was provided via KeysInterface, thus you should
14+
/// have stored somewhere how to spend script_pubkey!
15+
StaticOutput {
16+
/// The outpoint spendable by user wallet
17+
outpoint: OutPoint,
18+
/// The output which is referenced by the given outpoint
19+
output: TxOut,
20+
},
21+
/// Outpoint commits to a P2WSH, should be spend by the following witness :
22+
/// <local_delayedsig> 0 <witnessScript>
23+
/// With input nSequence set to_self_delay.
24+
DynamicOutput {
25+
/// Outpoint spendable by user wallet
26+
outpoint: OutPoint,
27+
/// local_delayedkey = delayed_payment_basepoint_secret + SHA256(per_commitment_point || delayed_payment_basepoint
28+
local_delayedkey: SecretKey,
29+
/// witness redeemScript encumbering output
30+
witness_script: Script,
31+
/// nSequence input must commit to self_delay to satisfy script's OP_CSV
32+
to_self_delay: u16,
33+
}
34+
}

src/chain/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
33
pub mod chaininterface;
44
pub mod transaction;
5+
pub mod keysinterface;

src/ln/channel.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ impl Channel {
489489
let secp_ctx = Secp256k1::new();
490490
let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &chan_keys.channel_monitor_claim_key).serialize());
491491
let our_channel_monitor_claim_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script();
492-
let channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key,
493-
&PublicKey::from_secret_key(&secp_ctx, &chan_keys.delayed_payment_base_key),
492+
let channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
494493
&chan_keys.htlc_base_key,
495494
BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script);
496495

@@ -651,8 +650,7 @@ impl Channel {
651650
let secp_ctx = Secp256k1::new();
652651
let our_channel_monitor_claim_key_hash = Hash160::from_data(&PublicKey::from_secret_key(&secp_ctx, &chan_keys.channel_monitor_claim_key).serialize());
653652
let our_channel_monitor_claim_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_monitor_claim_key_hash[..]).into_script();
654-
let mut channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key,
655-
&PublicKey::from_secret_key(&secp_ctx, &chan_keys.delayed_payment_base_key),
653+
let mut channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
656654
&chan_keys.htlc_base_key,
657655
BREAKDOWN_TIMEOUT, our_channel_monitor_claim_script);
658656
channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);

0 commit comments

Comments
 (0)