Skip to content

Commit f48d1c3

Browse files
author
Antoine Riard
committed
Add RBF-bumping of preimage/timeout txn on remote HTLC outputs
Given they are only signed by us we can RBF at wish
1 parent e3f0133 commit f48d1c3

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/ln/channelmonitor.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,10 @@ impl ChannelMonitor {
25332533
inputs_witnesses_weight += Self::get_witnesses_weight(if !is_htlc { &[InputDescriptors::RevokedOutput] } else if script.len() == OFFERED_HTLC_SCRIPT_WEIGHT { &[InputDescriptors::RevokedOfferedHTLC] } else if script.len() == ACCEPTED_HTLC_SCRIPT_WEIGHT { &[InputDescriptors::RevokedReceivedHTLC] } else { &[] });
25342534
amt = *amount;
25352535
},
2536-
&TxMaterial::RemoteHTLC { .. } => {},
2536+
&TxMaterial::RemoteHTLC { ref preimage, ref amount, .. } => {
2537+
inputs_witnesses_weight += Self::get_witnesses_weight(if preimage.is_some() { &[InputDescriptors::OfferedHTLC] } else { &[InputDescriptors::ReceivedHTLC] });
2538+
amt = *amount;
2539+
},
25372540
&TxMaterial::LocalHTLC { .. } => {},
25382541
}
25392542
}
@@ -2564,7 +2567,20 @@ impl ChannelMonitor {
25642567
bumped_tx.input[i].witness.push(script.clone().into_bytes());
25652568
log_trace!(self, "Going to broadcast bumped Penalty Transaction {} claiming revoked {} output {} from {} with new feerate {}", bumped_tx.txid(), if !is_htlc { "to_local" } else if script.len() == OFFERED_HTLC_SCRIPT_WEIGHT { "offered" } else if script.len() == ACCEPTED_HTLC_SCRIPT_WEIGHT { "received" } else { "" }, vout, txid, new_feerate);
25662569
},
2567-
&TxMaterial::RemoteHTLC { .. } => {},
2570+
&TxMaterial::RemoteHTLC { ref script, ref key, ref preimage, ref amount } => {
2571+
let sighash_parts = bip143::SighashComponents::new(&bumped_tx);
2572+
let sighash = hash_to_message!(&sighash_parts.sighash_all(&bumped_tx.input[0], &script, *amount)[..]);
2573+
let sig = self.secp_ctx.sign(&sighash, &key);
2574+
bumped_tx.input[0].witness.push(sig.serialize_der().to_vec());
2575+
bumped_tx.input[0].witness[0].push(SigHashType::All as u8);
2576+
if let &Some(preimage) = preimage {
2577+
bumped_tx.input[0].witness.push(preimage.clone().0.to_vec());
2578+
} else {
2579+
bumped_tx.input[0].witness.push(vec![0]);
2580+
}
2581+
bumped_tx.input[0].witness.push(script.clone().into_bytes());
2582+
log_trace!(self, "Going to broadcast bumped Claim Transaction {} claiming remote htlc output {} from {} with new feerate {}", bumped_tx.txid(), vout, txid, new_feerate);
2583+
},
25682584
&TxMaterial::LocalHTLC { .. } => {
25692585
//TODO : Given that Local Commitment Transaction and HTLC-Timeout/HTLC-Success are counter-signed by peer, we can't
25702586
// RBF them. Need a Lightning specs change and package relay modification :

0 commit comments

Comments
 (0)