@@ -73,7 +73,7 @@ static bool find_connected_pair(const struct state *state,
73
73
return false;
74
74
}
75
75
76
- void check_chains (struct state * state )
76
+ void check_chains (struct state * state , bool all )
77
77
{
78
78
const struct block * i ;
79
79
size_t n , num_next_level = 1 ;
@@ -88,6 +88,37 @@ void check_chains(struct state *state)
88
88
assert (cmp_work (state -> longest_knowns [n ],
89
89
state -> longest_knowns [0 ]) == 0 );
90
90
91
+
92
+ /* preferred_chain should be a descendent of longest_knowns[0] */
93
+ for (i = state -> preferred_chain ;
94
+ i != state -> longest_knowns [0 ];
95
+ i = i -> prev ) {
96
+ assert (i != genesis_block (state ));
97
+ assert (!i -> all_known );
98
+ }
99
+
100
+ /*
101
+ * preferred_chain is *not* state->longest_chains[0], then no
102
+ * chain should connect any longest_knowns to longest_chains.
103
+ */
104
+ if (state -> preferred_chain != state -> longest_chains [0 ]) {
105
+ size_t a , b ;
106
+ assert (!find_connected_pair (state , & a , & b ));
107
+ }
108
+
109
+ /* We ignore blocks which have a problem. */
110
+ assert (!state -> preferred_chain -> complaint );
111
+
112
+ for (n = 0 ; n < tal_count (state -> longest_knowns ); n ++ )
113
+ assert (!state -> longest_knowns [n ]-> complaint );
114
+
115
+ for (n = 0 ; n < tal_count (state -> longest_chains ); n ++ )
116
+ assert (!state -> longest_chains [n ]-> complaint );
117
+
118
+ /* Checking the actual blocks is expensive! */
119
+ if (!all )
120
+ return ;
121
+
91
122
for (n = 0 ; n < tal_count (state -> block_depth ); n ++ ) {
92
123
size_t num_this_level = num_next_level ;
93
124
list_check (state -> block_depth [n ], "bad block depth" );
@@ -109,42 +140,16 @@ void check_chains(struct state *state)
109
140
cmp_work (i , state -> longest_chains [0 ]) <= 0 );
110
141
if (!i -> complaint && i -> all_known )
111
142
assert (cmp_work (i , state -> longest_knowns [0 ]) <= 0 );
112
-
143
+
113
144
list_for_each (& i -> children , b , sibling ) {
114
145
num_next_level ++ ;
115
146
assert (b -> prev == i );
116
147
}
117
- check_block (state , i );
148
+ check_block (state , i , all );
118
149
}
119
- assert (num_this_level == 0 );
150
+ assert (num_this_level == 0 );
120
151
}
121
152
assert (num_next_level == 0 );
122
-
123
- /* preferred_chain should be a descendent of longest_knowns[0] */
124
- for (i = state -> preferred_chain ;
125
- i != state -> longest_knowns [0 ];
126
- i = i -> prev ) {
127
- assert (i != genesis_block (state ));
128
- assert (!i -> all_known );
129
- }
130
-
131
- /*
132
- * preferred_chain is *not* state->longest_chains[0], then no
133
- * chain should connect any longest_knowns to longest_chains.
134
- */
135
- if (state -> preferred_chain != state -> longest_chains [0 ]) {
136
- size_t a , b ;
137
- assert (!find_connected_pair (state , & a , & b ));
138
- }
139
-
140
- /* We ignore blocks which have a problem. */
141
- assert (!state -> preferred_chain -> complaint );
142
-
143
- for (n = 0 ; n < tal_count (state -> longest_knowns ); n ++ )
144
- assert (!state -> longest_knowns [n ]-> complaint );
145
-
146
- for (n = 0 ; n < tal_count (state -> longest_chains ); n ++ )
147
- assert (!state -> longest_chains [n ]-> complaint );
148
153
}
149
154
150
155
static void swap_blockptr (const struct block * * a , const struct block * * b )
@@ -301,7 +306,6 @@ static bool update_known(struct state *state, struct block *block)
301
306
302
307
order_block_pointers (state );
303
308
update_preferred_chain (state );
304
- check_chains (state );
305
309
306
310
if (state -> longest_knowns [0 ] != prev_known ) {
307
311
/* Any transactions from old branch go into pending. */
@@ -409,8 +413,6 @@ void update_block_ptrs_new_block(struct state *state, struct block *block)
409
413
410
414
/* FIXME: Only needed if a descendent of known[0] */
411
415
update_preferred_chain (state );
412
-
413
- check_chains (state );
414
416
}
415
417
416
418
/* Filled a new shard; update state->longest_chains, state->longest_knowns,
@@ -446,7 +448,7 @@ void update_block_ptrs_invalidated(struct state *state,
446
448
find_longest_descendents (g , & state -> longest_chains );
447
449
update_known (state , cast_const (struct block * , g ));
448
450
449
- check_chains (state );
451
+ check_chains (state , false );
450
452
451
453
/* We don't need to know anything about this or any decendents. */
452
454
forget_about_all (state , block );
0 commit comments