Skip to content

Commit 223081e

Browse files
committed
scripted-diff: rename block and undo functions for consistency
Co-authored-by: Ryan Ofsky <ryan@ofsky.org> Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com> -BEGIN VERIFY SCRIPT- grep -r -wE 'WriteBlock|ReadRawBlock|ReadBlock|WriteBlockUndo|ReadBlockUndo' $(git ls-files src/ ':!src/leveldb') && \ echo "Error: One or more target names already exist!" && exit 1 sed -i \ -e 's/\bSaveBlockToDisk/WriteBlock/g' \ -e 's/\bReadRawBlockFromDisk/ReadRawBlock/g' \ -e 's/\bReadBlockFromDisk/ReadBlock/g' \ -e 's/\bWriteUndoDataForBlock/WriteBlockUndo/g' \ -e 's/\bUndoReadFromDisk/ReadBlockUndo/g' \ $(git ls-files src/ ':!src/leveldb') -END VERIFY SCRIPT-
1 parent baaa3b2 commit 223081e

18 files changed

+73
-73
lines changed

src/bench/readwriteblock.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,36 @@ static void SaveBlockBench(benchmark::Bench& bench)
3333
auto& blockman{testing_setup->m_node.chainman->m_blockman};
3434
const CBlock block{CreateTestBlock()};
3535
bench.run([&] {
36-
const auto pos{blockman.SaveBlockToDisk(block, 413'567)};
36+
const auto pos{blockman.WriteBlock(block, 413'567)};
3737
assert(!pos.IsNull());
3838
});
3939
}
4040

41-
static void ReadBlockFromDiskBench(benchmark::Bench& bench)
41+
static void ReadBlockBench(benchmark::Bench& bench)
4242
{
4343
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
4444
auto& blockman{testing_setup->m_node.chainman->m_blockman};
45-
const auto pos{blockman.SaveBlockToDisk(CreateTestBlock(), 413'567)};
45+
const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)};
4646
CBlock block;
4747
bench.run([&] {
48-
const auto success{blockman.ReadBlockFromDisk(block, pos)};
48+
const auto success{blockman.ReadBlock(block, pos)};
4949
assert(success);
5050
});
5151
}
5252

53-
static void ReadRawBlockFromDiskBench(benchmark::Bench& bench)
53+
static void ReadRawBlockBench(benchmark::Bench& bench)
5454
{
5555
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
5656
auto& blockman{testing_setup->m_node.chainman->m_blockman};
57-
const auto pos{blockman.SaveBlockToDisk(CreateTestBlock(), 413'567)};
57+
const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)};
5858
std::vector<uint8_t> block_data;
59-
blockman.ReadRawBlockFromDisk(block_data, pos); // warmup
59+
blockman.ReadRawBlock(block_data, pos); // warmup
6060
bench.run([&] {
61-
const auto success{blockman.ReadRawBlockFromDisk(block_data, pos)};
61+
const auto success{blockman.ReadRawBlock(block_data, pos)};
6262
assert(success);
6363
});
6464
}
6565

6666
BENCHMARK(SaveBlockBench, benchmark::PriorityLevel::HIGH);
67-
BENCHMARK(ReadBlockFromDiskBench, benchmark::PriorityLevel::HIGH);
68-
BENCHMARK(ReadRawBlockFromDiskBench, benchmark::PriorityLevel::HIGH);
67+
BENCHMARK(ReadBlockBench, benchmark::PriorityLevel::HIGH);
68+
BENCHMARK(ReadRawBlockBench, benchmark::PriorityLevel::HIGH);

src/index/base.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void BaseIndex::Sync()
188188

189189
CBlock block;
190190
interfaces::BlockInfo block_info = kernel::MakeBlockInfo(pindex);
191-
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *pindex)) {
191+
if (!m_chainstate->m_blockman.ReadBlock(block, *pindex)) {
192192
FatalErrorf("%s: Failed to read block %s from disk",
193193
__func__, pindex->GetBlockHash().ToString());
194194
return;
@@ -256,7 +256,7 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti
256256
// In the case of a reorg, ensure persisted block locator is not stale.
257257
// Pruning has a minimum of 288 blocks-to-keep and getting the index
258258
// out of sync may be possible but a users fault.
259-
// In case we reorg beyond the pruned depth, ReadBlockFromDisk would
259+
// In case we reorg beyond the pruned depth, ReadBlock would
260260
// throw and lead to a graceful shutdown
261261
SetBestBlockIndex(new_tip);
262262
if (!Commit()) {

src/index/blockfilterindex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
256256
// pindex variable gives indexing code access to node internals. It
257257
// will be removed in upcoming commit
258258
const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate->m_blockman.LookupBlockIndex(block.hash));
259-
if (!m_chainstate->m_blockman.UndoReadFromDisk(block_undo, *pindex)) {
259+
if (!m_chainstate->m_blockman.ReadBlockUndo(block_undo, *pindex)) {
260260
return false;
261261
}
262262
}

src/index/coinstatsindex.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
123123
// pindex variable gives indexing code access to node internals. It
124124
// will be removed in upcoming commit
125125
const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate->m_blockman.LookupBlockIndex(block.hash));
126-
if (!m_chainstate->m_blockman.UndoReadFromDisk(block_undo, *pindex)) {
126+
if (!m_chainstate->m_blockman.ReadBlockUndo(block_undo, *pindex)) {
127127
return false;
128128
}
129129

@@ -287,7 +287,7 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockRef& current_tip, const
287287
do {
288288
CBlock block;
289289

290-
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *iter_tip)) {
290+
if (!m_chainstate->m_blockman.ReadBlock(block, *iter_tip)) {
291291
LogError("%s: Failed to read block %s from disk\n",
292292
__func__, iter_tip->GetBlockHash().ToString());
293293
return false;
@@ -415,7 +415,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
415415

416416
// Ignore genesis block
417417
if (pindex->nHeight > 0) {
418-
if (!m_chainstate->m_blockman.UndoReadFromDisk(block_undo, *pindex)) {
418+
if (!m_chainstate->m_blockman.ReadBlockUndo(block_undo, *pindex)) {
419419
return false;
420420
}
421421

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15881588
g_zmq_notification_interface = CZMQNotificationInterface::Create(
15891589
[&chainman = node.chainman](std::vector<uint8_t>& block, const CBlockIndex& index) {
15901590
assert(chainman);
1591-
return chainman->m_blockman.ReadRawBlockFromDisk(block, WITH_LOCK(cs_main, return index.GetBlockPos()));
1591+
return chainman->m_blockman.ReadRawBlock(block, WITH_LOCK(cs_main, return index.GetBlockPos()));
15921592
});
15931593

15941594
if (g_zmq_notification_interface) {

src/net_processing.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
22682268
// Fast-path: in this case it is possible to serve the block directly from disk,
22692269
// as the network format matches the format on disk
22702270
std::vector<uint8_t> block_data;
2271-
if (!m_chainman.m_blockman.ReadRawBlockFromDisk(block_data, block_pos)) {
2271+
if (!m_chainman.m_blockman.ReadRawBlock(block_data, block_pos)) {
22722272
if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) {
22732273
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs));
22742274
} else {
@@ -2282,7 +2282,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
22822282
} else {
22832283
// Send block from disk
22842284
std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>();
2285-
if (!m_chainman.m_blockman.ReadBlockFromDisk(*pblockRead, block_pos)) {
2285+
if (!m_chainman.m_blockman.ReadBlock(*pblockRead, block_pos)) {
22862286
if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) {
22872287
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs));
22882288
} else {
@@ -4096,7 +4096,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
40964096

40974097
if (!block_pos.IsNull()) {
40984098
CBlock block;
4099-
const bool ret{m_chainman.m_blockman.ReadBlockFromDisk(block, block_pos)};
4099+
const bool ret{m_chainman.m_blockman.ReadBlock(block, block_pos)};
41004100
// If height is above MAX_BLOCKTXN_DEPTH then this block cannot get
41014101
// pruned after we release cs_main above, so this read should never fail.
41024102
assert(ret);
@@ -5599,7 +5599,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
55995599
PushMessage(*pto, std::move(cached_cmpctblock_msg.value()));
56005600
} else {
56015601
CBlock block;
5602-
const bool ret{m_chainman.m_blockman.ReadBlockFromDisk(block, *pBestIndex)};
5602+
const bool ret{m_chainman.m_blockman.ReadBlock(block, *pBestIndex)};
56035603
assert(ret);
56045604
CBlockHeaderAndShortTxIDs cmpctblock{block, m_rng.rand64()};
56055605
MakeAndPushMessage(*pto, NetMsgType::CMPCTBLOCK, cmpctblock);

src/node/blockstorage.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
669669
return &m_blockfile_info.at(n);
670670
}
671671

672-
bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& index) const
672+
bool BlockManager::ReadBlockUndo(CBlockUndo& blockundo, const CBlockIndex& index) const
673673
{
674674
const FlatFilePos pos{WITH_LOCK(::cs_main, return index.GetUndoPos())};
675675

@@ -936,7 +936,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
936936
return true;
937937
}
938938

939-
bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
939+
bool BlockManager::WriteBlockUndo(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
940940
{
941941
AssertLockHeld(::cs_main);
942942
const BlockfileType type = BlockfileTypeForHeight(block.nHeight);
@@ -995,7 +995,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
995995
return true;
996996
}
997997

998-
bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) const
998+
bool BlockManager::ReadBlock(CBlock& block, const FlatFilePos& pos) const
999999
{
10001000
block.SetNull();
10011001

@@ -1029,11 +1029,11 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
10291029
return true;
10301030
}
10311031

1032-
bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) const
1032+
bool BlockManager::ReadBlock(CBlock& block, const CBlockIndex& index) const
10331033
{
10341034
const FlatFilePos block_pos{WITH_LOCK(cs_main, return index.GetBlockPos())};
10351035

1036-
if (!ReadBlockFromDisk(block, block_pos)) {
1036+
if (!ReadBlock(block, block_pos)) {
10371037
return false;
10381038
}
10391039
if (block.GetHash() != index.GetBlockHash()) {
@@ -1043,7 +1043,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) co
10431043
return true;
10441044
}
10451045

1046-
bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos) const
1046+
bool BlockManager::ReadRawBlock(std::vector<uint8_t>& block, const FlatFilePos& pos) const
10471047
{
10481048
FlatFilePos hpos = pos;
10491049
// If nPos is less than 8 the pos is null and we don't have the block data
@@ -1088,7 +1088,7 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
10881088
return true;
10891089
}
10901090

1091-
FlatFilePos BlockManager::SaveBlockToDisk(const CBlock& block, int nHeight)
1091+
FlatFilePos BlockManager::WriteBlock(const CBlock& block, int nHeight)
10921092
{
10931093
const unsigned int block_size{static_cast<unsigned int>(GetSerializeSize(TX_WITH_WITNESS(block)))};
10941094
FlatFilePos pos{FindNextBlockPos(block_size + BLOCK_SERIALIZATION_HEADER_SIZE, nHeight, block.GetBlockTime())};

src/node/blockstorage.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
7474
/** The maximum size of a blk?????.dat file (since 0.8) */
7575
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
7676

77-
/** Size of header written by SaveBlockToDisk before a serialized CBlock (8 bytes) */
77+
/** Size of header written by WriteBlock before a serialized CBlock (8 bytes) */
7878
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE{std::tuple_size_v<MessageStartChars> + sizeof(unsigned int)};
7979

8080
/** Total overhead when writing undo data: header (8 bytes) plus checksum (32 bytes) */
@@ -324,7 +324,7 @@ class BlockManager
324324
/** Get block file info entry for one block file */
325325
CBlockFileInfo* GetBlockFileInfo(size_t n);
326326

327-
bool WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
327+
bool WriteBlockUndo(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex& block)
328328
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
329329

330330
/** Store block on disk and update block file statistics.
@@ -335,7 +335,7 @@ class BlockManager
335335
* @returns in case of success, the position to which the block was written to
336336
* in case of an error, an empty FlatFilePos
337337
*/
338-
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight);
338+
FlatFilePos WriteBlock(const CBlock& block, int nHeight);
339339

340340
/** Update blockfile info while processing a block during reindex. The block must be available on disk.
341341
*
@@ -414,11 +414,11 @@ class BlockManager
414414
void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune) const;
415415

416416
/** Functions for disk access for blocks */
417-
bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) const;
418-
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex& index) const;
419-
bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos) const;
417+
bool ReadBlock(CBlock& block, const FlatFilePos& pos) const;
418+
bool ReadBlock(CBlock& block, const CBlockIndex& index) const;
419+
bool ReadRawBlock(std::vector<uint8_t>& block, const FlatFilePos& pos) const;
420420

421-
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& index) const;
421+
bool ReadBlockUndo(CBlockUndo& blockundo, const CBlockIndex& index) const;
422422

423423
void CleanupBlockRevFiles() const;
424424
};

src/node/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<Rec
442442
if (block.m_next_block) FillBlock(active[index->nHeight] == index ? active[index->nHeight + 1] : nullptr, *block.m_next_block, lock, active, blockman);
443443
if (block.m_data) {
444444
REVERSE_LOCK(lock);
445-
if (!blockman.ReadBlockFromDisk(*block.m_data, *index)) block.m_data->SetNull();
445+
if (!blockman.ReadBlock(*block.m_data, *index)) block.m_data->SetNull();
446446
}
447447
block.found = true;
448448
return true;

src/node/transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
144144
}
145145
if (block_index) {
146146
CBlock block;
147-
if (blockman.ReadBlockFromDisk(block, *block_index)) {
147+
if (blockman.ReadBlock(block, *block_index)) {
148148
for (const auto& tx : block.vtx) {
149149
if (tx->GetHash() == hash) {
150150
hashBlock = block_index->GetBlockHash();

0 commit comments

Comments
 (0)