protocol: add commitment fee logic.

Both sides elect a commitment fee, and the lowest is chosen.  That means
you can't game the other side (but if you offer too low, then can error
out of course).

Fees are split 50-50 if possible: originally the whole fee has to be
paid by the (single) funder.  Neither side can withdraw funds which
would make them unable to pay fees.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2015-07-29 16:16:24 +09:30
parent eac3af06f1
commit 3260fb2ed1
20 changed files with 115 additions and 28 deletions

View File

@@ -29,6 +29,7 @@ int main(int argc, char *argv[])
struct pkt *pkt;
const tal_t *ctx = tal_arr(NULL, char, 0);
unsigned int locktime_seconds, min_confirms;
u64 commit_tx_fee;
bool offer_anchor = false;
struct pubkey commitkey, finalkey;
@@ -38,6 +39,8 @@ int main(int argc, char *argv[])
locktime_seconds = LOCKTIME_MIN + 24 * 60 * 60;
/* Zero, unless they set --offer-anchor or --min-anchor-confirms */
min_confirms = 0;
/* We only need this for involuntary close, so make it larger. */
commit_tx_fee = 100000;
opt_register_noarg("--help|-h", opt_usage_and_exit,
"<seed> <commitpubkey> <finalpubkey>\n"
@@ -52,6 +55,9 @@ int main(int argc, char *argv[])
opt_register_noarg("--offer-anchor",
opt_set_bool, &offer_anchor,
"Offer to create anchor transaction");
opt_register_arg("--commitment-fee=<bits>",
opt_set_bits, opt_show_bits, &commit_tx_fee,
"100's of satoshi to pay for commitment");
opt_parse(&argc, argv, opt_log_stderr_exit);
@@ -76,7 +82,8 @@ int main(int argc, char *argv[])
revocation_hash.u.u8, sizeof(revocation_hash.u.u8));
pkt = open_channel_pkt(ctx, &revocation_hash, &commitkey, &finalkey,
locktime_seconds, offer_anchor, min_confirms);
locktime_seconds, offer_anchor, min_confirms,
commit_tx_fee);
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
err(1, "Writing out packet");