forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 1
/
channeld_wiregen.c
1140 lines (1006 loc) · 42.1 KB
/
channeld_wiregen.c
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
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This file was generated by generate-wire.py */
/* Do not modify this file! Modify the .csv file it was generated from. */
/* Original template can be found at tools/gen/impl_template */
#include <channeld/channeld_wiregen.h>
#include <assert.h>
#include <ccan/array_size/array_size.h>
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <common/utils.h>
#include <stdio.h>
#ifndef SUPERVERBOSE
#define SUPERVERBOSE(...)
#endif
const char *channeld_wire_name(int e)
{
static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)];
switch ((enum channeld_wire)e) {
case WIRE_CHANNELD_INIT: return "WIRE_CHANNELD_INIT";
case WIRE_CHANNELD_FUNDING_DEPTH: return "WIRE_CHANNELD_FUNDING_DEPTH";
case WIRE_CHANNELD_OFFER_HTLC: return "WIRE_CHANNELD_OFFER_HTLC";
case WIRE_CHANNELD_OFFER_HTLC_REPLY: return "WIRE_CHANNELD_OFFER_HTLC_REPLY";
case WIRE_CHANNELD_FULFILL_HTLC: return "WIRE_CHANNELD_FULFILL_HTLC";
case WIRE_CHANNELD_FAIL_HTLC: return "WIRE_CHANNELD_FAIL_HTLC";
case WIRE_CHANNELD_GOT_FUNDING_LOCKED: return "WIRE_CHANNELD_GOT_FUNDING_LOCKED";
case WIRE_CHANNELD_SENDING_COMMITSIG: return "WIRE_CHANNELD_SENDING_COMMITSIG";
case WIRE_CHANNELD_SENDING_COMMITSIG_REPLY: return "WIRE_CHANNELD_SENDING_COMMITSIG_REPLY";
case WIRE_CHANNELD_GOT_COMMITSIG: return "WIRE_CHANNELD_GOT_COMMITSIG";
case WIRE_CHANNELD_GOT_COMMITSIG_REPLY: return "WIRE_CHANNELD_GOT_COMMITSIG_REPLY";
case WIRE_CHANNELD_GOT_REVOKE: return "WIRE_CHANNELD_GOT_REVOKE";
case WIRE_CHANNELD_GOT_REVOKE_REPLY: return "WIRE_CHANNELD_GOT_REVOKE_REPLY";
case WIRE_CHANNELD_SEND_SHUTDOWN: return "WIRE_CHANNELD_SEND_SHUTDOWN";
case WIRE_CHANNELD_GOT_SHUTDOWN: return "WIRE_CHANNELD_GOT_SHUTDOWN";
case WIRE_CHANNELD_SHUTDOWN_COMPLETE: return "WIRE_CHANNELD_SHUTDOWN_COMPLETE";
case WIRE_CHANNELD_DEV_REENABLE_COMMIT: return "WIRE_CHANNELD_DEV_REENABLE_COMMIT";
case WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY: return "WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY";
case WIRE_CHANNELD_FEERATES: return "WIRE_CHANNELD_FEERATES";
case WIRE_CHANNELD_DEV_MEMLEAK: return "WIRE_CHANNELD_DEV_MEMLEAK";
case WIRE_CHANNELD_DEV_MEMLEAK_REPLY: return "WIRE_CHANNELD_DEV_MEMLEAK_REPLY";
case WIRE_CHANNELD_FAIL_FALLEN_BEHIND: return "WIRE_CHANNELD_FAIL_FALLEN_BEHIND";
case WIRE_CHANNELD_SPECIFIC_FEERATES: return "WIRE_CHANNELD_SPECIFIC_FEERATES";
case WIRE_CHANNELD_GOT_ANNOUNCEMENT: return "WIRE_CHANNELD_GOT_ANNOUNCEMENT";
case WIRE_CHANNELD_SEND_ERROR: return "WIRE_CHANNELD_SEND_ERROR";
case WIRE_CHANNELD_SEND_ERROR_REPLY: return "WIRE_CHANNELD_SEND_ERROR_REPLY";
case WIRE_CHANNELD_DEV_QUIESCE: return "WIRE_CHANNELD_DEV_QUIESCE";
case WIRE_CHANNELD_DEV_QUIESCE_REPLY: return "WIRE_CHANNELD_DEV_QUIESCE_REPLY";
case WIRE_CHANNELD_UPGRADED: return "WIRE_CHANNELD_UPGRADED";
}
snprintf(invalidbuf, sizeof(invalidbuf), "INVALID %i", e);
return invalidbuf;
}
bool channeld_wire_is_defined(u16 type)
{
switch ((enum channeld_wire)type) {
case WIRE_CHANNELD_INIT:;
case WIRE_CHANNELD_FUNDING_DEPTH:;
case WIRE_CHANNELD_OFFER_HTLC:;
case WIRE_CHANNELD_OFFER_HTLC_REPLY:;
case WIRE_CHANNELD_FULFILL_HTLC:;
case WIRE_CHANNELD_FAIL_HTLC:;
case WIRE_CHANNELD_GOT_FUNDING_LOCKED:;
case WIRE_CHANNELD_SENDING_COMMITSIG:;
case WIRE_CHANNELD_SENDING_COMMITSIG_REPLY:;
case WIRE_CHANNELD_GOT_COMMITSIG:;
case WIRE_CHANNELD_GOT_COMMITSIG_REPLY:;
case WIRE_CHANNELD_GOT_REVOKE:;
case WIRE_CHANNELD_GOT_REVOKE_REPLY:;
case WIRE_CHANNELD_SEND_SHUTDOWN:;
case WIRE_CHANNELD_GOT_SHUTDOWN:;
case WIRE_CHANNELD_SHUTDOWN_COMPLETE:;
case WIRE_CHANNELD_DEV_REENABLE_COMMIT:;
case WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY:;
case WIRE_CHANNELD_FEERATES:;
case WIRE_CHANNELD_DEV_MEMLEAK:;
case WIRE_CHANNELD_DEV_MEMLEAK_REPLY:;
case WIRE_CHANNELD_FAIL_FALLEN_BEHIND:;
case WIRE_CHANNELD_SPECIFIC_FEERATES:;
case WIRE_CHANNELD_GOT_ANNOUNCEMENT:;
case WIRE_CHANNELD_SEND_ERROR:;
case WIRE_CHANNELD_SEND_ERROR_REPLY:;
case WIRE_CHANNELD_DEV_QUIESCE:;
case WIRE_CHANNELD_DEV_QUIESCE_REPLY:;
case WIRE_CHANNELD_UPGRADED:;
return true;
}
return false;
}
/* WIRE: CHANNELD_INIT */
/* Begin! (passes gossipd-client fd) */
u8 *towire_channeld_init(const tal_t *ctx, const struct chainparams *chainparams, const struct feature_set *our_features, const struct channel_id *channel_id, const struct bitcoin_txid *funding_txid, u16 funding_txout, struct amount_sat funding_satoshi, u32 minimum_depth, const struct channel_config *our_config, const struct channel_config *their_config, const struct fee_states *fee_states, u32 feerate_min, u32 feerate_max, u32 feerate_penalty, const struct bitcoin_signature *first_commit_sig, const struct per_peer_state *per_peer_state, const struct pubkey *remote_fundingkey, const struct basepoints *remote_basepoints, const struct pubkey *remote_per_commit, const struct pubkey *old_remote_per_commit, enum side opener, u32 fee_base, u32 fee_proportional, struct amount_msat local_msatoshi, const struct basepoints *our_basepoints, const struct pubkey *our_funding_pubkey, const struct node_id *local_node_id, const struct node_id *remote_node_id, u32 commit_msec, u16 cltv_delta, bool last_was_revoke, const struct changed_htlc *last_sent_commit, u64 next_index_local, u64 next_index_remote, u64 revocations_received, u64 next_htlc_id, const struct existing_htlc **htlcs, bool local_funding_locked, bool remote_funding_locked, const struct short_channel_id *funding_short_id, bool reestablish, bool send_shutdown, bool remote_shutdown_received, const u8 *final_scriptpubkey, u8 flags, const u8 *init_peer_pkt, bool reached_announce_depth, const struct secret *last_remote_secret, const u8 *their_features, const u8 *upfront_shutdown_script, const secp256k1_ecdsa_signature *remote_ann_node_sig, const secp256k1_ecdsa_signature *remote_ann_bitcoin_sig, bool option_static_remotekey, bool option_anchor_outputs, bool dev_fast_gossip, bool dev_fail_process_onionpacket, const struct penalty_base *pbases)
{
u16 num_last_sent_commit = tal_count(last_sent_commit);
u16 num_existing_htlcs = tal_count(htlcs);
u16 final_scriptpubkey_len = tal_count(final_scriptpubkey);
u16 init_peer_pkt_len = tal_count(init_peer_pkt);
u16 flen = tal_count(their_features);
u16 upfront_shutdown_script_len = tal_count(upfront_shutdown_script);
u32 num_penalty_bases = tal_count(pbases);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_INIT);
towire_chainparams(&p, chainparams);
towire_feature_set(&p, our_features);
towire_channel_id(&p, channel_id);
towire_bitcoin_txid(&p, funding_txid);
towire_u16(&p, funding_txout);
towire_amount_sat(&p, funding_satoshi);
towire_u32(&p, minimum_depth);
towire_channel_config(&p, our_config);
towire_channel_config(&p, their_config);
towire_fee_states(&p, fee_states);
towire_u32(&p, feerate_min);
towire_u32(&p, feerate_max);
towire_u32(&p, feerate_penalty);
towire_bitcoin_signature(&p, first_commit_sig);
towire_per_peer_state(&p, per_peer_state);
towire_pubkey(&p, remote_fundingkey);
towire_basepoints(&p, remote_basepoints);
towire_pubkey(&p, remote_per_commit);
towire_pubkey(&p, old_remote_per_commit);
towire_side(&p, opener);
towire_u32(&p, fee_base);
towire_u32(&p, fee_proportional);
towire_amount_msat(&p, local_msatoshi);
towire_basepoints(&p, our_basepoints);
towire_pubkey(&p, our_funding_pubkey);
towire_node_id(&p, local_node_id);
towire_node_id(&p, remote_node_id);
towire_u32(&p, commit_msec);
towire_u16(&p, cltv_delta);
towire_bool(&p, last_was_revoke);
towire_u16(&p, num_last_sent_commit);
for (size_t i = 0; i < num_last_sent_commit; i++)
towire_changed_htlc(&p, last_sent_commit + i);
towire_u64(&p, next_index_local);
towire_u64(&p, next_index_remote);
towire_u64(&p, revocations_received);
towire_u64(&p, next_htlc_id);
towire_u16(&p, num_existing_htlcs);
for (size_t i = 0; i < num_existing_htlcs; i++)
towire_existing_htlc(&p, htlcs[i]);
towire_bool(&p, local_funding_locked);
towire_bool(&p, remote_funding_locked);
towire_short_channel_id(&p, funding_short_id);
towire_bool(&p, reestablish);
towire_bool(&p, send_shutdown);
towire_bool(&p, remote_shutdown_received);
towire_u16(&p, final_scriptpubkey_len);
towire_u8_array(&p, final_scriptpubkey, final_scriptpubkey_len);
towire_u8(&p, flags);
towire_u16(&p, init_peer_pkt_len);
towire_u8_array(&p, init_peer_pkt, init_peer_pkt_len);
towire_bool(&p, reached_announce_depth);
towire_secret(&p, last_remote_secret);
towire_u16(&p, flen);
towire_u8_array(&p, their_features, flen);
towire_u16(&p, upfront_shutdown_script_len);
towire_u8_array(&p, upfront_shutdown_script, upfront_shutdown_script_len);
if (!remote_ann_node_sig)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_secp256k1_ecdsa_signature(&p, remote_ann_node_sig);
}
if (!remote_ann_bitcoin_sig)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_secp256k1_ecdsa_signature(&p, remote_ann_bitcoin_sig);
}
towire_bool(&p, option_static_remotekey);
towire_bool(&p, option_anchor_outputs);
towire_bool(&p, dev_fast_gossip);
towire_bool(&p, dev_fail_process_onionpacket);
towire_u32(&p, num_penalty_bases);
for (size_t i = 0; i < num_penalty_bases; i++)
towire_penalty_base(&p, pbases + i);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_init(const tal_t *ctx, const void *p, const struct chainparams **chainparams, struct feature_set **our_features, struct channel_id *channel_id, struct bitcoin_txid *funding_txid, u16 *funding_txout, struct amount_sat *funding_satoshi, u32 *minimum_depth, struct channel_config *our_config, struct channel_config *their_config, struct fee_states **fee_states, u32 *feerate_min, u32 *feerate_max, u32 *feerate_penalty, struct bitcoin_signature *first_commit_sig, struct per_peer_state **per_peer_state, struct pubkey *remote_fundingkey, struct basepoints *remote_basepoints, struct pubkey *remote_per_commit, struct pubkey *old_remote_per_commit, enum side *opener, u32 *fee_base, u32 *fee_proportional, struct amount_msat *local_msatoshi, struct basepoints *our_basepoints, struct pubkey *our_funding_pubkey, struct node_id *local_node_id, struct node_id *remote_node_id, u32 *commit_msec, u16 *cltv_delta, bool *last_was_revoke, struct changed_htlc **last_sent_commit, u64 *next_index_local, u64 *next_index_remote, u64 *revocations_received, u64 *next_htlc_id, struct existing_htlc ***htlcs, bool *local_funding_locked, bool *remote_funding_locked, struct short_channel_id *funding_short_id, bool *reestablish, bool *send_shutdown, bool *remote_shutdown_received, u8 **final_scriptpubkey, u8 *flags, u8 **init_peer_pkt, bool *reached_announce_depth, struct secret *last_remote_secret, u8 **their_features, u8 **upfront_shutdown_script, secp256k1_ecdsa_signature **remote_ann_node_sig, secp256k1_ecdsa_signature **remote_ann_bitcoin_sig, bool *option_static_remotekey, bool *option_anchor_outputs, bool *dev_fast_gossip, bool *dev_fail_process_onionpacket, struct penalty_base **pbases)
{
u16 num_last_sent_commit;
u16 num_existing_htlcs;
u16 final_scriptpubkey_len;
u16 init_peer_pkt_len;
u16 flen;
u16 upfront_shutdown_script_len;
u32 num_penalty_bases;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_INIT)
return false;
fromwire_chainparams(&cursor, &plen, chainparams);
*our_features = fromwire_feature_set(ctx, &cursor, &plen);
fromwire_channel_id(&cursor, &plen, channel_id);
fromwire_bitcoin_txid(&cursor, &plen, funding_txid);
*funding_txout = fromwire_u16(&cursor, &plen);
*funding_satoshi = fromwire_amount_sat(&cursor, &plen);
*minimum_depth = fromwire_u32(&cursor, &plen);
fromwire_channel_config(&cursor, &plen, our_config);
fromwire_channel_config(&cursor, &plen, their_config);
*fee_states = fromwire_fee_states(ctx, &cursor, &plen);
*feerate_min = fromwire_u32(&cursor, &plen);
*feerate_max = fromwire_u32(&cursor, &plen);
*feerate_penalty = fromwire_u32(&cursor, &plen);
fromwire_bitcoin_signature(&cursor, &plen, first_commit_sig);
*per_peer_state = fromwire_per_peer_state(ctx, &cursor, &plen);
fromwire_pubkey(&cursor, &plen, remote_fundingkey);
fromwire_basepoints(&cursor, &plen, remote_basepoints);
fromwire_pubkey(&cursor, &plen, remote_per_commit);
fromwire_pubkey(&cursor, &plen, old_remote_per_commit);
*opener = fromwire_side(&cursor, &plen);
*fee_base = fromwire_u32(&cursor, &plen);
*fee_proportional = fromwire_u32(&cursor, &plen);
*local_msatoshi = fromwire_amount_msat(&cursor, &plen);
fromwire_basepoints(&cursor, &plen, our_basepoints);
fromwire_pubkey(&cursor, &plen, our_funding_pubkey);
fromwire_node_id(&cursor, &plen, local_node_id);
fromwire_node_id(&cursor, &plen, remote_node_id);
*commit_msec = fromwire_u32(&cursor, &plen);
*cltv_delta = fromwire_u16(&cursor, &plen);
*last_was_revoke = fromwire_bool(&cursor, &plen);
num_last_sent_commit = fromwire_u16(&cursor, &plen);
// 2nd case last_sent_commit
*last_sent_commit = num_last_sent_commit ? tal_arr(ctx, struct changed_htlc, num_last_sent_commit) : NULL;
for (size_t i = 0; i < num_last_sent_commit; i++)
fromwire_changed_htlc(&cursor, &plen, *last_sent_commit + i);
*next_index_local = fromwire_u64(&cursor, &plen);
*next_index_remote = fromwire_u64(&cursor, &plen);
*revocations_received = fromwire_u64(&cursor, &plen);
*next_htlc_id = fromwire_u64(&cursor, &plen);
num_existing_htlcs = fromwire_u16(&cursor, &plen);
// 2nd case htlcs
*htlcs = num_existing_htlcs ? tal_arr(ctx, struct existing_htlc *, num_existing_htlcs) : NULL;
for (size_t i = 0; i < num_existing_htlcs; i++)
(*htlcs)[i] = fromwire_existing_htlc(*htlcs, &cursor, &plen);
*local_funding_locked = fromwire_bool(&cursor, &plen);
*remote_funding_locked = fromwire_bool(&cursor, &plen);
fromwire_short_channel_id(&cursor, &plen, funding_short_id);
*reestablish = fromwire_bool(&cursor, &plen);
*send_shutdown = fromwire_bool(&cursor, &plen);
*remote_shutdown_received = fromwire_bool(&cursor, &plen);
final_scriptpubkey_len = fromwire_u16(&cursor, &plen);
// 2nd case final_scriptpubkey
*final_scriptpubkey = final_scriptpubkey_len ? tal_arr(ctx, u8, final_scriptpubkey_len) : NULL;
fromwire_u8_array(&cursor, &plen, *final_scriptpubkey, final_scriptpubkey_len);
*flags = fromwire_u8(&cursor, &plen);
init_peer_pkt_len = fromwire_u16(&cursor, &plen);
// 2nd case init_peer_pkt
*init_peer_pkt = init_peer_pkt_len ? tal_arr(ctx, u8, init_peer_pkt_len) : NULL;
fromwire_u8_array(&cursor, &plen, *init_peer_pkt, init_peer_pkt_len);
*reached_announce_depth = fromwire_bool(&cursor, &plen);
fromwire_secret(&cursor, &plen, last_remote_secret);
flen = fromwire_u16(&cursor, &plen);
// 2nd case their_features
*their_features = flen ? tal_arr(ctx, u8, flen) : NULL;
fromwire_u8_array(&cursor, &plen, *their_features, flen);
upfront_shutdown_script_len = fromwire_u16(&cursor, &plen);
// 2nd case upfront_shutdown_script
*upfront_shutdown_script = upfront_shutdown_script_len ? tal_arr(ctx, u8, upfront_shutdown_script_len) : NULL;
fromwire_u8_array(&cursor, &plen, *upfront_shutdown_script, upfront_shutdown_script_len);
if (!fromwire_bool(&cursor, &plen))
*remote_ann_node_sig = NULL;
else {
*remote_ann_node_sig = tal(ctx, secp256k1_ecdsa_signature);
fromwire_secp256k1_ecdsa_signature(&cursor, &plen, *remote_ann_node_sig);
}
if (!fromwire_bool(&cursor, &plen))
*remote_ann_bitcoin_sig = NULL;
else {
*remote_ann_bitcoin_sig = tal(ctx, secp256k1_ecdsa_signature);
fromwire_secp256k1_ecdsa_signature(&cursor, &plen, *remote_ann_bitcoin_sig);
}
*option_static_remotekey = fromwire_bool(&cursor, &plen);
*option_anchor_outputs = fromwire_bool(&cursor, &plen);
*dev_fast_gossip = fromwire_bool(&cursor, &plen);
*dev_fail_process_onionpacket = fromwire_bool(&cursor, &plen);
num_penalty_bases = fromwire_u32(&cursor, &plen);
// 2nd case pbases
*pbases = num_penalty_bases ? tal_arr(ctx, struct penalty_base, num_penalty_bases) : NULL;
for (size_t i = 0; i < num_penalty_bases; i++)
fromwire_penalty_base(&cursor, &plen, *pbases + i);
return cursor != NULL;
}
/* WIRE: CHANNELD_FUNDING_DEPTH */
/* master->channeld funding hit new depth(funding locked if >= lock depth) */
u8 *towire_channeld_funding_depth(const tal_t *ctx, const struct short_channel_id *short_channel_id, u32 depth)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_FUNDING_DEPTH);
if (!short_channel_id)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_short_channel_id(&p, short_channel_id);
}
towire_u32(&p, depth);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_funding_depth(const tal_t *ctx, const void *p, struct short_channel_id **short_channel_id, u32 *depth)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FUNDING_DEPTH)
return false;
if (!fromwire_bool(&cursor, &plen))
*short_channel_id = NULL;
else {
*short_channel_id = tal(ctx, struct short_channel_id);
fromwire_short_channel_id(&cursor, &plen, *short_channel_id);
}
*depth = fromwire_u32(&cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNELD_OFFER_HTLC */
/* Tell channel to offer this htlc */
u8 *towire_channeld_offer_htlc(const tal_t *ctx, struct amount_msat amount_msat, u32 cltv_expiry, const struct sha256 *payment_hash, const u8 onion_routing_packet[1366], const struct pubkey *blinding)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_OFFER_HTLC);
towire_amount_msat(&p, amount_msat);
towire_u32(&p, cltv_expiry);
towire_sha256(&p, payment_hash);
towire_u8_array(&p, onion_routing_packet, 1366);
if (!blinding)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_pubkey(&p, blinding);
}
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_offer_htlc(const tal_t *ctx, const void *p, struct amount_msat *amount_msat, u32 *cltv_expiry, struct sha256 *payment_hash, u8 onion_routing_packet[1366], struct pubkey **blinding)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_OFFER_HTLC)
return false;
*amount_msat = fromwire_amount_msat(&cursor, &plen);
*cltv_expiry = fromwire_u32(&cursor, &plen);
fromwire_sha256(&cursor, &plen, payment_hash);
fromwire_u8_array(&cursor, &plen, onion_routing_packet, 1366);
if (!fromwire_bool(&cursor, &plen))
*blinding = NULL;
else {
*blinding = tal(ctx, struct pubkey);
fromwire_pubkey(&cursor, &plen, *blinding);
}
return cursor != NULL;
}
/* WIRE: CHANNELD_OFFER_HTLC_REPLY */
/* Reply; synchronous since IDs have to increment. */
u8 *towire_channeld_offer_htlc_reply(const tal_t *ctx, u64 id, const u8 *failuremsg, const wirestring *failurestr)
{
u16 len = tal_count(failuremsg);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_OFFER_HTLC_REPLY);
towire_u64(&p, id);
/* Empty failure message means success. */
towire_u16(&p, len);
towire_u8_array(&p, failuremsg, len);
towire_wirestring(&p, failurestr);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_offer_htlc_reply(const tal_t *ctx, const void *p, u64 *id, u8 **failuremsg, wirestring **failurestr)
{
u16 len;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_OFFER_HTLC_REPLY)
return false;
*id = fromwire_u64(&cursor, &plen);
/* Empty failure message means success. */
len = fromwire_u16(&cursor, &plen);
// 2nd case failuremsg
*failuremsg = len ? tal_arr(ctx, u8, len) : NULL;
fromwire_u8_array(&cursor, &plen, *failuremsg, len);
*failurestr = fromwire_wirestring(ctx, &cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNELD_FULFILL_HTLC */
/* Main daemon found out the preimage for an HTLC */
u8 *towire_channeld_fulfill_htlc(const tal_t *ctx, const struct fulfilled_htlc *fulfilled_htlc)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_FULFILL_HTLC);
towire_fulfilled_htlc(&p, fulfilled_htlc);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_fulfill_htlc(const void *p, struct fulfilled_htlc *fulfilled_htlc)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FULFILL_HTLC)
return false;
fromwire_fulfilled_htlc(&cursor, &plen, fulfilled_htlc);
return cursor != NULL;
}
/* WIRE: CHANNELD_FAIL_HTLC */
/* Main daemon says HTLC failed */
u8 *towire_channeld_fail_htlc(const tal_t *ctx, const struct failed_htlc *failed_htlc)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_FAIL_HTLC);
towire_failed_htlc(&p, failed_htlc);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_fail_htlc(const tal_t *ctx, const void *p, struct failed_htlc **failed_htlc)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FAIL_HTLC)
return false;
*failed_htlc = fromwire_failed_htlc(ctx, &cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNELD_GOT_FUNDING_LOCKED */
/* When we receive funding_locked. */
u8 *towire_channeld_got_funding_locked(const tal_t *ctx, const struct pubkey *next_per_commit_point)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_GOT_FUNDING_LOCKED);
towire_pubkey(&p, next_per_commit_point);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_got_funding_locked(const void *p, struct pubkey *next_per_commit_point)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_FUNDING_LOCKED)
return false;
fromwire_pubkey(&cursor, &plen, next_per_commit_point);
return cursor != NULL;
}
/* WIRE: CHANNELD_SENDING_COMMITSIG */
/* When we send a commitment_signed message */
u8 *towire_channeld_sending_commitsig(const tal_t *ctx, u64 commitnum, const struct penalty_base *pbase, const struct fee_states *fee_states, const struct changed_htlc *changed, const struct bitcoin_signature *commit_sig, const struct bitcoin_signature *htlc_sigs)
{
u16 num_changed = tal_count(changed);
u16 num_htlc_sigs = tal_count(htlc_sigs);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_SENDING_COMMITSIG);
towire_u64(&p, commitnum);
if (!pbase)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_penalty_base(&p, pbase);
}
towire_fee_states(&p, fee_states);
/* SENT_ADD_COMMIT */
towire_u16(&p, num_changed);
for (size_t i = 0; i < num_changed; i++)
towire_changed_htlc(&p, changed + i);
towire_bitcoin_signature(&p, commit_sig);
towire_u16(&p, num_htlc_sigs);
for (size_t i = 0; i < num_htlc_sigs; i++)
towire_bitcoin_signature(&p, htlc_sigs + i);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_sending_commitsig(const tal_t *ctx, const void *p, u64 *commitnum, struct penalty_base **pbase, struct fee_states **fee_states, struct changed_htlc **changed, struct bitcoin_signature *commit_sig, struct bitcoin_signature **htlc_sigs)
{
u16 num_changed;
u16 num_htlc_sigs;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SENDING_COMMITSIG)
return false;
*commitnum = fromwire_u64(&cursor, &plen);
if (!fromwire_bool(&cursor, &plen))
*pbase = NULL;
else {
*pbase = tal(ctx, struct penalty_base);
fromwire_penalty_base(&cursor, &plen, *pbase);
}
*fee_states = fromwire_fee_states(ctx, &cursor, &plen);
/* SENT_ADD_COMMIT */
num_changed = fromwire_u16(&cursor, &plen);
// 2nd case changed
*changed = num_changed ? tal_arr(ctx, struct changed_htlc, num_changed) : NULL;
for (size_t i = 0; i < num_changed; i++)
fromwire_changed_htlc(&cursor, &plen, *changed + i);
fromwire_bitcoin_signature(&cursor, &plen, commit_sig);
num_htlc_sigs = fromwire_u16(&cursor, &plen);
// 2nd case htlc_sigs
*htlc_sigs = num_htlc_sigs ? tal_arr(ctx, struct bitcoin_signature, num_htlc_sigs) : NULL;
for (size_t i = 0; i < num_htlc_sigs; i++)
fromwire_bitcoin_signature(&cursor, &plen, *htlc_sigs + i);
return cursor != NULL;
}
/* WIRE: CHANNELD_SENDING_COMMITSIG_REPLY */
/* Wait for reply */
u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_SENDING_COMMITSIG_REPLY);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_sending_commitsig_reply(const void *p)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SENDING_COMMITSIG_REPLY)
return false;
return cursor != NULL;
}
/* WIRE: CHANNELD_GOT_COMMITSIG */
/* When we have a commitment_signed message */
u8 *towire_channeld_got_commitsig(const tal_t *ctx, u64 commitnum, const struct fee_states *fee_states, const struct bitcoin_signature *signature, const struct bitcoin_signature *htlc_signature, const struct added_htlc *added, const struct fulfilled_htlc *fulfilled, const struct failed_htlc **failed, const struct changed_htlc *changed, const struct bitcoin_tx *tx)
{
u16 num_htlcs = tal_count(htlc_signature);
u16 num_added = tal_count(added);
u16 num_fulfilled = tal_count(fulfilled);
u16 num_failed = tal_count(failed);
u16 num_changed = tal_count(changed);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_GOT_COMMITSIG);
towire_u64(&p, commitnum);
towire_fee_states(&p, fee_states);
towire_bitcoin_signature(&p, signature);
towire_u16(&p, num_htlcs);
for (size_t i = 0; i < num_htlcs; i++)
towire_bitcoin_signature(&p, htlc_signature + i);
/* RCVD_ADD_COMMIT: we're now committed to their new offered HTLCs. */
towire_u16(&p, num_added);
for (size_t i = 0; i < num_added; i++)
towire_added_htlc(&p, added + i);
/* RCVD_REMOVE_COMMIT: we're now no longer committed to these HTLCs. */
towire_u16(&p, num_fulfilled);
for (size_t i = 0; i < num_fulfilled; i++)
towire_fulfilled_htlc(&p, fulfilled + i);
towire_u16(&p, num_failed);
for (size_t i = 0; i < num_failed; i++)
towire_failed_htlc(&p, failed[i]);
/* RCVD_ADD_ACK_COMMIT */
towire_u16(&p, num_changed);
for (size_t i = 0; i < num_changed; i++)
towire_changed_htlc(&p, changed + i);
towire_bitcoin_tx(&p, tx);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_got_commitsig(const tal_t *ctx, const void *p, u64 *commitnum, struct fee_states **fee_states, struct bitcoin_signature *signature, struct bitcoin_signature **htlc_signature, struct added_htlc **added, struct fulfilled_htlc **fulfilled, struct failed_htlc ***failed, struct changed_htlc **changed, struct bitcoin_tx **tx)
{
u16 num_htlcs;
u16 num_added;
u16 num_fulfilled;
u16 num_failed;
u16 num_changed;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_COMMITSIG)
return false;
*commitnum = fromwire_u64(&cursor, &plen);
*fee_states = fromwire_fee_states(ctx, &cursor, &plen);
fromwire_bitcoin_signature(&cursor, &plen, signature);
num_htlcs = fromwire_u16(&cursor, &plen);
// 2nd case htlc_signature
*htlc_signature = num_htlcs ? tal_arr(ctx, struct bitcoin_signature, num_htlcs) : NULL;
for (size_t i = 0; i < num_htlcs; i++)
fromwire_bitcoin_signature(&cursor, &plen, *htlc_signature + i);
/* RCVD_ADD_COMMIT: we're now committed to their new offered HTLCs. */
num_added = fromwire_u16(&cursor, &plen);
// 2nd case added
*added = num_added ? tal_arr(ctx, struct added_htlc, num_added) : NULL;
for (size_t i = 0; i < num_added; i++)
fromwire_added_htlc(&cursor, &plen, *added + i);
/* RCVD_REMOVE_COMMIT: we're now no longer committed to these HTLCs. */
num_fulfilled = fromwire_u16(&cursor, &plen);
// 2nd case fulfilled
*fulfilled = num_fulfilled ? tal_arr(ctx, struct fulfilled_htlc, num_fulfilled) : NULL;
for (size_t i = 0; i < num_fulfilled; i++)
fromwire_fulfilled_htlc(&cursor, &plen, *fulfilled + i);
num_failed = fromwire_u16(&cursor, &plen);
// 2nd case failed
*failed = num_failed ? tal_arr(ctx, struct failed_htlc *, num_failed) : NULL;
for (size_t i = 0; i < num_failed; i++)
(*failed)[i] = fromwire_failed_htlc(*failed, &cursor, &plen);
/* RCVD_ADD_ACK_COMMIT */
num_changed = fromwire_u16(&cursor, &plen);
// 2nd case changed
*changed = num_changed ? tal_arr(ctx, struct changed_htlc, num_changed) : NULL;
for (size_t i = 0; i < num_changed; i++)
fromwire_changed_htlc(&cursor, &plen, *changed + i);
*tx = fromwire_bitcoin_tx(ctx, &cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNELD_GOT_COMMITSIG_REPLY */
/* Wait for reply */
u8 *towire_channeld_got_commitsig_reply(const tal_t *ctx)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_GOT_COMMITSIG_REPLY);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_got_commitsig_reply(const void *p)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_COMMITSIG_REPLY)
return false;
return cursor != NULL;
}
/* WIRE: CHANNELD_GOT_REVOKE */
u8 *towire_channeld_got_revoke(const tal_t *ctx, u64 revokenum, const struct secret *per_commitment_secret, const struct pubkey *next_per_commit_point, const struct fee_states *fee_states, const struct changed_htlc *changed, const struct penalty_base *pbase, const struct bitcoin_tx *penalty_tx)
{
u16 num_changed = tal_count(changed);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_GOT_REVOKE);
towire_u64(&p, revokenum);
towire_secret(&p, per_commitment_secret);
towire_pubkey(&p, next_per_commit_point);
/* RCVD_ADD_ACK_REVOCATION */
towire_fee_states(&p, fee_states);
towire_u16(&p, num_changed);
for (size_t i = 0; i < num_changed; i++)
towire_changed_htlc(&p, changed + i);
if (!pbase)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_penalty_base(&p, pbase);
}
if (!penalty_tx)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_bitcoin_tx(&p, penalty_tx);
}
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_got_revoke(const tal_t *ctx, const void *p, u64 *revokenum, struct secret *per_commitment_secret, struct pubkey *next_per_commit_point, struct fee_states **fee_states, struct changed_htlc **changed, struct penalty_base **pbase, struct bitcoin_tx **penalty_tx)
{
u16 num_changed;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_REVOKE)
return false;
*revokenum = fromwire_u64(&cursor, &plen);
fromwire_secret(&cursor, &plen, per_commitment_secret);
fromwire_pubkey(&cursor, &plen, next_per_commit_point);
/* RCVD_ADD_ACK_REVOCATION */
*fee_states = fromwire_fee_states(ctx, &cursor, &plen);
num_changed = fromwire_u16(&cursor, &plen);
// 2nd case changed
*changed = num_changed ? tal_arr(ctx, struct changed_htlc, num_changed) : NULL;
for (size_t i = 0; i < num_changed; i++)
fromwire_changed_htlc(&cursor, &plen, *changed + i);
if (!fromwire_bool(&cursor, &plen))
*pbase = NULL;
else {
*pbase = tal(ctx, struct penalty_base);
fromwire_penalty_base(&cursor, &plen, *pbase);
}
if (!fromwire_bool(&cursor, &plen))
*penalty_tx = NULL;
else {
*penalty_tx = fromwire_bitcoin_tx(ctx, &cursor, &plen);
}
return cursor != NULL;
}
/* WIRE: CHANNELD_GOT_REVOKE_REPLY */
/* Wait for reply */
/* (eg. if we sent another commitment_signed */
u8 *towire_channeld_got_revoke_reply(const tal_t *ctx)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_GOT_REVOKE_REPLY);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_got_revoke_reply(const void *p)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_REVOKE_REPLY)
return false;
return cursor != NULL;
}
/* WIRE: CHANNELD_SEND_SHUTDOWN */
/* Tell peer to shut down channel. */
u8 *towire_channeld_send_shutdown(const tal_t *ctx, const u8 *shutdown_scriptpubkey, const struct bitcoin_outpoint *wrong_funding)
{
u16 shutdown_len = tal_count(shutdown_scriptpubkey);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_SEND_SHUTDOWN);
towire_u16(&p, shutdown_len);
towire_u8_array(&p, shutdown_scriptpubkey, shutdown_len);
if (!wrong_funding)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_bitcoin_outpoint(&p, wrong_funding);
}
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_send_shutdown(const tal_t *ctx, const void *p, u8 **shutdown_scriptpubkey, struct bitcoin_outpoint **wrong_funding)
{
u16 shutdown_len;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SEND_SHUTDOWN)
return false;
shutdown_len = fromwire_u16(&cursor, &plen);
// 2nd case shutdown_scriptpubkey
*shutdown_scriptpubkey = shutdown_len ? tal_arr(ctx, u8, shutdown_len) : NULL;
fromwire_u8_array(&cursor, &plen, *shutdown_scriptpubkey, shutdown_len);
if (!fromwire_bool(&cursor, &plen))
*wrong_funding = NULL;
else {
*wrong_funding = tal(ctx, struct bitcoin_outpoint);
fromwire_bitcoin_outpoint(&cursor, &plen, *wrong_funding);
}
return cursor != NULL;
}
/* WIRE: CHANNELD_GOT_SHUTDOWN */
/* Peer told us that channel is shutting down */
u8 *towire_channeld_got_shutdown(const tal_t *ctx, const u8 *scriptpubkey, const struct bitcoin_outpoint *wrong_funding)
{
u16 scriptpubkey_len = tal_count(scriptpubkey);
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_GOT_SHUTDOWN);
towire_u16(&p, scriptpubkey_len);
towire_u8_array(&p, scriptpubkey, scriptpubkey_len);
if (!wrong_funding)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_bitcoin_outpoint(&p, wrong_funding);
}
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_got_shutdown(const tal_t *ctx, const void *p, u8 **scriptpubkey, struct bitcoin_outpoint **wrong_funding)
{
u16 scriptpubkey_len;
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_GOT_SHUTDOWN)
return false;
scriptpubkey_len = fromwire_u16(&cursor, &plen);
// 2nd case scriptpubkey
*scriptpubkey = scriptpubkey_len ? tal_arr(ctx, u8, scriptpubkey_len) : NULL;
fromwire_u8_array(&cursor, &plen, *scriptpubkey, scriptpubkey_len);
if (!fromwire_bool(&cursor, &plen))
*wrong_funding = NULL;
else {
*wrong_funding = tal(ctx, struct bitcoin_outpoint);
fromwire_bitcoin_outpoint(&cursor, &plen, *wrong_funding);
}
return cursor != NULL;
}
/* WIRE: CHANNELD_SHUTDOWN_COMPLETE */
/* Shutdown is complete */
u8 *towire_channeld_shutdown_complete(const tal_t *ctx, const struct per_peer_state *per_peer_state)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_SHUTDOWN_COMPLETE);
towire_per_peer_state(&p, per_peer_state);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_shutdown_complete(const tal_t *ctx, const void *p, struct per_peer_state **per_peer_state)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_SHUTDOWN_COMPLETE)
return false;
*per_peer_state = fromwire_per_peer_state(ctx, &cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNELD_DEV_REENABLE_COMMIT */
/* Re-enable commit timer. */
u8 *towire_channeld_dev_reenable_commit(const tal_t *ctx)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_DEV_REENABLE_COMMIT);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_dev_reenable_commit(const void *p)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_REENABLE_COMMIT)
return false;
return cursor != NULL;
}
/* WIRE: CHANNELD_DEV_REENABLE_COMMIT_REPLY */
u8 *towire_channeld_dev_reenable_commit_reply(const tal_t *ctx)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_dev_reenable_commit_reply(const void *p)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_REENABLE_COMMIT_REPLY)
return false;
return cursor != NULL;
}
/* WIRE: CHANNELD_FEERATES */
u8 *towire_channeld_feerates(const tal_t *ctx, u32 feerate, u32 min_feerate, u32 max_feerate, u32 penalty_feerate)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_FEERATES);
towire_u32(&p, feerate);
towire_u32(&p, min_feerate);
towire_u32(&p, max_feerate);
towire_u32(&p, penalty_feerate);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_feerates(const void *p, u32 *feerate, u32 *min_feerate, u32 *max_feerate, u32 *penalty_feerate)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FEERATES)
return false;
*feerate = fromwire_u32(&cursor, &plen);
*min_feerate = fromwire_u32(&cursor, &plen);
*max_feerate = fromwire_u32(&cursor, &plen);
*penalty_feerate = fromwire_u32(&cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNELD_DEV_MEMLEAK */
/* master -> channeld: do you have a memleak? */
u8 *towire_channeld_dev_memleak(const tal_t *ctx)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_DEV_MEMLEAK);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_dev_memleak(const void *p)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_MEMLEAK)
return false;
return cursor != NULL;
}
/* WIRE: CHANNELD_DEV_MEMLEAK_REPLY */
u8 *towire_channeld_dev_memleak_reply(const tal_t *ctx, bool leak)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_DEV_MEMLEAK_REPLY);
towire_bool(&p, leak);
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_dev_memleak_reply(const void *p, bool *leak)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_DEV_MEMLEAK_REPLY)
return false;
*leak = fromwire_bool(&cursor, &plen);
return cursor != NULL;
}
/* WIRE: CHANNELD_FAIL_FALLEN_BEHIND */
/* Peer presented proof it was from the future. */
u8 *towire_channeld_fail_fallen_behind(const tal_t *ctx, const struct pubkey *remote_per_commitment_point)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_FAIL_FALLEN_BEHIND);
/* This is NULL if option_static_remotekey. */
if (!remote_per_commitment_point)
towire_bool(&p, false);
else {
towire_bool(&p, true);
towire_pubkey(&p, remote_per_commitment_point);
}
return memcheck(p, tal_count(p));
}
bool fromwire_channeld_fail_fallen_behind(const tal_t *ctx, const void *p, struct pubkey **remote_per_commitment_point)
{
const u8 *cursor = p;
size_t plen = tal_count(p);
if (fromwire_u16(&cursor, &plen) != WIRE_CHANNELD_FAIL_FALLEN_BEHIND)
return false;
/* This is NULL if option_static_remotekey. */
if (!fromwire_bool(&cursor, &plen))
*remote_per_commitment_point = NULL;
else {
*remote_per_commitment_point = tal(ctx, struct pubkey);
fromwire_pubkey(&cursor, &plen, *remote_per_commitment_point);
}
return cursor != NULL;
}
/* WIRE: CHANNELD_SPECIFIC_FEERATES */
/* Handle a channel specific feerate base ppm configuration */
u8 *towire_channeld_specific_feerates(const tal_t *ctx, u32 feerate_base, u32 feerate_ppm)
{
u8 *p = tal_arr(ctx, u8, 0);
towire_u16(&p, WIRE_CHANNELD_SPECIFIC_FEERATES);
towire_u32(&p, feerate_base);
towire_u32(&p, feerate_ppm);
return memcheck(p, tal_count(p));