forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.h
794 lines (669 loc) · 22.4 KB
/
channel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
#ifndef LIGHTNING_LIGHTNINGD_CHANNEL_H
#define LIGHTNING_LIGHTNINGD_CHANNEL_H
#include "config.h"
#include <common/channel_config.h>
#include <common/channel_id.h>
#include <common/channel_type.h>
#include <common/derive_basepoints.h>
#include <common/scb_wiregen.h>
#include <common/tx_roles.h>
#include <common/utils.h>
#include <gossipd/gossipd_wiregen.h>
#include <lightningd/channel_state.h>
#include <wallet/wallet.h>
struct uncommitted_channel;
struct wally_psbt;
/* FIXME: Define serialization primitive for this? */
struct channel_info {
struct channel_config their_config;
struct pubkey remote_fundingkey;
struct basepoints theirbase;
/* The old_remote_per_commit is for the locked-in remote commit_tx,
* and the remote_per_commit is for the commit_tx we're modifying now. */
struct pubkey remote_per_commit, old_remote_per_commit;
};
struct billboard {
/* Status information to display on listpeers */
const char *permanent[CHANNEL_STATE_MAX+1];
const char *transient;
};
struct funding_info {
struct bitcoin_outpoint outpoint;
u32 feerate;
struct amount_sat total_funds;
/* Our original funds, in funding amount */
struct amount_sat our_funds;
/* Relative splicing balance change */
s64 splice_amnt;
};
struct channel_inflight {
/* Inside channel->inflights. */
struct list_node list;
/* Channel context */
struct channel *channel;
/* Funding info */
const struct funding_info *funding;
struct wally_psbt *funding_psbt;
bool remote_tx_sigs;
bool tx_broadcast;
/* Commitment tx and sigs */
struct bitcoin_tx *last_tx;
struct bitcoin_signature last_sig;
/* Channel lease infos */
u32 lease_expiry;
secp256k1_ecdsa_signature *lease_commit_sig;
u32 lease_chan_max_msat;
u16 lease_chan_max_ppt;
u32 lease_blockheight_start;
/* We save this data so we can do nice accounting;
* on the channel we slot it into the 'push' field */
struct amount_msat lease_fee;
/* Amount requested to lease for this open */
struct amount_sat lease_amt;
/* Did I initate this splice attempt? */
bool i_am_initiator;
/* On reestablish recovery; should I sign first? */
bool force_sign_first;
/* Note: This field is not stored in the database.
*
* After splice_locked, we need a way to stop the chain watchers from
* thinking the old channel was spent.
*
* Leaving the inflight in memory-only with splice_locked true leaves
* moves the responsiblity of cleaning up the inflight to the watcher,
* avoiding any potential race conditions. */
bool splice_locked_memonly;
};
struct open_attempt {
/* on uncommitted_channel struct */
struct channel *channel;
struct channel_config our_config;
enum tx_role role;
bool aborted;
/* On funding_channel struct */
struct command *cmd;
struct amount_sat funding;
const u8 *our_upfront_shutdown_script;
/* First msg to send to dualopend (to make it create channel) */
const u8 *open_msg;
};
struct channel {
/* Inside peer->channels. */
struct list_node list;
/* Peer context */
struct peer *peer;
/* Inflight channel opens */
struct list_head inflights;
/* Open attempt */
struct open_attempt *open_attempt;
/* Database ID: 0 == not in db yet */
u64 dbid;
/* Populated by new_unsaved_channel */
u64 unsaved_dbid;
/* Error message (iff in error state) */
u8 *error;
/* Their shachain. */
struct wallet_shachain their_shachain;
/* What's happening. */
enum channel_state state;
/* Which side offered channel? */
enum side opener;
/* Is there a single subdaemon responsible for us? */
struct subd *owner;
/* History */
struct logger *log;
struct billboard billboard;
/* Channel flags from opening message. */
u8 channel_flags;
/* Our channel config. */
struct channel_config our_config;
/* Require confirmed inputs for interactive tx */
bool req_confirmed_ins[NUM_SIDES];
/* Minimum funding depth (specified by us if they fund). */
u32 minimum_depth;
/* Depth of the funding TX as reported by the txout
* watch. Only used while we're in state
* CHANNELD_AWAITING_LOCKING, afterwards the watches do not
* trigger anymore. */
u32 depth;
/* Tracking commitment transaction numbers. */
u64 next_index[NUM_SIDES];
u64 next_htlc_id;
/* Funding outpoint and amount */
struct bitcoin_outpoint funding;
struct amount_sat funding_sats;
/* Watch we have on funding output. */
struct txowatch *funding_spend_watch;
/* Our original funds, in funding amount */
struct amount_sat our_funds;
struct amount_msat push;
bool remote_channel_ready;
/* Channel if locked locally. */
struct short_channel_id *scid;
/* Alias used for option_zeroconf, or option_scid_alias, if
* present. LOCAL are all the alias we told the peer about and
* REMOTE is one of the aliases we got from the peer and we'll
* use in a routehint. */
struct short_channel_id *alias[NUM_SIDES];
struct channel_id cid;
/* Amount going to us, not counting unfinished HTLCs; if we have one. */
struct amount_msat our_msat;
/* Statistics for min and max our_msatoshi. */
struct amount_msat msat_to_us_min;
struct amount_msat msat_to_us_max;
/* Last tx they gave us. */
struct bitcoin_tx *last_tx;
struct bitcoin_signature last_sig;
const struct bitcoin_signature *last_htlc_sigs;
/* Keys for channel */
struct channel_info channel_info;
/* Fee status */
const struct fee_states *fee_states;
/* Height states (option_will_fund, update_blockheight) */
const struct height_states *blockheight_states;
/* Our local basepoints */
struct basepoints local_basepoints;
/* Our funding tx pubkey. */
struct pubkey local_funding_pubkey;
/* scriptpubkey for shutdown, if applicable. */
const u8 *shutdown_scriptpubkey[NUM_SIDES];
/* Address for any final outputs */
u64 final_key_idx;
/* Amount to give up on each step of the closing fee negotiation. */
u64 closing_fee_negotiation_step;
/* Whether closing_fee_negotiation_step is in satoshi or %. */
u8 closing_fee_negotiation_step_unit;
/* optional wrong_funding for mutual close */
const struct bitcoin_outpoint *shutdown_wrong_funding;
/* optional feerate min/max for mutual close */
u32 *closing_feerate_range;
/* Reestablishment stuff: last sent commit and revocation details. */
bool last_was_revoke;
struct changed_htlc *last_sent_commit;
/* Blockheight at creation, scans for funding confirmations
* will start here */
u32 first_blocknum;
/* Feerate range */
u32 min_possible_feerate, max_possible_feerate;
/* Do we have an "impossible" future per_commitment_point from
* peer via option_data_loss_protect? */
const struct pubkey *future_per_commitment_point;
/* Min/max htlc amount allowed in channel. */
struct amount_msat htlc_minimum_msat, htlc_maximum_msat;
/* Feerate per channel */
u32 feerate_base, feerate_ppm;
/* But allow these feerates/htlcs up until this time. */
struct timeabs old_feerate_timeout;
u32 old_feerate_base, old_feerate_ppm;
struct amount_msat old_htlc_minimum_msat, old_htlc_maximum_msat;
/* If they used option_upfront_shutdown_script. */
const u8 *remote_upfront_shutdown_script;
/* At what commit numbers does `option_static_remotekey` apply? */
u64 static_remotekey_start[NUM_SIDES];
/* What features apply to this channel? */
const struct channel_type *type;
/* Any commands trying to forget us. */
struct command **forgets;
/* Our position in the round-robin list. */
u64 rr_number;
/* the one that initiated a bilateral close, NUM_SIDES if unknown. */
enum side closer;
/* Block height we saw closing tx at */
u32 *close_blockheight;
/* Last known state_change cause */
enum state_change state_change_cause;
/* Outstanding command for this channel, v2 only */
struct command *openchannel_signed_cmd;
/* Block lease expires at, zero is no lease */
u32 lease_expiry;
/* Lease commitment, useful someone breaks their promise
* wrt channel fees */
secp256k1_ecdsa_signature *lease_commit_sig;
/* Lease commited maximum channel fee base msat */
u32 lease_chan_max_msat;
/* Lease commited max part per thousandth channel fee (ppm * 1000) */
u16 lease_chan_max_ppt;
/* Channel incoming fee rates, cltv delta min/max htlc from
* peer. Used to generate route hints, blinded paths. */
const struct peer_update *peer_update;
/* Latest channel_update, for use in error messages. */
u8 *channel_update;
/* `Channel-shell` of this channel
* (Minimum information required to backup this channel). */
struct scb_chan *scb;
/* Do we allow the peer to set any fee it wants? */
bool ignore_fee_limits;
};
bool channel_is_connected(const struct channel *channel);
/* For v2 opens, a channel that has not yet been committed/saved to disk */
struct channel *new_unsaved_channel(struct peer *peer,
u32 feerate_base,
u32 feerate_ppm);
struct open_attempt *new_channel_open_attempt(struct channel *channel);
struct channel *new_channel(struct peer *peer, u64 dbid,
/* NULL or stolen */
struct wallet_shachain *their_shachain STEALS,
enum channel_state state,
enum side opener,
/* NULL or stolen */
struct logger *log STEALS,
const char *transient_billboard TAKES,
u8 channel_flags,
bool req_confirmed_ins_local,
bool req_confirmed_ins_remote,
const struct channel_config *our_config,
u32 minimum_depth,
u64 next_index_local,
u64 next_index_remote,
u64 next_htlc_id,
const struct bitcoin_outpoint *funding,
struct amount_sat funding_sats,
struct amount_msat push,
struct amount_sat our_funds,
bool remote_channel_ready,
/* NULL or stolen */
struct short_channel_id *scid STEALS,
struct short_channel_id *alias_local STEALS,
struct short_channel_id *alias_remote STEALS,
struct channel_id *cid,
struct amount_msat our_msatoshi,
struct amount_msat msatoshi_to_us_min,
struct amount_msat msatoshi_to_us_max,
struct bitcoin_tx *last_tx STEALS,
const struct bitcoin_signature *last_sig,
/* NULL or stolen */
const struct bitcoin_signature *last_htlc_sigs STEALS,
const struct channel_info *channel_info,
const struct fee_states *fee_states TAKES,
/* NULL or stolen */
u8 *remote_shutdown_scriptpubkey STEALS,
const u8 *local_shutdown_scriptpubkey,
u64 final_key_idx,
bool last_was_revoke,
/* NULL or stolen */
struct changed_htlc *last_sent_commit STEALS,
u32 first_blocknum,
u32 min_possible_feerate,
u32 max_possible_feerate,
const struct basepoints *local_basepoints,
const struct pubkey *local_funding_pubkey,
const struct pubkey *future_per_commitment_point,
u32 feerate_base,
u32 feerate_ppm,
/* NULL or stolen */
const u8 *remote_upfront_shutdown_script STEALS,
u64 local_static_remotekey_start,
u64 remote_static_remotekey_start,
const struct channel_type *type STEALS,
enum side closer,
enum state_change reason,
/* NULL or stolen */
const struct bitcoin_outpoint *shutdown_wrong_funding STEALS,
const struct height_states *height_states TAKES,
u32 lease_expiry,
secp256k1_ecdsa_signature *lease_commit_sig STEALS,
u32 lease_chan_max_msat,
u16 lease_chan_max_ppt,
struct amount_msat htlc_minimum_msat,
struct amount_msat htlc_maximum_msat,
bool ignore_fee_limits,
/* NULL or stolen */
struct peer_update *peer_update STEALS);
/* new_inflight - Create a new channel_inflight for a channel */
struct channel_inflight *new_inflight(struct channel *channel,
const struct bitcoin_outpoint *funding_outpoint,
u32 funding_feerate,
struct amount_sat funding_sat,
struct amount_sat our_funds,
struct wally_psbt *funding_psbt STEALS,
const u32 lease_expiry,
const secp256k1_ecdsa_signature *lease_commit_sig,
const u32 lease_chan_max_msat,
const u16 lease_chan_max_ppt,
const u32 lease_blockheight_start,
const struct amount_msat lease_fee,
const struct amount_sat lease_amt,
s64 splice_amnt,
bool i_am_initiator,
bool force_sign_first);
/* Add a last_tx and sig to an inflight */
void inflight_set_last_tx(struct channel_inflight *inflight,
struct bitcoin_tx *last_tx STEALS,
const struct bitcoin_signature last_sig);
/* If the last inflight has no commitment tx, remove it */
bool maybe_cleanup_last_inflight(struct channel *channel);
/* Given a txid, find an inflight channel stub. Returns NULL if none found */
struct channel_inflight *channel_inflight_find(struct channel *channel,
const struct bitcoin_txid *txid);
/* What's the most recent inflight for this channel? */
struct channel_inflight *
channel_current_inflight(const struct channel *channel);
/* What's the last feerate used for a funding tx on this channel? */
u32 channel_last_funding_feerate(const struct channel *channel);
void delete_channel(struct channel *channel STEALS);
const char *channel_state_name(const struct channel *channel);
const char *channel_state_str(enum channel_state state);
/* Can this channel send an HTLC? */
static inline bool channel_state_can_add_htlc(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_SIGEXCHANGE:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
return false;
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
return true;
}
abort();
}
/* Can this channel remove an HTLC? */
static inline bool channel_state_can_remove_htlc(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case CLOSINGD_SIGEXCHANGE:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
return false;
case CHANNELD_SHUTTING_DOWN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
return true;
}
abort();
}
static inline bool channel_state_closing(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
case CHANNELD_AWAITING_SPLICE:
return false;
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_SIGEXCHANGE:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
return true;
}
abort();
}
static inline bool channel_state_fees_can_change(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
return false;
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
return true;
}
abort();
}
static inline bool channel_state_failing_onchain(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_COMPLETE:
case CLOSED:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
return false;
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
return true;
}
abort();
}
static inline bool channel_state_pre_open(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
return true;
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
return false;
}
abort();
}
static inline bool channel_state_closed(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
return false;
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
return true;
}
abort();
}
/* Not even in the database yet? */
static inline bool channel_state_uncommitted(enum channel_state state)
{
switch (state) {
case DUALOPEND_OPEN_INIT:
return true;
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case CHANNELD_AWAITING_LOCKIN:
case DUALOPEND_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
return false;
}
abort();
}
/* Established enough, that we could reach out to peer to discuss */
static inline bool channel_state_wants_peercomms(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case DUALOPEND_AWAITING_LOCKIN:
case DUALOPEND_OPEN_COMMIT_READY:
case DUALOPEND_OPEN_COMMITTED:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
return true;
case DUALOPEND_OPEN_INIT:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
return false;
}
abort();
}
/* Established enough, that we have to fail onto chain */
static inline bool channel_state_wants_onchain_fail(enum channel_state state)
{
switch (state) {
case CHANNELD_AWAITING_LOCKIN:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
return true;
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
return false;
}
abort();
}
static inline bool channel_state_open_uncommitted(enum channel_state state)
{
switch (state) {
case DUALOPEND_OPEN_INIT:
case DUALOPEND_OPEN_COMMIT_READY:
return true;
case CLOSINGD_COMPLETE:
case AWAITING_UNILATERAL:
case FUNDING_SPEND_SEEN:
case ONCHAIN:
case CLOSED:
case CHANNELD_AWAITING_LOCKIN:
case DUALOPEND_OPEN_COMMITTED:
case DUALOPEND_AWAITING_LOCKIN:
case CHANNELD_NORMAL:
case CHANNELD_AWAITING_SPLICE:
case CLOSINGD_SIGEXCHANGE:
case CHANNELD_SHUTTING_DOWN:
return false;
}
abort();
}
void channel_set_owner(struct channel *channel, struct subd *owner);
/* Channel has failed, but can try again. Usually, set disconnect to true. */
void channel_fail_transient(struct channel *channel,
bool disconnect,
const char *fmt, ...) PRINTF_FMT(3, 4);
/* Channel has failed, give up on it. */
void channel_fail_permanent(struct channel *channel,
enum state_change reason,
const char *fmt,
...);
/* Forget the channel. This is only used for the case when we "receive" error
* during CHANNELD_AWAITING_LOCKIN if we are "fundee". */
void channel_fail_forget(struct channel *channel, const char *fmt, ...);
/* Permanent error, but due to internal problems, not peer. */
void channel_internal_error(struct channel *channel, const char *fmt, ...);
/* Clean up any in-progress commands for a channel */
void channel_cleanup_commands(struct channel *channel, const char *why);
void channel_set_state(struct channel *channel,
enum channel_state old_state,
enum channel_state state,
enum state_change reason,
char *why);
const char *channel_change_state_reason_str(enum state_change reason);
/* Find a channel which is passes filter, if any: sets *others if there
* is more than one. */
struct channel *peer_any_channel(struct peer *peer,
bool (*channel_state_filter)(enum channel_state),
bool *others);
struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid);
/* Includes both real scids and aliases. If !privacy_leak_ok, then private
* channels' real scids are not included. */
struct channel *any_channel_by_scid(struct lightningd *ld,
const struct short_channel_id *scid,
bool privacy_leak_ok);
/* Get channel by channel_id */
struct channel *channel_by_cid(struct lightningd *ld,
const struct channel_id *cid);
/* Find this channel within peer */
struct channel *find_channel_by_id(const struct peer *peer,
const struct channel_id *cid);
/* Find this channel within peer */
struct channel *find_channel_by_scid(const struct peer *peer,
const struct short_channel_id *scid);
/* Find a channel by its alias, either local or remote. */
struct channel *find_channel_by_alias(const struct peer *peer,
const struct short_channel_id *alias,
enum side side);
/* Do we have any channel with option_anchors_zero_fee_htlc_tx? (i.e. we
* might need to CPFP the fee if it force closes!) */
bool have_anchor_channel(struct lightningd *ld);
void channel_set_last_tx(struct channel *channel,
struct bitcoin_tx *tx,
const struct bitcoin_signature *sig);
static inline bool channel_has(const struct channel *channel, int f)
{
return channel_type_has(channel->type, f);
}
/**
* Either returns the short_channel_id if it is known or the local alias.
*
* This is used to refer to a channel by its scid. But sometimes we
* don't have a scid yet, e.g., for `zeroconf` channels, so we resort
* to referencing it by the local alias, which we have in that case.
*/
const struct short_channel_id *channel_scid_or_local_alias(const struct channel *chan);
void get_channel_basepoints(struct lightningd *ld,
const struct node_id *peer_id,
const u64 dbid,
struct basepoints *local_basepoints,
struct pubkey *local_funding_pubkey);
void channel_set_billboard(struct channel *channel, bool perm,
const char *str TAKES);
struct htlc_in *channel_has_htlc_in(struct channel *channel);
struct htlc_out *channel_has_htlc_out(struct channel *channel);
const u8 *get_channel_update(struct channel *channel);
struct amount_msat htlc_max_possible_send(const struct channel *channel);
#endif /* LIGHTNING_LIGHTNINGD_CHANNEL_H */