Skip to content

Commit

Permalink
simplify GossipVerifier types using APeerManager
Browse files Browse the repository at this point in the history
  • Loading branch information
johncantrell97 committed Dec 5, 2023
1 parent 37150b4 commit 6765967
Showing 1 changed file with 16 additions and 47 deletions.
63 changes: 16 additions & 47 deletions lightning-block-sync/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use bitcoin::blockdata::constants::ChainHash;
use bitcoin::blockdata::transaction::{TxOut, OutPoint};
use bitcoin::hash_types::BlockHash;

use lightning::sign::NodeSigner;

use lightning::ln::peer_handler::{CustomMessageHandler, PeerManager, SocketDescriptor};
use lightning::ln::msgs::{ChannelMessageHandler, OnionMessageHandler};
use lightning::ln::peer_handler::APeerManager;

use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
use lightning::routing::utxo::{UtxoFuture, UtxoLookup, UtxoResult, UtxoLookupError};
Expand Down Expand Up @@ -135,21 +132,14 @@ impl<
pub struct GossipVerifier<S: FutureSpawner,
Blocks: Deref + Send + Sync + 'static + Clone,
L: Deref + Send + Sync + 'static,
Descriptor: SocketDescriptor + Send + Sync + 'static,
CM: Deref + Send + Sync + 'static,
OM: Deref + Send + Sync + 'static,
CMH: Deref + Send + Sync + 'static,
NS: Deref + Send + Sync + 'static,
APM: Deref + Send + Sync + 'static + Clone,
> where
Blocks::Target: UtxoSource,
L::Target: Logger,
CM::Target: ChannelMessageHandler,
OM::Target: OnionMessageHandler,
CMH::Target: CustomMessageHandler,
NS::Target: NodeSigner,
APM::Target: APeerManager,
{
source: Blocks,
peer_manager: Arc<PeerManager<Descriptor, CM, Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Self, L>>, OM, L, CMH, NS>>,
peer_manager: APM,

This comment has been minimized.

Copy link
@eauxxs

eauxxs Jan 14, 2024

here, APM == Arc<PeerManager<Descriptor, CM, Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Self, L>>, OM, L, CMH, NS>>

but look
P2PGossipSync<G, U: UtxoLookup, L>, its second generic param must satisfy UtxoLookup, and when you remove Self and impl UtxoLookup for GossipVerifier<S, Blocks, L, APM>, so if i can never put P2PGossipSync<G, U: GossipVerifier, L> in GossipVerifier, due to deleting Self.

This comment has been minimized.

Copy link
@tnull

tnull Jan 15, 2024

Contributor

@eauxxs Note this commit was partially reverted by #2822 recently so any issues should be fixed with the next release.

gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Self, L>>,
spawn: S,
block_cache: Arc<Mutex<VecDeque<(u32, Block)>>>,
Expand All @@ -160,24 +150,17 @@ const BLOCK_CACHE_SIZE: usize = 5;
impl<S: FutureSpawner,
Blocks: Deref + Send + Sync + Clone,
L: Deref + Send + Sync,
Descriptor: SocketDescriptor + Send + Sync,
CM: Deref + Send + Sync,
OM: Deref + Send + Sync,
CMH: Deref + Send + Sync,
NS: Deref + Send + Sync,
> GossipVerifier<S, Blocks, L, Descriptor, CM, OM, CMH, NS> where
APM: Deref + Send + Sync + Clone,
> GossipVerifier<S, Blocks, L, APM> where
Blocks::Target: UtxoSource,
L::Target: Logger,
CM::Target: ChannelMessageHandler,
OM::Target: OnionMessageHandler,
CMH::Target: CustomMessageHandler,
NS::Target: NodeSigner,
APM::Target: APeerManager,
{
/// Constructs a new [`GossipVerifier`].
///
/// This is expected to be given to a [`P2PGossipSync`] (initially constructed with `None` for
/// the UTXO lookup) via [`P2PGossipSync::add_utxo_lookup`].
pub fn new(source: Blocks, spawn: S, gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Self, L>>, peer_manager: Arc<PeerManager<Descriptor, CM, Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Self, L>>, OM, L, CMH, NS>>) -> Self {
pub fn new(source: Blocks, spawn: S, gossiper: Arc<P2PGossipSync<Arc<NetworkGraph<L>>, Self, L>>, peer_manager: APM) -> Self {
Self {
source, spawn, gossiper, peer_manager,
block_cache: Arc::new(Mutex::new(VecDeque::with_capacity(BLOCK_CACHE_SIZE))),
Expand Down Expand Up @@ -269,18 +252,11 @@ impl<S: FutureSpawner,
impl<S: FutureSpawner,
Blocks: Deref + Send + Sync + Clone,
L: Deref + Send + Sync,
Descriptor: SocketDescriptor + Send + Sync,
CM: Deref + Send + Sync,
OM: Deref + Send + Sync,
CMH: Deref + Send + Sync,
NS: Deref + Send + Sync,
> Deref for GossipVerifier<S, Blocks, L, Descriptor, CM, OM, CMH, NS> where
APM: Deref + Send + Sync + Clone,
> Deref for GossipVerifier<S, Blocks, L, APM> where
Blocks::Target: UtxoSource,
L::Target: Logger,
CM::Target: ChannelMessageHandler,
OM::Target: OnionMessageHandler,
CMH::Target: CustomMessageHandler,
NS::Target: NodeSigner,
APM::Target: APeerManager,
{
type Target = Self;
fn deref(&self) -> &Self { self }
Expand All @@ -290,30 +266,23 @@ impl<S: FutureSpawner,
impl<S: FutureSpawner,
Blocks: Deref + Send + Sync + Clone,
L: Deref + Send + Sync,
Descriptor: SocketDescriptor + Send + Sync,
CM: Deref + Send + Sync,
OM: Deref + Send + Sync,
CMH: Deref + Send + Sync,
NS: Deref + Send + Sync,
> UtxoLookup for GossipVerifier<S, Blocks, L, Descriptor, CM, OM, CMH, NS> where
APM: Deref + Send + Sync + Clone,
> UtxoLookup for GossipVerifier<S, Blocks, L, APM> where
Blocks::Target: UtxoSource,
L::Target: Logger,
CM::Target: ChannelMessageHandler,
OM::Target: OnionMessageHandler,
CMH::Target: CustomMessageHandler,
NS::Target: NodeSigner,
APM::Target: APeerManager,
{
fn get_utxo(&self, _chain_hash: &ChainHash, short_channel_id: u64) -> UtxoResult {
let res = UtxoFuture::new();
let fut = res.clone();
let source = self.source.clone();
let gossiper = Arc::clone(&self.gossiper);
let block_cache = Arc::clone(&self.block_cache);
let pm = Arc::clone(&self.peer_manager);
let pm = self.peer_manager.clone();
self.spawn.spawn(async move {
let res = Self::retrieve_utxo(source, block_cache, short_channel_id).await;
fut.resolve(gossiper.network_graph(), &*gossiper, res);
pm.process_events();
pm.as_ref().process_events();
});
UtxoResult::Async(res)
}
Expand Down

0 comments on commit 6765967

Please sign in to comment.