@@ -35,20 +35,20 @@ BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
35
35
};
36
36
BlockManager blockman{*Assert (m_node.shutdown ), blockman_opts};
37
37
// simulate adding a genesis block normally
38
- BOOST_CHECK_EQUAL (blockman.SaveBlockToDisk (params->GenesisBlock (), 0 , nullptr ).nPos , BLOCK_SERIALIZATION_HEADER_SIZE);
38
+ BOOST_CHECK_EQUAL (blockman.SaveBlockToDisk (params->GenesisBlock (), 0 ).nPos , BLOCK_SERIALIZATION_HEADER_SIZE);
39
39
// simulate what happens during reindex
40
40
// simulate a well-formed genesis block being found at offset 8 in the blk00000.dat file
41
41
// the block is found at offset 8 because there is an 8 byte serialization header
42
42
// consisting of 4 magic bytes + 4 length bytes before each block in a well-formed blk file.
43
- FlatFilePos pos{0 , BLOCK_SERIALIZATION_HEADER_SIZE};
44
- BOOST_CHECK_EQUAL ( blockman.SaveBlockToDisk (params->GenesisBlock (), 0 , & pos). nPos , BLOCK_SERIALIZATION_HEADER_SIZE );
43
+ const FlatFilePos pos{0 , BLOCK_SERIALIZATION_HEADER_SIZE};
44
+ blockman.UpdateBlockInfo (params->GenesisBlock (), 0 , pos);
45
45
// now simulate what happens after reindex for the first new block processed
46
46
// the actual block contents don't matter, just that it's a block.
47
47
// verify that the write position is at offset 0x12d.
48
48
// this is a check to make sure that https://github.com/bitcoin/bitcoin/issues/21379 does not recur
49
49
// 8 bytes (for serialization header) + 285 (for serialized genesis block) = 293
50
50
// add another 8 bytes for the second block's serialization header and we get 293 + 8 = 301
51
- FlatFilePos actual{blockman.SaveBlockToDisk (params->GenesisBlock (), 1 , nullptr )};
51
+ FlatFilePos actual{blockman.SaveBlockToDisk (params->GenesisBlock (), 1 )};
52
52
BOOST_CHECK_EQUAL (actual.nPos , BLOCK_SERIALIZATION_HEADER_SIZE + ::GetSerializeSize (TX_WITH_WITNESS (params->GenesisBlock ())) + BLOCK_SERIALIZATION_HEADER_SIZE);
53
53
}
54
54
@@ -156,12 +156,11 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
156
156
// Blockstore is empty
157
157
BOOST_CHECK_EQUAL (blockman.CalculateCurrentUsage (), 0 );
158
158
159
- // Write the first block; dbp=nullptr means this block doesn't already have a disk
160
- // location, so allocate a free location and write it there.
161
- FlatFilePos pos1{blockman.SaveBlockToDisk (block1, /* nHeight=*/ 1 , /* dbp=*/ nullptr )};
159
+ // Write the first block to a new location.
160
+ FlatFilePos pos1{blockman.SaveBlockToDisk (block1, /* nHeight=*/ 1 )};
162
161
163
162
// Write second block
164
- FlatFilePos pos2{blockman.SaveBlockToDisk (block2, /* nHeight=*/ 2 , /* dbp= */ nullptr )};
163
+ FlatFilePos pos2{blockman.SaveBlockToDisk (block2, /* nHeight=*/ 2 )};
165
164
166
165
// Two blocks in the file
167
166
BOOST_CHECK_EQUAL (blockman.CalculateCurrentUsage (), (TEST_BLOCK_SIZE + BLOCK_SERIALIZATION_HEADER_SIZE) * 2 );
@@ -181,22 +180,19 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
181
180
BOOST_CHECK_EQUAL (read_block.nVersion , 2 );
182
181
}
183
182
184
- // When FlatFilePos* dbp is given, SaveBlockToDisk() will not write or
185
- // overwrite anything to the flat file block storage. It will, however,
186
- // update the blockfile metadata. This is to facilitate reindexing
187
- // when the user has the blocks on disk but the metadata is being rebuilt.
183
+ // During reindex, the flat file block storage will not be written to.
184
+ // UpdateBlockInfo will, however, update the blockfile metadata.
188
185
// Verify this behavior by attempting (and failing) to write block 3 data
189
186
// to block 2 location.
190
187
CBlockFileInfo* block_data = blockman.GetBlockFileInfo (0 );
191
188
BOOST_CHECK_EQUAL (block_data->nBlocks , 2 );
192
- BOOST_CHECK ( blockman.SaveBlockToDisk (block3, /* nHeight=*/ 3 , /* dbp =*/ &pos2) == pos2);
189
+ blockman.UpdateBlockInfo (block3, /* nHeight=*/ 3 , /* pos =*/ pos2);
193
190
// Metadata is updated...
194
191
BOOST_CHECK_EQUAL (block_data->nBlocks , 3 );
195
192
// ...but there are still only two blocks in the file
196
193
BOOST_CHECK_EQUAL (blockman.CalculateCurrentUsage (), (TEST_BLOCK_SIZE + BLOCK_SERIALIZATION_HEADER_SIZE) * 2 );
197
194
198
195
// Block 2 was not overwritten:
199
- // SaveBlockToDisk() did not call WriteBlockToDisk() because `FlatFilePos* dbp` was non-null
200
196
blockman.ReadBlockFromDisk (read_block, pos2);
201
197
BOOST_CHECK_EQUAL (read_block.nVersion , 2 );
202
198
}
0 commit comments