mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Merge UP TO 551c8e9526 into merged_master (UP TO bitcoin/bitcoin#26349)
Includes FIXMEs for a few functional tests
This commit is contained in:
commit
ca0a68b350
295 changed files with 5068 additions and 1834 deletions
|
|
@ -535,6 +535,16 @@ void BlockManager::FlushUndoFile(int block_file, bool finalize)
|
|||
void BlockManager::FlushBlockFile(bool fFinalize, bool finalize_undo)
|
||||
{
|
||||
LOCK(cs_LastBlockFile);
|
||||
|
||||
if (m_blockfile_info.size() < 1) {
|
||||
// Return if we haven't loaded any blockfiles yet. This happens during
|
||||
// chainstate init, when we call ChainstateManager::MaybeRebalanceCaches() (which
|
||||
// then calls FlushStateToDisk()), resulting in a call to this function before we
|
||||
// have populated `m_blockfile_info` via LoadBlockIndexDB().
|
||||
return;
|
||||
}
|
||||
assert(static_cast<int>(m_blockfile_info.size()) > m_last_blockfile);
|
||||
|
||||
FlatFilePos block_pos_old(m_last_blockfile, m_blockfile_info[m_last_blockfile].nSize);
|
||||
if (!BlockFileSeq().Flush(block_pos_old, fFinalize)) {
|
||||
AbortNode("Flushing block file to disk failed. This is likely the result of an I/O error.");
|
||||
|
|
@ -800,19 +810,24 @@ bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, c
|
|||
return true;
|
||||
}
|
||||
|
||||
/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
|
||||
FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp)
|
||||
{
|
||||
unsigned int nBlockSize = ::GetSerializeSize(block, CLIENT_VERSION);
|
||||
FlatFilePos blockPos;
|
||||
if (dbp != nullptr) {
|
||||
const auto position_known {dbp != nullptr};
|
||||
if (position_known) {
|
||||
blockPos = *dbp;
|
||||
} else {
|
||||
// when known, blockPos.nPos points at the offset of the block data in the blk file. that already accounts for
|
||||
// the serialization header present in the file (the 4 magic message start bytes + the 4 length bytes = 8 bytes = BLOCK_SERIALIZATION_HEADER_SIZE).
|
||||
// we add BLOCK_SERIALIZATION_HEADER_SIZE only for new blocks since they will have the serialization header added when written to disk.
|
||||
nBlockSize += static_cast<unsigned int>(BLOCK_SERIALIZATION_HEADER_SIZE);
|
||||
}
|
||||
if (!FindBlockPos(blockPos, nBlockSize + 8, nHeight, active_chain, block.GetBlockTime(), dbp != nullptr)) {
|
||||
if (!FindBlockPos(blockPos, nBlockSize, nHeight, active_chain, block.GetBlockTime(), position_known)) {
|
||||
error("%s: FindBlockPos failed", __func__);
|
||||
return FlatFilePos();
|
||||
}
|
||||
if (dbp == nullptr) {
|
||||
if (!position_known) {
|
||||
if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) {
|
||||
AbortNode("Failed to write block");
|
||||
return FlatFilePos();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue