Skip to content

Commit 1eca8a8

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 31c12f9 commit 1eca8a8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,15 @@ impl Node {
13191319
},
13201320
};
13211321

1322+
// insert channel's funding utxo into the wallet so we can later calculate fees
1323+
// correctly when viewing this splice-in.
1324+
self.wallet.insert_txo(funding_txo.into_bitcoin_outpoint(), funding_output).map_err(
1325+
|e| {
1326+
log_error!(self.logger, "Failed to splice channel: {:?}", e);
1327+
Error::ChannelSplicingFailed
1328+
},
1329+
)?;
1330+
13221331
self.channel_manager
13231332
.splice_channel(
13241333
&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)