You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Batch-sign local HTLC txn with a well-doc'd API, returning sigs
1107ab0 introduced an API to have a
ChannelKeys implementer sign HTLC transactions by calling into the
LocalCommitmentTransaction object, which would then store the tx.
This API was incredibly awkward, both because it required an
external signer trust our own internal interfaces, but also because
it didn't allow for any inspection of what was about to be signed.
Further, it signed the HTLC transactions one-by-one in a somewhat
inefficient way, and there isn't a clear way to resolve this (as
the which-HTLC parameter has to refer to something in between the
HTLC's arbitrary index, and its index in the commitment tx, which
has "holes" for the non-HTLC outputs and skips some HTLCs).
We replace it with a new function in ChannelKeys which allows us
to sign all HTLCs in a given commitment transaction (which allows
for a bit more effeciency on the signers' part, as well as
sidesteps the which-HTLC issue). This may also simplify the signer
implementation as we will always want to sign all HTLCs spending a
given commitment transaction at once anyway.
We also de-mut the LocalCommitmentTransaction passed to the
ChanKeys, instead opting to make LocalCommitmentTransaction const
and avoid storing any new HTLC-related data in it.
if !this_htlc.0.offered && preimage.is_none(){return;}// if we don't have preimage for HTLC-Success, don't try to generate
618
-
let htlc_secret = if !this_htlc.0.offered{ preimage }else{None};// if we have a preimage for HTLC-Timeout, don't use it that's likely a duplicate HTLC hash
619
-
if this_htlc.1.is_none(){return;}// we don't have any remote signature for this htlc
620
-
if htlc_tx.input.len() != 1{return;}
621
-
if htlc_tx.input[0].witness.len() != 0{return;}
622
-
623
-
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0,&self.local_keys.a_htlc_key,&self.local_keys.b_htlc_key,&self.local_keys.revocation_key);
if this_htlc.0.transaction_output_index.is_some(){
621
+
let htlc_tx = build_htlc_transaction(&txid,self.feerate_per_kw, local_csv,&this_htlc.0,&self.local_keys.a_delayed_payment_key,&self.local_keys.revocation_key);
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0,&self.local_keys.a_htlc_key,&self.local_keys.b_htlc_key,&self.local_keys.revocation_key);
644
626
645
-
this_htlc.2 = Some(htlc_tx);
646
-
}else{return;}
627
+
let sighash = hash_to_message!(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx.input[0],&htlc_redeemscript, this_htlc.0.amount_msat / 1000)[..]);
// Channel should have checked that we have a remote signature for this HTLC at
648
+
// creation, and we should have a sensible htlc transaction:
649
+
assert!(this_htlc.1.is_some());
650
+
assert_eq!(htlc_tx.input.len(),1);
651
+
assert_eq!(htlc_tx.input[0].witness.len(),0);
652
+
653
+
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc.0,&self.local_keys.a_htlc_key,&self.local_keys.b_htlc_key,&self.local_keys.revocation_key);
654
+
655
+
htlc_tx.input[0].witness.push(Vec::new());// First is the multisig dummy
0 commit comments