Skip to content

Commit a063ba1

Browse files
author
Antoine Riard
committed
Rename InputMaterial script to witness_script
1 parent da8f8e4 commit a063ba1

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
@@ -452,21 +452,21 @@ struct LocalSignedTx {
452452
#[derive(Clone, PartialEq)]
453453
pub(crate) enum InputMaterial {
454454
Revoked {
455-
script: Script,
455+
witness_script: Script,
456456
pubkey: Option<PublicKey>,
457457
key: SecretKey,
458458
is_htlc: bool,
459459
revoked_amount: u64,
460460
},
461461
RemoteHTLC {
462-
script: Script,
462+
witness_script: Script,
463463
key: SecretKey,
464464
preimage: Option<PaymentPreimage>,
465465
remote_amount: u64,
466466
locktime: u32,
467467
},
468468
LocalHTLC {
469-
script: Script,
469+
witness_script: Script,
470470
sigs: (Signature, Signature),
471471
preimage: Option<PaymentPreimage>,
472472
local_amount: u64,
@@ -476,9 +476,9 @@ pub(crate) enum InputMaterial {
476476
impl Writeable for InputMaterial {
477477
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
478478
match self {
479-
&InputMaterial::Revoked { ref script, ref pubkey, ref key, ref is_htlc, ref revoked_amount} => {
479+
&InputMaterial::Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc, ref revoked_amount} => {
480480
writer.write_all(&[0; 1])?;
481-
script.write(writer)?;
481+
witness_script.write(writer)?;
482482
pubkey.write(writer)?;
483483
writer.write_all(&key[..])?;
484484
if *is_htlc {
@@ -488,17 +488,17 @@ impl Writeable for InputMaterial {
488488
}
489489
writer.write_all(&byte_utils::be64_to_array(*revoked_amount))?;
490490
},
491-
&InputMaterial::RemoteHTLC { ref script, ref key, ref preimage, ref remote_amount, ref locktime } => {
491+
&InputMaterial::RemoteHTLC { ref witness_script, ref key, ref preimage, ref remote_amount, ref locktime } => {
492492
writer.write_all(&[1; 1])?;
493-
script.write(writer)?;
493+
witness_script.write(writer)?;
494494
key.write(writer)?;
495495
preimage.write(writer)?;
496496
writer.write_all(&byte_utils::be64_to_array(*remote_amount))?;
497497
writer.write_all(&byte_utils::be32_to_array(*locktime))?;
498498
},
499-
&InputMaterial::LocalHTLC { ref script, ref sigs, ref preimage, ref local_amount } => {
499+
&InputMaterial::LocalHTLC { ref witness_script, ref sigs, ref preimage, ref local_amount } => {
500500
writer.write_all(&[2; 1])?;
501-
script.write(writer)?;
501+
witness_script.write(writer)?;
502502
sigs.0.write(writer)?;
503503
sigs.1.write(writer)?;
504504
preimage.write(writer)?;
@@ -513,7 +513,7 @@ impl<R: ::std::io::Read> Readable<R> for InputMaterial {
513513
fn read(reader: &mut R) -> Result<Self, DecodeError> {
514514
let input_material = match <u8 as Readable<R>>::read(reader)? {
515515
0 => {
516-
let script = Readable::read(reader)?;
516+
let witness_script = Readable::read(reader)?;
517517
let pubkey = Readable::read(reader)?;
518518
let key = Readable::read(reader)?;
519519
let is_htlc = match <u8 as Readable<R>>::read(reader)? {
@@ -523,35 +523,35 @@ impl<R: ::std::io::Read> Readable<R> for InputMaterial {
523523
};
524524
let revoked_amount = Readable::read(reader)?;
525525
InputMaterial::Revoked {
526-
script,
526+
witness_script,
527527
pubkey,
528528
key,
529529
is_htlc,
530530
revoked_amount
531531
}
532532
},
533533
1 => {
534-
let script = Readable::read(reader)?;
534+
let witness_script = Readable::read(reader)?;
535535
let key = Readable::read(reader)?;
536536
let preimage = Readable::read(reader)?;
537537
let remote_amount = Readable::read(reader)?;
538538
let locktime = Readable::read(reader)?;
539539
InputMaterial::RemoteHTLC {
540-
script,
540+
witness_script,
541541
key,
542542
preimage,
543543
remote_amount,
544544
locktime
545545
}
546546
},
547547
2 => {
548-
let script = Readable::read(reader)?;
548+
let witness_script = Readable::read(reader)?;
549549
let their_sig = Readable::read(reader)?;
550550
let our_sig = Readable::read(reader)?;
551551
let preimage = Readable::read(reader)?;
552552
let local_amount = Readable::read(reader)?;
553553
InputMaterial::LocalHTLC {
554-
script,
554+
witness_script,
555555
sigs: (their_sig, our_sig),
556556
preimage,
557557
local_amount
@@ -1464,7 +1464,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14641464
// First, process non-htlc outputs (to_local & to_remote)
14651465
for (idx, outp) in tx.output.iter().enumerate() {
14661466
if outp.script_pubkey == revokeable_p2wsh {
1467-
let witness_data = InputMaterial::Revoked { script: revokeable_redeemscript.clone(), pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: outp.value };
1467+
let witness_data = InputMaterial::Revoked { witness_script: revokeable_redeemscript.clone(), pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: outp.value };
14681468
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});
14691469
} else if Some(&outp.script_pubkey) == local_payment_p2wpkh.as_ref() {
14701470
spendable_descriptor = Some(SpendableOutputDescriptor::DynamicOutputP2WPKH {
@@ -1485,7 +1485,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14851485
tx.output[transaction_output_index as usize].script_pubkey != expected_script.to_v0_p2wsh() {
14861486
return (claim_requests_per_txid, (commitment_txid, watch_outputs), spendable_descriptor); // Corrupted per_commitment_data, fuck this user
14871487
}
1488-
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 };
1488+
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 };
14891489
outpoints.push(ClaimRequest { absolute_timelock: htlc.cltv_expiry, aggregable: true, outpoint: BitcoinOutPoint { txid: commitment_txid, vout: transaction_output_index }, witness_data });
14901490
}
14911491
}
@@ -1649,7 +1649,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16491649
let preimage = if htlc.offered { if let Some(p) = self.payment_preimages.get(&htlc.payment_hash) { Some(*p) } else { None } } else { None };
16501650
let aggregable = if !htlc.offered { false } else { true };
16511651
if preimage.is_some() || !htlc.offered {
1652-
let witness_data = InputMaterial::RemoteHTLC { script: expected_script, key: htlc_privkey, preimage, remote_amount: htlc.amount_msat / 1000, locktime: htlc.cltv_expiry };
1652+
let witness_data = InputMaterial::RemoteHTLC { witness_script: expected_script, key: htlc_privkey, preimage, remote_amount: htlc.amount_msat / 1000, locktime: htlc.cltv_expiry };
16531653
outpoints.push(ClaimRequest { absolute_timelock: htlc.cltv_expiry, aggregable, outpoint: BitcoinOutPoint { txid: commitment_txid, vout: transaction_output_index }, witness_data });
16541654
}
16551655
}
@@ -1705,7 +1705,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17051705
let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
17061706

17071707
log_trace!(self, "Remote HTLC broadcast {}:{}", htlc_txid, 0);
1708-
let witness_data = InputMaterial::Revoked { script: redeemscript, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: tx.output[0].value };
1708+
let witness_data = InputMaterial::Revoked { witness_script: redeemscript, pubkey: Some(revocation_pubkey), key: revocation_key, is_htlc: false, revoked_amount: tx.output[0].value };
17091709
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 });
17101710
let mut claimable_outpoints = HashMap::with_capacity(1);
17111711
claimable_outpoints.insert(htlc_txid, outpoints);
@@ -1755,7 +1755,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17551755

17561756
add_dynamic_output!(htlc_timeout_tx, 0);
17571757
let mut per_input_material = HashMap::with_capacity(1);
1758-
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});
1758+
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});
17591759
//TODO: with option_simplified_commitment track outpoint too
17601760
log_trace!(self, "Outpoint {}:{} is being being claimed", htlc_timeout_tx.input[0].previous_output.vout, htlc_timeout_tx.input[0].previous_output.txid);
17611761
res.push(htlc_timeout_tx);
@@ -1771,7 +1771,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
17711771

17721772
add_dynamic_output!(htlc_success_tx, 0);
17731773
let mut per_input_material = HashMap::with_capacity(1);
1774-
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});
1774+
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});
17751775
//TODO: with option_simplified_commitment track outpoint too
17761776
log_trace!(self, "Outpoint {}:{} is being being claimed", htlc_success_tx.input[0].previous_output.vout, htlc_success_tx.input[0].previous_output.txid);
17771777
res.push(htlc_success_tx);

lightning/src/ln/onchaintx.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ impl OnchainTxHandler {
400400
let mut total_amount = 0;
401401
for per_outp_material in cached_claim_datas.per_input_material.values() {
402402
match per_outp_material {
403-
&InputMaterial::Revoked { ref script, ref is_htlc, ref revoked_amount, .. } => {
404-
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 { &[] });
403+
&InputMaterial::Revoked { ref witness_script, ref is_htlc, ref revoked_amount, .. } => {
404+
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 { &[] });
405405
total_amount += *revoked_amount;
406406
},
407407
&InputMaterial::RemoteHTLC { ref preimage, ref remote_amount, .. } => {
@@ -434,9 +434,9 @@ impl OnchainTxHandler {
434434

435435
for (i, (outp, per_outp_material)) in cached_claim_datas.per_input_material.iter().enumerate() {
436436
match per_outp_material {
437-
&InputMaterial::Revoked { ref script, ref pubkey, ref key, ref is_htlc, ref revoked_amount } => {
437+
&InputMaterial::Revoked { ref witness_script, ref pubkey, ref key, ref is_htlc, ref revoked_amount } => {
438438
let sighash_parts = bip143::SighashComponents::new(&bumped_tx);
439-
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &script, *revoked_amount)[..]);
439+
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &witness_script, *revoked_amount)[..]);
440440
let sig = self.secp_ctx.sign(&sighash, &key);
441441
bumped_tx.input[i].witness.push(sig.serialize_der().to_vec());
442442
bumped_tx.input[i].witness[0].push(SigHashType::All as u8);
@@ -445,13 +445,13 @@ impl OnchainTxHandler {
445445
} else {
446446
bumped_tx.input[i].witness.push(vec!(1));
447447
}
448-
bumped_tx.input[i].witness.push(script.clone().into_bytes());
449-
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);
448+
bumped_tx.input[i].witness.push(witness_script.clone().into_bytes());
449+
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);
450450
},
451-
&InputMaterial::RemoteHTLC { ref script, ref key, ref preimage, ref remote_amount, ref locktime } => {
451+
&InputMaterial::RemoteHTLC { ref witness_script, ref key, ref preimage, ref remote_amount, ref locktime } => {
452452
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
453453
let sighash_parts = bip143::SighashComponents::new(&bumped_tx);
454-
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &script, *remote_amount)[..]);
454+
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[i], &witness_script, *remote_amount)[..]);
455455
let sig = self.secp_ctx.sign(&sighash, &key);
456456
bumped_tx.input[i].witness.push(sig.serialize_der().to_vec());
457457
bumped_tx.input[i].witness[0].push(SigHashType::All as u8);
@@ -460,7 +460,7 @@ impl OnchainTxHandler {
460460
} else {
461461
bumped_tx.input[i].witness.push(vec![0]);
462462
}
463-
bumped_tx.input[i].witness.push(script.clone().into_bytes());
463+
bumped_tx.input[i].witness.push(witness_script.clone().into_bytes());
464464
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);
465465
},
466466
&InputMaterial::LocalHTLC { .. } => {

0 commit comments

Comments
 (0)