Skip to content

Commit

Permalink
More option cleanups.
Browse files Browse the repository at this point in the history
Because we have too many which are never used and I don't want to document
them.

1. Remove unused anchor_onchain_wait.  When implemented, it should be
   hardcoded to 100 or more.
2. Remove anchor_confirms_max.  10 always reasonable, and we can readd
   an override option should someone need it.
3. max_htlc_expiry should be the same as locktime_max (which increases
   from 3 to 5 days by default): they're both a limit on how long
   funds can be locked up.
4. channel_update_interval should always be a dev option.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed May 20, 2018
1 parent 0aa2274 commit edf1b3c
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 64 deletions.
9 changes: 0 additions & 9 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ struct config {
/* How long do we let them lock up our funds? (blocks) */
u32 locktime_max;

/* How many blocks before we expect to see anchor?. */
u32 anchor_onchain_wait;

/* How many confirms until we consider an anchor "settled". */
u32 anchor_confirms;

/* How long will we accept them waiting? */
u32 anchor_confirms_max;

/* Maximum percent of fee rate we'll accept. */
u32 commitment_fee_max_percent;

Expand All @@ -44,9 +38,6 @@ struct config {
/* Minimum CLTV if we're the final hop.*/
u32 cltv_final;

/* Maximum time for an expiring HTLC (blocks). */
u32 max_htlc_expiry;

/* Fee rates. */
u32 fee_base;
s32 fee_per_satoshi;
Expand Down
11 changes: 4 additions & 7 deletions lightningd/opening_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,12 +624,10 @@ new_uncommitted_channel(struct lightningd *ld,
static void channel_config(struct lightningd *ld,
struct channel_config *ours,
u32 *max_to_self_delay,
u32 *max_minimum_depth,
u64 *min_effective_htlc_capacity_msat)
{
/* FIXME: depend on feerate. */
*max_to_self_delay = ld->config.locktime_max;
*max_minimum_depth = ld->config.anchor_confirms_max;
/* This is 1c at $1000/BTC */
*min_effective_htlc_capacity_msat = 1000000;

Expand Down Expand Up @@ -678,7 +676,7 @@ u8 *peer_accept_channel(const tal_t *ctx,
const struct channel_id *channel_id,
const u8 *open_msg)
{
u32 max_to_self_delay, max_minimum_depth;
u32 max_to_self_delay;
u64 min_effective_htlc_capacity_msat;
u8 *msg;
struct uncommitted_channel *uc;
Expand Down Expand Up @@ -723,7 +721,7 @@ u8 *peer_accept_channel(const tal_t *ctx,
uc->minimum_depth = ld->config.anchor_confirms;

channel_config(ld, &uc->our_config,
&max_to_self_delay, &max_minimum_depth,
&max_to_self_delay,
&min_effective_htlc_capacity_msat);

msg = towire_opening_init(uc, get_chainparams(ld)->index,
Expand Down Expand Up @@ -751,7 +749,7 @@ static void peer_offer_channel(struct lightningd *ld,
int peer_fd, int gossip_fd)
{
u8 *msg;
u32 max_to_self_delay, max_minimum_depth;
u32 max_to_self_delay;
u64 min_effective_htlc_capacity_msat;

/* Remove from list, it's not pending any more. */
Expand Down Expand Up @@ -793,7 +791,7 @@ static void peer_offer_channel(struct lightningd *ld,
}

channel_config(ld, &fc->uc->our_config,
&max_to_self_delay, &max_minimum_depth,
&max_to_self_delay,
&min_effective_htlc_capacity_msat);

msg = towire_opening_init(fc,
Expand All @@ -807,7 +805,6 @@ static void peer_offer_channel(struct lightningd *ld,
msg = towire_opening_funder(fc, fc->wtx.amount,
fc->push_msat,
get_feerate(ld->topology, FEERATE_NORMAL),
max_minimum_depth,
fc->wtx.change, fc->wtx.change_key_index,
fc->channel_flags,
fc->wtx.utxos,
Expand Down
45 changes: 9 additions & 36 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,9 @@ static void config_register_opts(struct lightningd *ld)
opt_register_arg("--max-locktime-blocks", opt_set_u32, opt_show_u32,
&ld->config.locktime_max,
"Maximum blocks a peer can lock up our funds");
opt_register_arg("--anchor-onchain", opt_set_u32, opt_show_u32,
&ld->config.anchor_onchain_wait,
"Blocks before we give up on pending anchor transaction");
opt_register_arg("--anchor-confirms", opt_set_u32, opt_show_u32,
&ld->config.anchor_confirms,
"Confirmations required for anchor transaction");
opt_register_arg("--max-anchor-confirms", opt_set_u32, opt_show_u32,
&ld->config.anchor_confirms_max,
"Maximum confirmations other side can wait for anchor transaction");
opt_register_arg("--commit-fee-min=<percent>", opt_set_u32, opt_show_u32,
&ld->config.commitment_fee_min_percent,
"Minimum percentage of fee to accept for commitment");
Expand All @@ -331,9 +325,6 @@ static void config_register_opts(struct lightningd *ld)
opt_register_arg("--cltv-final", opt_set_u32, opt_show_u32,
&ld->config.cltv_final,
"Number of blocks for final ctlv_expiry");
opt_register_arg("--max-htlc-expiry", opt_set_u32, opt_show_u32,
&ld->config.max_htlc_expiry,
"Maximum number of blocks to accept an HTLC before expiry");
opt_register_arg("--commit-time", opt_set_time, opt_show_time,
&ld->config.commit_time,
"Time after changes before sending out COMMIT");
Expand Down Expand Up @@ -447,25 +438,24 @@ static void dev_register_opts(struct lightningd *ld)
opt_register_arg("--dev-override-fee-rates", opt_set_fee_rates, NULL,
ld->topology,
"Force a specific rates (immediate/normal/slow) in satoshis per kw regardless of estimated fees");

opt_register_arg(
"--dev-channel-update-interval=<s>", opt_set_u32, opt_show_u32,
&ld->config.channel_update_interval,
"Time in seconds between channel updates for our own channels.");
}
#endif

static const struct config testnet_config = {
/* 6 blocks to catch cheating attempts. */
.locktime_blocks = 6,

/* They can have up to 3 days. */
.locktime_max = 3 * 6 * 24,

/* Testnet can have long runs of empty blocks. */
.anchor_onchain_wait = 100,
/* They can have up to 5 days. */
.locktime_max = 5 * 6 * 24,

/* We're fairly trusting, under normal circumstances. */
.anchor_confirms = 1,

/* More than 10 confirms seems overkill. */
.anchor_confirms_max = 10,

/* Testnet fees are crazy, allow infinite feerange. */
.commitment_fee_min_percent = 0,
.commitment_fee_max_percent = 0,
Expand All @@ -477,9 +467,6 @@ static const struct config testnet_config = {
.cltv_expiry_delta = 6,
.cltv_final = 6,

/* Don't lock up channel for more than 5 days. */
.max_htlc_expiry = 5 * 6 * 24,

/* Send commit 10msec after receiving; almost immediately. */
.commit_time = TIME_FROM_MSEC(10),

Expand Down Expand Up @@ -507,18 +494,12 @@ static const struct config mainnet_config = {
/* ~one day to catch cheating attempts. */
.locktime_blocks = 6 * 24,

/* They can have up to 3 days. */
.locktime_max = 3 * 6 * 24,

/* You should get in within 10 blocks. */
.anchor_onchain_wait = 10,
/* They can have up to 5 days. */
.locktime_max = 5 * 6 * 24,

/* We're fairly trusting, under normal circumstances. */
.anchor_confirms = 3,

/* More than 10 confirms seems overkill. */
.anchor_confirms_max = 10,

/* Insist between 2 and 20 times the 2-block fee. */
.commitment_fee_min_percent = 200,
.commitment_fee_max_percent = 2000,
Expand All @@ -538,9 +519,6 @@ static const struct config mainnet_config = {
* worst case for the terminal node C lower at `2R+G+S` blocks */
.cltv_final = 8,

/* Don't lock up channel for more than 5 days. */
.max_htlc_expiry = 5 * 6 * 24,

/* Send commit 10msec after receiving; almost immediately. */
.commit_time = TIME_FROM_MSEC(10),

Expand Down Expand Up @@ -739,11 +717,6 @@ void register_opts(struct lightningd *ld)
&ld->pidfile,
"Specify pid file");

opt_register_arg(
"--channel-update-interval=<s>", opt_set_u32, opt_show_u32,
&ld->config.channel_update_interval,
"Time in seconds between channel updates for our own channels.");

opt_register_logging(ld);
opt_register_version();

Expand Down
4 changes: 2 additions & 2 deletions lightningd/peer_htlcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,12 @@ static void forward_htlc(struct htlc_in *hin,
* 1. type: 21 (`expiry_too_far`)
*/
if (get_block_height(ld->topology)
+ ld->config.max_htlc_expiry < outgoing_cltv_value) {
+ ld->config.locktime_max < outgoing_cltv_value) {
log_debug(hin->key.channel->log,
"Expiry cltv %u too far from current %u + max %u",
outgoing_cltv_value,
get_block_height(ld->topology),
ld->config.max_htlc_expiry);
ld->config.locktime_max);
failcode = WIRE_EXPIRY_TOO_FAR;
goto fail;
}
Expand Down
11 changes: 5 additions & 6 deletions openingd/opening.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ static u8 *opening_read_peer_msg(struct state *state)
static u8 *funder_channel(struct state *state,
const struct pubkey *our_funding_pubkey,
const struct basepoints *ours,
u32 max_minimum_depth,
u64 change_satoshis, u32 change_keyindex,
u8 channel_flags,
struct utxo **utxos,
Expand Down Expand Up @@ -352,10 +351,10 @@ static u8 *funder_channel(struct state *state,
* Other fields have the same requirements as their counterparts in
* `open_channel`.
*/
if (minimum_depth > max_minimum_depth)
if (minimum_depth > 10)
negotiation_failed(state,
"minimum_depth %u larger than %u",
minimum_depth, max_minimum_depth);
minimum_depth, 10);

/* BOLT #2:
*
Expand Down Expand Up @@ -800,7 +799,7 @@ int main(int argc, char *argv[])
struct privkey seed;
struct basepoints our_points;
struct pubkey our_funding_pubkey;
u32 minimum_depth, max_minimum_depth;
u32 minimum_depth;
u32 min_feerate, max_feerate;
u64 change_satoshis;
u32 change_keyindex;
Expand Down Expand Up @@ -849,11 +848,11 @@ int main(int argc, char *argv[])
if (fromwire_opening_funder(state, msg,
&state->funding_satoshis,
&state->push_msat,
&state->feerate_per_kw, &max_minimum_depth,
&state->feerate_per_kw,
&change_satoshis, &change_keyindex,
&channel_flags, &utxos, &bip32_base)) {
msg = funder_channel(state, &our_funding_pubkey, &our_points,
max_minimum_depth, change_satoshis,
change_satoshis,
change_keyindex, channel_flags,
utxos, &bip32_base);
peer_billboard(false,
Expand Down
1 change: 0 additions & 1 deletion openingd/opening_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ opening_funder,6001
opening_funder,,funding_satoshis,u64
opening_funder,,push_msat,u64
opening_funder,,feerate_per_kw,u32
opening_funder,,max_minimum_depth,u32
opening_funder,,change_satoshis,u64
opening_funder,,change_keyindex,u32
opening_funder,,channel_flags,u8
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
DEVELOPER = os.getenv("DEVELOPER", "0") == "1"


@unittest.skipIf(not DEVELOPER, "needs DEVELOPER=1 for --dev-broadcast-interval")
@unittest.skipIf(not DEVELOPER, "needs --dev-broadcast-interval, --dev-channelupdate-interval")
def test_gossip_pruning(node_factory, bitcoind):
""" Create channel and see it being updated in time before pruning
"""
opts = {'channel-update-interval': 5}
opts = {'dev-channel-update-interval': 5}
l1, l2, l3 = node_factory.get_nodes(3, opts)

l1.rpc.connect(l2.info['id'], 'localhost', l2.port)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lightningd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3623,7 +3623,7 @@ def test_funding_fail(self):
"""Add some funds, fund a channel without enough funds"""
# Previous runs with same bitcoind can leave funds!
l1 = self.node_factory.get_node(random_hsm=True)
max_locktime = 3 * 6 * 24
max_locktime = 5 * 6 * 24
l2 = self.node_factory.get_node(options={'locktime-blocks': max_locktime + 1})
l1.rpc.connect(l2.info['id'], 'localhost', l2.port)

Expand Down

0 comments on commit edf1b3c

Please sign in to comment.