Skip to content

Commit 9888ff3

Browse files
author
Antoine Riard
committed
Rename InputMaterial script to witness_script
1 parent 1eaa112 commit 9888ff3

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

lightning/src/ln/channelmonitor.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -451,21 +451,21 @@ struct LocalSignedTx {
451451
#[derive(Clone, PartialEq)]
452452
pub(crate) enum InputMaterial {
453453
Revoked {
454-
script: Script,
454+
witness_script: Script,
455455
pubkey: Option<PublicKey>,
456456
key: SecretKey,
457457
is_htlc: bool,
458458
revoked_amount: u64,
459459
},
460460
RemoteHTLC {
461-
script: Script,
461+
witness_script: Script,
462462
key: SecretKey,
463463
preimage: Option<PaymentPreimage>,
464464
remote_amount: u64,
465465
locktime: u32,
466466
},
467467
LocalHTLC {
468-
script: Script,
468+
witness_script: Script,
469469
sigs: (Signature, Signature),
470470
preimage: Option<PaymentPreimage>,
471471
local_amount: u64,
@@ -475,9 +475,9 @@ pub(crate) enum InputMaterial {
475475
impl Writeable for InputMaterial {
476476
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
477477
match self {
478-
&InputMaterial::Revoked { ref script, ref pubkey, ref key, ref is_htlc, ref revoked_amount} => {
478+
&InputMaterial::Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc, ref revoked_amount} => {
479479
writer.write_all(&[0; 1])?;
480-
script.write(writer)?;
480+
witness_script.write(writer)?;
481481
pubkey.write(writer)?;
482482
writer.write_all(&key[..])?;
483483
if *is_htlc {
@@ -487,17 +487,17 @@ impl Writeable for InputMaterial {
487487
}
488488
writer.write_all(&byte_utils::be64_to_array(*revoked_amount))?;
489489
},
490-
&InputMaterial::RemoteHTLC { ref script, ref key, ref preimage, ref remote_amount, ref locktime } => {
490+
&InputMaterial::RemoteHTLC { ref witness_script, ref key, ref preimage, ref remote_amount, ref locktime } => {
491491
writer.write_all(&[1; 1])?;
492-
script.write(writer)?;
492+
witness_script.write(writer)?;
493493
key.write(writer)?;
494494
preimage.write(writer)?;
495495
writer.write_all(&byte_utils::be64_to_array(*remote_amount))?;
496496
writer.write_all(&byte_utils::be32_to_array(*locktime))?;
497497
},
498-
&InputMaterial::LocalHTLC { ref script, ref sigs, ref preimage, ref local_amount } => {
498+
&InputMaterial::LocalHTLC { ref witness_script, ref sigs, ref preimage, ref local_amount } => {
499499
writer.write_all(&[2; 1])?;
500-
script.write(writer)?;
500+
witness_script.write(writer)?;
501501
sigs.0.write(writer)?;
502502
sigs.1.write(writer)?;
503503
preimage.write(writer)?;
@@ -512,7 +512,7 @@ impl<R: ::std::io::Read> Readable<R> for InputMaterial {
512512
fn read(reader: &mut R) -> Result<Self, DecodeError> {
513513
let input_material = match <u8 as Readable<R>>::read(reader)? {
514514
0 => {
515-
let script = Readable::read(reader)?;
515+
let witness_script = Readable::read(reader)?;
516516
let pubkey = Readable::read(reader)?;
517517
let key = Readable::read(reader)?;
518518
let is_htlc = match <u8 as Readable<R>>::read(reader)? {
@@ -522,35 +522,35 @@ impl<R: ::std::io::Read> Readable<R> for InputMaterial {
522522
};
523523
let revoked_amount = Readable::read(reader)?;
524524
InputMaterial::Revoked {
525-
script,
525+
witness_script,
526526
pubkey,
527527
key,
528528
is_htlc,
529529
revoked_amount
530530
}
531531
},
532532
1 => {
533-
let script = Readable::read(reader)?;
533+
let witness_script = Readable::read(reader)?;
534534
let key = Readable::read(reader)?;
535535
let preimage = Readable::read(reader)?;
536536
let remote_amount = Readable::read(reader)?;
537537
let locktime = Readable::read(reader)?;
538538
InputMaterial::RemoteHTLC {
539-
script,
539+
witness_script,
540540
key,
541541
preimage,
542542
remote_amount,
543543
locktime
544544
}
545545
},
546546
2 => {
547-
let script = Readable::read(reader)?;
547+
let witness_script = Readable::read(reader)?;
548548
let their_sig = Readable::read(reader)?;
549549
let our_sig = Readable::read(reader)?;
550550
let preimage = Readable::read(reader)?;
551551
let local_amount = Readable::read(reader)?;
552552
InputMaterial::LocalHTLC {
553-
script,
553+
witness_script,
554554
sigs: (their_sig, our_sig),
555555
preimage,
556556
local_amount
@@ -1488,7 +1488,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14881488
// First, process non-htlc outputs (to_local & to_remote)
14891489
for (idx, outp) in tx.output.iter().enumerate() {
14901490
if outp.script_pubkey == revokeable_p2wsh {
1491-
let witness_data = InputMaterial::Revoked { script: revokeable_redeemscript.clone(), pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: outp.value };
1491+
let witness_data = InputMaterial::Revoked { witness_script: revokeable_redeemscript.clone(), pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: outp.value };
14921492
outpoints.push(ClaimRequest { absolute_timelock: height + self.our_to_self_delay as u32, aggregable: true, outpoint: BitcoinOutPoint { txid: commitment_txid, vout: idx as u32 }, witness_data});
14931493
} else if Some(&outp.script_pubkey) == local_payment_p2wpkh.as_ref() {
14941494
spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WPKH {
@@ -1509,7 +1509,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
15091509
tx.output[transaction_output_index as usize].script_pubkey != expected_script.to_v0_p2wsh() {
15101510
return (claim_requests_per_txid, (commitment_txid, watch_outputs), spendable_outputs); // Corrupted per_commitment_data, fuck this user
15111511
}
1512-
let witness_data = InputMaterial::Revoked { script: expected_script, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: true, revoked_amount: tx.output[transaction_output_index as usize].value };
1512+
let witness_data = InputMaterial::Revoked { witness_script: expected_script, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: true, revoked_amount: tx.output[transaction_output_index as usize].value };
15131513
outpoints.push(ClaimRequest { absolute_timelock: htlc.cltv_expiry, aggregable: true, outpoint: BitcoinOutPoint { txid: commitment_txid, vout: transaction_output_index }, witness_data });
15141514
}
15151515
}
@@ -1673,7 +1673,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16731673
let preimage = if htlc.offered { if let Some(p) = self.payment_preimages.get(&htlc.payment_hash) { Some(*p) } else { None } } else { None };
16741674
let aggregable = if !htlc.offered { false } else { true };
16751675
if preimage.is_some() || !htlc.offered {
1676-
let witness_data = InputMaterial::RemoteHTLC { script: expected_script, key: htlc_privkey, preimage, remote_amount: htlc.amount_msat / 1000, locktime: htlc.cltv_expiry };
1676+
let witness_data = InputMaterial::RemoteHTLC { witness_script: expected_script, key: htlc_privkey, preimage, remote_amount: htlc.amount_msat / 1000, locktime: htlc.cltv_expiry };
16771677
outpoints.push(ClaimRequest { absolute_timelock: htlc.cltv_expiry, aggregable, outpoint: BitcoinOutPoint { txid: commitment_txid, vout: transaction_output_index }, witness_data });
16781678
}
16791679
}
@@ -1729,7 +1729,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17291729
let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
17301730

17311731
log_trace!(self, "Remote HTLC broadcast {}:{}", htlc_txid, 0);
1732-
let witness_data = InputMaterial::Revoked { script: redeemscript, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: tx.output[0].value };
1732+
let witness_data = InputMaterial::Revoked { witness_script: redeemscript, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: tx.output[0].value };
17331733
let outpoints = vec!(ClaimRequest { absolute_timelock: height + self.our_to_self_delay as u32, aggregable: true, outpoint: BitcoinOutPoint { txid: htlc_txid, vout: 0}, witness_data });
17341734
let mut claimable_outpoints = HashMap::with_capacity(1);
17351735
claimable_outpoints.insert(htlc_txid, outpoints);
@@ -1779,7 +1779,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17791779

17801780
add_dynamic_output!(htlc_timeout_tx, 0);
17811781
let mut per_input_material = HashMap::with_capacity(1);
1782-
per_input_material.insert(htlc_timeout_tx.input[0].previous_output, InputMaterial::LocalHTLC { script: htlc_script, sigs: (*their_sig, our_sig), preimage: None, local_amount: htlc.amount_msat / 1000});
1782+
per_input_material.insert(htlc_timeout_tx.input[0].previous_output, InputMaterial::LocalHTLC { witness_script: htlc_script, sigs: (*their_sig, our_sig), preimage: None, local_amount: htlc.amount_msat / 1000});
17831783
//TODO: with option_simplified_commitment track outpoint too
17841784
log_trace!(self, "Outpoint {}:{} is being being claimed", htlc_timeout_tx.input[0].previous_output.vout, htlc_timeout_tx.input[0].previous_output.txid);
17851785
res.push(htlc_timeout_tx);
@@ -1795,7 +1795,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17951795

17961796
add_dynamic_output!(htlc_success_tx, 0);
17971797
let mut per_input_material = HashMap::with_capacity(1);
1798-
per_input_material.insert(htlc_success_tx.input[0].previous_output, InputMaterial::LocalHTLC { script: htlc_script, sigs: (*their_sig, our_sig), preimage: Some(*payment_preimage), local_amount: htlc.amount_msat / 1000});
1798+
per_input_material.insert(htlc_success_tx.input[0].previous_output, InputMaterial::LocalHTLC { witness_script: htlc_script, sigs: (*their_sig, our_sig), preimage: Some(*payment_preimage), local_amount: htlc.amount_msat / 1000});
17991799
//TODO: with option_simplified_commitment track outpoint too
18001800
log_trace!(self, "Outpoint {}:{} is being being claimed", htlc_success_tx.input[0].previous_output.vout, htlc_success_tx.input[0].previous_output.txid);
18011801
res.push(htlc_success_tx);

lightning/src/ln/onchaintx.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ impl OnchainTxHandler {
402402
let mut total_amount = 0;
403403
for per_outp_material in cached_claim_datas.per_input_material.values() {
404404
match per_outp_material {
405-
&InputMaterial::Revoked { ref script, ref is_htlc, ref revoked_amount, .. } => {
406-
inputs_witnesses_weight += Self::get_witnesses_weight(if !is_htlc { &[InputDescriptors::RevokedOutput] } else if HTLCType::scriptlen_to_htlctype(script.len()) == Some(HTLCType::OfferedHTLC) { &[InputDescriptors::RevokedOfferedHTLC] } else if HTLCType::scriptlen_to_htlctype(script.len()) == Some(HTLCType::AcceptedHTLC) { &[InputDescriptors::RevokedReceivedHTLC] } else { &[] });
405+
&InputMaterial::Revoked { ref witness_script, ref is_htlc, ref revoked_amount, .. } => {
406+
inputs_witnesses_weight += Self::get_witnesses_weight(if !is_htlc { &[InputDescriptors::RevokedOutput] } else if HTLCType::scriptlen_to_htlctype(witness_script.len()) == Some(HTLCType::OfferedHTLC) { &[InputDescriptors::RevokedOfferedHTLC] } else if HTLCType::scriptlen_to_htlctype(witness_script.len()) == Some(HTLCType::AcceptedHTLC) { &[InputDescriptors::RevokedReceivedHTLC] } else { &[] });
407407
total_amount += *revoked_amount;
408408
},
409409
&InputMaterial::RemoteHTLC { ref preimage, ref remote_amount, .. } => {
@@ -436,9 +436,9 @@ impl OnchainTxHandler {
436436

437437
for (i, (outp, per_outp_material)) in cached_claim_datas.per_input_material.iter().enumerate() {
438438
match per_outp_material {
439-
&InputMaterial::Revoked { ref script, ref pubkey, ref key, ref is_htlc, ref revoked_amount } => {
439+
&InputMaterial::Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc, ref revoked_amount } => {
440440
let sighash_parts = bip143::SighashComponents::new(&bumped_tx);
441-
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &script, *revoked_amount)[..]);
441+
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &witness_script, *revoked_amount)[..]);
442442
let sig = self.secp_ctx.sign(&sighash, &key);
443443
bumped_tx.input[i].witness.push(sig.serialize_der().to_vec());
444444
bumped_tx.input[i].witness[0].push(SigHashType::All as u8);
@@ -447,13 +447,13 @@ impl OnchainTxHandler {
447447
} else {
448448
bumped_tx.input[i].witness.push(vec!(1));
449449
}
450-
bumped_tx.input[i].witness.push(script.clone().into_bytes());
451-
log_trace!(self, "Going to broadcast Penalty Transaction {} claiming revoked {} output {} from {} with new feerate {}...", bumped_tx.txid(), if !is_htlc { "to_local" } else if HTLCType::scriptlen_to_htlctype(script.len()) == Some(HTLCType::OfferedHTLC) { "offered" } else if HTLCType::scriptlen_to_htlctype(script.len()) == Some(HTLCType::AcceptedHTLC) { "received" } else { "" }, outp.vout, outp.txid, new_feerate);
450+
bumped_tx.input[i].witness.push(witness_script.clone().into_bytes());
451+
log_trace!(self, "Going to broadcast Penalty Transaction {} claiming revoked {} output {} from {} with new feerate {}...", bumped_tx.txid(), if !is_htlc { "to_local" } else if HTLCType::scriptlen_to_htlctype(witness_script.len()) == Some(HTLCType::OfferedHTLC) { "offered" } else if HTLCType::scriptlen_to_htlctype(witness_script.len()) == Some(HTLCType::AcceptedHTLC) { "received" } else { "" }, outp.vout, outp.txid, new_feerate);
452452
},
453-
&InputMaterial::RemoteHTLC { ref script, ref key, ref preimage, ref remote_amount, ref locktime } => {
453+
&InputMaterial::RemoteHTLC { ref witness_script, ref key, ref preimage, ref remote_amount, ref locktime } => {
454454
if !preimage.is_some() { bumped_tx.lock_time = *locktime }; // Right now we don't aggregate time-locked transaction, if we do we should set lock_time before to avoid breaking hash computation
455455
let sighash_parts = bip143::SighashComponents::new(&bumped_tx);
456-
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &script, *remote_amount)[..]);
456+
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &witness_script, *remote_amount)[..]);
457457
let sig = self.secp_ctx.sign(&sighash, &key);
458458
bumped_tx.input[i].witness.push(sig.serialize_der().to_vec());
459459
bumped_tx.input[i].witness[0].push(SigHashType::All as u8);
@@ -462,7 +462,7 @@ impl OnchainTxHandler {
462462
} else {
463463
bumped_tx.input[i].witness.push(vec![0]);
464464
}
465-
bumped_tx.input[i].witness.push(script.clone().into_bytes());
465+
bumped_tx.input[i].witness.push(witness_script.clone().into_bytes());
466466
log_trace!(self, "Going to broadcast Claim Transaction {} claiming remote {} htlc output {} from {} with new feerate {}...", bumped_tx.txid(), if preimage.is_some() { "offered" } else { "received" }, outp.vout, outp.txid, new_feerate);
467467
},
468468
&InputMaterial::LocalHTLC { .. } => {

0 commit comments

Comments
 (0)