|
|
|
@ -27,20 +27,20 @@ BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
|
|
|
|
|
BlockManager blockman{blockman_opts};
|
|
|
|
|
CChain chain {};
|
|
|
|
|
// simulate adding a genesis block normally
|
|
|
|
|
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, *params, nullptr).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
|
|
|
|
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, nullptr).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
|
|
|
|
// simulate what happens during reindex
|
|
|
|
|
// simulate a well-formed genesis block being found at offset 8 in the blk00000.dat file
|
|
|
|
|
// the block is found at offset 8 because there is an 8 byte serialization header
|
|
|
|
|
// consisting of 4 magic bytes + 4 length bytes before each block in a well-formed blk file.
|
|
|
|
|
FlatFilePos pos{0, BLOCK_SERIALIZATION_HEADER_SIZE};
|
|
|
|
|
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, *params, &pos).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
|
|
|
|
BOOST_CHECK_EQUAL(blockman.SaveBlockToDisk(params->GenesisBlock(), 0, chain, &pos).nPos, BLOCK_SERIALIZATION_HEADER_SIZE);
|
|
|
|
|
// now simulate what happens after reindex for the first new block processed
|
|
|
|
|
// the actual block contents don't matter, just that it's a block.
|
|
|
|
|
// verify that the write position is at offset 0x12d.
|
|
|
|
|
// this is a check to make sure that https://github.com/bitcoin/bitcoin/issues/21379 does not recur
|
|
|
|
|
// 8 bytes (for serialization header) + 285 (for serialized genesis block) = 293
|
|
|
|
|
// add another 8 bytes for the second block's serialization header and we get 293 + 8 = 301
|
|
|
|
|
FlatFilePos actual{blockman.SaveBlockToDisk(params->GenesisBlock(), 1, chain, *params, nullptr)};
|
|
|
|
|
FlatFilePos actual{blockman.SaveBlockToDisk(params->GenesisBlock(), 1, chain, nullptr)};
|
|
|
|
|
BOOST_CHECK_EQUAL(actual.nPos, BLOCK_SERIALIZATION_HEADER_SIZE + ::GetSerializeSize(params->GenesisBlock(), CLIENT_VERSION) + BLOCK_SERIALIZATION_HEADER_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|