Skip to content

Commit 6e1318b

Browse files
committed
Make docs look nicer by adding explicit spacing
1 parent 92ff499 commit 6e1318b

File tree

10 files changed

+94
-17
lines changed

10 files changed

+94
-17
lines changed

src/chain/chaininterface.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Traits and utility impls which allow other parts of rust-lightning to interact with the
2-
//! blockchain - receiving notifications of new blocks and block disconnections and allowing
3-
//! rust-lightning to request that you monitor the chain for certain outpoints/transactions.
2+
//! blockchain.
3+
//!
4+
//! Includes traits for monitoring and receiving notifications of new blocks and block
5+
//! disconnections, transactio broadcasting, and feerate information requests.
46
57
use bitcoin::blockdata::block::{Block, BlockHeader};
68
use bitcoin::blockdata::transaction::Transaction;
@@ -28,6 +30,7 @@ pub enum ChainError {
2830

2931
/// An interface to request notification of certain scripts as they appear the
3032
/// chain.
33+
///
3134
/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
3235
/// called from inside the library in response to ChainListener events, P2P events, or timer
3336
/// events).
@@ -66,8 +69,10 @@ pub trait ChainListener: Sync + Send {
6669
/// Note that if a new transaction/outpoint is watched during a block_connected call, the block
6770
/// *must* be re-scanned with the new transaction/outpoints and block_connected should be
6871
/// called again with the same header and (at least) the new transactions.
72+
///
6973
/// Note that if non-new transaction/outpoints may be registered during a call, a second call
7074
/// *must not* happen.
75+
///
7176
/// This also means those counting confirmations using block_connected callbacks should watch
7277
/// for duplicate headers and not count them towards confirmations!
7378
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]);
@@ -89,15 +94,19 @@ pub enum ConfirmationTarget {
8994

9095
/// A trait which should be implemented to provide feerate information on a number of time
9196
/// horizons.
97+
///
9298
/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
9399
/// called from inside the library in response to ChainListener events, P2P events, or timer
94100
/// events).
95101
pub trait FeeEstimator: Sync + Send {
96-
/// Gets estimated satoshis of fee required per 1000 Weight-Units. This translates to:
97-
/// * satoshis-per-byte * 250
98-
/// * ceil(satoshis-per-kbyte / 4)
102+
/// Gets estimated satoshis of fee required per 1000 Weight-Units.
103+
///
99104
/// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs
100105
/// don't put us below 1 satoshi-per-byte).
106+
///
107+
/// This translates to:
108+
/// * satoshis-per-byte * 250
109+
/// * ceil(satoshis-per-kbyte / 4)
101110
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64;
102111
}
103112

@@ -189,6 +198,7 @@ impl ChainWatchedUtil {
189198
}
190199

191200
/// Utility to capture some common parts of ChainWatchInterface implementors.
201+
///
192202
/// Keeping a local copy of this in a ChainWatchInterface implementor is likely useful.
193203
pub struct ChainWatchInterfaceUtil {
194204
network: Network,
@@ -247,6 +257,7 @@ impl ChainWatchInterfaceUtil {
247257
}
248258

249259
/// Notify listeners that a block was connected given a full, unfiltered block.
260+
///
250261
/// Handles re-scanning the block and calling block_connected again if listeners register new
251262
/// watch data during the callbacks for you (see ChainListener::block_connected for more info).
252263
pub fn block_connected_with_filtering(&self, block: &Block, height: u32) {
@@ -280,6 +291,7 @@ impl ChainWatchInterfaceUtil {
280291

281292
/// Notify listeners that a block was connected, given pre-filtered list of transactions in the
282293
/// block which matched the filter (probably using does_match_tx).
294+
///
283295
/// Returns true if notified listeners registered additional watch data (implying that the
284296
/// block must be re-scanned and this function called again prior to further block_connected
285297
/// calls, see ChainListener::block_connected for more info).

src/chain/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//! Module provides structs and traits which allow other parts of rust-lightning to interact with
2-
//! the blockchain.
1+
//! Structs and traits which allow other parts of rust-lightning to interact with the blockchain.
32
43
pub mod chaininterface;
54
pub mod transaction;

src/chain/transaction.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bitcoin::util::hash::Sha256dHash;
44
use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
55

66
/// A reference to a transaction output.
7+
///
78
/// Differs from bitcoin::blockdata::transaction::OutPoint as the index is a u16 instead of u32
89
/// due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way.
910
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]

src/ln/channelmanager.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! The top-level channel management and payment tracking stuff lives here.
2+
//!
23
//! The ChannelManager is the main chunk of logic implementing the lightning protocol and is
34
//! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those
45
//! upon reconnect to the relevant peer(s).
6+
//!
57
//! It does not manage routing logic (see ln::router for that) nor does it manage constructing
68
//! on-chain transactions (it only monitors the chain to watch for any force-closes that might
79
//! imply it needs to fail HTLCs/payments/channels it manages).
@@ -223,6 +225,7 @@ const ERR: () = "You need at least 32 bit pointers (well, usize, but we'll assum
223225

224226
/// Manager which keeps track of a number of channels and sends messages to the appropriate
225227
/// channel, also tracking HTLC preimages and forwarding onion packets appropriately.
228+
///
226229
/// Implements ChannelMessageHandler, handling the multi-channel parts and passing things through
227230
/// to individual Channels.
228231
pub struct ChannelManager {
@@ -285,10 +288,14 @@ pub struct ChannelDetails {
285288
}
286289

287290
impl ChannelManager {
288-
/// Constructs a new ChannelManager to hold several channels and route between them. This is
289-
/// the main "logic hub" for all channel-related actions, and implements ChannelMessageHandler.
291+
/// Constructs a new ChannelManager to hold several channels and route between them.
292+
///
293+
/// This is the main "logic hub" for all channel-related actions, and implements
294+
/// ChannelMessageHandler.
295+
///
290296
/// fee_proportional_millionths is an optional fee to charge any payments routed through us.
291297
/// Non-proportional fees are fixed according to our risk using the provided fee estimator.
298+
///
292299
/// panics if channel_value_satoshis is >= `MAX_FUNDING_SATOSHIS`!
293300
pub fn new(our_network_key: SecretKey, fee_proportional_millionths: u32, announce_channels_publicly: bool, network: Network, feeest: Arc<FeeEstimator>, monitor: Arc<ManyChannelMonitor>, chain_monitor: Arc<ChainWatchInterface>, tx_broadcaster: Arc<BroadcasterInterface>, logger: Arc<Logger>) -> Result<Arc<ChannelManager>, secp256k1::Error> {
294301
let secp_ctx = Secp256k1::new();
@@ -324,12 +331,15 @@ impl ChannelManager {
324331
}
325332

326333
/// Creates a new outbound channel to the given remote node and with the given value.
334+
///
327335
/// user_id will be provided back as user_channel_id in FundingGenerationReady and
328336
/// FundingBroadcastSafe events to allow tracking of which events correspond with which
329337
/// create_channel call. Note that user_channel_id defaults to 0 for inbound channels, so you
330338
/// may wish to avoid using 0 for user_id here.
339+
///
331340
/// If successful, will generate a SendOpenChannel event, so you should probably poll
332341
/// PeerManager::process_events afterwards.
342+
///
333343
/// Raises APIError::APIMisuseError when channel_value_satoshis > 2**24 or push_msat being greater than channel_value_satoshis * 1k
334344
pub fn create_channel(&self, their_network_key: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_id: u64) -> Result<(), APIError> {
335345
let chan_keys = if cfg!(feature = "fuzztarget") {
@@ -407,6 +417,7 @@ impl ChannelManager {
407417
/// Begins the process of closing a channel. After this call (plus some timeout), no new HTLCs
408418
/// will be accepted on the given channel, and after additional timeout/the closing of all
409419
/// pending HTLCs, the channel will be closed on chain.
420+
///
410421
/// May generate a SendShutdown event on success, which should be relayed.
411422
pub fn close_channel(&self, channel_id: &[u8; 32]) -> Result<(), HandleError> {
412423
let (mut res, node_id, chan_option) = {
@@ -947,16 +958,19 @@ impl ChannelManager {
947958
}
948959

949960
/// Sends a payment along a given route.
961+
///
950962
/// Value parameters are provided via the last hop in route, see documentation for RouteHop
951963
/// fields for more info.
964+
///
952965
/// Note that if the payment_hash already exists elsewhere (eg you're sending a duplicative
953966
/// payment), we don't do anything to stop you! We always try to ensure that if the provided
954967
/// next hop knows the preimage to payment_hash they can claim an additional amount as
955968
/// specified in the last hop in the route! Thus, you should probably do your own
956969
/// payment_preimage tracking (which you should already be doing as they represent "proof of
957970
/// payment") and prevent double-sends yourself.
958-
/// See-also docs on Channel::send_htlc_and_commit.
971+
///
959972
/// May generate a SendHTLCs event on success, which should be relayed.
973+
///
960974
/// Raises APIError::RoutError when invalid route or forward parameter
961975
/// (cltv_delta, fee, node public key) is specified
962976
pub fn send_payment(&self, route: Route, payment_hash: [u8; 32]) -> Result<(), APIError> {
@@ -1033,7 +1047,9 @@ impl ChannelManager {
10331047
}
10341048

10351049
/// Call this upon creation of a funding transaction for the given channel.
1050+
///
10361051
/// Panics if a funding transaction has already been provided for this channel.
1052+
///
10371053
/// May panic if the funding_txo is duplicative with some other channel (note that this should
10381054
/// be trivially prevented by using unique funding transaction keys per-channel).
10391055
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_txo: OutPoint) {
@@ -1107,6 +1123,7 @@ impl ChannelManager {
11071123
}
11081124

11091125
/// Processes HTLCs which are pending waiting on random forward delay.
1126+
///
11101127
/// Should only really ever be called in response to an PendingHTLCsForwardable event.
11111128
/// Will likely generate further events.
11121129
pub fn process_pending_htlc_forwards(&self) {
@@ -1323,6 +1340,7 @@ impl ChannelManager {
13231340
/// Provides a payment preimage in response to a PaymentReceived event, returning true and
13241341
/// generating message events for the net layer to claim the payment, if possible. Thus, you
13251342
/// should probably kick the net layer to go send messages if this returns true!
1343+
///
13261344
/// May panic if called except in response to a PaymentReceived event.
13271345
pub fn claim_funds(&self, payment_preimage: [u8; 32]) -> bool {
13281346
let mut sha = Sha256::new();

src/ln/channelmonitor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! The logic to monitor for on-chain transactions and create the relevant claim responses lives
22
//! here.
3+
//!
34
//! ChannelMonitor objects are generated by ChannelManager in response to relevant
45
//! messages/actions, and MUST be persisted to disk (and, preferably, remotely) before progress can
56
//! be made in responding to certain messages, see ManyChannelMonitor for more.
7+
//!
68
//! Note that ChannelMonitors are an important part of the lightning trust model and a copy of the
79
//! latest ChannelMonitor must always be actively monitoring for chain updates (and no out-of-date
810
//! ChannelMonitors should do so). Thus, if you're building rust-lightning into an HSM or other
@@ -40,6 +42,7 @@ use std::{hash,cmp};
4042
pub enum ChannelMonitorUpdateErr {
4143
/// Used to indicate a temporary failure (eg connection to a watchtower failed, but is expected
4244
/// to succeed at some point in the future).
45+
///
4346
/// Such a failure will "freeze" a channel, preventing us from revoking old states or
4447
/// submitting new commitment transactions to the remote party.
4548
/// ChannelManager::test_restore_channel_monitor can be used to retry the update(s) and restore
@@ -55,12 +58,14 @@ pub enum ChannelMonitorUpdateErr {
5558
/// them. Generally should be implemented by keeping a local SimpleManyChannelMonitor and passing
5659
/// events to it, while also taking any add_update_monitor events and passing them to some remote
5760
/// server(s).
61+
///
5862
/// Note that any updates to a channel's monitor *must* be applied to each instance of the
5963
/// channel's monitor everywhere (including remote watchtowers) *before* this function returns. If
6064
/// an update occurs and a remote watchtower is left with old state, it may broadcast transactions
6165
/// which we have revoked, allowing our counterparty to claim all funds in the channel!
6266
pub trait ManyChannelMonitor: Send + Sync {
6367
/// Adds or updates a monitor for the given `funding_txo`.
68+
///
6469
/// Implementor must also ensure that the funding_txo outpoint is registered with any relevant
6570
/// ChainWatchInterfaces such that the provided monitor receives block_connected callbacks with
6671
/// any spends of it.
@@ -69,10 +74,13 @@ pub trait ManyChannelMonitor: Send + Sync {
6974

7075
/// A simple implementation of a ManyChannelMonitor and ChainListener. Can be used to create a
7176
/// watchtower or watch our own channels.
77+
///
7278
/// Note that you must provide your own key by which to refer to channels.
79+
///
7380
/// If you're accepting remote monitors (ie are implementing a watchtower), you must verify that
7481
/// users cannot overwrite a given channel by providing a duplicate key. ie you should probably
7582
/// index by a PublicKey which is required to sign any updates.
83+
///
7684
/// If you're using this for local monitoring of your own channels, you probably want to use
7785
/// `OutPoint` as the key, which will give you a ManyChannelMonitor implementation.
7886
pub struct SimpleManyChannelMonitor<Key> {
@@ -180,6 +188,7 @@ const MIN_SERIALIZATION_VERSION: u8 = 1;
180188

181189
/// A ChannelMonitor handles chain events (blocks connected and disconnected) and generates
182190
/// on-chain transactions to ensure no loss of funds occurs.
191+
///
183192
/// You MUST ensure that no ChannelMonitors for a given channel anywhere contain out-of-date
184193
/// information and are actively monitoring the chain.
185194
pub struct ChannelMonitor {

src/ln/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! High level lightning structs and impls live here.
2+
//!
23
//! You probably want to create a channelmanager::ChannelManager, and a router::Router first.
34
//! Then, you probably want to pass them both on to a peer_handler::PeerManager and use that to
45
//! create/manage connections and call get_and_clear_pending_events after each action, handling
56
//! them appropriately.
7+
//!
68
//! When you want to open/close a channel or send a payment, call into your ChannelManager and when
79
//! you want to learn things about the network topology (eg get a route for sending a payment),
810
//! call into your Router.

src/ln/msgs.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Wire messages, traits representing wire message handlers, and a few error types live here.
2+
//!
23
//! For a normal node you probably don't need to use anything here, however, if you wish to split a
34
//! node into an internet-facing route/message socket handling daemon and a separate daemon (or
45
//! server entirely) which handles only channel-related messages you may wish to implement
56
//! ChannelMessageHandler yourself and use it to re-serialize messages and pass them across
67
//! daemons/servers.
8+
//!
79
//! Note that if you go with such an architecture (instead of passing raw socket events to a
810
//! non-internet-facing system) you trust the frontend internet-facing system to not lie about the
911
//! source node_id of the mssage, however this does allow you to significantly reduce bandwidth
@@ -484,9 +486,10 @@ pub enum HTLCFailChannelUpdate {
484486
},
485487
}
486488

487-
/// A trait to describe an object which can receive channel messages. Messages MAY be called in
488-
/// parallel when they originate from different their_node_ids, however they MUST NOT be called in
489-
/// parallel when the two calls have the same their_node_id.
489+
/// A trait to describe an object which can receive channel messages.
490+
///
491+
/// Messages MAY be called in parallel when they originate from different their_node_ids, however
492+
/// they MUST NOT be called in parallel when the two calls have the same their_node_id.
490493
pub trait ChannelMessageHandler : events::EventsProvider + Send + Sync {
491494
//Channel init:
492495
/// Handle an incoming open_channel message from the given peer.

0 commit comments

Comments
 (0)