Skip to content

Commit baaa3b2

Browse files
l0rincajtownshodlinator
committed
refactor,blocks: remove costly asserts and modernize affected logs
When the behavior was changes in a previous commit (caching `GetSerializeSize` and avoiding `AutoFile.tell`), (static)asserts were added to make sure the behavior was kept - to make sure reviewers and CI validates it. We can safely remove them now. Logs were also slightly modernized since they were trivial to do. Co-authored-by: Anthony Towns <aj@erisian.com.au> Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
1 parent fa39f27 commit baaa3b2

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/node/blockstorage.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
676676
// Open history file to read
677677
AutoFile filein{OpenUndoFile(pos, true)};
678678
if (filein.IsNull()) {
679-
LogError("%s: OpenUndoFile failed for %s\n", __func__, pos.ToString());
679+
LogError("OpenUndoFile failed for %s", pos.ToString());
680680
return false;
681681
}
682682

@@ -946,24 +946,21 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
946946
if (block.GetUndoPos().IsNull()) {
947947
FlatFilePos pos;
948948
const unsigned int blockundo_size{static_cast<unsigned int>(GetSerializeSize(blockundo))};
949-
static_assert(UNDO_DATA_DISK_OVERHEAD == 40); // TODO remove
950949
if (!FindUndoPos(state, block.nFile, pos, blockundo_size + UNDO_DATA_DISK_OVERHEAD)) {
951-
LogError("%s: FindUndoPos failed\n", __func__);
950+
LogError("FindUndoPos failed");
952951
return false;
953952
}
954953
// Open history file to append
955954
AutoFile fileout{OpenUndoFile(pos)};
956955
if (fileout.IsNull()) {
957-
LogError("%s: OpenUndoFile failed\n", __func__);
956+
LogError("OpenUndoFile failed");
958957
return FatalError(m_opts.notifications, state, _("Failed to write undo data."));
959958
}
960959

961960
// Write index header
962-
assert(blockundo_size == GetSerializeSize(blockundo)); // TODO remove
963961
fileout << GetParams().MessageStart() << blockundo_size;
964962
// Write undo data
965963
pos.nPos += BLOCK_SERIALIZATION_HEADER_SIZE;
966-
assert(pos.nPos == fileout.tell()); // TODO remove
967964
fileout << blockundo;
968965

969966
// Calculate & write checksum
@@ -1096,22 +1093,20 @@ FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight)
10961093
const unsigned int block_size{static_cast<unsigned int>(GetSerializeSize(TX_WITH_WITNESS(block)))};
10971094
FlatFilePos pos{FindNextBlockPos(block_size + BLOCK_SERIALIZATION_HEADER_SIZE, nHeight, block.GetBlockTime())};
10981095
if (pos.IsNull()) {
1099-
LogError("%s: FindNextBlockPos failed\n", __func__);
1096+
LogError("FindNextBlockPos failed");
11001097
return FlatFilePos();
11011098
}
11021099
AutoFile fileout{OpenBlockFile(pos)};
11031100
if (fileout.IsNull()) {
1104-
LogError("%s: OpenBlockFile failed\n", __func__);
1101+
LogError("OpenBlockFile failed");
11051102
m_opts.notifications.fatalError(_("Failed to write block."));
11061103
return FlatFilePos();
11071104
}
11081105

1109-
assert(block_size == GetSerializeSize(TX_WITH_WITNESS(block))); // TODO remove
11101106
// Write index header
11111107
fileout << GetParams().MessageStart() << block_size;
11121108
// Write block
11131109
pos.nPos += BLOCK_SERIALIZATION_HEADER_SIZE;
1114-
assert(pos.nPos == fileout.tell()); // TODO remove
11151110
fileout << TX_WITH_WITNESS(block);
11161111
return pos;
11171112
}

0 commit comments

Comments
 (0)