@@ -184,9 +184,9 @@ static void add_our_htlc_ourside(struct peer *peer, void *arg)
184
184
struct channel_htlc * htlc = arg ;
185
185
186
186
/* FIXME: must add even if can't pay fee any more! */
187
- if (!funding_a_add_htlc (peer -> local .staging_cstate ,
188
- htlc -> msatoshis , & htlc -> expiry ,
189
- & htlc -> rhash , htlc -> id ))
187
+ if (!funding_add_htlc (peer -> local .staging_cstate ,
188
+ htlc -> msatoshis , & htlc -> expiry ,
189
+ & htlc -> rhash , htlc -> id , OURS ))
190
190
fatal ("FIXME: Failed to add htlc %" PRIu64 " to self on ack" ,
191
191
htlc -> id );
192
192
tal_free (htlc );
@@ -209,11 +209,11 @@ void queue_pkt_htlc_add(struct peer *peer,
209
209
routing__init (u -> route );
210
210
211
211
/* We're about to send this, so their side will have it from now on. */
212
- if (!funding_b_add_htlc (peer -> remote .staging_cstate ,
213
- htlc_prog -> stage .add .htlc .msatoshis ,
214
- & htlc_prog -> stage .add .htlc .expiry ,
215
- & htlc_prog -> stage .add .htlc .rhash ,
216
- htlc_prog -> stage .add .htlc .id ))
212
+ if (!funding_add_htlc (peer -> remote .staging_cstate ,
213
+ htlc_prog -> stage .add .htlc .msatoshis ,
214
+ & htlc_prog -> stage .add .htlc .expiry ,
215
+ & htlc_prog -> stage .add .htlc .rhash ,
216
+ htlc_prog -> stage .add .htlc .id , THEIRS ))
217
217
fatal ("Could not add HTLC?" );
218
218
219
219
peer_add_htlc_expiry (peer , & htlc_prog -> stage .add .htlc .expiry );
@@ -230,8 +230,9 @@ static void fulfill_their_htlc_ourside(struct peer *peer, void *arg)
230
230
{
231
231
size_t n ;
232
232
233
- n = funding_htlc_by_id (& peer -> local .staging_cstate -> b , ptr2int (arg ));
234
- funding_b_fulfill_htlc (peer -> local .staging_cstate , n );
233
+ n = funding_htlc_by_id (peer -> local .staging_cstate , ptr2int (arg ), THEIRS );
234
+ assert (n != -1 );
235
+ funding_fulfill_htlc (peer -> local .staging_cstate , n , THEIRS );
235
236
}
236
237
237
238
void queue_pkt_htlc_fulfill (struct peer * peer ,
@@ -247,8 +248,9 @@ void queue_pkt_htlc_fulfill(struct peer *peer,
247
248
f -> r = sha256_to_proto (f , & htlc_prog -> stage .fulfill .r );
248
249
249
250
/* We're about to send this, so their side will have it from now on. */
250
- n = funding_htlc_by_id (& peer -> remote .staging_cstate -> a , f -> id );
251
- funding_a_fulfill_htlc (peer -> remote .staging_cstate , n );
251
+ n = funding_htlc_by_id (peer -> remote .staging_cstate , f -> id , OURS );
252
+ assert (n != -1 );
253
+ funding_fulfill_htlc (peer -> remote .staging_cstate , n , OURS );
252
254
their_commit_changed (peer );
253
255
254
256
queue_pkt_with_ack (peer , PKT__PKT_UPDATE_FULFILL_HTLC , f ,
@@ -260,8 +262,9 @@ static void fail_their_htlc_ourside(struct peer *peer, void *arg)
260
262
{
261
263
size_t n ;
262
264
263
- n = funding_htlc_by_id (& peer -> local .staging_cstate -> b , ptr2int (arg ));
264
- funding_b_fail_htlc (peer -> local .staging_cstate , n );
265
+ n = funding_htlc_by_id (peer -> local .staging_cstate , ptr2int (arg ), THEIRS );
266
+ assert (n != -1 );
267
+ funding_fail_htlc (peer -> local .staging_cstate , n , THEIRS );
265
268
}
266
269
267
270
void queue_pkt_htlc_fail (struct peer * peer ,
@@ -279,8 +282,9 @@ void queue_pkt_htlc_fail(struct peer *peer,
279
282
fail_reason__init (f -> reason );
280
283
281
284
/* We're about to send this, so their side will have it from now on. */
282
- n = funding_htlc_by_id (& peer -> remote .staging_cstate -> a , f -> id );
283
- funding_a_fail_htlc (peer -> remote .staging_cstate , n );
285
+ n = funding_htlc_by_id (peer -> remote .staging_cstate , f -> id , OURS );
286
+ assert (n != -1 );
287
+ funding_fail_htlc (peer -> remote .staging_cstate , n , OURS );
284
288
285
289
their_commit_changed (peer );
286
290
queue_pkt_with_ack (peer , PKT__PKT_UPDATE_FAIL_HTLC , f ,
@@ -309,10 +313,10 @@ void queue_pkt_commit(struct peer *peer)
309
313
& ci -> map );
310
314
311
315
log_debug (peer -> log , "Signing tx for %u/%u msatoshis, %zu/%zu htlcs" ,
312
- ci -> cstate -> a .pay_msat ,
313
- ci -> cstate -> b .pay_msat ,
314
- tal_count (ci -> cstate -> a .htlcs ),
315
- tal_count (ci -> cstate -> b .htlcs ));
316
+ ci -> cstate -> side [ OURS ] .pay_msat ,
317
+ ci -> cstate -> side [ THEIRS ] .pay_msat ,
318
+ tal_count (ci -> cstate -> side [ OURS ] .htlcs ),
319
+ tal_count (ci -> cstate -> side [ THEIRS ] .htlcs ));
316
320
317
321
/* BOLT #2:
318
322
*
@@ -563,23 +567,21 @@ Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt)
563
567
* A node MUST NOT add a HTLC if it would result in it
564
568
* offering more than 300 HTLCs in either commitment transaction.
565
569
*/
566
- if (tal_count (peer -> remote .staging_cstate -> a .htlcs ) == 300
567
- || tal_count (peer -> local .staging_cstate -> b .htlcs ) == 300 )
570
+ if (tal_count (peer -> remote .staging_cstate -> side [ OURS ] .htlcs ) == 300
571
+ || tal_count (peer -> local .staging_cstate -> side [ THEIRS ] .htlcs ) == 300 )
568
572
return pkt_err (peer , "Too many HTLCs" );
569
573
570
574
/* BOLT #2:
571
575
*
572
576
* A node MUST NOT set `id` equal to another HTLC which is in
573
577
* the current staged commitment transaction.
574
578
*/
575
- if (funding_htlc_by_id (& peer -> remote .staging_cstate -> a , u -> id )
576
- < tal_count (peer -> remote .staging_cstate -> a .htlcs ))
579
+ if (funding_htlc_by_id (peer -> remote .staging_cstate , u -> id , OURS ) != -1 )
577
580
return pkt_err (peer , "HTLC id %" PRIu64 " clashes for you" , u -> id );
578
581
579
582
/* FIXME: Assert this... */
580
583
/* Note: these should be in sync, so this should be redundant! */
581
- if (funding_htlc_by_id (& peer -> local .staging_cstate -> b , u -> id )
582
- < tal_count (peer -> local .staging_cstate -> b .htlcs ))
584
+ if (funding_htlc_by_id (peer -> local .staging_cstate , u -> id , THEIRS ) != -1 )
583
585
return pkt_err (peer , "HTLC id %" PRIu64 " clashes for us" , u -> id );
584
586
585
587
/* BOLT #2:
@@ -593,16 +595,16 @@ Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt)
593
595
/* FIXME: This is wrong! We may have already added more txs to
594
596
* them.staging_cstate, driving that fee up.
595
597
* We should check against the last version they acknowledged. */
596
- if (!funding_a_add_htlc (peer -> remote .staging_cstate ,
597
- u -> amount_msat , & expiry , & rhash , u -> id ))
598
+ if (!funding_add_htlc (peer -> remote .staging_cstate ,
599
+ u -> amount_msat , & expiry , & rhash , u -> id , OURS ))
598
600
return pkt_err (peer , "Cannot afford %" PRIu64 " milli-satoshis"
599
601
" in your commitment tx" ,
600
602
u -> amount_msat );
601
603
602
604
/* If we fail here, we've already changed them.staging_cstate, so
603
605
* MUST terminate. */
604
- if (!funding_b_add_htlc (peer -> local .staging_cstate ,
605
- u -> amount_msat , & expiry , & rhash , u -> id ))
606
+ if (!funding_add_htlc (peer -> local .staging_cstate ,
607
+ u -> amount_msat , & expiry , & rhash , u -> id , THEIRS ))
606
608
return pkt_err (peer , "Cannot afford %" PRIu64 " milli-satoshis"
607
609
" in our commitment tx" ,
608
610
u -> amount_msat );
@@ -623,19 +625,19 @@ static Pkt *find_commited_htlc(struct peer *peer, uint64_t id,
623
625
* current commitment transaction, and MUST fail the
624
626
* connection if it does not.
625
627
*/
626
- * n_us = funding_htlc_by_id (& peer -> local .commit -> cstate -> a , id );
627
- if (* n_us == tal_count ( peer -> local . commit -> cstate -> a . htlcs ) )
628
+ * n_us = funding_htlc_by_id (peer -> local .commit -> cstate , id , OURS );
629
+ if (* n_us == -1 )
628
630
return pkt_err (peer , "Did not find HTLC %" PRIu64 , id );
629
631
630
632
/* They must not fail/fulfill twice, so it should be in staging, too. */
631
- * n_us = funding_htlc_by_id (& peer -> local .staging_cstate -> a , id );
632
- if (* n_us == tal_count ( peer -> local . staging_cstate -> a . htlcs ) )
633
+ * n_us = funding_htlc_by_id (peer -> local .staging_cstate , id , OURS );
634
+ if (* n_us == -1 )
633
635
return pkt_err (peer , "Already removed HTLC %" PRIu64 , id );
634
636
635
637
/* FIXME: Assert this... */
636
638
/* Note: these should match. */
637
- * n_them = funding_htlc_by_id (& peer -> remote .staging_cstate -> b , id );
638
- if (* n_them == tal_count ( peer -> remote . staging_cstate -> b . htlcs ) )
639
+ * n_them = funding_htlc_by_id (peer -> remote .staging_cstate , id , THEIRS );
640
+ if (* n_them == -1 )
639
641
return pkt_err (peer , "Did not find your HTLC %" PRIu64 , id );
640
642
641
643
return NULL ;
@@ -653,8 +655,8 @@ Pkt *accept_pkt_htlc_fail(struct peer *peer, const Pkt *pkt)
653
655
654
656
/* FIXME: Save reason. */
655
657
656
- funding_a_fail_htlc (peer -> local .staging_cstate , n_us );
657
- funding_b_fail_htlc (peer -> remote .staging_cstate , n_them );
658
+ funding_fail_htlc (peer -> local .staging_cstate , n_us , OURS );
659
+ funding_fail_htlc (peer -> remote .staging_cstate , n_them , THEIRS );
658
660
their_commit_changed (peer );
659
661
return NULL ;
660
662
}
@@ -674,14 +676,14 @@ Pkt *accept_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt)
674
676
proto_to_sha256 (f -> r , & r );
675
677
sha256 (& rhash , & r , sizeof (r ));
676
678
677
- if (!structeq (& rhash , & peer -> local .staging_cstate -> a .htlcs [n_us ].rhash ))
679
+ if (!structeq (& rhash , & peer -> local .staging_cstate -> side [ OURS ] .htlcs [n_us ].rhash ))
678
680
return pkt_err (peer , "Invalid r for %" PRIu64 , f -> id );
679
681
680
682
/* Same ID must have same rhash */
681
- assert (structeq (& rhash , & peer -> remote .staging_cstate -> b .htlcs [n_them ].rhash ));
683
+ assert (structeq (& rhash , & peer -> remote .staging_cstate -> side [ THEIRS ] .htlcs [n_them ].rhash ));
682
684
683
- funding_a_fulfill_htlc (peer -> local .staging_cstate , n_us );
684
- funding_b_fulfill_htlc (peer -> remote .staging_cstate , n_them );
685
+ funding_fulfill_htlc (peer -> local .staging_cstate , n_us , OURS );
686
+ funding_fulfill_htlc (peer -> remote .staging_cstate , n_them , THEIRS );
685
687
their_commit_changed (peer );
686
688
return NULL ;
687
689
}
0 commit comments