Skip to content

Commit 3c4236c

Browse files
committed
Insert channel funding utxo before a splice-in
We insert a channel's funding utxo into our wallet so we can later calculate the fees for the transaction, otherwise our wallet would have incomplete information. We do it before the splice-in and not just on the ChannelReady event to ensure better backwards compatibility.
1 parent 3fc4a43 commit 3c4236c

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ impl Node {
12851285

12861286
let shared_output = bitcoin::TxOut {
12871287
value: shared_input.previous_utxo.value + Amount::from_sat(splice_amount_sats),
1288-
script_pubkey: funding_output.script_pubkey,
1288+
script_pubkey: funding_output.script_pubkey.clone(),
12891289
};
12901290

12911291
let fee_rate = self.fee_estimator.estimate_fee_rate(ConfirmationTarget::ChannelFunding);
@@ -1317,6 +1317,15 @@ impl Node {
13171317
},
13181318
};
13191319

1320+
// insert channel's funding utxo into the wallet so we can later calculate fees
1321+
// correctly when viewing this splice-in.
1322+
self.wallet.insert_txo(funding_txo.into_bitcoin_outpoint(), funding_output).map_err(
1323+
|e| {
1324+
log_error!(self.logger, "Failed to splice channel: {:?}", e);
1325+
Error::ChannelSplicingFailed
1326+
},
1327+
)?;
1328+
13201329
self.channel_manager
13211330
.splice_channel(
13221331
&channel_details.channel_id,

src/wallet/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
2626
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
2727
use bitcoin::secp256k1::{All, PublicKey, Scalar, Secp256k1, SecretKey};
2828
use bitcoin::{
29-
Address, Amount, FeeRate, ScriptBuf, Transaction, TxOut, Txid, WPubkeyHash, Weight,
29+
Address, Amount, FeeRate, OutPoint, ScriptBuf, Transaction, TxOut, Txid, WPubkeyHash, Weight,
3030
WitnessProgram, WitnessVersion,
3131
};
3232
use lightning::chain::chaininterface::BroadcasterInterface;
@@ -153,6 +153,19 @@ impl Wallet {
153153
Ok(())
154154
}
155155

156+
pub(crate) fn insert_txo(&self, outpoint: OutPoint, txout: TxOut) -> Result<(), Error> {
157+
let mut locked_wallet = self.inner.lock().unwrap();
158+
locked_wallet.insert_txout(outpoint, txout);
159+
160+
let mut locked_persister = self.persister.lock().unwrap();
161+
locked_wallet.persist(&mut locked_persister).map_err(|e| {
162+
log_error!(self.logger, "Failed to persist wallet: {}", e);
163+
Error::PersistenceFailed
164+
})?;
165+
166+
Ok(())
167+
}
168+
156169
fn update_payment_store<'a>(
157170
&self, locked_wallet: &'a mut PersistedWallet<KVStoreWalletPersister>,
158171
) -> Result<(), Error> {

0 commit comments

Comments
 (0)