Skip to content

Commit a4a5e01

Browse files
author
Antoine Riard
committed
Rename InputMaterial script to witness_script
1 parent e8cb076 commit a4a5e01

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
amount: u64,
459459
},
460460
RemoteHTLC {
461-
script: Script,
461+
witness_script: Script,
462462
key: SecretKey,
463463
preimage: Option<PaymentPreimage>,
464464
amount: u64,
465465
locktime: u32,
466466
},
467467
LocalHTLC {
468-
script: Script,
468+
witness_script: Script,
469469
sigs: (Signature, Signature),
470470
preimage: Option<PaymentPreimage>,
471471
amount: u64,
@@ -475,25 +475,25 @@ 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 amount} => {
478+
&InputMaterial::Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc, ref 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
is_htlc.write(writer)?;
484484
writer.write_all(&byte_utils::be64_to_array(*amount))?;
485485
},
486-
&InputMaterial::RemoteHTLC { ref script, ref key, ref preimage, ref amount, ref locktime } => {
486+
&InputMaterial::RemoteHTLC { ref witness_script, ref key, ref preimage, ref amount, ref locktime } => {
487487
writer.write_all(&[1; 1])?;
488-
script.write(writer)?;
488+
witness_script.write(writer)?;
489489
key.write(writer)?;
490490
preimage.write(writer)?;
491491
writer.write_all(&byte_utils::be64_to_array(*amount))?;
492492
writer.write_all(&byte_utils::be32_to_array(*locktime))?;
493493
},
494-
&InputMaterial::LocalHTLC { ref script, ref sigs, ref preimage, ref amount } => {
494+
&InputMaterial::LocalHTLC { ref witness_script, ref sigs, ref preimage, ref amount } => {
495495
writer.write_all(&[2; 1])?;
496-
script.write(writer)?;
496+
witness_script.write(writer)?;
497497
sigs.0.write(writer)?;
498498
sigs.1.write(writer)?;
499499
preimage.write(writer)?;
@@ -508,41 +508,41 @@ impl Readable for InputMaterial {
508508
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
509509
let input_material = match <u8 as Readable>::read(reader)? {
510510
0 => {
511-
let script = Readable::read(reader)?;
511+
let witness_script = Readable::read(reader)?;
512512
let pubkey = Readable::read(reader)?;
513513
let key = Readable::read(reader)?;
514514
let is_htlc = Readable::read(reader)?;
515515
let amount = Readable::read(reader)?;
516516
InputMaterial::Revoked {
517-
script,
517+
witness_script,
518518
pubkey,
519519
key,
520520
is_htlc,
521521
amount
522522
}
523523
},
524524
1 => {
525-
let script = Readable::read(reader)?;
525+
let witness_script = Readable::read(reader)?;
526526
let key = Readable::read(reader)?;
527527
let preimage = Readable::read(reader)?;
528528
let amount = Readable::read(reader)?;
529529
let locktime = Readable::read(reader)?;
530530
InputMaterial::RemoteHTLC {
531-
script,
531+
witness_script,
532532
key,
533533
preimage,
534534
amount,
535535
locktime
536536
}
537537
},
538538
2 => {
539-
let script = Readable::read(reader)?;
539+
let witness_script = Readable::read(reader)?;
540540
let their_sig = Readable::read(reader)?;
541541
let our_sig = Readable::read(reader)?;
542542
let preimage = Readable::read(reader)?;
543543
let amount = Readable::read(reader)?;
544544
InputMaterial::LocalHTLC {
545-
script,
545+
witness_script,
546546
sigs: (their_sig, our_sig),
547547
preimage,
548548
amount
@@ -1461,7 +1461,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14611461
// First, process non-htlc outputs (to_local & to_remote)
14621462
for (idx, outp) in tx.output.iter().enumerate() {
14631463
if outp.script_pubkey == revokeable_p2wsh {
1464-
let witness_data = InputMaterial::Revoked { script: revokeable_redeemscript.clone(), pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, amount: outp.value };
1464+
let witness_data = InputMaterial::Revoked { witness_script: revokeable_redeemscript.clone(), pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, amount: outp.value };
14651465
claimable_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});
14661466
} else if Some(&outp.script_pubkey) == local_payment_p2wpkh.as_ref() {
14671467
spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WPKH {
@@ -1482,7 +1482,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14821482
tx.output[transaction_output_index as usize].script_pubkey != expected_script.to_v0_p2wsh() {
14831483
return (claimable_outpoints, (commitment_txid, watch_outputs), spendable_outputs); // Corrupted per_commitment_data, fuck this user
14841484
}
1485-
let witness_data = InputMaterial::Revoked { script: expected_script, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: true, amount: tx.output[transaction_output_index as usize].value };
1485+
let witness_data = InputMaterial::Revoked { witness_script: expected_script, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: true, amount: tx.output[transaction_output_index as usize].value };
14861486
claimable_outpoints.push(ClaimRequest { absolute_timelock: htlc.cltv_expiry, aggregable: true, outpoint: BitcoinOutPoint { txid: commitment_txid, vout: transaction_output_index }, witness_data });
14871487
}
14881488
}
@@ -1646,7 +1646,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16461646
let preimage = if htlc.offered { if let Some(p) = self.payment_preimages.get(&htlc.payment_hash) { Some(*p) } else { None } } else { None };
16471647
let aggregable = if !htlc.offered { false } else { true };
16481648
if preimage.is_some() || !htlc.offered {
1649-
let witness_data = InputMaterial::RemoteHTLC { script: expected_script, key: htlc_privkey, preimage, amount: htlc.amount_msat / 1000, locktime: htlc.cltv_expiry };
1649+
let witness_data = InputMaterial::RemoteHTLC { witness_script: expected_script, key: htlc_privkey, preimage, amount: htlc.amount_msat / 1000, locktime: htlc.cltv_expiry };
16501650
claimable_outpoints.push(ClaimRequest { absolute_timelock: htlc.cltv_expiry, aggregable, outpoint: BitcoinOutPoint { txid: commitment_txid, vout: transaction_output_index }, witness_data });
16511651
}
16521652
}
@@ -1701,7 +1701,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17011701
let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
17021702

17031703
log_trace!(self, "Remote HTLC broadcast {}:{}", htlc_txid, 0);
1704-
let witness_data = InputMaterial::Revoked { script: redeemscript, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, amount: tx.output[0].value };
1704+
let witness_data = InputMaterial::Revoked { witness_script: redeemscript, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, amount: tx.output[0].value };
17051705
let claimable_outpoints = vec!(ClaimRequest { absolute_timelock: height + self.our_to_self_delay as u32, aggregable: true, outpoint: BitcoinOutPoint { txid: htlc_txid, vout: 0}, witness_data });
17061706
claimable_outpoints
17071707
}
@@ -1749,7 +1749,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17491749

17501750
add_dynamic_output!(htlc_timeout_tx, 0);
17511751
let mut per_input_material = HashMap::with_capacity(1);
1752-
per_input_material.insert(htlc_timeout_tx.input[0].previous_output, InputMaterial::LocalHTLC { script: htlc_script, sigs: (*their_sig, our_sig), preimage: None, amount: htlc.amount_msat / 1000});
1752+
per_input_material.insert(htlc_timeout_tx.input[0].previous_output, InputMaterial::LocalHTLC { witness_script: htlc_script, sigs: (*their_sig, our_sig), preimage: None, amount: htlc.amount_msat / 1000});
17531753
//TODO: with option_simplified_commitment track outpoint too
17541754
log_trace!(self, "Outpoint {}:{} is being being claimed", htlc_timeout_tx.input[0].previous_output.vout, htlc_timeout_tx.input[0].previous_output.txid);
17551755
res.push(htlc_timeout_tx);
@@ -1765,7 +1765,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17651765

17661766
add_dynamic_output!(htlc_success_tx, 0);
17671767
let mut per_input_material = HashMap::with_capacity(1);
1768-
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), amount: htlc.amount_msat / 1000});
1768+
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), amount: htlc.amount_msat / 1000});
17691769
//TODO: with option_simplified_commitment track outpoint too
17701770
log_trace!(self, "Outpoint {}:{} is being being claimed", htlc_success_tx.input[0].previous_output.vout, htlc_success_tx.input[0].previous_output.txid);
17711771
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 amt = 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 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 { unreachable!() });
405+
&InputMaterial::Revoked { ref witness_script, ref is_htlc, ref 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 { unreachable!() });
407407
amt += *amount;
408408
},
409409
&InputMaterial::RemoteHTLC { ref preimage, ref 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 amount } => {
439+
&InputMaterial::Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc, ref 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, *amount)[..]);
441+
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &witness_script, *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 amount, ref locktime } => {
453+
&InputMaterial::RemoteHTLC { ref witness_script, ref key, ref preimage, ref 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, *amount)[..]);
456+
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &witness_script, *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)