From 658123aa94670e24e81d88a439425974275b9ca2 Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 5 Dec 2024 11:32:56 +0800 Subject: [PATCH] fix invoice status --- src/fiber/channel.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/fiber/channel.rs b/src/fiber/channel.rs index 5850693b..c73636b4 100644 --- a/src/fiber/channel.rs +++ b/src/fiber/channel.rs @@ -663,7 +663,8 @@ where .apply_remove_tlc_operation(state, remove_tlc) .await .map_err(|e| { - error!("Error handling RemoveTlc command: {:?}", e); + debug!("error happened in apply_remove_tlc_operation: {:?}", e); + error!("Error handling apply_remove_tlc_operation: {:?}", e); }); } } @@ -740,10 +741,18 @@ where CkbInvoiceStatus::Paid => { unreachable!("Paid invoice shold not be paid again"); } - _ => {} + _ => { + self.store + .update_invoice_status(&tlc.payment_hash, CkbInvoiceStatus::Paid) + .expect("update invoice status error"); + } } } + debug!( + "register remove reason: {:?} with reason: {:?}", + tlc.tlc_id, remove_reason + ); self.register_tlc_remove(state, tlc.tlc_id, remove_reason); } @@ -903,15 +912,6 @@ where let channel_id = state.get_id(); let remove_reason = remove_tlc.reason.clone(); let tlc_info = state.remove_tlc_with_reason(remove_tlc.tlc_id, &remove_reason)?; - if let RemoveTlcReason::RemoveTlcFulfill(_) = remove_reason { - if let Some(invoice) = self.store.get_invoice(&tlc_info.payment_hash) { - let status = self.get_invoice_status(&invoice); - assert_eq!(status, CkbInvoiceStatus::Received); - self.store - .update_invoice_status(&tlc_info.payment_hash, CkbInvoiceStatus::Paid) - .expect("update invoice status failed"); - } - } if let ( Some(ref udt_type_script), RemoveTlcReason::RemoveTlcFulfill(RemoveTlcFulfill { payment_preimage }), @@ -4125,6 +4125,7 @@ impl ChannelActorState { self.to_remote_amount = to_remote_amount; debug!("Updated local balance to {} and remote balance to {} by removing tlc {:?} with reason {:?}", to_local_amount, to_remote_amount, tlc_id, reason); + self.tlc_state .apply_tlc_remove(tlc_id, removed_at, reason.clone()); current