Skip to content

Commit 0d3e990

Browse files
committed
f justice
1 parent 018dd52 commit 0d3e990

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

lightning/src/chain/keysinterface.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ pub trait BaseSign {
310310
/// revoked the state which they eventually broadcast. It's not a _holder_ secret key and does
311311
/// not allow the spending of any funds by itself (you need our holder revocation_secret to do
312312
/// so).
313-
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
313+
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, SignError>;
314314

315315
/// Create a signature for the given input in a transaction spending a commitment transaction
316316
/// HTLC output when our counterparty broadcasts an old state.
@@ -329,7 +329,7 @@ pub trait BaseSign {
329329
///
330330
/// htlc holds HTLC elements (hash, timelock), thus changing the format of the witness script
331331
/// (which is committed to in the BIP 143 signatures).
332-
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()>;
332+
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, SignError>;
333333

334334
/// Create a signature for a claiming transaction for a HTLC output on a counterparty's commitment
335335
/// transaction, either offered or received.
@@ -714,26 +714,26 @@ impl BaseSign for InMemorySigner {
714714
Ok((sig, htlc_sigs))
715715
}
716716

717-
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
718-
let revocation_key = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key).map_err(|_| ())?;
717+
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, SignError> {
718+
let revocation_key = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key).map_err(|_| SignError::Internal)?;
719719
let per_commitment_point = PublicKey::from_secret_key(secp_ctx, &per_commitment_key);
720-
let revocation_pubkey = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint).map_err(|_| ())?;
720+
let revocation_pubkey = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint).map_err(|_| SignError::Internal)?;
721721
let witness_script = {
722-
let counterparty_delayedpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().delayed_payment_basepoint).map_err(|_| ())?;
722+
let counterparty_delayedpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().delayed_payment_basepoint).map_err(|_| SignError::Internal)?;
723723
chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.holder_selected_contest_delay(), &counterparty_delayedpubkey)
724724
};
725725
let mut sighash_parts = sighash::SighashCache::new(justice_tx);
726726
let sighash = hash_to_message!(&sighash_parts.segwit_signature_hash(input, &witness_script, amount, EcdsaSighashType::All).unwrap()[..]);
727727
return Ok(sign(secp_ctx, &sighash, &revocation_key))
728728
}
729729

730-
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
731-
let revocation_key = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key).map_err(|_| ())?;
730+
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, SignError> {
731+
let revocation_key = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key).map_err(|_| SignError::Internal)?;
732732
let per_commitment_point = PublicKey::from_secret_key(secp_ctx, &per_commitment_key);
733-
let revocation_pubkey = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint).map_err(|_| ())?;
733+
let revocation_pubkey = chan_utils::derive_public_revocation_key(&secp_ctx, &per_commitment_point, &self.pubkeys().revocation_basepoint).map_err(|_| SignError::Internal)?;
734734
let witness_script = {
735-
let counterparty_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint).map_err(|_| ())?;
736-
let holder_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint).map_err(|_| ())?;
735+
let counterparty_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.counterparty_pubkeys().htlc_basepoint).map_err(|_| SignError::Internal)?;
736+
let holder_htlcpubkey = chan_utils::derive_public_key(&secp_ctx, &per_commitment_point, &self.pubkeys().htlc_basepoint).map_err(|_| SignError::Internal)?;
737737
chan_utils::get_htlc_redeemscript_with_explicit_keys(&htlc, self.opt_anchors(), &counterparty_htlcpubkey, &holder_htlcpubkey, &revocation_pubkey)
738738
};
739739
let mut sighash_parts = sighash::SighashCache::new(justice_tx);

lightning/src/chain/package.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl PackageSolvingData {
346346
_ => { mem::discriminant(self) == mem::discriminant(&input) }
347347
}
348348
}
349-
fn finalize_input<Signer: Sign>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> bool {
349+
fn finalize_input<Signer: Sign>(&self, bumped_tx: &mut Transaction, i: usize, onchain_handler: &mut OnchainTxHandler<Signer>) -> Result<bool, SignError> {
350350
match self {
351351
PackageSolvingData::RevokedOutput(ref outp) => {
352352
if let Ok(chan_keys) = TxCreationKeys::derive_new(&onchain_handler.secp_ctx, &outp.per_commitment_point, &outp.counterparty_delayed_payment_base_key, &outp.counterparty_htlc_base_key, &onchain_handler.signer.pubkeys().revocation_basepoint, &onchain_handler.signer.pubkeys().htlc_basepoint) {
@@ -358,7 +358,7 @@ impl PackageSolvingData {
358358
bumped_tx.input[i].witness.push(ser_sig);
359359
bumped_tx.input[i].witness.push(vec!(1));
360360
bumped_tx.input[i].witness.push(witness_script.clone().into_bytes());
361-
} else { return false; }
361+
} else { return Ok(false); }
362362
}
363363
},
364364
PackageSolvingData::RevokedHTLCOutput(ref outp) => {
@@ -371,7 +371,7 @@ impl PackageSolvingData {
371371
bumped_tx.input[i].witness.push(ser_sig);
372372
bumped_tx.input[i].witness.push(chan_keys.revocation_key.clone().serialize().to_vec());
373373
bumped_tx.input[i].witness.push(witness_script.clone().into_bytes());
374-
} else { return false; }
374+
} else { return Ok(false); }
375375
}
376376
},
377377
PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => {
@@ -404,7 +404,7 @@ impl PackageSolvingData {
404404
},
405405
_ => { panic!("API Error!"); }
406406
}
407-
true
407+
Ok(true)
408408
}
409409
fn get_finalized_tx<Signer: Sign>(&self, outpoint: &BitcoinOutPoint, onchain_handler: &mut OnchainTxHandler<Signer>) -> Result<Option<Transaction>, SignError> {
410410
match self {
@@ -630,7 +630,7 @@ impl PackageTemplate {
630630
}
631631
for (i, (outpoint, out)) in self.inputs.iter().enumerate() {
632632
log_debug!(logger, "Adding claiming input for outpoint {}:{}", outpoint.txid, outpoint.vout);
633-
if !out.finalize_input(&mut bumped_tx, i, onchain_handler) { return Ok(None); }
633+
if !out.finalize_input(&mut bumped_tx, i, onchain_handler)? { return Ok(None); }
634634
}
635635
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
636636
return Ok(Some(bumped_tx));

lightning/src/util/enforcing_trait_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ impl BaseSign for EnforcingSigner {
172172
Ok(self.inner.unsafe_sign_holder_commitment_and_htlcs(commitment_tx, secp_ctx).unwrap())
173173
}
174174

175-
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
175+
fn sign_justice_revoked_output(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, SignError> {
176176
Ok(self.inner.sign_justice_revoked_output(justice_tx, input, amount, per_commitment_key, secp_ctx).unwrap())
177177
}
178178

179-
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, ()> {
179+
fn sign_justice_revoked_htlc(&self, justice_tx: &Transaction, input: usize, amount: u64, per_commitment_key: &SecretKey, htlc: &HTLCOutputInCommitment, secp_ctx: &Secp256k1<secp256k1::All>) -> Result<Signature, SignError> {
180180
Ok(self.inner.sign_justice_revoked_htlc(justice_tx, input, amount, per_commitment_key, htlc, secp_ctx).unwrap())
181181
}
182182

0 commit comments

Comments
 (0)