diff --git a/doc/lightning-listconfigs.7.md b/doc/lightning-listconfigs.7.md index 6d6e4506d..cd315a46f 100644 --- a/doc/lightning-listconfigs.7.md +++ b/doc/lightning-listconfigs.7.md @@ -349,6 +349,7 @@ On success, an object is returned, containing: - **announce-addr-dns** (boolean, optional): Whether we put DNS entries into node\_announcement **deprecated, removal in v24.05** *(added v22.11.1)* - **require-confirmed-inputs** (boolean, optional): Request peers to only send confirmed inputs (dual-fund only) **deprecated, removal in v24.05** - **commit-fee** (u64, optional): The percentage of the 6-block fee estimate to use for commitment transactions **deprecated, removal in v24.05** *(added v23.05)* +- **min-emergency-msat** (msat, optional): field from config or cmdline, or default *(added v23.08)* [comment]: # (GENERATE-FROM-SCHEMA-END) @@ -466,4 +467,4 @@ RESOURCES Main web site: -[comment]: # ( SHA256STAMP:d24d8d540253bbe3cf9113b265fd3128e351d4615c28f6054730d1b03b363155) +[comment]: # ( SHA256STAMP:a40882cad0d889aa736a2932250102be43ae7e62b3d2429b26e0961e4c315f7b) diff --git a/doc/lightningd-config.5.md b/doc/lightningd-config.5.md index b0bfecb3b..97c06a0fb 100644 --- a/doc/lightningd-config.5.md +++ b/doc/lightningd-config.5.md @@ -440,6 +440,11 @@ have to do that. This option specifies that these (comma-separated) types are to be accepted, and ignored. +* **min-emergency-msat**=*msat* + + This is the amount of funds to keep in the wallet to close anchor channels (which don't carry their own transaction fees). It defaults to 25000sat, and is only maintained if there are any anchor channels (or, when opening an anchor channel). This amount may be insufficient for multiple closes at once, however. + + ### Cleanup control options: * **autoclean-cycle**=*SECONDS* [plugin `autoclean`, *dynamic*] diff --git a/doc/schemas/listconfigs.schema.json b/doc/schemas/listconfigs.schema.json index 9a1339d93..9e92409ca 100644 --- a/doc/schemas/listconfigs.schema.json +++ b/doc/schemas/listconfigs.schema.json @@ -1712,6 +1712,11 @@ "type": "u64", "added": "v23.05", "description": "The percentage of the 6-block fee estimate to use for commitment transactions" + }, + "min-emergency-msat": { + "type": "msat", + "added": "v23.08", + "description": "field from config or cmdline, or default" } } } diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index cb5da09bd..f64f3d2a6 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -322,6 +322,19 @@ static struct lightningd *new_lightningd(const tal_t *ctx) * case this is a pointer to an enum feerate-indexed array of values */ ld->force_feerates = NULL; + /*~ We need some funds to help CPFP spend unilateral closes. How + * much? But let's assume we want to boost the commitment tx (1112 + * Sipa). + * + * Anchor witness script is 40 bytes, sig is 72, input bytes is 32 + 4 + * + 1 + 1 + 4, core is 10 bytes, P2WKH output is 8 + 1 + 1 + 1 + 32 + * bytes. Weight (40 + 42 + 10 + 43)*4 + 40 + 72 = 652. + * + * So every 441 sats we can increase feerate by 1 sat / vbyte. Set + * the default minimum at 25,000 sats. + */ + ld->emergency_sat = AMOUNT_SAT(25000); + return ld; } diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index b04252540..00cecbed1 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -365,6 +365,9 @@ struct lightningd { /* --experimental-upgrade-protocol */ bool experimental_upgrade_protocol; + + /* For anchors: how much do we keep for spending close txs? */ + struct amount_sat emergency_sat; }; /* Turning this on allows a tal allocation to return NULL, rather than aborting. diff --git a/lightningd/options.c b/lightningd/options.c index 0db82c321..9ff4d4473 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -1116,6 +1116,25 @@ static char *opt_set_msat(const char *arg, struct amount_msat *amt) return NULL; } +static char *opt_set_sat(const char *arg, struct amount_sat *sat) +{ + struct amount_msat msat; + if (!parse_amount_msat(&msat, arg, strlen(arg))) + return tal_fmt(NULL, "Unable to parse millisatoshi '%s'", arg); + if (!amount_msat_to_sat(sat, msat)) + return tal_fmt(NULL, "'%s' is not a whole number of sats", arg); + return NULL; +} + +static bool opt_show_sat(char *buf, size_t len, const struct amount_sat *sat) +{ + struct amount_msat msat; + if (!amount_sat_to_msat(&msat, *sat)) + abort(); + return opt_show_u64(buf, len, + &msat.millisatoshis); /* Raw: show sats number */ +} + static char *opt_set_wumbo(struct lightningd *ld) { feature_set_or(ld->our_features, @@ -1427,6 +1446,9 @@ static void register_opts(struct lightningd *ld) clnopt_witharg("--commit-fee", OPT_SHOWINT, opt_set_u64, opt_show_u64, &ld->config.commit_fee_percent, "Percentage of fee to request for their commitment"); + clnopt_witharg("--min-emergency-msat", OPT_SHOWMSATS, + opt_set_sat, opt_show_sat, &ld->emergency_sat, + "Amount to leave in wallet for spending anchor closes"); clnopt_witharg("--subdaemon", OPT_MULTI, opt_subdaemon, NULL,