Skip to content

Commit

Permalink
scripted-diff: Rename CBlockDiskPos to FlatFilePos.
Browse files Browse the repository at this point in the history
-BEGIN VERIFY SCRIPT-
sed -i 's/CDiskBlockPos/FlatFilePos/g' $(git ls-files 'src/*.h' 'src/*.cpp')
-END VERIFY SCRIPT-
  • Loading branch information
jimpo authored and furszy committed May 15, 2021
1 parent 472857a commit bbb9a90
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ std::string CBlockIndex::ToString() const
GetBlockHash().ToString());
}

CDiskBlockPos CBlockIndex::GetBlockPos() const
FlatFilePos CBlockIndex::GetBlockPos() const
{
CDiskBlockPos ret;
FlatFilePos ret;
if (nStatus & BLOCK_HAVE_DATA) {
ret.nFile = nFile;
ret.nPos = nDataPos;
}
return ret;
}

CDiskBlockPos CBlockIndex::GetUndoPos() const
FlatFilePos CBlockIndex::GetUndoPos() const
{
CDiskBlockPos ret;
FlatFilePos ret;
if (nStatus & BLOCK_HAVE_UNDO) {
ret.nFile = nFile;
ret.nPos = nUndoPos;
Expand Down
4 changes: 2 additions & 2 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ class CBlockIndex

std::string ToString() const;

CDiskBlockPos GetBlockPos() const;
CDiskBlockPos GetUndoPos() const;
FlatFilePos GetBlockPos() const;
FlatFilePos GetUndoPos() const;
CBlockHeader GetBlockHeader() const;
uint256 GetBlockHash() const { return *phashBlock; }
int64_t GetBlockTime() const { return (int64_t)nTime; }
Expand Down
12 changes: 6 additions & 6 deletions src/flatfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ FlatFileSeq::FlatFileSeq(fs::path dir, const char* prefix, size_t chunk_size) :
}
}

std::string CDiskBlockPos::ToString() const
std::string FlatFilePos::ToString() const
{
return strprintf("CDiskBlockPos(nFile=%i, nPos=%i)", nFile, nPos);
return strprintf("FlatFilePos(nFile=%i, nPos=%i)", nFile, nPos);
}

fs::path FlatFileSeq::FileName(const CDiskBlockPos& pos) const
fs::path FlatFileSeq::FileName(const FlatFilePos& pos) const
{
return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile);
}

FILE* FlatFileSeq::Open(const CDiskBlockPos& pos, bool fReadOnly)
FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool fReadOnly)
{
if (pos.IsNull())
return nullptr;
Expand All @@ -53,7 +53,7 @@ FILE* FlatFileSeq::Open(const CDiskBlockPos& pos, bool fReadOnly)
return file;
}

size_t FlatFileSeq::Allocate(const CDiskBlockPos& pos, size_t add_size, bool& out_of_space)
size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_of_space)
{
out_of_space = false;

Expand All @@ -79,7 +79,7 @@ size_t FlatFileSeq::Allocate(const CDiskBlockPos& pos, size_t add_size, bool& ou
return 0;
}

bool FlatFileSeq::Flush(const CDiskBlockPos& pos, bool finalize)
bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize)
{
FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
if (!file) {
Expand Down
18 changes: 9 additions & 9 deletions src/flatfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "fs.h"
#include "serialize.h"

struct CDiskBlockPos
struct FlatFilePos
{
int nFile;
unsigned int nPos;
Expand All @@ -24,20 +24,20 @@ struct CDiskBlockPos
READWRITE(VARINT(nPos));
}

CDiskBlockPos() {
FlatFilePos() {
SetNull();
}

CDiskBlockPos(int nFileIn, unsigned int nPosIn) {
FlatFilePos(int nFileIn, unsigned int nPosIn) {
nFile = nFileIn;
nPos = nPosIn;
}

friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) {
friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) {
return (a.nFile == b.nFile && a.nPos == b.nPos);
}

friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) {
friend bool operator!=(const FlatFilePos &a, const FlatFilePos &b) {
return !(a == b);
}

Expand Down Expand Up @@ -69,10 +69,10 @@ class FlatFileSeq
FlatFileSeq(fs::path dir, const char* prefix, size_t chunk_size);

/** Get the name of the file at the given position. */
fs::path FileName(const CDiskBlockPos& pos) const;
fs::path FileName(const FlatFilePos& pos) const;

/** Open a handle to the file at the given position. */
FILE* Open(const CDiskBlockPos& pos, bool fReadOnly = false);
FILE* Open(const FlatFilePos& pos, bool fReadOnly = false);

/**
* Allocate additional space in a file after the given starting position. The amount allocated
Expand All @@ -83,7 +83,7 @@ class FlatFileSeq
* @param[out] out_of_space Whether the allocation failed due to insufficient disk space.
* @return The number of bytes successfully allocated.
*/
size_t Allocate(const CDiskBlockPos& pos, size_t add_size, bool& out_of_space);
size_t Allocate(const FlatFilePos& pos, size_t add_size, bool& out_of_space);

/**
* Commit a file to disk, and optionally truncate off extra pre-allocated bytes if final.
Expand All @@ -92,7 +92,7 @@ class FlatFileSeq
* @param[in] finalize True if no more data will be written to this file.
* @return true on success, false on failure.
*/
bool Flush(const CDiskBlockPos& pos, bool finalize = false);
bool Flush(const FlatFilePos& pos, bool finalize = false);
};

#endif // BITCOIN_FLATFILE_H
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ void ThreadImport(const std::vector<fs::path>& vImportFiles)
CImportingNow imp;
int nFile = 0;
while (true) {
CDiskBlockPos pos(nFile, 0);
FlatFilePos pos(nFile, 0);
if (!fs::exists(GetBlockPosFilename(pos)))
break; // No block files left to reindex
FILE* file = OpenBlockFile(pos, true);
Expand Down
8 changes: 4 additions & 4 deletions src/txdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
//! min. -dbcache in (MiB)
static const int64_t nMinDbCache = 4;

struct CDiskTxPos : public CDiskBlockPos
struct CDiskTxPos : public FlatFilePos
{
unsigned int nTxOffset; // after header

Expand All @@ -41,11 +41,11 @@ struct CDiskTxPos : public CDiskBlockPos
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITEAS(CDiskBlockPos, *this);
READWRITEAS(FlatFilePos, *this);
READWRITE(VARINT(nTxOffset));
}

CDiskTxPos(const CDiskBlockPos& blockIn, unsigned int nTxOffsetIn) : CDiskBlockPos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn)
CDiskTxPos(const FlatFilePos& blockIn, unsigned int nTxOffsetIn) : FlatFilePos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn)
{
}

Expand All @@ -56,7 +56,7 @@ struct CDiskTxPos : public CDiskBlockPos

void SetNull()
{
CDiskBlockPos::SetNull();
FlatFilePos::SetNull();
nTxOffset = 0;
}
};
Expand Down
52 changes: 26 additions & 26 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ bool GetTransaction(const uint256& hash, CTransactionRef& txOut, uint256& hashBl
// CBlock and CBlockIndex
//

bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos)
bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos)
{
// Open history file to append
CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
Expand All @@ -800,7 +800,7 @@ bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos)
return true;
}

bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos)
{
block.SetNull();

Expand All @@ -827,7 +827,7 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)

bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex)
{
CDiskBlockPos blockPos = WITH_LOCK(cs_main, return pindex->GetBlockPos(); );
FlatFilePos blockPos = WITH_LOCK(cs_main, return pindex->GetBlockPos(); );
if (!ReadBlockFromDisk(block, blockPos)) {
return false;
}
Expand Down Expand Up @@ -1218,7 +1218,7 @@ static bool AbortNode(CValidationState& state, const std::string& strMessage, co

namespace {

bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint256& hashBlock)
bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock)
{
// Open history file to append
CAutoFile fileout(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
Expand All @@ -1245,7 +1245,7 @@ bool UndoWriteToDisk(const CBlockUndo& blockundo, CDiskBlockPos& pos, const uint
return true;
}

bool UndoReadFromDisk(CBlockUndo& blockundo, const CDiskBlockPos& pos, const uint256& hashBlock)
bool UndoReadFromDisk(CBlockUndo& blockundo, const FlatFilePos& pos, const uint256& hashBlock)
{
// Open history file to read
CAutoFile filein(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
Expand Down Expand Up @@ -1332,7 +1332,7 @@ DisconnectResult DisconnectBlock(CBlock& block, const CBlockIndex* pindex, CCoin
bool fClean = true;

CBlockUndo blockUndo;
CDiskBlockPos pos = pindex->GetUndoPos();
FlatFilePos pos = pindex->GetUndoPos();
if (pos.IsNull()) {
error("%s: no undo data available", __func__);
return DISCONNECT_FAILED;
Expand Down Expand Up @@ -1429,8 +1429,8 @@ void static FlushBlockFile(bool fFinalize = false)
{
LOCK(cs_LastBlockFile);

CDiskBlockPos block_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nSize);
CDiskBlockPos undo_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nUndoSize);
FlatFilePos block_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nSize);
FlatFilePos undo_pos_old(nLastBlockFile, vinfoBlockFile[nLastBlockFile].nUndoSize);

bool status = true;
status &= BlockFileSeq().Flush(block_pos_old, fFinalize);
Expand All @@ -1440,7 +1440,7 @@ void static FlushBlockFile(bool fFinalize = false)
}
}

bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigned int nAddSize);
bool FindUndoPos(CValidationState& state, int nFile, FlatFilePos& pos, unsigned int nAddSize);

static CCheckQueue<CScriptCheck> scriptcheckqueue(128);

Expand Down Expand Up @@ -1746,7 +1746,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
// Write undo information to disk
if (pindex->GetUndoPos().IsNull() || !pindex->IsValid(BLOCK_VALID_SCRIPTS)) {
if (pindex->GetUndoPos().IsNull()) {
CDiskBlockPos diskPosBlock;
FlatFilePos diskPosBlock;
if (!FindUndoPos(state, pindex->nFile, diskPosBlock, ::GetSerializeSize(blockundo, SER_DISK, CLIENT_VERSION) + 40))
return error("ConnectBlock() : FindUndoPos failed");
if (!UndoWriteToDisk(blockundo, diskPosBlock, pindex->pprev->GetBlockHash()))
Expand Down Expand Up @@ -2543,7 +2543,7 @@ CBlockIndex* AddToBlockIndex(const CBlock& block)
}

/** Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). */
bool ReceivedBlockTransactions(const CBlock& block, CValidationState& state, CBlockIndex* pindexNew, const CDiskBlockPos& pos)
bool ReceivedBlockTransactions(const CBlock& block, CValidationState& state, CBlockIndex* pindexNew, const FlatFilePos& pos)
{
if (block.IsProofOfStake())
pindexNew->SetProofOfStake();
Expand Down Expand Up @@ -2609,7 +2609,7 @@ bool ReceivedBlockTransactions(const CBlock& block, CValidationState& state, CBl
return true;
}

bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false)
bool FindBlockPos(CValidationState& state, FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false)
{
LOCK(cs_LastBlockFile);

Expand Down Expand Up @@ -2656,7 +2656,7 @@ bool FindBlockPos(CValidationState& state, CDiskBlockPos& pos, unsigned int nAdd
return true;
}

bool FindUndoPos(CValidationState& state, int nFile, CDiskBlockPos& pos, unsigned int nAddSize)
bool FindUndoPos(CValidationState& state, int nFile, FlatFilePos& pos, unsigned int nAddSize)
{
pos.nFile = nFile;

Expand Down Expand Up @@ -3122,7 +3122,7 @@ bool AcceptBlockHeader(const CBlock& block, CValidationState& state, CBlockIndex
return true;
}

bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockIndex** ppindex, CDiskBlockPos* dbp)
bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockIndex** ppindex, FlatFilePos* dbp)
{
AssertLockHeld(cs_main);

Expand Down Expand Up @@ -3351,7 +3351,7 @@ bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockIndex** ppi
// Write block to history file
try {
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
CDiskBlockPos blockPos;
FlatFilePos blockPos;
if (dbp != NULL)
blockPos = *dbp;
if (!FindBlockPos(state, blockPos, nBlockSize + 8, nHeight, block.GetBlockTime(), dbp != NULL))
Expand All @@ -3368,7 +3368,7 @@ bool AcceptBlock(const CBlock& block, CValidationState& state, CBlockIndex** ppi
return true;
}

bool ProcessNewBlock(CValidationState& state, CNode* pfrom, const std::shared_ptr<const CBlock> pblock, CDiskBlockPos* dbp, bool* fAccepted)
bool ProcessNewBlock(CValidationState& state, CNode* pfrom, const std::shared_ptr<const CBlock> pblock, FlatFilePos* dbp, bool* fAccepted)
{
AssertLockNotHeld(cs_main);

Expand Down Expand Up @@ -3452,17 +3452,17 @@ static FlatFileSeq UndoFileSeq()
return FlatFileSeq(GetBlocksDir(), "rev", UNDOFILE_CHUNK_SIZE);
}

FILE* OpenBlockFile(const CDiskBlockPos& pos, bool fReadOnly)
FILE* OpenBlockFile(const FlatFilePos& pos, bool fReadOnly)
{
return BlockFileSeq().Open(pos, fReadOnly);
}

FILE* OpenUndoFile(const CDiskBlockPos& pos, bool fReadOnly)
FILE* OpenUndoFile(const FlatFilePos& pos, bool fReadOnly)
{
return UndoFileSeq().Open(pos, fReadOnly);
}

fs::path GetBlockPosFilename(const CDiskBlockPos &pos)
fs::path GetBlockPosFilename(const FlatFilePos &pos)
{
return BlockFileSeq().FileName(pos);
}
Expand Down Expand Up @@ -3568,7 +3568,7 @@ bool static LoadBlockIndexDB(std::string& strError)
}
}
for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++) {
CDiskBlockPos pos(*it, 0);
FlatFilePos pos(*it, 0);
if (CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION).IsNull()) {
return false;
}
Expand Down Expand Up @@ -3677,7 +3677,7 @@ bool CVerifyDB::VerifyDB(CCoinsView* coinsview, int nCheckLevel, int nCheckDepth
// check level 2: verify undo validity
if (nCheckLevel >= 2 && pindex) {
CBlockUndo undo;
CDiskBlockPos pos = pindex->GetUndoPos();
FlatFilePos pos = pindex->GetUndoPos();
if (!pos.IsNull()) {
if (!UndoReadFromDisk(undo, pos, pindex->pprev->GetBlockHash()))
return error("%s: *** found bad undo data at %d, hash=%s\n", __func__, pindex->nHeight, pindex->GetBlockHash().ToString());
Expand Down Expand Up @@ -3881,7 +3881,7 @@ bool LoadGenesisBlock()
CBlock& block = const_cast<CBlock&>(Params().GenesisBlock());
// Start new block file
unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION);
CDiskBlockPos blockPos;
FlatFilePos blockPos;
CValidationState state;
if (!FindBlockPos(state, blockPos, nBlockSize + 8, 0, block.GetBlockTime()))
return error("%s: FindBlockPos failed", __func__);
Expand All @@ -3898,10 +3898,10 @@ bool LoadGenesisBlock()
}


bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos* dbp)
bool LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp)
{
// Map of disk positions for blocks with unknown parent (only used for reindex)
static std::multimap<uint256, CDiskBlockPos> mapBlocksUnknownParent;
static std::multimap<uint256, FlatFilePos> mapBlocksUnknownParent;
int64_t nStart = GetTimeMillis();

int nLoaded = 0;
Expand Down Expand Up @@ -3971,9 +3971,9 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos* dbp)
while (!queue.empty()) {
uint256 head = queue.front();
queue.pop_front();
std::pair<std::multimap<uint256, CDiskBlockPos>::iterator, std::multimap<uint256, CDiskBlockPos>::iterator> range = mapBlocksUnknownParent.equal_range(head);
std::pair<std::multimap<uint256, FlatFilePos>::iterator, std::multimap<uint256, FlatFilePos>::iterator> range = mapBlocksUnknownParent.equal_range(head);
while (range.first != range.second) {
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
std::multimap<uint256, FlatFilePos>::iterator it = range.first;
if (ReadBlockFromDisk(block, it->second)) {
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
head.ToString());
Expand Down
Loading

0 comments on commit bbb9a90

Please sign in to comment.