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

@@ -55,7 +55,7 @@ int main(int argc, char *argv[])
errx(1, "Private key '%s' not on testnet!", argv[4]);
/* Now create THEIR commitment tx to spend 2/2 output of anchor. */
if (!initial_funding(o1, o2, a, &to_us, &to_them))
if (!initial_funding(o1, o2, a, commit_fee(o1, o2), &to_us, &to_them))
errx(1, "Invalid open combination (need 1 anchor offer)");
proto_to_sha256(o2->revocation_hash, &rhash);