@@ -81,7 +81,7 @@ Pkt *pkt_open(const tal_t *ctx, const struct peer *peer,
81
81
locktime__init (o -> delay );
82
82
o -> delay -> locktime_case = LOCKTIME__LOCKTIME_SECONDS ;
83
83
o -> delay -> seconds = rel_locktime_to_seconds (& peer -> us .locktime );
84
- o -> commitment_fee = peer -> us .commit_fee ;
84
+ o -> initial_fee_rate = peer -> us .commit_fee_rate ;
85
85
if (anchor == OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR )
86
86
assert (peer -> us .offer_anchor == CMD_OPEN_WITH_ANCHOR );
87
87
else {
@@ -289,8 +289,8 @@ Pkt *accept_pkt_open(const tal_t *ctx,
289
289
return pkt_err (ctx , "Delay too great" );
290
290
if (o -> min_depth > peer -> dstate -> config .anchor_confirms_max )
291
291
return pkt_err (ctx , "min_depth too great" );
292
- if (o -> commitment_fee < peer -> dstate -> config .commitment_fee_min )
293
- return pkt_err (ctx , "Commitment fee too low" );
292
+ if (o -> initial_fee_rate < peer -> dstate -> config .commitment_fee_rate_min )
293
+ return pkt_err (ctx , "Commitment fee rate too low" );
294
294
if (o -> anch == OPEN_CHANNEL__ANCHOR_OFFER__WILL_CREATE_ANCHOR )
295
295
peer -> them .offer_anchor = CMD_OPEN_WITH_ANCHOR ;
296
296
else if (o -> anch == OPEN_CHANNEL__ANCHOR_OFFER__WONT_CREATE_ANCHOR )
@@ -304,7 +304,7 @@ Pkt *accept_pkt_open(const tal_t *ctx,
304
304
if (!proto_to_rel_locktime (o -> delay , & peer -> them .locktime ))
305
305
return pkt_err (ctx , "Malformed locktime" );
306
306
peer -> them .mindepth = o -> min_depth ;
307
- peer -> them .commit_fee = o -> commitment_fee ;
307
+ peer -> them .commit_fee_rate = o -> initial_fee_rate ;
308
308
if (!proto_to_pubkey (peer -> dstate -> secpctx ,
309
309
o -> commit_key , & peer -> them .commitkey ))
310
310
return pkt_err (ctx , "Bad commitkey" );
@@ -326,7 +326,6 @@ Pkt *accept_pkt_anchor(const tal_t *ctx,
326
326
const Pkt * pkt )
327
327
{
328
328
const OpenAnchor * a = pkt -> open_anchor ;
329
- u64 commitfee ;
330
329
331
330
/* They must be offering anchor for us to try accepting */
332
331
assert (peer -> us .offer_anchor == CMD_OPEN_WITHOUT_ANCHOR );
@@ -336,15 +335,13 @@ Pkt *accept_pkt_anchor(const tal_t *ctx,
336
335
peer -> anchor .index = a -> output_index ;
337
336
peer -> anchor .satoshis = a -> amount ;
338
337
339
- /* Create funder's cstate, invert to get ours. */
340
- commitfee = commit_fee (peer -> them .commit_fee , peer -> us .commit_fee );
338
+ /* Create our cstate. */
341
339
peer -> cstate = initial_funding (peer ,
342
- peer -> us .offer_anchor ,
340
+ peer -> us .offer_anchor == CMD_OPEN_WITH_ANCHOR ,
343
341
peer -> anchor .satoshis ,
344
- commitfee );
342
+ peer -> us . commit_fee_rate );
345
343
if (!peer -> cstate )
346
344
return pkt_err (ctx , "Insufficient funds for fee" );
347
- invert_cstate (peer -> cstate );
348
345
349
346
/* Now we can make initial (unsigned!) commit txs. */
350
347
make_commit_txs (peer , peer ,
@@ -449,18 +446,14 @@ Pkt *accept_pkt_htlc_add(const tal_t *ctx,
449
446
}
450
447
451
448
cur -> cstate = copy_funding (cur , peer -> cstate );
452
- if (!funding_delta (peer -> anchor .satoshis ,
453
- 0 , cur -> stage .add .htlc .msatoshis ,
454
- & cur -> cstate -> b , & cur -> cstate -> a )) {
449
+ if (!funding_b_add_htlc (cur -> cstate ,
450
+ cur -> stage .add .htlc .msatoshis ,
451
+ & cur -> stage .add .htlc .expiry ,
452
+ & cur -> stage .add .htlc .rhash )) {
455
453
err = pkt_err (ctx , "Cannot afford %" PRIu64 " milli-satoshis" ,
456
454
cur -> stage .add .htlc .msatoshis );
457
455
goto fail ;
458
456
}
459
- /* Add the htlc to their side of channel. */
460
- funding_add_htlc (& cur -> cstate -> b ,
461
- cur -> stage .add .htlc .msatoshis ,
462
- & cur -> stage .add .htlc .expiry ,
463
- & cur -> stage .add .htlc .rhash );
464
457
peer_add_htlc_expiry (peer , & cur -> stage .add .htlc .expiry );
465
458
466
459
peer_get_revocation_hash (peer , peer -> commit_tx_counter + 1 ,
@@ -498,7 +491,6 @@ Pkt *accept_pkt_htlc_fail(const tal_t *ctx, struct peer *peer, const Pkt *pkt)
498
491
Pkt * err ;
499
492
size_t i ;
500
493
struct sha256 rhash ;
501
- struct channel_htlc * htlc ;
502
494
503
495
proto_to_sha256 (f -> revocation_hash , & cur -> their_revocation_hash );
504
496
proto_to_sha256 (f -> r_hash , & rhash );
@@ -511,17 +503,10 @@ Pkt *accept_pkt_htlc_fail(const tal_t *ctx, struct peer *peer, const Pkt *pkt)
511
503
512
504
cur -> stage .fail .fail = HTLC_FAIL ;
513
505
cur -> stage .fail .index = i ;
514
- htlc = & peer -> cstate -> a .htlcs [i ];
515
506
516
- /* Removing it should not fail: we regain HTLC amount */
507
+ /* We regain HTLC amount */
517
508
cur -> cstate = copy_funding (cur , peer -> cstate );
518
- if (!funding_delta (peer -> anchor .satoshis ,
519
- 0 , - htlc -> msatoshis ,
520
- & cur -> cstate -> a , & cur -> cstate -> b )) {
521
- fatal ("Unexpected failure fulfilling HTLC of %" PRIu64
522
- " milli-satoshis" , htlc -> msatoshis );
523
- }
524
- funding_remove_htlc (& cur -> cstate -> a , i );
509
+ funding_a_fail_htlc (cur -> cstate , i );
525
510
/* FIXME: Remove timer. */
526
511
527
512
peer_get_revocation_hash (peer , peer -> commit_tx_counter + 1 ,
@@ -550,7 +535,6 @@ Pkt *accept_pkt_htlc_fulfill(const tal_t *ctx,
550
535
Pkt * err ;
551
536
size_t i ;
552
537
struct sha256 rhash ;
553
- struct channel_htlc * htlc ;
554
538
555
539
cur -> stage .fulfill .fulfill = HTLC_FULFILL ;
556
540
proto_to_sha256 (f -> r , & cur -> stage .fulfill .r );
@@ -564,19 +548,10 @@ Pkt *accept_pkt_htlc_fulfill(const tal_t *ctx,
564
548
}
565
549
cur -> stage .fulfill .index = i ;
566
550
567
- htlc = & peer -> cstate -> a .htlcs [i ];
568
-
569
- /* Removing it should not fail: they gain HTLC amount */
551
+ /* Removing it: they gain HTLC amount */
570
552
cur -> cstate = copy_funding (cur , peer -> cstate );
571
- if (!funding_delta (peer -> anchor .satoshis ,
572
- - htlc -> msatoshis ,
573
- - htlc -> msatoshis ,
574
- & cur -> cstate -> a , & cur -> cstate -> b )) {
575
- fatal ("Unexpected failure fulfilling HTLC of %" PRIu64
576
- " milli-satoshis" , htlc -> msatoshis );
577
- }
578
- funding_remove_htlc (& cur -> cstate -> a , i );
579
-
553
+ funding_a_fulfill_htlc (cur -> cstate , i );
554
+
580
555
peer_get_revocation_hash (peer , peer -> commit_tx_counter + 1 ,
581
556
& cur -> our_revocation_hash );
582
557
@@ -729,13 +704,16 @@ Pkt *accept_pkt_close_sig(const tal_t *ctx, struct peer *peer, const Pkt *pkt,
729
704
struct bitcoin_signature theirsig ;
730
705
731
706
/* BOLT #2:
732
-
707
+ *
733
708
* The sender MUST set `close_fee` lower than or equal to the fee of the
734
709
* final commitment transaction, and MUST set `close_fee` to an even
735
710
* number of satoshis.
736
711
*/
737
- if (c -> close_fee & 1 || c -> close_fee > peer -> them .commit_fee )
712
+ if ((c -> close_fee & 1 )
713
+ || c -> close_fee > commit_tx_fee (peer -> them .commit ,
714
+ peer -> anchor .satoshis )) {
738
715
return pkt_err (ctx , "Invalid close fee" );
716
+ }
739
717
740
718
/* FIXME: Don't accept tiny fee at all? */
741
719
0 commit comments