Skip to content

Commit 580696e

Browse files
Drop Deref indirection for UtxoLookup
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6d28678 commit 580696e

4 files changed

Lines changed: 30 additions & 62 deletions

File tree

lightning-background-processor/src/lib.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,9 @@ pub enum GossipSync<
200200
P: Deref<Target = P2PGossipSync<G, U, L>>,
201201
R: Deref<Target = RapidGossipSync<G, L>>,
202202
G: Deref<Target = NetworkGraph<L>>,
203-
U: Deref,
203+
U: UtxoLookup,
204204
L: Logger,
205-
> where
206-
U::Target: UtxoLookup,
207-
{
205+
> {
208206
/// Gossip sync via the lightning peer-to-peer network as defined by BOLT 7.
209207
P2P(P),
210208
/// Rapid gossip sync from a trusted server.
@@ -217,11 +215,9 @@ impl<
217215
P: Deref<Target = P2PGossipSync<G, U, L>>,
218216
R: Deref<Target = RapidGossipSync<G, L>>,
219217
G: Deref<Target = NetworkGraph<L>>,
220-
U: Deref,
218+
U: UtxoLookup,
221219
L: Logger,
222220
> GossipSync<P, R, G, U, L>
223-
where
224-
U::Target: UtxoLookup,
225221
{
226222
fn network_graph(&self) -> Option<&G> {
227223
match self {
@@ -258,11 +254,9 @@ where
258254
impl<
259255
P: Deref<Target = P2PGossipSync<G, U, L>>,
260256
G: Deref<Target = NetworkGraph<L>>,
261-
U: Deref,
257+
U: UtxoLookup,
262258
L: Logger,
263259
> GossipSync<P, &RapidGossipSync<G, L>, G, U, L>
264-
where
265-
U::Target: UtxoLookup,
266260
{
267261
/// Initializes a new [`GossipSync::P2P`] variant.
268262
pub fn p2p(gossip_sync: P) -> Self {
@@ -928,7 +922,7 @@ use futures_util::{dummy_waker, Joiner, OptionalSelector, Selector, SelectorOutp
928922
///```
929923
pub async fn process_events_async<
930924
'a,
931-
UL: Deref,
925+
UL: UtxoLookup,
932926
CF: chain::Filter,
933927
T: BroadcasterInterface,
934928
F: FeeEstimator,
@@ -961,7 +955,6 @@ pub async fn process_events_async<
961955
sleeper: Sleeper, mobile_interruptable_platform: bool, fetch_time: FetchTime,
962956
) -> Result<(), lightning::io::Error>
963957
where
964-
UL::Target: UtxoLookup,
965958
P::Target: Persist<<CM::Target as AChannelManager>::Signer>,
966959
CM::Target: AChannelManager,
967960
OM::Target: AOnionMessenger,
@@ -1422,7 +1415,7 @@ fn check_and_reset_sleeper<
14221415
/// Async events processor that is based on [`process_events_async`] but allows for [`KVStoreSync`] to be used for
14231416
/// synchronous background persistence.
14241417
pub async fn process_events_async_with_kv_store_sync<
1425-
UL: Deref,
1418+
UL: UtxoLookup,
14261419
CF: chain::Filter,
14271420
T: BroadcasterInterface,
14281421
F: FeeEstimator,
@@ -1455,7 +1448,6 @@ pub async fn process_events_async_with_kv_store_sync<
14551448
sleeper: Sleeper, mobile_interruptable_platform: bool, fetch_time: FetchTime,
14561449
) -> Result<(), lightning::io::Error>
14571450
where
1458-
UL::Target: UtxoLookup,
14591451
P::Target: Persist<<CM::Target as AChannelManager>::Signer>,
14601452
CM::Target: AChannelManager,
14611453
OM::Target: AOnionMessenger,
@@ -1530,7 +1522,7 @@ impl BackgroundProcessor {
15301522
/// [`NetworkGraph::write`]: lightning::routing::gossip::NetworkGraph#impl-Writeable
15311523
pub fn start<
15321524
'a,
1533-
UL: 'static + Deref,
1525+
UL: 'static + UtxoLookup,
15341526
CF: 'static + chain::Filter,
15351527
T: 'static + BroadcasterInterface,
15361528
F: 'static + FeeEstimator + Send,
@@ -1563,7 +1555,6 @@ impl BackgroundProcessor {
15631555
liquidity_manager: Option<LM>, sweeper: Option<OS>, logger: L, scorer: Option<S>,
15641556
) -> Self
15651557
where
1566-
UL::Target: 'static + UtxoLookup,
15671558
L::Target: 'static + Logger,
15681559
P::Target: 'static + Persist<<CM::Target as AChannelManager>::Signer>,
15691560
CM::Target: AChannelManager,

lightning-block-sync/src/gossip.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,6 @@ where
239239
}
240240
}
241241

242-
impl<S: FutureSpawner, Blocks: Deref + Send + Sync + Clone> Deref for GossipVerifier<S, Blocks>
243-
where
244-
Blocks::Target: UtxoSource,
245-
{
246-
type Target = Self;
247-
fn deref(&self) -> &Self {
248-
self
249-
}
250-
}
251-
252242
impl<S: FutureSpawner, Blocks: Deref + Send + Sync + Clone> UtxoLookup for GossipVerifier<S, Blocks>
253243
where
254244
Blocks::Target: UtxoSource,

lightning/src/routing/gossip.rs

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,7 @@ impl MaybeReadable for NetworkUpdate {
319319
/// This network graph is then used for routing payments.
320320
/// Provides interface to help with initial routing sync by
321321
/// serving historical announcements.
322-
pub struct P2PGossipSync<G: Deref<Target = NetworkGraph<L>>, U: Deref, L: Logger>
323-
where
324-
U::Target: UtxoLookup,
325-
{
322+
pub struct P2PGossipSync<G: Deref<Target = NetworkGraph<L>>, U: UtxoLookup, L: Logger> {
326323
network_graph: G,
327324
#[cfg(any(feature = "_test_utils", test))]
328325
pub(super) utxo_lookup: Option<U>,
@@ -333,10 +330,7 @@ where
333330
logger: L,
334331
}
335332

336-
impl<G: Deref<Target = NetworkGraph<L>>, U: Deref, L: Logger> P2PGossipSync<G, U, L>
337-
where
338-
U::Target: UtxoLookup,
339-
{
333+
impl<G: Deref<Target = NetworkGraph<L>>, U: UtxoLookup, L: Logger> P2PGossipSync<G, U, L> {
340334
/// Creates a new tracker of the actual state of the network of channels and nodes,
341335
/// assuming an existing [`NetworkGraph`].
342336
///
@@ -534,10 +528,8 @@ pub fn verify_channel_announcement<C: Verification>(
534528
Ok(())
535529
}
536530

537-
impl<G: Deref<Target = NetworkGraph<L>>, U: Deref, L: Logger> RoutingMessageHandler
531+
impl<G: Deref<Target = NetworkGraph<L>>, U: UtxoLookup, L: Logger> RoutingMessageHandler
538532
for P2PGossipSync<G, U, L>
539-
where
540-
U::Target: UtxoLookup,
541533
{
542534
fn handle_node_announcement(
543535
&self, _their_node_id: Option<PublicKey>, msg: &msgs::NodeAnnouncement,
@@ -761,10 +753,8 @@ where
761753
}
762754
}
763755

764-
impl<G: Deref<Target = NetworkGraph<L>>, U: Deref, L: Logger> BaseMessageHandler
756+
impl<G: Deref<Target = NetworkGraph<L>>, U: UtxoLookup, L: Logger> BaseMessageHandler
765757
for P2PGossipSync<G, U, L>
766-
where
767-
U::Target: UtxoLookup,
768758
{
769759
/// Initiates a stateless sync of routing gossip information with a peer
770760
/// using [`gossip_queries`]. The default strategy used by this implementation
@@ -1951,12 +1941,9 @@ impl<L: Logger> NetworkGraph<L> {
19511941
///
19521942
/// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
19531943
/// the corresponding UTXO exists on chain and is correctly-formatted.
1954-
pub fn update_channel_from_announcement<U: Deref>(
1944+
pub fn update_channel_from_announcement<U: UtxoLookup>(
19551945
&self, msg: &msgs::ChannelAnnouncement, utxo_lookup: &Option<U>,
1956-
) -> Result<(), LightningError>
1957-
where
1958-
U::Target: UtxoLookup,
1959-
{
1946+
) -> Result<(), LightningError> {
19601947
self.pre_channel_announcement_validation_check(&msg.contents, utxo_lookup)?;
19611948
verify_channel_announcement(msg, &self.secp_ctx)?;
19621949
self.update_channel_from_unsigned_announcement_intern(&msg.contents, Some(msg), utxo_lookup)
@@ -1981,12 +1968,9 @@ impl<L: Logger> NetworkGraph<L> {
19811968
///
19821969
/// If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
19831970
/// the corresponding UTXO exists on chain and is correctly-formatted.
1984-
pub fn update_channel_from_unsigned_announcement<U: Deref>(
1971+
pub fn update_channel_from_unsigned_announcement<U: UtxoLookup>(
19851972
&self, msg: &msgs::UnsignedChannelAnnouncement, utxo_lookup: &Option<U>,
1986-
) -> Result<(), LightningError>
1987-
where
1988-
U::Target: UtxoLookup,
1989-
{
1973+
) -> Result<(), LightningError> {
19901974
self.pre_channel_announcement_validation_check(&msg, utxo_lookup)?;
19911975
self.update_channel_from_unsigned_announcement_intern(msg, None, utxo_lookup)
19921976
}
@@ -2105,12 +2089,9 @@ impl<L: Logger> NetworkGraph<L> {
21052089
///
21062090
/// In those cases, this will return an `Err` that we can return immediately. Otherwise it will
21072091
/// return an `Ok(())`.
2108-
fn pre_channel_announcement_validation_check<U: Deref>(
2092+
fn pre_channel_announcement_validation_check<U: UtxoLookup>(
21092093
&self, msg: &msgs::UnsignedChannelAnnouncement, utxo_lookup: &Option<U>,
2110-
) -> Result<(), LightningError>
2111-
where
2112-
U::Target: UtxoLookup,
2113-
{
2094+
) -> Result<(), LightningError> {
21142095
let channels = self.channels.read().unwrap();
21152096

21162097
if let Some(chan) = channels.get(&msg.short_channel_id) {
@@ -2149,13 +2130,10 @@ impl<L: Logger> NetworkGraph<L> {
21492130
///
21502131
/// Generally [`Self::pre_channel_announcement_validation_check`] should have been called
21512132
/// first.
2152-
fn update_channel_from_unsigned_announcement_intern<U: Deref>(
2133+
fn update_channel_from_unsigned_announcement_intern<U: UtxoLookup>(
21532134
&self, msg: &msgs::UnsignedChannelAnnouncement,
21542135
full_msg: Option<&msgs::ChannelAnnouncement>, utxo_lookup: &Option<U>,
2155-
) -> Result<(), LightningError>
2156-
where
2157-
U::Target: UtxoLookup,
2158-
{
2136+
) -> Result<(), LightningError> {
21592137
if msg.node_id_1 == msg.node_id_2 || msg.bitcoin_key_1 == msg.bitcoin_key_2 {
21602138
return Err(LightningError {
21612139
err: "Channel announcement node had a channel with itself".to_owned(),

lightning/src/routing/utxo.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ pub trait UtxoLookup {
7575
) -> UtxoResult;
7676
}
7777

78+
impl<T: UtxoLookup + ?Sized, U: Deref<Target = T>> UtxoLookup for U {
79+
fn get_utxo(
80+
&self, chain_hash: &ChainHash, short_channel_id: u64,
81+
async_completion_notifier: Arc<Notifier>,
82+
) -> UtxoResult {
83+
self.deref().get_utxo(chain_hash, short_channel_id, async_completion_notifier)
84+
}
85+
}
86+
7887
enum ChannelAnnouncement {
7988
Full(msgs::ChannelAnnouncement),
8089
Unsigned(msgs::UnsignedChannelAnnouncement),
@@ -332,10 +341,10 @@ impl PendingChecks {
332341
}
333342

334343
#[rustfmt::skip]
335-
pub(super) fn check_channel_announcement<U: Deref>(&self,
344+
pub(super) fn check_channel_announcement<U: UtxoLookup>(&self,
336345
utxo_lookup: &Option<U>, msg: &msgs::UnsignedChannelAnnouncement,
337346
full_msg: Option<&msgs::ChannelAnnouncement>
338-
) -> Result<Option<Amount>, msgs::LightningError> where U::Target: UtxoLookup {
347+
) -> Result<Option<Amount>, msgs::LightningError> {
339348
let handle_result = |res| {
340349
match res {
341350
Ok(TxOut { value, script_pubkey }) => {

0 commit comments

Comments
 (0)