Skip to content

Commit a8d00c7

Browse files
committed
Rename rgb_rename_files + restore return type
1 parent 167a2c4 commit a8d00c7

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use crate::ln::types::ChannelId;
7878
use crate::ln::LN_MAX_MSG_LEN;
7979
use crate::offers::static_invoice::StaticInvoice;
8080
use crate::rgb_utils::{
81-
color_closing, color_commitment, color_htlc, get_rgb_channel_info_pending, rename_rgb_files,
81+
color_closing, color_commitment, color_htlc, get_rgb_channel_info_pending, update_rgb_channel_id,
8282
update_rgb_channel_amount_pending, RgbKvStoreExt,
8383
};
8484
use crate::routing::gossip::NodeId;
@@ -3251,7 +3251,7 @@ where
32513251
let temporary_channel_id = context.channel_id;
32523252
context.channel_id = channel_id;
32533253
if context.is_colored() && temporary_channel_id != channel_id {
3254-
rename_rgb_files(&context.channel_id, &temporary_channel_id, context.rgb_kv_store.as_ref());
3254+
update_rgb_channel_id(&context.channel_id, &temporary_channel_id, context.rgb_kv_store.as_ref());
32553255
}
32563256

32573257
assert!(!context.channel_state.is_monitor_update_in_progress()); // We have not had any monitor(s) yet to fail update!
@@ -13703,7 +13703,7 @@ where
1370313703
let temporary_channel_id = self.context.channel_id;
1370413704
self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
1370513705
if self.context.is_colored() {
13706-
rename_rgb_files(&self.context.channel_id, &temporary_channel_id, self.context.rgb_kv_store.as_ref());
13706+
update_rgb_channel_id(&self.context.channel_id, &temporary_channel_id, self.context.rgb_kv_store.as_ref());
1370713707
}
1370813708

1370913709
// If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100.

lightning/src/ln/outbound_payment.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,7 @@ impl OutboundPayments {
10481048

10491049
let mut filtered_first_hops = first_hops.into_iter().collect::<Vec<_>>();
10501050
let rgb_payment = if self.rgb_kv_store.is_payment_rgb(&payment_hash) {
1051-
self.rgb_kv_store.filter_first_hops(&payment_hash, &mut filtered_first_hops);
1052-
let info = self.rgb_kv_store.read_rgb_payment_info(&payment_hash, false)
1053-
.expect("payment info must exist");
1054-
Some((info.contract_id, info.amount))
1051+
Some(self.rgb_kv_store.filter_first_hops(&payment_hash, &mut filtered_first_hops))
10551052
} else {
10561053
None
10571054
};

lightning/src/rgb_utils/mod.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ pub fn write_rgb_payment_info_file(
583583
.expect("able to write rgb payment info pending");
584584
}
585585

586-
/// Rename RGB channel info from temporary to final channel ID in KVStore
587-
pub(crate) fn rename_rgb_files(
586+
/// update RGB data from temporary to final channel ID in KVStore
587+
pub(crate) fn update_rgb_channel_id(
588588
channel_id: &ChannelId, temporary_channel_id: &ChannelId, kv_store: &dyn KVStoreSync,
589589
) {
590590
let temp_chan_id = temporary_channel_id.0.as_hex().to_string();
@@ -734,7 +734,7 @@ pub trait RgbKvStoreExt {
734734
/// filter first hops to only include channels with sufficient RGB assets
735735
fn filter_first_hops(
736736
&self, payment_hash: &PaymentHash, first_hops: &mut Vec<ChannelDetails>,
737-
);
737+
) -> (ContractId, u64);
738738
}
739739

740740
impl<K: KVStoreSync + ?Sized> RgbKvStoreExt for K {
@@ -806,11 +806,11 @@ impl<K: KVStoreSync + ?Sized> RgbKvStoreExt for K {
806806
|| self.read_rgb_payment_info(payment_hash, true).is_ok()
807807
}
808808

809-
fn filter_first_hops(&self, payment_hash: &PaymentHash, first_hops: &mut Vec<ChannelDetails>) {
810-
let rgb_payment_info = match self.read_rgb_payment_info(payment_hash, false) {
811-
Ok(info) => info,
812-
Err(_) => return,
813-
};
809+
fn filter_first_hops(
810+
&self, payment_hash: &PaymentHash, first_hops: &mut Vec<ChannelDetails>,
811+
) -> (ContractId, u64) {
812+
let rgb_payment_info = self.read_rgb_payment_info(payment_hash, false)
813+
.expect("payment info must exist");
814814
let contract_id = rgb_payment_info.contract_id;
815815
let rgb_amount = rgb_payment_info.amount;
816816
first_hops.retain(|h| {
@@ -822,5 +822,6 @@ impl<K: KVStoreSync + ?Sized> RgbKvStoreExt for K {
822822
Err(_) => false,
823823
}
824824
});
825+
(contract_id, rgb_amount)
825826
}
826827
}

0 commit comments

Comments
 (0)