-
Notifications
You must be signed in to change notification settings - Fork 390
[0.17] blockheaders include block height, nodes validate it #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,7 @@ class CBlockIndex | |
int32_t nVersion; | ||
uint256 hashMerkleRoot; | ||
uint32_t nTime; | ||
uint32_t block_height; | ||
uint32_t nBits; | ||
uint32_t nNonce; | ||
|
||
|
@@ -238,6 +239,7 @@ class CBlockIndex | |
nVersion = 0; | ||
hashMerkleRoot = uint256(); | ||
nTime = 0; | ||
block_height = 0; | ||
nBits = 0; | ||
nNonce = 0; | ||
} | ||
|
@@ -254,6 +256,7 @@ class CBlockIndex | |
nVersion = block.nVersion; | ||
hashMerkleRoot = block.hashMerkleRoot; | ||
nTime = block.nTime; | ||
block_height = block.block_height; | ||
nBits = block.nBits; | ||
nNonce = block.nNonce; | ||
} | ||
|
@@ -284,6 +287,7 @@ class CBlockIndex | |
block.hashPrevBlock = pprev->GetBlockHash(); | ||
block.hashMerkleRoot = hashMerkleRoot; | ||
block.nTime = nTime; | ||
block.block_height = block_height; | ||
block.nBits = nBits; | ||
block.nNonce = nNonce; | ||
return block; | ||
|
@@ -403,6 +407,7 @@ class CDiskBlockIndex : public CBlockIndex | |
READWRITE(hashPrev); | ||
READWRITE(hashMerkleRoot); | ||
READWRITE(nTime); | ||
READWRITE(block_height); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this doesn't need to be conditional. Bitcoin block indexes sure won't have height here... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure myself, but Greg discussed it with Jorge here: #431 (comment) |
||
READWRITE(nBits); | ||
READWRITE(nNonce); | ||
} | ||
|
@@ -414,6 +419,7 @@ class CDiskBlockIndex : public CBlockIndex | |
block.hashPrevBlock = hashPrev; | ||
block.hashMerkleRoot = hashMerkleRoot; | ||
block.nTime = nTime; | ||
block.block_height = block_height; | ||
block.nBits = nBits; | ||
block.nNonce = nNonce; | ||
return block.GetHash(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,6 +435,10 @@ class CCustomParams : public CRegTestParams { | |
// No subsidy for custom chains by default | ||
consensus.genesis_subsidy = args.GetArg("-con_blocksubsidy", 0); | ||
|
||
// Note: This global is needed to avoid circular dependency | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. with chainparams (ie if the global was a field in chainparams), because chainparams depends on block. |
||
// Defaults to true for custom chains. | ||
g_con_blockheightinheader = gArgs.GetBoolArg("-con_blockheightinheader", true); | ||
|
||
// All non-zero coinbase outputs must go to this scriptPubKey | ||
std::vector<unsigned char> man_bytes = ParseHex(gArgs.GetArg("-con_mandatorycoinbase", "")); | ||
consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,9 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc | |
// Fill in header | ||
pblock->hashPrevBlock = pindexPrev->GetBlockHash(); | ||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); | ||
if (g_con_blockheightinheader) { | ||
pblock->block_height = nHeight; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment probably doesn't need to be conditional. |
||
} | ||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus()); | ||
pblock->nNonce = 0; | ||
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]); | ||
|
Uh oh!
There was an error while loading. Please reload this page.