Skip to content

Commit 01303b3

Browse files
authored
Merge pull request #133 from keyuebao/keyue/issue-132
[Java] Update ChannelManagerConstructor
2 parents a672396 + fc1713f commit 01303b3

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/main/java/org/ldk/batteries/ChannelManagerConstructor.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public static class InvalidSerializedDataException extends Exception {
7878
*/
7979
private final ProbabilisticScorer prob_scorer;
8080
private final Logger logger;
81-
private final KeysManager keys_manager;
81+
private final EntropySource entropy_source;
82+
private final NodeSigner node_signer;
8283

8384
/**
8485
* Exposes the `ProbabilisticScorer` wrapped inside a lock. Don't forget to `close` this lock when you're done with
@@ -132,13 +133,14 @@ Result_RouteLightningErrorZ find_route(byte[] payer_node_id, RouteParameters rou
132133
* @param router_wrapper If provided, routes will be fetched by calling the given router rather than an LDK `DefaultRouter`.
133134
*/
134135
public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] channel_monitors_serialized, UserConfig config,
135-
KeysManager keys_manager, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
136+
EntropySource entropy_source, NodeSigner node_signer, SignerProvider signer_provider,
137+
FeeEstimator fee_estimator, ChainMonitor chain_monitor,
136138
@Nullable Filter filter, byte[] net_graph_serialized,
137139
ProbabilisticScoringParameters scoring_params, byte[] probabilistic_scorer_bytes,
138140
@Nullable RouterWrapper router_wrapper,
139141
BroadcasterInterface tx_broadcaster, Logger logger) throws InvalidSerializedDataException {
140-
this.keys_manager = keys_manager;
141-
EntropySource entropy_source = keys_manager.as_EntropySource();
142+
this.entropy_source = entropy_source;
143+
this.node_signer = node_signer;
142144

143145
Result_NetworkGraphDecodeErrorZ graph_res = NetworkGraph.read(net_graph_serialized, logger);
144146
if (!graph_res.is_ok()) {
@@ -173,7 +175,7 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
173175
this.channel_monitors = new TwoTuple_BlockHashChannelMonitorZ[monitors.length];
174176
HashSet<OutPoint> monitor_funding_set = new HashSet();
175177
for (int i = 0; i < monitors.length; i++) {
176-
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(channel_monitors_serialized[i], entropy_source, keys_manager.as_SignerProvider());
178+
Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ res = UtilMethods.C2Tuple_BlockHashChannelMonitorZ_read(channel_monitors_serialized[i], entropy_source, signer_provider);
177179
if (res instanceof Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_Err) {
178180
throw new InvalidSerializedDataException("Serialized ChannelMonitor was corrupt");
179181
}
@@ -184,8 +186,8 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
184186
throw new InvalidSerializedDataException("Set of ChannelMonitors contained duplicates (ie the same funding_txo was set on multiple monitors)");
185187
}
186188
Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ res =
187-
UtilMethods.C2Tuple_BlockHashChannelManagerZ_read(channel_manager_serialized, keys_manager.as_EntropySource(),
188-
keys_manager.as_NodeSigner(), keys_manager.as_SignerProvider(), fee_estimator, chain_monitor.as_Watch(),
189+
UtilMethods.C2Tuple_BlockHashChannelManagerZ_read(channel_manager_serialized, entropy_source,
190+
node_signer, signer_provider, fee_estimator, chain_monitor.as_Watch(),
189191
tx_broadcaster, router, logger, config, monitors);
190192
if (!res.is_ok()) {
191193
throw new InvalidSerializedDataException("Serialized ChannelManager was corrupt");
@@ -207,13 +209,13 @@ public ChannelManagerConstructor(byte[] channel_manager_serialized, byte[][] cha
207209
* @param router_wrapper If provided, routes will be fetched by calling the given router rather than an LDK `DefaultRouter`.
208210
*/
209211
public ChannelManagerConstructor(Network network, UserConfig config, byte[] current_blockchain_tip_hash, int current_blockchain_tip_height,
210-
KeysManager keys_manager, FeeEstimator fee_estimator, ChainMonitor chain_monitor,
212+
EntropySource entropy_source, NodeSigner node_signer, SignerProvider signer_provider,
213+
FeeEstimator fee_estimator, ChainMonitor chain_monitor,
211214
NetworkGraph net_graph, ProbabilisticScoringParameters scoring_params,
212215
@Nullable RouterWrapper router_wrapper,
213216
BroadcasterInterface tx_broadcaster, Logger logger) {
214-
this.keys_manager = keys_manager;
215-
EntropySource entropy_source = keys_manager.as_EntropySource();
216-
217+
this.entropy_source = entropy_source;
218+
this.node_signer = node_signer;
217219
this.net_graph = net_graph;
218220
assert(scoring_params != null);
219221
this.prob_scorer = ProbabilisticScorer.of(scoring_params, net_graph, logger);
@@ -239,7 +241,7 @@ public ChannelManagerConstructor(Network network, UserConfig config, byte[] curr
239241
BestBlock block = BestBlock.of(current_blockchain_tip_hash, current_blockchain_tip_height);
240242
ChainParameters params = ChainParameters.of(network, block);
241243
channel_manager = ChannelManager.of(fee_estimator, chain_monitor.as_Watch(), tx_broadcaster, router, logger,
242-
keys_manager.as_EntropySource(), keys_manager.as_NodeSigner(), keys_manager.as_SignerProvider(), config, params);
244+
entropy_source, node_signer, signer_provider, config, params);
243245
this.logger = logger;
244246
}
245247

@@ -279,8 +281,8 @@ public void chain_sync_completed(EventHandler event_handler, boolean use_p2p_gra
279281
P2PGossipSync graph_msg_handler = P2PGossipSync.of(net_graph, Option_UtxoLookupZ.none(), logger);
280282
this.peer_manager = PeerManager.of(channel_manager.as_ChannelMessageHandler(),
281283
ignoring_handler.as_RoutingMessageHandler(), ignoring_handler.as_OnionMessageHandler(),
282-
(int)(System.currentTimeMillis() / 1000), this.keys_manager.as_EntropySource().get_secure_random_bytes(),
283-
logger, ignoring_handler.as_CustomMessageHandler(), keys_manager.as_NodeSigner());
284+
(int)(System.currentTimeMillis() / 1000), this.entropy_source.get_secure_random_bytes(),
285+
logger, ignoring_handler.as_CustomMessageHandler(), this.node_signer);
284286

285287
try {
286288
this.nio_peer_handler = new NioPeerHandler(peer_manager);

src/test/java/org/ldk/HumanObjectPeerTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ private void setup_route_handler() {
379379

380380
if (use_chan_manager_constructor) {
381381
this.constructor = new ChannelManagerConstructor(Network.LDKNetwork_Bitcoin, get_config(), new byte[32], 0,
382-
this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, this.net_graph,
382+
this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
383+
this.fee_estimator, this.chain_monitor, this.net_graph,
383384
ProbabilisticScoringParameters.with_default(), (ChannelManagerConstructor.RouterWrapper)
384385
(payer_node_id, route_params, first_hops, inflight_htlcs, payment_hash, payment_id, default_router) -> {
385386
assert payment_hash != null && payment_id != null;
@@ -466,7 +467,8 @@ public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters para
466467
filter_nullable = ((Option_FilterZ.Some) this.filter).some;
467468
}
468469
this.constructor = new ChannelManagerConstructor(serialized, monitors, get_config(),
469-
this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, filter_nullable,
470+
this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
471+
this.fee_estimator, this.chain_monitor, filter_nullable,
470472
serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer, null,
471473
this.tx_broadcaster, this.logger);
472474
try {
@@ -475,7 +477,8 @@ public Result_RouteLightningErrorZ find_route(byte[] payer, RouteParameters para
475477
monitors_dupd[0] = monitors[0];
476478
monitors_dupd[1] = monitors[0];
477479
ChannelManagerConstructor constr = new ChannelManagerConstructor(serialized, monitors_dupd, get_config(),
478-
this.explicit_keys_manager, this.fee_estimator, this.chain_monitor, filter_nullable,
480+
this.explicit_keys_manager.as_EntropySource(), this.explicit_keys_manager.as_NodeSigner(), this.explicit_keys_manager.as_SignerProvider(),
481+
this.fee_estimator, this.chain_monitor, filter_nullable,
479482
serialized_graph, ProbabilisticScoringParameters.with_default(), serialized_scorer, null,
480483
this.tx_broadcaster, this.logger);
481484
assert false;

0 commit comments

Comments
 (0)