Package org.ldk.batteries
Class ChannelManagerConstructor
- java.lang.Object
-
- org.ldk.batteries.ChannelManagerConstructor
-
public class ChannelManagerConstructor extends Object
A simple utility class which assists in constructing a fresh or deserializing from disk a ChannelManager and one or more ChannelMonitors. Also constructs a PeerManager and spawns a background thread to monitor for and notify you of relevant Events. Note that you must ensure you hold a reference to any constructed ChannelManagerConstructor objects to ensure you continue to receive events generated by the background thread which will be stopped if this object is garbage collected.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ChannelManagerConstructor.EventHandler
Abstract interface which should handle Events and persist the ChannelManager.static class
ChannelManagerConstructor.InvalidSerializedDataException
An Exception that indicates the serialized data is invalid and has been corrupted on disk.static interface
ChannelManagerConstructor.RouterWrapper
A simple interface to provide routes to LDK.class
ChannelManagerConstructor.ScorerWrapper
Exposes the `ProbabilisticScorer` wrapped inside a lock.
-
Field Summary
Fields Modifier and Type Field Description ChannelManager
channel_manager
The ChannelManager either deserialized or newly-constructed.byte[]
channel_manager_latest_block_hash
The latest block has the channel manager saw.TwoTuple_BlockHashChannelMonitorZ[]
channel_monitors
A list of ChannelMonitors and the last block they each saw.NetworkGraph
net_graph
The `NetworkGraph` deserialized from the byte given to the constructor when deserializing or the `NetworkGraph` given explicitly to the new-object constructor.NioPeerHandler
nio_peer_handler
A NioPeerHandler which manages a background thread to handle socket events and pass them to the peer_manager.PeerManager
peer_manager
A PeerManager which is constructed to pass messages and handle connections to peers.MultiThreadedLockableScore
scorer
A mutex holding the `ProbabilisticScorer` which was loaded on startup.
-
Constructor Summary
Constructors Constructor Description ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized, UserConfig config, EntropySource entropy_source, NodeSigner node_signer, SignerProvider signer_provider, FeeEstimator fee_estimator, ChainMonitor chain_monitor, Filter filter, byte[] net_graph_serialized, ProbabilisticScoringParameters scoring_params, byte[] probabilistic_scorer_bytes, ChannelManagerConstructor.RouterWrapper router_wrapper, BroadcasterInterface tx_broadcaster, Logger logger)
Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementationsChannelManagerConstructor(Network network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height, EntropySource entropy_source, NodeSigner node_signer, SignerProvider signer_provider, FeeEstimator fee_estimator, ChainMonitor chain_monitor, NetworkGraph net_graph, ProbabilisticScoringParameters scoring_params, ChannelManagerConstructor.RouterWrapper router_wrapper, BroadcasterInterface tx_broadcaster, Logger logger)
Constructs a channel manager from the given interface implementations
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
chain_sync_completed(ChannelManagerConstructor.EventHandler event_handler, boolean use_p2p_graph_sync)
Utility which adds all of the deserialized ChannelMonitors to the chain watch so that further updates from the ChannelManager are processed as normal.ChannelManagerConstructor.ScorerWrapper
get_locked_scorer()
Gets the `ProbabilisticScorer` which backs the public lockable `scorer`.void
interrupt()
Interrupt the background thread, stopping the background handling of events.
-
-
-
Field Detail
-
channel_manager
public final ChannelManager channel_manager
The ChannelManager either deserialized or newly-constructed.
-
channel_manager_latest_block_hash
public final byte[] channel_manager_latest_block_hash
The latest block has the channel manager saw. If this is non-null it is a 32-byte block hash. You should sync the blockchain starting with the block that builds on this block.
-
channel_monitors
public final TwoTuple_BlockHashChannelMonitorZ[] channel_monitors
A list of ChannelMonitors and the last block they each saw. You should sync the blockchain on each individually starting with the block that builds on the hash given. After doing so (and syncing the blockchain on the channel manager as well), you should call chain_sync_completed() and then continue to normal application operation.
-
peer_manager
public PeerManager peer_manager
A PeerManager which is constructed to pass messages and handle connections to peers. This is `null` until `chain_sync_completed` is called.
-
nio_peer_handler
public NioPeerHandler nio_peer_handler
A NioPeerHandler which manages a background thread to handle socket events and pass them to the peer_manager. This is `null` until `chain_sync_completed` is called.
-
net_graph
public final NetworkGraph net_graph
The `NetworkGraph` deserialized from the byte given to the constructor when deserializing or the `NetworkGraph` given explicitly to the new-object constructor.
-
scorer
public final MultiThreadedLockableScore scorer
A mutex holding the `ProbabilisticScorer` which was loaded on startup.
-
-
Constructor Detail
-
ChannelManagerConstructor
public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized, UserConfig config, EntropySource entropy_source, NodeSigner node_signer, SignerProvider signer_provider, FeeEstimator fee_estimator, ChainMonitor chain_monitor, @Nullable Filter filter, byte[] net_graph_serialized, ProbabilisticScoringParameters scoring_params, byte[] probabilistic_scorer_bytes, @Nullable ChannelManagerConstructor.RouterWrapper router_wrapper, BroadcasterInterface tx_broadcaster, Logger logger) throws ChannelManagerConstructor.InvalidSerializedDataException
Deserializes a channel manager and a set of channel monitors from the given serialized copies and interface implementations- Parameters:
filter
- If provided, the outputs which were previously registered to be monitored for will be loaded into the filter. Note that if the provided Watch is a ChainWatch and has an associated filter, the previously registered outputs will be loaded when chain_sync_completed is called.router_wrapper
- If provided, routes will be fetched by calling the given router rather than an LDK `DefaultRouter`.- Throws:
ChannelManagerConstructor.InvalidSerializedDataException
-
ChannelManagerConstructor
public ChannelManagerConstructor(Network network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height, EntropySource entropy_source, NodeSigner node_signer, SignerProvider signer_provider, FeeEstimator fee_estimator, ChainMonitor chain_monitor, NetworkGraph net_graph, ProbabilisticScoringParameters scoring_params, @Nullable ChannelManagerConstructor.RouterWrapper router_wrapper, BroadcasterInterface tx_broadcaster, Logger logger)
Constructs a channel manager from the given interface implementations- Parameters:
router_wrapper
- If provided, routes will be fetched by calling the given router rather than an LDK `DefaultRouter`.
-
-
Method Detail
-
get_locked_scorer
public ChannelManagerConstructor.ScorerWrapper get_locked_scorer()
Gets the `ProbabilisticScorer` which backs the public lockable `scorer`. Don't forget to `close` the lock when you're done with it.
-
chain_sync_completed
public void chain_sync_completed(ChannelManagerConstructor.EventHandler event_handler, boolean use_p2p_graph_sync)
Utility which adds all of the deserialized ChannelMonitors to the chain watch so that further updates from the ChannelManager are processed as normal. This also spawns a background thread which will call the appropriate methods on the provided EventHandler as required.- Parameters:
use_p2p_graph_sync
- determines if we will sync the network graph from peers over the standard (but inefficient) lightning P2P protocol. Note that doing so currently requires trusting peers as no DoS mechanism is enforced to ensure we don't accept bogus gossip. Alternatively, you may sync the net_graph exposed in this object via Rapid Gossip Sync.
-
interrupt
public void interrupt()
Interrupt the background thread, stopping the background handling of events.
-
-