Skip to content

Commit 5ac1202

Browse files
committed
Rename rgb_rename_files + restore return type
1 parent 09b42b1 commit 5ac1202

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!
@@ -13694,7 +13694,7 @@ where
1369413694
let temporary_channel_id = self.context.channel_id;
1369513695
self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
1369613696
if self.context.is_colored() {
13697-
rename_rgb_files(&self.context.channel_id, &temporary_channel_id, self.context.rgb_kv_store.as_ref());
13697+
update_rgb_channel_id(&self.context.channel_id, &temporary_channel_id, self.context.rgb_kv_store.as_ref());
1369813698
}
1369913699

1370013700
// 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
@@ -573,8 +573,8 @@ pub fn write_rgb_payment_info_file(
573573
.expect("able to write rgb payment info pending");
574574
}
575575

576-
/// Rename RGB channel info from temporary to final channel ID in KVStore
577-
pub(crate) fn rename_rgb_files(
576+
/// update RGB data from temporary to final channel ID in KVStore
577+
pub(crate) fn update_rgb_channel_id(
578578
channel_id: &ChannelId, temporary_channel_id: &ChannelId, kv_store: &dyn KVStoreSync,
579579
) {
580580
let temp_chan_id = temporary_channel_id.0.as_hex().to_string();
@@ -723,7 +723,7 @@ pub trait RgbKvStoreExt {
723723
/// filter first hops to only include channels with sufficient RGB assets
724724
fn filter_first_hops(
725725
&self, payment_hash: &PaymentHash, first_hops: &mut Vec<ChannelDetails>,
726-
);
726+
) -> (ContractId, u64);
727727
}
728728

729729
impl<K: KVStoreSync + ?Sized> RgbKvStoreExt for K {
@@ -795,11 +795,11 @@ impl<K: KVStoreSync + ?Sized> RgbKvStoreExt for K {
795795
|| self.read_rgb_payment_info(payment_hash, true).is_ok()
796796
}
797797

798-
fn filter_first_hops(&self, payment_hash: &PaymentHash, first_hops: &mut Vec<ChannelDetails>) {
799-
let rgb_payment_info = match self.read_rgb_payment_info(payment_hash, false) {
800-
Ok(info) => info,
801-
Err(_) => return,
802-
};
798+
fn filter_first_hops(
799+
&self, payment_hash: &PaymentHash, first_hops: &mut Vec<ChannelDetails>,
800+
) -> (ContractId, u64) {
801+
let rgb_payment_info = self.read_rgb_payment_info(payment_hash, false)
802+
.expect("payment info must exist");
803803
let contract_id = rgb_payment_info.contract_id;
804804
let rgb_amount = rgb_payment_info.amount;
805805
first_hops.retain(|h| {
@@ -811,5 +811,6 @@ impl<K: KVStoreSync + ?Sized> RgbKvStoreExt for K {
811811
Err(_) => false,
812812
}
813813
});
814+
(contract_id, rgb_amount)
814815
}
815816
}

0 commit comments

Comments
 (0)