Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class CMainParams : public CChainParams {
// Build the genesis block. Note that the output of the genesis coinbase cannot
// be spent as it did not originally exist in the database.
//
// CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
// CBlock(hash=000000000019d6, ver=1, hashPrev=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
// CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
// CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
// CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
Expand All @@ -135,7 +135,7 @@ class CMainParams : public CChainParams {
txNew.vout[0].nValue = 50 * COIN;
txNew.vout[0].scriptPubKey = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
genesis.vtx.push_back(txNew);
genesis.hashPrevBlock = 0;
genesis.hashPrev = 0;
genesis.hashMerkleRoot = genesis.BuildMerkleTree();
genesis.nVersion = 1;
genesis.nTime = 1231006505;
Expand Down
4 changes: 2 additions & 2 deletions src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMer

void CBlock::print() const
{
LogPrintf("CBlock(hash=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
LogPrintf("CBlock(hash=%s, ver=%d, hashPrev=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%u)\n",
GetHash().ToString(),
nVersion,
hashPrevBlock.ToString(),
hashPrev.ToString(),
hashMerkleRoot.ToString(),
nTime, nBits, nNonce,
vtx.size());
Expand Down
18 changes: 3 additions & 15 deletions src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class CBlockHeader
// header
static const int CURRENT_VERSION=2;
int nVersion;
uint256 hashPrevBlock;
uint256 hashPrev;
uint256 hashMerkleRoot;
unsigned int nTime;
unsigned int nBits;
Expand All @@ -421,7 +421,7 @@ class CBlockHeader
(
READWRITE(this->nVersion);
nVersion = this->nVersion;
READWRITE(hashPrevBlock);
READWRITE(hashPrev);
READWRITE(hashMerkleRoot);
READWRITE(nTime);
READWRITE(nBits);
Expand All @@ -431,7 +431,7 @@ class CBlockHeader
void SetNull()
{
nVersion = CBlockHeader::CURRENT_VERSION;
hashPrevBlock = 0;
hashPrev = 0;
hashMerkleRoot = 0;
nTime = 0;
nBits = 0;
Expand Down Expand Up @@ -485,18 +485,6 @@ class CBlock : public CBlockHeader
vMerkleTree.clear();
}

CBlockHeader GetBlockHeader() const
{
CBlockHeader block;
block.nVersion = nVersion;
block.hashPrevBlock = hashPrevBlock;
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
return block;
}

uint256 BuildMerkleTree() const;

std::vector<uint256> GetMerkleBranch(int nIndex) const;
Expand Down
97 changes: 45 additions & 52 deletions src/main.cpp

Large diffs are not rendered by default.

79 changes: 15 additions & 64 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ enum BlockStatus {
* candidates to be the next block. A blockindex may have multiple pprev pointing
* to it, but at most one of them can be part of the currently active branch.
*/
class CBlockIndex
class CBlockIndex : public CBlockHeader
{
public:
// pointer to the hash of the block, if any. memory is owned by this CBlockIndex
Expand Down Expand Up @@ -708,18 +708,12 @@ class CBlockIndex
// Verification status of this block. See enum BlockStatus
unsigned int nStatus;

// block header
int nVersion;
uint256 hashMerkleRoot;
unsigned int nTime;
unsigned int nBits;
unsigned int nNonce;

// (memory only) Sequencial id assigned to distinguish order in which blocks are received.
uint32_t nSequenceId;

CBlockIndex()
void SetNull()
{
CBlockHeader::SetNull();
phashBlock = NULL;
pprev = NULL;
pskip = NULL;
Expand All @@ -732,34 +726,17 @@ class CBlockIndex
nChainTx = 0;
nStatus = 0;
nSequenceId = 0;
}

nVersion = 0;
hashMerkleRoot = 0;
nTime = 0;
nBits = 0;
nNonce = 0;
CBlockIndex()
{
SetNull();
}

CBlockIndex(CBlockHeader& block)
{
phashBlock = NULL;
pprev = NULL;
pskip = NULL;
nHeight = 0;
nFile = 0;
nDataPos = 0;
nUndoPos = 0;
nChainWork = 0;
nTx = 0;
nChainTx = 0;
nStatus = 0;
nSequenceId = 0;

nVersion = block.nVersion;
hashMerkleRoot = block.hashMerkleRoot;
nTime = block.nTime;
nBits = block.nBits;
nNonce = block.nNonce;
SetNull();
*((CBlockHeader*)this) = block;
}

CDiskBlockPos GetBlockPos() const {
Expand All @@ -780,29 +757,11 @@ class CBlockIndex
return ret;
}

CBlockHeader GetBlockHeader() const
{
CBlockHeader block;
block.nVersion = nVersion;
if (pprev)
block.hashPrevBlock = pprev->GetBlockHash();
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
return block;
}

uint256 GetBlockHash() const
uint256 GetHash() const
{
return *phashBlock;
}

int64_t GetBlockTime() const
{
return (int64_t)nTime;
}

uint256 GetBlockWork() const
{
uint256 bnTarget;
Expand Down Expand Up @@ -847,7 +806,7 @@ class CBlockIndex
return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
pprev, nHeight,
hashMerkleRoot.ToString(),
GetBlockHash().ToString());
GetHash().ToString());
}

void print() const
Expand Down Expand Up @@ -897,7 +856,7 @@ class CDiskBlockIndex : public CBlockIndex
}

explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex) {
hashPrev = (pprev ? pprev->GetBlockHash() : 0);
hashPrev = (pprev ? pprev->GetHash() : 0);
}

IMPLEMENT_SERIALIZE
Expand All @@ -924,25 +883,17 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(nNonce);
)

uint256 GetBlockHash() const
uint256 GetHash() const
{
CBlockHeader block;
block.nVersion = nVersion;
block.hashPrevBlock = hashPrev;
block.hashMerkleRoot = hashMerkleRoot;
block.nTime = nTime;
block.nBits = nBits;
block.nNonce = nNonce;
return block.GetHash();
return CBlockHeader::GetHash();
}


std::string ToString() const
{
std::string str = "CDiskBlockIndex(";
str += CBlockIndex::ToString();
str += strprintf("\n hashBlock=%s, hashPrev=%s)",
GetBlockHash().ToString(),
GetHash().ToString(),
hashPrev.ToString());
return str;
}
Expand Down
8 changes: 4 additions & 4 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
pblocktemplate->vTxFees[0] = -nFees;

// Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
pblock->hashPrev = pindexPrev->GetHash();
UpdateTime(*pblock, pindexPrev);
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
pblock->nNonce = 0;
Expand All @@ -334,10 +334,10 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
{
// Update nExtraNonce
static uint256 hashPrevBlock;
if (hashPrevBlock != pblock->hashPrevBlock)
if (hashPrevBlock != pblock->hashPrev)
{
nExtraNonce = 0;
hashPrevBlock = pblock->hashPrevBlock;
hashPrevBlock = pblock->hashPrev;
}
++nExtraNonce;
unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2
Expand Down Expand Up @@ -419,7 +419,7 @@ bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey)
// Found a solution
{
LOCK(cs_main);
if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash())
if (pblock->hashPrev != chainActive.Tip()->GetHash())
return error("BitcoinMiner : generated block is stale");
}

Expand Down
12 changes: 6 additions & 6 deletions src/rpcblockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));

if (blockindex->pprev)
result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
result.push_back(Pair("previousblockhash", blockindex->pprev->GetHash().GetHex()));
CBlockIndex *pnext = chainActive.Next(blockindex);
if (pnext)
result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
result.push_back(Pair("nextblockhash", pnext->GetHash().GetHex()));
return result;
}

Expand Down Expand Up @@ -108,7 +108,7 @@ Value getbestblockhash(const Array& params, bool fHelp)
+ HelpExampleRpc("getbestblockhash", "")
);

return chainActive.Tip()->GetBlockHash().GetHex();
return chainActive.Tip()->GetHash().GetHex();
}

Value getdifficulty(const Array& params, bool fHelp)
Expand Down Expand Up @@ -225,7 +225,7 @@ Value getblockhash(const Array& params, bool fHelp)
throw runtime_error("Block number out of range.");

CBlockIndex* pblockindex = chainActive[nHeight];
return pblockindex->GetBlockHash().GetHex();
return pblockindex->GetHash().GetHex();
}

Value getblock(const Array& params, bool fHelp)
Expand Down Expand Up @@ -389,7 +389,7 @@ Value gettxout(const Array& params, bool fHelp)

std::map<uint256, CBlockIndex*>::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
CBlockIndex *pindex = it->second;
ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
ret.push_back(Pair("bestblock", pindex->GetHash().GetHex()));
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)
ret.push_back(Pair("confirmations", 0));
else
Expand Down Expand Up @@ -453,7 +453,7 @@ Value getblockchaininfo(const Array& params, bool fHelp)
Object obj;
obj.push_back(Pair("chain", Params().NetworkIDString()));
obj.push_back(Pair("blocks", (int)chainActive.Height()));
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetHash().GetHex()));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
Expand Down
2 changes: 1 addition & 1 deletion src/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ Value dumpwallet(const Array& params, bool fHelp)
// produce output
file << strprintf("# Wallet dump created by Bitcoin %s (%s)\n", CLIENT_BUILD, CLIENT_DATE);
file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime()));
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString());
file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetHash().ToString());
file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->nTime));
file << "\n";
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
Expand Down
2 changes: 1 addition & 1 deletion src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ Value getblocktemplate(const Array& params, bool fHelp)

Object result;
result.push_back(Pair("version", pblock->nVersion));
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
result.push_back(Pair("previousblockhash", pblock->hashPrev.GetHex()));
result.push_back(Pair("transactions", transactions));
result.push_back(Pair("coinbaseaux", aux));
result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
Expand Down
2 changes: 1 addition & 1 deletion src/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ Value listsinceblock(const Array& params, bool fHelp)
}

CBlockIndex *pblockLast = chainActive[chainActive.Height() + 1 - target_confirms];
uint256 lastblock = pblockLast ? pblockLast->GetBlockHash() : 0;
uint256 lastblock = pblockLast ? pblockLast->GetHash() : 0;

Object ret;
ret.push_back(Pair("transactions", transactions));
Expand Down
2 changes: 1 addition & 1 deletion src/test/miner_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
CValidationState state;
BOOST_CHECK(ProcessBlock(state, NULL, pblock));
BOOST_CHECK(state.IsValid());
pblock->hashPrevBlock = pblock->GetHash();
pblock->hashPrev = pblock->GetHash();
}
delete pblocktemplate;

Expand Down
6 changes: 3 additions & 3 deletions src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevel

bool CBlockTreeDB::WriteBlockIndex(const CDiskBlockIndex& blockindex)
{
return Write(make_pair('b', blockindex.GetBlockHash()), blockindex);
return Write(make_pair('b', blockindex.GetHash()), blockindex);
}

bool CBlockTreeDB::WriteBlockFileInfo(int nFile, const CBlockFileInfo &info) {
Expand Down Expand Up @@ -199,7 +199,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
ssValue >> diskindex;

// Construct block index object
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetBlockHash());
CBlockIndex* pindexNew = InsertBlockIndex(diskindex.GetHash());
pindexNew->pprev = InsertBlockIndex(diskindex.hashPrev);
pindexNew->nHeight = diskindex.nHeight;
pindexNew->nFile = diskindex.nFile;
Expand All @@ -213,7 +213,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
pindexNew->nStatus = diskindex.nStatus;
pindexNew->nTx = diskindex.nTx;

if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits))
if (!CheckProofOfWork(pindexNew->GetHash(), pindexNew->nBits))
return error("LoadBlockIndex() : CheckProofOfWork failed: %s", pindexNew->ToString());

pcursor->Next();
Expand Down