Skip to content

Commit 3baaebe

Browse files
authored
Merge pull request #1251 from lightning-signer/2022-01-signer-preimages
Provide payment preimages to signer on HTLC success
2 parents 35d4ebb + 6e19d1f commit 3baaebe

File tree

4 files changed

+155
-54
lines changed

4 files changed

+155
-54
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use util::{byte_utils, transaction_utils};
3434
use util::ser::{Writeable, Writer, Readable};
3535

3636
use chain::transaction::OutPoint;
37-
use ln::chan_utils;
37+
use ln::{chan_utils, PaymentPreimage};
3838
use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelPublicKeys, HolderCommitmentTransaction, ChannelTransactionParameters, CommitmentTransaction, ClosingTransaction};
3939
use ln::msgs::UnsignedChannelAnnouncement;
4040
use ln::script::ShutdownScript;
@@ -226,7 +226,14 @@ pub trait BaseSign {
226226
/// secret won't leave us without a broadcastable holder transaction.
227227
/// Policy checks should be implemented in this function, including checking the amount
228228
/// sent to us and checking the HTLCs.
229-
fn validate_holder_commitment(&self, holder_tx: &HolderCommitmentTransaction) -> Result<(), ()>;
229+
///
230+
/// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
231+
/// A validating signer should ensure that an HTLC output is removed only when the matching
232+
/// preimage is provided, or when the value to holder is restored.
233+
///
234+
/// NOTE: all the relevant preimages will be provided, but there may also be additional
235+
/// irrelevant or duplicate preimages.
236+
fn validate_holder_commitment(&self, holder_tx: &HolderCommitmentTransaction, preimages: Vec<PaymentPreimage>) -> Result<(), ()>;
230237
/// Gets the holder's channel public keys and basepoints
231238
fn pubkeys(&self) -> &ChannelPublicKeys;
232239
/// Gets an arbitrary identifier describing the set of keys which are provided back to you in
@@ -240,9 +247,16 @@ pub trait BaseSign {
240247
///
241248
/// Policy checks should be implemented in this function, including checking the amount
242249
/// sent to us and checking the HTLCs.
250+
///
251+
/// The preimages of outgoing HTLCs that were fulfilled since the last commitment are provided.
252+
/// A validating signer should ensure that an HTLC output is removed only when the matching
253+
/// preimage is provided, or when the value to holder is restored.
254+
///
255+
/// NOTE: all the relevant preimages will be provided, but there may also be additional
256+
/// irrelevant or duplicate preimages.
243257
//
244258
// TODO: Document the things someone using this interface should enforce before signing.
245-
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()>;
259+
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()>;
246260
/// Validate the counterparty's revocation.
247261
///
248262
/// This is required in order for the signer to make sure that the state has moved
@@ -601,14 +615,14 @@ impl BaseSign for InMemorySigner {
601615
chan_utils::build_commitment_secret(&self.commitment_seed, idx)
602616
}
603617

604-
fn validate_holder_commitment(&self, _holder_tx: &HolderCommitmentTransaction) -> Result<(), ()> {
618+
fn validate_holder_commitment(&self, _holder_tx: &HolderCommitmentTransaction, _preimages: Vec<PaymentPreimage>) -> Result<(), ()> {
605619
Ok(())
606620
}
607621

608622
fn pubkeys(&self) -> &ChannelPublicKeys { &self.holder_channel_pubkeys }
609623
fn channel_keys_id(&self) -> [u8; 32] { self.channel_keys_id }
610624

611-
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
625+
fn sign_counterparty_commitment(&self, commitment_tx: &CommitmentTransaction, _preimages: Vec<PaymentPreimage>, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<(Signature, Vec<Signature>), ()> {
612626
let trusted_tx = commitment_tx.trust();
613627
let keys = trusted_tx.keys();
614628

0 commit comments

Comments
 (0)