Skip to content

Peer Storage Feature – Part 2 #3623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a0bf86c
Add method to derive Peer Storage encryption key
Jan 17, 2025
66090c2
Add OurPeerStorage for serialized Peer Storage backups
adi2011 Feb 26, 2025
fa7e350
Enable ChainMonitor to distribute PeerStorage
Jan 18, 2025
d5a996a
Distribute PeerStorage from ChainMonitor
Jan 19, 2025
99b0572
Handle PeerStorageRetrieval in ChannelManager
Jan 19, 2025
306943e
test: update test_peer_storage to validate latest changes
adi2011 Mar 7, 2025
09c7748
Introduce constants for derivation path indices
adi2011 Mar 13, 2025
680731c
fixup: Enable ChainMonitor to distribute PeerStorage
adi2011 Apr 7, 2025
4e4c4ae
fixup: Add OurPeerStorage for serialized Peer Storage backups
adi2011 Apr 7, 2025
c0e5008
fixup: Enable ChainMonitor to distribute PeerStorage
adi2011 Apr 9, 2025
5643873
fixup: Add method to derive Peer Storage encryption key
adi2011 Apr 9, 2025
351df68
fixup: Handle PeerStorageRetrieval in ChannelManager
adi2011 Apr 9, 2025
2fbb5e5
fixup: Add OurPeerStorage for serialized Peer Storage backups
adi2011 Apr 9, 2025
28aff94
fixup: Enable ChainMonitor to distribute PeerStorage
adi2011 Apr 9, 2025
7abc134
fixup: Add OurPeerStorage for serialized Peer Storage backups
adi2011 Apr 14, 2025
7a6306b
fixup: Enable ChainMonitor to distribute PeerStorage
adi2011 Apr 14, 2025
34e97f7
fixup: Distribute PeerStorage from ChainMonitor
adi2011 Apr 14, 2025
8a0dd68
fixup: Handle PeerStorageRetrieval in ChannelManager
adi2011 Apr 14, 2025
9cae0a2
fixup: Enable ChainMonitor to distribute PeerStorage
adi2011 Apr 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessa
use lightning::routing::router::{
InFlightHtlcs, Path, PaymentParameters, Route, RouteHop, RouteParameters, Router,
};
use lightning::sign::{EntropySource, InMemorySigner, NodeSigner, Recipient, SignerProvider};
use lightning::sign::{
EntropySource, InMemorySigner, NodeSigner, PeerStorageKey, Recipient, SignerProvider,
};
use lightning::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::util::config::UserConfig;
use lightning::util::hash_tables::*;
Expand Down Expand Up @@ -204,6 +206,7 @@ impl TestChainMonitor {
logger.clone(),
feeest,
Arc::clone(&persister),
keys.get_peer_storage_key(),
)),
logger,
keys,
Expand Down Expand Up @@ -337,6 +340,10 @@ impl NodeSigner for KeyProvider {
unreachable!()
}

fn get_peer_storage_key(&self) -> PeerStorageKey {
PeerStorageKey::new([42; 32])
}

fn sign_bolt12_invoice(
&self, _invoice: &UnsignedBolt12Invoice,
) -> Result<schnorr::Signature, ()> {
Expand Down
23 changes: 16 additions & 7 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use lightning::blinded_path::message::{BlindedMessagePath, MessageContext};
use lightning::blinded_path::payment::{BlindedPaymentPath, ReceiveTlvs};
use lightning::chain;
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
use lightning::chain::chainmonitor;
use lightning::chain::chainmonitor::{self, PeerStorageKey};
use lightning::chain::transaction::OutPoint;
use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
use lightning::events::Event;
Expand Down Expand Up @@ -242,6 +242,7 @@ type PeerMan<'a> = PeerManager<
Arc<dyn Logger>,
IgnoringMessageHandler,
Arc<KeyProvider>,
IgnoringMessageHandler,
>;

struct MoneyLossDetector<'a> {
Expand Down Expand Up @@ -420,6 +421,10 @@ impl NodeSigner for KeyProvider {
let secp_ctx = Secp256k1::signing_only();
Ok(secp_ctx.sign_ecdsa(&msg_hash, &self.node_secret))
}

fn get_peer_storage_key(&self) -> PeerStorageKey {
PeerStorageKey::new([42; 32])
}
}

impl SignerProvider for KeyProvider {
Expand Down Expand Up @@ -608,20 +613,23 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
];

let broadcast = Arc::new(TestBroadcaster { txn_broadcasted: Mutex::new(Vec::new()) });

let keys_manager = Arc::new(KeyProvider {
node_secret: our_network_key.clone(),
inbound_payment_key: ExpandedKey::new(inbound_payment_key),
counter: AtomicU64::new(0),
signer_state: RefCell::new(new_hash_map()),
});

let monitor = Arc::new(chainmonitor::ChainMonitor::new(
None,
broadcast.clone(),
Arc::clone(&logger),
fee_est.clone(),
Arc::new(TestPersister { update_ret: Mutex::new(ChannelMonitorUpdateStatus::Completed) }),
keys_manager.get_peer_storage_key(),
));

let keys_manager = Arc::new(KeyProvider {
node_secret: our_network_key.clone(),
inbound_payment_key: ExpandedKey::new(inbound_payment_key),
counter: AtomicU64::new(0),
signer_state: RefCell::new(new_hash_map()),
});
let network = Network::Bitcoin;
let best_block_timestamp = genesis_block(network).header.time;
let params = ChainParameters { network, best_block: BestBlock::from_network(network) };
Expand Down Expand Up @@ -653,6 +661,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
route_handler: gossip_sync.clone(),
onion_message_handler: IgnoringMessageHandler {},
custom_message_handler: IgnoringMessageHandler {},
send_only_message_handler: IgnoringMessageHandler {},
};
let random_data = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Expand Down
5 changes: 5 additions & 0 deletions fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use lightning::blinded_path::message::{
AsyncPaymentsContext, BlindedMessagePath, MessageContext, OffersContext,
};
use lightning::blinded_path::EmptyNodeIdLookUp;
use lightning::chain::chainmonitor::PeerStorageKey;
use lightning::ln::inbound_payment::ExpandedKey;
use lightning::ln::msgs::{self, BaseMessageHandler, DecodeError, OnionMessageHandler};
use lightning::ln::peer_handler::IgnoringMessageHandler;
Expand Down Expand Up @@ -249,6 +250,10 @@ impl NodeSigner for KeyProvider {
) -> Result<bitcoin::secp256k1::ecdsa::Signature, ()> {
unreachable!()
}

fn get_peer_storage_key(&self) -> PeerStorageKey {
unreachable!()
}
}

impl SignerProvider for KeyProvider {
Expand Down
20 changes: 16 additions & 4 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use lightning::onion_message::messenger::AOnionMessenger;
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
use lightning::routing::scoring::{ScoreUpdate, WriteableScore};
use lightning::routing::utxo::UtxoLookup;
use lightning::sign::EntropySource;
use lightning::util::logger::Logger;
use lightning::util::persist::Persister;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -649,7 +650,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
/// # type ChannelManager<B, F, FE> = lightning::ln::channelmanager::SimpleArcChannelManager<ChainMonitor<B, F, FE>, B, FE, Logger>;
/// # type OnionMessenger<B, F, FE> = lightning::onion_message::messenger::OnionMessenger<Arc<lightning::sign::KeysManager>, Arc<lightning::sign::KeysManager>, Arc<Logger>, Arc<ChannelManager<B, F, FE>>, Arc<lightning::onion_message::messenger::DefaultMessageRouter<Arc<NetworkGraph>, Arc<Logger>, Arc<lightning::sign::KeysManager>>>, Arc<ChannelManager<B, F, FE>>, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler, lightning::ln::peer_handler::IgnoringMessageHandler>;
/// # type Scorer = RwLock<lightning::routing::scoring::ProbabilisticScorer<Arc<NetworkGraph>, Arc<Logger>>>;
/// # type PeerManager<B, F, FE, UL> = lightning::ln::peer_handler::SimpleArcPeerManager<SocketDescriptor, ChainMonitor<B, F, FE>, B, FE, Arc<UL>, Logger>;
/// # type PeerManager<B, F, FE, UL> = lightning::ln::peer_handler::SimpleArcPeerManager<SocketDescriptor, ChainMonitor<B, F, FE>, B, FE, Arc<UL>, Logger, F, Store>;
/// #
/// # struct Node<
/// # B: lightning::chain::chaininterface::BroadcasterInterface + Send + Sync + 'static,
Expand Down Expand Up @@ -736,8 +737,9 @@ pub async fn process_events_async<
EventHandlerFuture: core::future::Future<Output = Result<(), ReplayEvent>>,
EventHandler: Fn(Event) -> EventHandlerFuture,
PS: 'static + Deref + Send,
ES: 'static + Deref + Send,
M: 'static
+ Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P>>
+ Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>>
+ Send
+ Sync,
CM: 'static + Deref + Send + Sync,
Expand All @@ -764,6 +766,7 @@ where
L::Target: 'static + Logger,
P::Target: 'static + Persist<<CM::Target as AChannelManager>::Signer>,
PS::Target: 'static + Persister<'a, CM, L, S>,
ES::Target: 'static + EntropySource,
CM::Target: AChannelManager + Send + Sync,
OM::Target: AOnionMessenger + Send + Sync,
PM::Target: APeerManager + Send + Sync,
Expand Down Expand Up @@ -911,8 +914,11 @@ impl BackgroundProcessor {
P: 'static + Deref + Send + Sync,
EH: 'static + EventHandler + Send,
PS: 'static + Deref + Send,
ES: 'static + Deref + Send,
M: 'static
+ Deref<Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P>>
+ Deref<
Target = ChainMonitor<<CM::Target as AChannelManager>::Signer, CF, T, F, L, P, ES>,
>
+ Send
+ Sync,
CM: 'static + Deref + Send + Sync,
Expand All @@ -935,6 +941,7 @@ impl BackgroundProcessor {
L::Target: 'static + Logger,
P::Target: 'static + Persist<<CM::Target as AChannelManager>::Signer>,
PS::Target: 'static + Persister<'a, CM, L, S>,
ES::Target: 'static + EntropySource,
CM::Target: AChannelManager + Send + Sync,
OM::Target: AOnionMessenger + Send + Sync,
PM::Target: APeerManager + Send + Sync,
Expand Down Expand Up @@ -1085,7 +1092,7 @@ mod tests {
use lightning::routing::gossip::{NetworkGraph, P2PGossipSync};
use lightning::routing::router::{CandidateRouteHop, DefaultRouter, Path, RouteHop};
use lightning::routing::scoring::{ChannelUsage, LockableScore, ScoreLookUp, ScoreUpdate};
use lightning::sign::{ChangeDestinationSource, InMemorySigner, KeysManager};
use lightning::sign::{ChangeDestinationSource, InMemorySigner, KeysManager, NodeSigner};
use lightning::types::features::{ChannelFeatures, NodeFeatures};
use lightning::types::payment::PaymentHash;
use lightning::util::config::UserConfig;
Expand Down Expand Up @@ -1160,6 +1167,7 @@ mod tests {
Arc<test_utils::TestFeeEstimator>,
Arc<test_utils::TestLogger>,
Arc<FilesystemStore>,
Arc<KeysManager>,
>;

type PGS = Arc<
Expand Down Expand Up @@ -1208,6 +1216,7 @@ mod tests {
Arc<test_utils::TestLogger>,
IgnoringMessageHandler,
Arc<KeysManager>,
IgnoringMessageHandler,
>,
>,
chain_monitor: Arc<ChainMonitor>,
Expand Down Expand Up @@ -1568,6 +1577,8 @@ mod tests {
logger.clone(),
fee_estimator.clone(),
kv_store.clone(),
keys_manager.clone(),
keys_manager.get_peer_storage_key(),
));
let best_block = BestBlock::from_network(network);
let params = ChainParameters { network, best_block };
Expand Down Expand Up @@ -1621,6 +1632,7 @@ mod tests {
route_handler: Arc::new(test_utils::TestRoutingMessageHandler::new()),
onion_message_handler: messenger.clone(),
custom_message_handler: IgnoringMessageHandler {},
send_only_message_handler: IgnoringMessageHandler {},
};
let peer_manager = Arc::new(PeerManager::new(
msg_handler,
Expand Down
2 changes: 1 addition & 1 deletion lightning-liquidity/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ where {
/// # type MyFilter = dyn lightning::chain::Filter + Send + Sync;
/// # type MyLogger = dyn lightning::util::logger::Logger + Send + Sync;
/// # type MyChainMonitor = lightning::chain::chainmonitor::ChainMonitor<lightning::sign::InMemorySigner, Arc<MyFilter>, Arc<MyBroadcaster>, Arc<MyFeeEstimator>, Arc<MyLogger>, Arc<MyStore>>;
/// # type MyPeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<MySocketDescriptor, MyChainMonitor, MyBroadcaster, MyFeeEstimator, Arc<MyUtxoLookup>, MyLogger>;
/// # type MyPeerManager = lightning::ln::peer_handler::SimpleArcPeerManager<MySocketDescriptor, MyChainMonitor, MyBroadcaster, MyFeeEstimator, Arc<MyUtxoLookup>, MyLogger, MyFilter, MyStore>;
/// # type MyNetworkGraph = lightning::routing::gossip::NetworkGraph<Arc<MyLogger>>;
/// # type MyGossipSync = lightning::routing::gossip::P2PGossipSync<Arc<MyNetworkGraph>, Arc<MyUtxoLookup>, Arc<MyLogger>>;
/// # type MyChannelManager = lightning::ln::channelmanager::SimpleArcChannelManager<MyChainMonitor, MyBroadcaster, MyFeeEstimator, MyLogger>;
Expand Down
7 changes: 6 additions & 1 deletion lightning-liquidity/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![allow(unused_macros)]

use lightning::chain::Filter;
use lightning::sign::EntropySource;
use lightning::sign::{EntropySource, NodeSigner};

use bitcoin::blockdata::constants::{genesis_block, ChainHash};
use bitcoin::blockdata::transaction::Transaction;
Expand Down Expand Up @@ -101,6 +101,7 @@ type ChainMonitor = chainmonitor::ChainMonitor<
Arc<test_utils::TestFeeEstimator>,
Arc<test_utils::TestLogger>,
Arc<FilesystemStore>,
Arc<KeysManager>,
>;

type PGS = Arc<
Expand Down Expand Up @@ -130,6 +131,7 @@ pub(crate) struct Node {
>,
>,
Arc<KeysManager>,
Arc<ChainMonitor>,
>,
>,
pub(crate) liquidity_manager:
Expand Down Expand Up @@ -430,6 +432,8 @@ pub(crate) fn create_liquidity_node(
logger.clone(),
fee_estimator.clone(),
kv_store.clone(),
keys_manager.clone(),
keys_manager.get_peer_storage_key(),
));
let best_block = BestBlock::from_network(network);
let chain_params = ChainParameters { network, best_block };
Expand Down Expand Up @@ -468,6 +472,7 @@ pub(crate) fn create_liquidity_node(
route_handler: Arc::new(test_utils::TestRoutingMessageHandler::new()),
onion_message_handler: IgnoringMessageHandler {},
custom_message_handler: Arc::clone(&liquidity_manager),
send_only_message_handler: Arc::clone(&chain_monitor),
};
let peer_manager =
Arc::new(PeerManager::new(msg_handler, 0, &seed, logger.clone(), keys_manager.clone()));
Expand Down
3 changes: 3 additions & 0 deletions lightning-net-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ mod tests {
route_handler: Arc::clone(&a_handler),
onion_message_handler: Arc::new(IgnoringMessageHandler {}),
custom_message_handler: Arc::new(IgnoringMessageHandler {}),
send_only_message_handler: Arc::new(IgnoringMessageHandler {}),
};
let a_manager = Arc::new(PeerManager::new(
a_msg_handler,
Expand All @@ -855,6 +856,7 @@ mod tests {
route_handler: Arc::clone(&b_handler),
onion_message_handler: Arc::new(IgnoringMessageHandler {}),
custom_message_handler: Arc::new(IgnoringMessageHandler {}),
send_only_message_handler: Arc::new(IgnoringMessageHandler {}),
};
let b_manager = Arc::new(PeerManager::new(
b_msg_handler,
Expand Down Expand Up @@ -917,6 +919,7 @@ mod tests {
onion_message_handler: Arc::new(IgnoringMessageHandler {}),
route_handler: Arc::new(lightning::ln::peer_handler::IgnoringMessageHandler {}),
custom_message_handler: Arc::new(IgnoringMessageHandler {}),
send_only_message_handler: Arc::new(IgnoringMessageHandler {}),
};
let a_manager = Arc::new(PeerManager::new(
a_msg_handler,
Expand Down
Loading
Loading