1 #include <ccan/array_size/array_size.h>
2 #include <common/htlc.h>
3 #include "htlc_state_names_gen.h"
4 #include <common/htlc_state.h>
5
htlc_state_name(enum htlc_state s)6 const char *htlc_state_name(enum htlc_state s)
7 {
8 size_t i;
9
10 for (i = 0; enum_htlc_state_names[i].name; i++)
11 if (enum_htlc_state_names[i].v == s)
12 return enum_htlc_state_names[i].name;
13 return "unknown";
14 }
15
16 /* This is the flags for each state. */
17 static const int per_state_bits[] = {
18 [SENT_ADD_HTLC] = HTLC_ADDING + HTLC_LOCAL_F_OWNER
19 + HTLC_REMOTE_F_PENDING,
20
21 [SENT_ADD_COMMIT] = HTLC_ADDING + HTLC_LOCAL_F_OWNER
22 + HTLC_REMOTE_F_COMMITTED
23 + HTLC_REMOTE_F_WAS_COMMITTED,
24
25 [RCVD_ADD_REVOCATION] = HTLC_ADDING + HTLC_LOCAL_F_OWNER
26 + HTLC_REMOTE_F_COMMITTED
27 + HTLC_REMOTE_F_REVOKED
28 + HTLC_LOCAL_F_PENDING
29 + HTLC_REMOTE_F_WAS_COMMITTED,
30
31 [RCVD_ADD_ACK_COMMIT] = HTLC_ADDING + HTLC_LOCAL_F_OWNER
32 + HTLC_REMOTE_F_COMMITTED
33 + HTLC_REMOTE_F_REVOKED
34 + HTLC_LOCAL_F_COMMITTED
35 + HTLC_LOCAL_F_WAS_COMMITTED
36 + HTLC_REMOTE_F_WAS_COMMITTED,
37
38 [SENT_ADD_ACK_REVOCATION] = HTLC_LOCAL_F_OWNER
39 + HTLC_REMOTE_F_COMMITTED
40 + HTLC_REMOTE_F_REVOKED
41 + HTLC_LOCAL_F_COMMITTED
42 + HTLC_LOCAL_F_REVOKED
43 + HTLC_LOCAL_F_WAS_COMMITTED
44 + HTLC_REMOTE_F_WAS_COMMITTED,
45
46 [RCVD_REMOVE_HTLC] = HTLC_REMOVING + HTLC_LOCAL_F_OWNER
47 + HTLC_LOCAL_F_PENDING + HTLC_LOCAL_F_COMMITTED
48 + HTLC_REMOTE_F_COMMITTED
49 + HTLC_LOCAL_F_WAS_COMMITTED
50 + HTLC_REMOTE_F_WAS_COMMITTED,
51
52 [RCVD_REMOVE_COMMIT] = HTLC_REMOVING + HTLC_LOCAL_F_OWNER
53 + HTLC_REMOTE_F_COMMITTED
54 + HTLC_LOCAL_F_WAS_COMMITTED
55 + HTLC_REMOTE_F_WAS_COMMITTED,
56
57 [SENT_REMOVE_REVOCATION] = HTLC_REMOVING + HTLC_LOCAL_F_OWNER
58 + HTLC_REMOTE_F_COMMITTED
59 + HTLC_LOCAL_F_REVOKED
60 + HTLC_REMOTE_F_PENDING
61 + HTLC_LOCAL_F_WAS_COMMITTED
62 + HTLC_REMOTE_F_WAS_COMMITTED,
63
64 [SENT_REMOVE_ACK_COMMIT] = HTLC_REMOVING + HTLC_LOCAL_F_OWNER
65 + HTLC_LOCAL_F_REVOKED
66 + HTLC_LOCAL_F_WAS_COMMITTED
67 + HTLC_REMOTE_F_WAS_COMMITTED,
68
69 [RCVD_REMOVE_ACK_REVOCATION] = HTLC_LOCAL_F_OWNER
70 + HTLC_LOCAL_F_REVOKED
71 + HTLC_REMOTE_F_REVOKED
72 + HTLC_LOCAL_F_WAS_COMMITTED
73 + HTLC_REMOTE_F_WAS_COMMITTED,
74
75 [RCVD_ADD_HTLC] = HTLC_ADDING + HTLC_REMOTE_F_OWNER
76 + HTLC_LOCAL_F_PENDING,
77
78 [RCVD_ADD_COMMIT] = HTLC_ADDING + HTLC_REMOTE_F_OWNER
79 + HTLC_LOCAL_F_COMMITTED
80 + HTLC_LOCAL_F_WAS_COMMITTED,
81
82 [SENT_ADD_REVOCATION] = HTLC_ADDING + HTLC_REMOTE_F_OWNER
83 + HTLC_LOCAL_F_COMMITTED
84 + HTLC_LOCAL_F_REVOKED
85 + HTLC_REMOTE_F_PENDING
86 + HTLC_LOCAL_F_WAS_COMMITTED,
87
88 [SENT_ADD_ACK_COMMIT] = HTLC_ADDING + HTLC_REMOTE_F_OWNER
89 + HTLC_LOCAL_F_COMMITTED
90 + HTLC_LOCAL_F_REVOKED
91 + HTLC_REMOTE_F_COMMITTED
92 + HTLC_LOCAL_F_WAS_COMMITTED
93 + HTLC_REMOTE_F_WAS_COMMITTED,
94
95 [RCVD_ADD_ACK_REVOCATION] = HTLC_REMOTE_F_OWNER
96 + HTLC_LOCAL_F_COMMITTED
97 + HTLC_LOCAL_F_REVOKED
98 + HTLC_REMOTE_F_COMMITTED
99 + HTLC_REMOTE_F_REVOKED
100 + HTLC_LOCAL_F_WAS_COMMITTED
101 + HTLC_REMOTE_F_WAS_COMMITTED,
102
103 [SENT_REMOVE_HTLC] = HTLC_REMOVING + HTLC_REMOTE_F_OWNER
104 + HTLC_REMOTE_F_PENDING
105 + HTLC_LOCAL_F_COMMITTED
106 + HTLC_REMOTE_F_COMMITTED
107 + HTLC_LOCAL_F_WAS_COMMITTED
108 + HTLC_REMOTE_F_WAS_COMMITTED,
109
110 [SENT_REMOVE_COMMIT] = HTLC_REMOVING + HTLC_REMOTE_F_OWNER
111 + HTLC_LOCAL_F_COMMITTED
112 + HTLC_LOCAL_F_WAS_COMMITTED
113 + HTLC_REMOTE_F_WAS_COMMITTED,
114
115 [RCVD_REMOVE_REVOCATION] = HTLC_REMOVING + HTLC_REMOTE_F_OWNER
116 + HTLC_LOCAL_F_COMMITTED
117 + HTLC_REMOTE_F_REVOKED
118 + HTLC_LOCAL_F_PENDING
119 + HTLC_LOCAL_F_WAS_COMMITTED
120 + HTLC_REMOTE_F_WAS_COMMITTED,
121
122 [RCVD_REMOVE_ACK_COMMIT] = HTLC_REMOVING + HTLC_REMOTE_F_OWNER
123 + HTLC_REMOTE_F_REVOKED
124 + HTLC_LOCAL_F_WAS_COMMITTED
125 + HTLC_REMOTE_F_WAS_COMMITTED,
126
127 [SENT_REMOVE_ACK_REVOCATION] = HTLC_REMOTE_F_OWNER
128 + HTLC_REMOTE_F_REVOKED
129 + HTLC_LOCAL_F_REVOKED
130 + HTLC_LOCAL_F_WAS_COMMITTED
131 + HTLC_REMOTE_F_WAS_COMMITTED
132 };
133
htlc_state_flags(enum htlc_state state)134 int htlc_state_flags(enum htlc_state state)
135 {
136 assert(state < ARRAY_SIZE(per_state_bits));
137 assert(per_state_bits[state]);
138 return per_state_bits[state];
139 }
140
141