Skip to content

Commit 348009c

Browse files
authored
Merge pull request #29 from TheBlueMatt/main
Update to LDK 0.0.99
2 parents d62373c + 12c3ea6 commit 348009c

34 files changed

+2962
-774
lines changed

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

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@
1616
public class NioPeerHandler {
1717
private static class Peer {
1818
SocketDescriptor descriptor;
19-
// When we are told by LDK to disconnect, we can't return to LDK until we are sure
20-
// won't call any more read/write PeerManager functions with the same connection.
21-
// This is set to true if we're in such a condition (with disconnect checked
22-
// before with the Peer monitor lock held) and false when we can return.
23-
boolean block_disconnect_socket = false;
24-
// Indicates LDK told us to disconnect this peer, and thus we should not call socket_disconnected.
25-
boolean disconnect_requested = false;
2619
SelectionKey key;
2720
}
2821

@@ -83,22 +76,12 @@ public long send_data(byte[] data, boolean resume_read) {
8376

8477
@Override
8578
public void disconnect_socket() {
86-
synchronized (peer) {
87-
peer.disconnect_requested = true;
88-
}
8979
try {
9080
do_selector_action(() -> {
9181
peer.key.cancel();
9282
peer.key.channel().close();
9383
});
9484
} catch (IOException ignored) { }
95-
synchronized (peer) {
96-
while (peer.block_disconnect_socket) {
97-
try {
98-
peer.wait();
99-
} catch (InterruptedException ignored) { }
100-
}
101-
}
10285
}
10386
@Override public boolean eq(SocketDescriptor other_arg) { return other_arg.hash() == our_id; }
10487
@Override public long hash() { return our_id; }
@@ -169,11 +152,6 @@ public NioPeerHandler(PeerManager manager) throws IOException {
169152
continue; // There is no attachment so the rest of the loop is useless
170153
}
171154
Peer peer = (Peer) key.attachment();
172-
synchronized (peer) {
173-
if (peer.disconnect_requested)
174-
continue;
175-
peer.block_disconnect_socket = true;
176-
}
177155
try {
178156
if (key.isValid() && (key.interestOps() & SelectionKey.OP_WRITE) != 0 && key.isWritable()) {
179157
Result_NonePeerHandleErrorZ res = this.peer_manager.write_buffer_space_avail(peer.descriptor);
@@ -208,10 +186,6 @@ public NioPeerHandler(PeerManager manager) throws IOException {
208186
key.cancel();
209187
peer_manager.socket_disconnected(peer.descriptor);
210188
}
211-
synchronized (peer) {
212-
peer.block_disconnect_socket = false;
213-
peer.notifyAll();
214-
}
215189
} catch (CancelledKeyException e) {
216190
try { key.channel().close(); } catch (IOException ignored) { }
217191
// The key is only cancelled when we have notified the PeerManager that the socket is closed, so
@@ -295,4 +269,4 @@ public void interrupt() {
295269
public void check_events() {
296270
selector.wakeup();
297271
}
298-
}
272+
}

src/main/java/org/ldk/enums/Level.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
* An enum representing the available verbosity levels of the logger.
55
*/
66
public enum Level {
7-
LDKLevel_Off,
8-
LDKLevel_Error,
9-
LDKLevel_Warn,
10-
LDKLevel_Info,
11-
LDKLevel_Debug,
127
LDKLevel_Trace,
8+
LDKLevel_Debug,
9+
LDKLevel_Info,
10+
LDKLevel_Warn,
11+
LDKLevel_Error,
1312
; static native void init();
1413
static { init(); }
1514
}

src/main/java/org/ldk/impl/bindings.java

Lines changed: 98 additions & 30 deletions
Large diffs are not rendered by default.

src/main/java/org/ldk/structs/BestBlock.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public BestBlock clone() {
2929
}
3030

3131
/**
32-
* Returns the best block from the genesis of the given network.
32+
* Constructs a `BestBlock` that represents the genesis block at height 0 of the given
33+
* network.
3334
*/
3435
public static BestBlock from_genesis(Network network) {
3536
long ret = bindings.BestBlock_from_genesis(network);
@@ -39,7 +40,7 @@ public static BestBlock from_genesis(Network network) {
3940
}
4041

4142
/**
42-
* Returns the best block as identified by the given block hash and height.
43+
* Returns a `BestBlock` as identified by the given block hash and height.
4344
*/
4445
public static BestBlock of(byte[] block_hash, int height) {
4546
long ret = bindings.BestBlock_new(block_hash, height);

src/main/java/org/ldk/structs/ChannelConfig.java

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,65 @@ protected void finalize() throws Throwable {
2020
}
2121

2222
/**
23-
* Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
23+
* Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
24+
* over the channel.
2425
* This may be allowed to change at runtime in a later update, however doing so must result in
2526
* update messages sent to notify all nodes of our updated relay fee.
2627
*
2728
* Default value: 0.
2829
*/
29-
public int get_fee_proportional_millionths() {
30-
int ret = bindings.ChannelConfig_get_fee_proportional_millionths(this.ptr);
30+
public int get_forwarding_fee_proportional_millionths() {
31+
int ret = bindings.ChannelConfig_get_forwarding_fee_proportional_millionths(this.ptr);
3132
return ret;
3233
}
3334

3435
/**
35-
* Amount (in millionths of a satoshi) the channel will charge per transferred satoshi.
36+
* Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound
37+
* over the channel.
3638
* This may be allowed to change at runtime in a later update, however doing so must result in
3739
* update messages sent to notify all nodes of our updated relay fee.
3840
*
3941
* Default value: 0.
4042
*/
41-
public void set_fee_proportional_millionths(int val) {
42-
bindings.ChannelConfig_set_fee_proportional_millionths(this.ptr, val);
43+
public void set_forwarding_fee_proportional_millionths(int val) {
44+
bindings.ChannelConfig_set_forwarding_fee_proportional_millionths(this.ptr, val);
45+
}
46+
47+
/**
48+
* Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
49+
* excess of [`forwarding_fee_proportional_millionths`].
50+
* This may be allowed to change at runtime in a later update, however doing so must result in
51+
* update messages sent to notify all nodes of our updated relay fee.
52+
*
53+
* The default value of a single satoshi roughly matches the market rate on many routing nodes
54+
* as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
55+
* this node.
56+
*
57+
* Default value: 1000.
58+
*
59+
* [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
60+
*/
61+
public int get_forwarding_fee_base_msat() {
62+
int ret = bindings.ChannelConfig_get_forwarding_fee_base_msat(this.ptr);
63+
return ret;
64+
}
65+
66+
/**
67+
* Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, in
68+
* excess of [`forwarding_fee_proportional_millionths`].
69+
* This may be allowed to change at runtime in a later update, however doing so must result in
70+
* update messages sent to notify all nodes of our updated relay fee.
71+
*
72+
* The default value of a single satoshi roughly matches the market rate on many routing nodes
73+
* as of July 2021. Adjusting it upwards or downwards may change whether nodes route through
74+
* this node.
75+
*
76+
* Default value: 1000.
77+
*
78+
* [`forwarding_fee_proportional_millionths`]: ChannelConfig::forwarding_fee_proportional_millionths
79+
*/
80+
public void set_forwarding_fee_base_msat(int val) {
81+
bindings.ChannelConfig_set_forwarding_fee_base_msat(this.ptr, val);
4382
}
4483

4584
/**
@@ -100,7 +139,7 @@ public void set_cltv_expiry_delta(short val) {
100139
* This should only be set to true for nodes which expect to be online reliably.
101140
*
102141
* As the node which funds a channel picks this value this will only apply for new outbound
103-
* channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
142+
* channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
104143
*
105144
* This cannot be changed after the initial channel handshake.
106145
*
@@ -118,7 +157,7 @@ public boolean get_announced_channel() {
118157
* This should only be set to true for nodes which expect to be online reliably.
119158
*
120159
* As the node which funds a channel picks this value this will only apply for new outbound
121-
* channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set.
160+
* channels unless [`ChannelHandshakeLimits::force_announced_channel_preference`] is set.
122161
*
123162
* This cannot be changed after the initial channel handshake.
124163
*
@@ -166,8 +205,8 @@ public void set_commit_upfront_shutdown_pubkey(boolean val) {
166205
/**
167206
* Constructs a new ChannelConfig given each field
168207
*/
169-
public static ChannelConfig of(int fee_proportional_millionths_arg, short cltv_expiry_delta_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg) {
170-
long ret = bindings.ChannelConfig_new(fee_proportional_millionths_arg, cltv_expiry_delta_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
208+
public static ChannelConfig of(int forwarding_fee_proportional_millionths_arg, int forwarding_fee_base_msat_arg, short cltv_expiry_delta_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg) {
209+
long ret = bindings.ChannelConfig_new(forwarding_fee_proportional_millionths_arg, forwarding_fee_base_msat_arg, cltv_expiry_delta_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
171210
ChannelConfig ret_hu_conv = new ChannelConfig(null, ret);
172211
ret_hu_conv.ptrs_to.add(ret_hu_conv);
173212
return ret_hu_conv;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package org.ldk.structs;
2+
3+
import org.ldk.impl.bindings;
4+
import org.ldk.enums.*;
5+
import org.ldk.util.*;
6+
import java.util.Arrays;
7+
8+
9+
/**
10+
* Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
11+
* to better separate parameters.
12+
*/
13+
@SuppressWarnings("unchecked") // We correctly assign various generic arrays
14+
public class ChannelCounterparty extends CommonBase {
15+
ChannelCounterparty(Object _dummy, long ptr) { super(ptr); }
16+
@Override @SuppressWarnings("deprecation")
17+
protected void finalize() throws Throwable {
18+
super.finalize();
19+
if (ptr != 0) { bindings.ChannelCounterparty_free(ptr); }
20+
}
21+
22+
/**
23+
* The node_id of our counterparty
24+
*/
25+
public byte[] get_node_id() {
26+
byte[] ret = bindings.ChannelCounterparty_get_node_id(this.ptr);
27+
return ret;
28+
}
29+
30+
/**
31+
* The node_id of our counterparty
32+
*/
33+
public void set_node_id(byte[] val) {
34+
bindings.ChannelCounterparty_set_node_id(this.ptr, val);
35+
}
36+
37+
/**
38+
* The Features the channel counterparty provided upon last connection.
39+
* Useful for routing as it is the most up-to-date copy of the counterparty's features and
40+
* many routing-relevant features are present in the init context.
41+
*/
42+
public InitFeatures get_features() {
43+
long ret = bindings.ChannelCounterparty_get_features(this.ptr);
44+
InitFeatures ret_hu_conv = new InitFeatures(null, ret);
45+
ret_hu_conv.ptrs_to.add(this);
46+
return ret_hu_conv;
47+
}
48+
49+
/**
50+
* The Features the channel counterparty provided upon last connection.
51+
* Useful for routing as it is the most up-to-date copy of the counterparty's features and
52+
* many routing-relevant features are present in the init context.
53+
*/
54+
public void set_features(InitFeatures val) {
55+
bindings.ChannelCounterparty_set_features(this.ptr, val == null ? 0 : val.ptr & ~1);
56+
this.ptrs_to.add(val);
57+
}
58+
59+
/**
60+
* The value, in satoshis, that must always be held in the channel for our counterparty. This
61+
* value ensures that if our counterparty broadcasts a revoked state, we can punish them by
62+
* claiming at least this value on chain.
63+
*
64+
* This value is not included in [`inbound_capacity_msat`] as it can never be spent.
65+
*
66+
* [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
67+
*/
68+
public long get_unspendable_punishment_reserve() {
69+
long ret = bindings.ChannelCounterparty_get_unspendable_punishment_reserve(this.ptr);
70+
return ret;
71+
}
72+
73+
/**
74+
* The value, in satoshis, that must always be held in the channel for our counterparty. This
75+
* value ensures that if our counterparty broadcasts a revoked state, we can punish them by
76+
* claiming at least this value on chain.
77+
*
78+
* This value is not included in [`inbound_capacity_msat`] as it can never be spent.
79+
*
80+
* [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
81+
*/
82+
public void set_unspendable_punishment_reserve(long val) {
83+
bindings.ChannelCounterparty_set_unspendable_punishment_reserve(this.ptr, val);
84+
}
85+
86+
/**
87+
* Creates a copy of the ChannelCounterparty
88+
*/
89+
public ChannelCounterparty clone() {
90+
long ret = bindings.ChannelCounterparty_clone(this.ptr);
91+
ChannelCounterparty ret_hu_conv = new ChannelCounterparty(null, ret);
92+
ret_hu_conv.ptrs_to.add(this);
93+
return ret_hu_conv;
94+
}
95+
96+
}

0 commit comments

Comments
 (0)