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 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 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 @@ -189,6 +191,7 @@ struct TestChainMonitor {
Arc<FuzzEstimator>,
Arc<dyn Logger>,
Arc<TestPersister>,
Arc<KeyProvider>,
>,
>,
pub latest_monitors: Mutex<HashMap<ChannelId, LatestMonitorState>>,
Expand All @@ -205,6 +208,8 @@ impl TestChainMonitor {
logger.clone(),
feeest,
Arc::clone(&persister),
Arc::clone(&keys),
keys.get_peer_storage_key(),
)),
logger,
keys,
Expand Down Expand Up @@ -338,6 +343,10 @@ impl NodeSigner for KeyProvider {
unreachable!()
}

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

fn sign_bolt12_invoice(
&self, _invoice: &UnsignedBolt12Invoice,
) -> Result<schnorr::Signature, ()> {
Expand Down
26 changes: 20 additions & 6 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use lightning::routing::router::{
InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router,
};
use lightning::routing::utxo::UtxoLookup;
use lightning::sign::PeerStorageKey;
use lightning::sign::{EntropySource, InMemorySigner, NodeSigner, Recipient, SignerProvider};
use lightning::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::util::config::{ChannelConfig, UserConfig};
Expand Down Expand Up @@ -223,6 +224,7 @@ type ChannelMan<'a> = ChannelManager<
Arc<FuzzEstimator>,
Arc<dyn Logger>,
Arc<TestPersister>,
Arc<KeyProvider>,
>,
>,
Arc<TestBroadcaster>,
Expand All @@ -242,6 +244,7 @@ type PeerMan<'a> = PeerManager<
Arc<dyn Logger>,
IgnoringMessageHandler,
Arc<KeyProvider>,
IgnoringMessageHandler,
>;

struct MoneyLossDetector<'a> {
Expand All @@ -254,6 +257,7 @@ struct MoneyLossDetector<'a> {
Arc<FuzzEstimator>,
Arc<dyn Logger>,
Arc<TestPersister>,
Arc<KeyProvider>,
>,
>,
handler: PeerMan<'a>,
Expand All @@ -278,6 +282,7 @@ impl<'a> MoneyLossDetector<'a> {
Arc<FuzzEstimator>,
Arc<dyn Logger>,
Arc<TestPersister>,
Arc<KeyProvider>,
>,
>,
handler: PeerMan<'a>,
Expand Down Expand Up @@ -428,6 +433,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 { inner: [42; 32] }
}
}

impl SignerProvider for KeyProvider {
Expand Down Expand Up @@ -616,20 +625,24 @@ 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) }),
Arc::clone(&keys_manager),
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 @@ -661,6 +674,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
6 changes: 5 additions & 1 deletion fuzz/src/onion_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use lightning::onion_message::messenger::{
};
use lightning::onion_message::offers::{OffersMessage, OffersMessageHandler};
use lightning::onion_message::packet::OnionMessageContents;
use lightning::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
use lightning::sign::{EntropySource, NodeSigner, PeerStorageKey, Recipient, SignerProvider};
use lightning::types::features::InitFeatures;
use lightning::util::logger::Logger;
use lightning::util::ser::{LengthReadable, Writeable, Writer};
Expand Down Expand Up @@ -249,6 +249,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 @@ -37,6 +37,7 @@ use lightning::routing::utxo::UtxoLookup;
use lightning::sign::ChangeDestinationSource;
#[cfg(feature = "std")]
use lightning::sign::ChangeDestinationSourceSync;
use lightning::sign::EntropySource;
use lightning::sign::OutputSpender;
use lightning::util::logger::Logger;
use lightning::util::persist::{KVStore, Persister};
Expand Down Expand Up @@ -675,7 +676,7 @@ use futures_util::{dummy_waker, OptionalSelector, Selector, SelectorOutput};
/// # 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 LiquidityManager<B, F, FE> = lightning_liquidity::LiquidityManager<Arc<lightning::sign::KeysManager>, Arc<ChannelManager<B, F, FE>>, Arc<F>>;
/// # 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 @@ -780,8 +781,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,
Expand Down Expand Up @@ -813,6 +815,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,
OM::Target: AOnionMessenger,
PM::Target: APeerManager,
Expand Down Expand Up @@ -976,8 +979,11 @@ impl BackgroundProcessor {
P: 'static + Deref,
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,
Expand Down Expand Up @@ -1005,6 +1011,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,
OM::Target: AOnionMessenger,
PM::Target: APeerManager,
Expand Down Expand Up @@ -1174,7 +1181,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::{ChangeDestinationSourceSync, InMemorySigner, KeysManager};
use lightning::sign::{ChangeDestinationSourceSync, InMemorySigner, KeysManager, NodeSigner};
use lightning::types::features::{ChannelFeatures, NodeFeatures};
use lightning::types::payment::PaymentHash;
use lightning::util::config::UserConfig;
Expand Down Expand Up @@ -1250,6 +1257,7 @@ mod tests {
Arc<test_utils::TestFeeEstimator>,
Arc<test_utils::TestLogger>,
Arc<FilesystemStore>,
Arc<KeysManager>,
>;

type PGS = Arc<
Expand Down Expand Up @@ -1301,6 +1309,7 @@ mod tests {
Arc<test_utils::TestLogger>,
IgnoringMessageHandler,
Arc<KeysManager>,
IgnoringMessageHandler,
>,
>,
liquidity_manager: Arc<LM>,
Expand Down Expand Up @@ -1662,6 +1671,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 @@ -1715,6 +1726,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
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 @@ -429,6 +431,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 @@ -467,6 +471,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 @@ -839,6 +839,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 @@ -862,6 +863,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 @@ -924,6 +926,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