Skip to content

Commit 7796735

Browse files
committed
WIP DROPME
We're failing fee calculation because we're missing information on the counterparty's change output.
1 parent 282605b commit 7796735

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

src/event.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,7 @@ where
13871387
former_temporary_channel_id,
13881388
counterparty_node_id,
13891389
funding_txo,
1390+
funding_redeem_script,
13901391
..
13911392
} => {
13921393
log_info!(
@@ -1396,6 +1397,24 @@ where
13961397
counterparty_node_id,
13971398
);
13981399

1400+
if let Some(channel_details) = self
1401+
.channel_manager
1402+
.list_channels()
1403+
.iter()
1404+
.find(|c| c.user_channel_id == user_channel_id)
1405+
{
1406+
let channel_value_satoshis = channel_details.channel_value_satoshis;
1407+
eprintln!("REDEEM: {:?}", funding_redeem_script);
1408+
if let Some(redeem_script) = funding_redeem_script {
1409+
let funding_output = bitcoin::TxOut {
1410+
value: bitcoin::Amount::from_sat(channel_value_satoshis),
1411+
script_pubkey: redeem_script.to_p2wsh(),
1412+
};
1413+
eprintln!("FUNDING_TXO: {:?}", funding_txo);
1414+
let res = self.wallet.insert_txo(funding_txo, funding_output);
1415+
eprintln!("RES: {:?}", res);
1416+
}
1417+
}
13991418
let event = Event::ChannelPending {
14001419
channel_id,
14011420
user_channel_id: UserChannelId(user_channel_id),

src/wallet/mod.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ impl Wallet {
240240
for event in events {
241241
match event {
242242
WalletEvent::TxConfirmed { txid, tx, block_time, .. } => {
243+
eprintln!("TX_CONFIRMED: {}", txid);
243244
let cur_height = locked_wallet.latest_checkpoint().height();
244245
let confirmation_height = block_time.block_id.height;
245246
let payment_status = if cur_height >= confirmation_height + ANTI_REORG_DELAY - 1
@@ -275,6 +276,7 @@ impl Wallet {
275276
self.pending_payment_store.insert_or_update(pending_payment)?;
276277
},
277278
WalletEvent::ChainTipChanged { new_tip, .. } => {
279+
eprint!(".");
278280
// Get all payments that are Pending with Confirmed status
279281
let pending_payments: Vec<PendingPaymentDetails> =
280282
self.pending_payment_store.list_filter(|p| {
@@ -304,6 +306,7 @@ impl Wallet {
304306
}
305307
},
306308
WalletEvent::TxUnconfirmed { txid, tx, old_block_time: None } => {
309+
eprintln!("TX_UNCONFIRMED: {}", txid);
307310
let payment_id = self
308311
.find_payment_by_txid(txid)
309312
.unwrap_or_else(|| PaymentId(txid.to_byte_array()));
@@ -322,6 +325,7 @@ impl Wallet {
322325
self.pending_payment_store.insert_or_update(pending_payment)?;
323326
},
324327
WalletEvent::TxReplaced { txid, conflicts, tx, .. } => {
328+
eprintln!("TX_REPLACED: {}", txid);
325329
let payment_id = self
326330
.find_payment_by_txid(txid)
327331
.unwrap_or_else(|| PaymentId(txid.to_byte_array()));
@@ -344,6 +348,7 @@ impl Wallet {
344348
self.pending_payment_store.insert_or_update(pending_payment_details)?;
345349
},
346350
WalletEvent::TxDropped { txid, tx } => {
351+
eprintln!("TX_DROPPED: {}", txid);
347352
let payment_id = self
348353
.find_payment_by_txid(txid)
349354
.unwrap_or_else(|| PaymentId(txid.to_byte_array()));
@@ -404,17 +409,27 @@ impl Wallet {
404409
},
405410
}
406411

412+
let tx = psbt.extract_tx().map_err(|e| {
413+
log_error!(self.logger, "Failed to extract transaction: {}", e);
414+
e
415+
})?;
416+
417+
eprintln!("FUNDING: {}", tx.txid());
418+
log_error!(self.logger, "FUNDING: {}", tx.txid());
419+
420+
let now = std::time::SystemTime::now()
421+
.duration_since(std::time::SystemTime::UNIX_EPOCH)
422+
.unwrap()
423+
.as_secs();
424+
let unconfirmed_txs = vec![(Arc::new(tx.clone()), now)];
425+
locked_wallet.apply_unconfirmed_txs(unconfirmed_txs);
426+
407427
let mut locked_persister = self.persister.lock().unwrap();
408428
locked_wallet.persist(&mut locked_persister).map_err(|e| {
409429
log_error!(self.logger, "Failed to persist wallet: {}", e);
410430
Error::PersistenceFailed
411431
})?;
412432

413-
let tx = psbt.extract_tx().map_err(|e| {
414-
log_error!(self.logger, "Failed to extract transaction: {}", e);
415-
e
416-
})?;
417-
418433
Ok(tx)
419434
}
420435

@@ -956,7 +971,14 @@ impl Wallet {
956971

957972
let kind = PaymentKind::Onchain { txid, status: confirmation_status };
958973

959-
let fee = locked_wallet.calculate_fee(tx).unwrap_or(Amount::ZERO);
974+
let fee = locked_wallet.calculate_fee(tx);
975+
for out in &tx.input {
976+
eprintln!("PREV_OUT: {:?}", out.previous_output);
977+
log_error!(self.logger, "PREV_OUT: {:?}", out.previous_output);
978+
}
979+
eprintln!("FEE RES: {:?}", fee);
980+
log_error!(self.logger, "FEE RES: {:?}", fee);
981+
let fee = fee.unwrap_or(Amount::ZERO);
960982
let (sent, received) = locked_wallet.sent_and_received(tx);
961983
let fee_sat = fee.to_sat();
962984

tests/common/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ pub(crate) async fn distribute_funds_unconfirmed<E: ElectrumApi>(
607607
.unwrap()
608608
.parse()
609609
.unwrap();
610+
eprintln!("DIST: {}", txid);
610611

611612
wait_for_tx(electrs, txid).await;
612613

tests/integration_tests_rust.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ async fn start_stop_reinit() {
293293
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
294294
async fn onchain_send_receive() {
295295
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
296-
let chain_source = random_chain_source(&bitcoind, &electrsd);
296+
//let chain_source = random_chain_source(&bitcoind, &electrsd);
297+
let chain_source = TestChainSource::BitcoindRpcSync(&bitcoind);
297298
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
298299

299300
let addr_a = node_a.onchain_payment().new_address().unwrap();
@@ -381,6 +382,7 @@ async fn onchain_send_receive() {
381382
let txid =
382383
node_b.onchain_payment().send_to_address(&addr_a, amount_to_send_sats, None).unwrap();
383384
wait_for_tx(&electrsd.client, txid).await;
385+
//generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 1).await;
384386
node_a.sync_wallets().unwrap();
385387
node_b.sync_wallets().unwrap();
386388

@@ -407,7 +409,7 @@ async fn onchain_send_receive() {
407409
assert_eq!(payment_a.amount_msat, payment_b.amount_msat);
408410
assert_eq!(payment_a.fee_paid_msat, payment_b.fee_paid_msat);
409411

410-
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6).await;
412+
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 5).await;
411413
node_a.sync_wallets().unwrap();
412414
node_b.sync_wallets().unwrap();
413415

0 commit comments

Comments
 (0)