@@ -38,6 +38,7 @@ void initialize_block_index_tree()
38
38
39
39
FUZZ_TARGET (block_index_tree, .init = initialize_block_index_tree)
40
40
{
41
+ SeedRandomStateForTest (SeedRand::ZEROS);
41
42
FuzzedDataProvider fuzzed_data_provider (buffer.data (), buffer.size ());
42
43
SetMockTime (ConsumeTime (fuzzed_data_provider));
43
44
ChainstateManager& chainman = *g_setup->m_node .chainman ;
@@ -98,6 +99,7 @@ FUZZ_TARGET(block_index_tree, .init = initialize_block_index_tree)
98
99
printf (" call ReceivedBlockTransactions, index is now BLOCK_VALID_TRANSACTIONS\n " );
99
100
}
100
101
} else {
102
+ // todo: better print statements
101
103
printf (" index->nTx == 0 = %d\n " , index ->nTx == 0 );
102
104
printf (" index->nStatus & BLOCK_FAILED_MASK = %d\n " , index ->nStatus & BLOCK_FAILED_MASK);
103
105
printf (" Don't do anything since index->nTx == %d is not 0 && index->nStatus = %s is BLOCK_FAILED_MASK\n " , index ->nTx , BlockStatusToString (index ->nStatus ).c_str ());
@@ -186,7 +188,7 @@ FUZZ_TARGET(block_index_tree, .init = initialize_block_index_tree)
186
188
printf (" 4. Prune chain\n " );
187
189
auto & chain = chainman.ActiveChain ();
188
190
int prune_height = fuzzed_data_provider.ConsumeIntegralInRange <int >(0 , chain.Height ());
189
- printf (" prune_height = %d\n " , prune_height);
191
+ printf (" chain.Height() = %d and prune_height = %d\n " , chain. Height () , prune_height);
190
192
CBlockIndex* prune_block{chain[prune_height]};
191
193
if (prune_block != chain.Tip ()) {
192
194
blockman.m_have_pruned = true ;
@@ -206,27 +208,30 @@ FUZZ_TARGET(block_index_tree, .init = initialize_block_index_tree)
206
208
}
207
209
},
208
210
[&] {
209
- // InvalidateBlock
210
- printf (" 5. Invalidateblock\n " );
211
- CBlockIndex* prev_block = PickValue (fuzzed_data_provider, blocks);
212
- printf (" block to invalidate (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
213
- BlockValidationState state;
214
- chainman.ActiveChainstate ().InvalidateBlock (state, prev_block);
215
- printf (" block after invalidation (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
216
- },
217
- [&] {
218
- // ReconsiderBlock
219
- LOCK (cs_main);
220
- printf (" 6. Reconsiderblock\n " );
221
- CBlockIndex* prev_block = PickValue (fuzzed_data_provider, blocks);
222
- printf (" block to reconsider (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
223
- chainman.ActiveChainstate ().ResetBlockFailureFlags (prev_block);
224
- printf (" block after reconsider (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
225
- });
226
- printf (" \n\n " );
211
+ if (fuzzed_data_provider.ConsumeBool ()) {
212
+ // InvalidateBlock
213
+ printf (" 5. Invalidateblock\n " );
214
+ CBlockIndex* prev_block = PickValue (fuzzed_data_provider, blocks);
215
+ printf (" block to invalidate (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
216
+ BlockValidationState state;
217
+ chainman.ActiveChainstate ().InvalidateBlock (state, prev_block);
218
+ printf (" block after invalidation (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
219
+ } else {
220
+ // ReconsiderBlock
221
+ LOCK (cs_main);
222
+ printf (" 6. Reconsiderblock\n " );
223
+ CBlockIndex* prev_block = PickValue (fuzzed_data_provider, blocks);
224
+ printf (" block to reconsider (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
225
+ chainman.ActiveChainstate ().ResetBlockFailureFlags (prev_block);
226
+ printf (" block after reconsider (height = %d, block hash = %s, nStatus = %s, chainwork = %s)\n " , prev_block->nHeight , prev_block->GetBlockHash ().ToString ().c_str (), BlockStatusToString (prev_block->nStatus ).c_str (), prev_block->nChainWork .ToString ().c_str ());
227
+ chainman.RecalculateBestHeader ();
228
+ // BlockValidationState state;
229
+ // chainman.ActiveChainstate().ActivateBestChain(state);
230
+ }
231
+ });
227
232
}
228
233
chainman.CheckBlockIndex ();
229
- printf (" END\n " );
234
+ printf (" END\n\n " );
230
235
231
236
// clean up global state changed by last iteration and prepare for next iteration
232
237
{
0 commit comments