mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Prepare block connection logic for headers-first.
This changes the block processing logic from "try to atomically switch to a new block" to a continuous "(dis)connect a block, aiming for the assumed best chain". This means the smallest atomic operations on the chainstate become individual block connections or disconnections, instead of entire reorganizations. It may mean that we try to reorganize to one block, fail, and rereorganize again to the old block. This is slower, but doesn't require unbounded RAM. It also means that a ConnectBlock which fails may be no longer called from the ProcessBlock which knows which node sent it. To deal with that, a mapBlockSource is kept, and invalid blocks cause asynchronous "reject" messages and banning (if necessary).
This commit is contained in:
20
src/main.h
20
src/main.h
@@ -165,10 +165,8 @@ bool IsInitialBlockDownload();
|
||||
std::string GetWarnings(std::string strFor);
|
||||
/** Retrieve a transaction (from memory pool, or from disk, if possible) */
|
||||
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow = false);
|
||||
/** Connect/disconnect blocks until pindexNew is the new tip of the active block chain */
|
||||
bool SetBestChain(CValidationState &state, CBlockIndex* pindexNew);
|
||||
/** Find the best known block, and make it the tip of the block chain */
|
||||
bool ConnectBestBlock(CValidationState &state);
|
||||
bool ActivateBestChain(CValidationState &state);
|
||||
int64_t GetBlockValue(int nHeight, int64_t nFees);
|
||||
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock);
|
||||
|
||||
@@ -716,6 +714,8 @@ public:
|
||||
unsigned int nBits;
|
||||
unsigned int nNonce;
|
||||
|
||||
// (memory only) Sequencial id assigned to distinguish order in which blocks are received.
|
||||
uint32_t nSequenceId;
|
||||
|
||||
CBlockIndex()
|
||||
{
|
||||
@@ -729,6 +729,7 @@ public:
|
||||
nTx = 0;
|
||||
nChainTx = 0;
|
||||
nStatus = 0;
|
||||
nSequenceId = 0;
|
||||
|
||||
nVersion = 0;
|
||||
hashMerkleRoot = 0;
|
||||
@@ -749,6 +750,7 @@ public:
|
||||
nTx = 0;
|
||||
nChainTx = 0;
|
||||
nStatus = 0;
|
||||
nSequenceId = 0;
|
||||
|
||||
nVersion = block.nVersion;
|
||||
hashMerkleRoot = block.hashMerkleRoot;
|
||||
@@ -958,23 +960,23 @@ public:
|
||||
AbortNode(msg);
|
||||
return Error();
|
||||
}
|
||||
bool IsValid() {
|
||||
bool IsValid() const {
|
||||
return mode == MODE_VALID;
|
||||
}
|
||||
bool IsInvalid() {
|
||||
bool IsInvalid() const {
|
||||
return mode == MODE_INVALID;
|
||||
}
|
||||
bool IsError() {
|
||||
bool IsError() const {
|
||||
return mode == MODE_ERROR;
|
||||
}
|
||||
bool IsInvalid(int &nDoSOut) {
|
||||
bool IsInvalid(int &nDoSOut) const {
|
||||
if (IsInvalid()) {
|
||||
nDoSOut = nDoS;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool CorruptionPossible() {
|
||||
bool CorruptionPossible() const {
|
||||
return corruptionPossible;
|
||||
}
|
||||
unsigned char GetRejectCode() const { return chRejectCode; }
|
||||
@@ -1041,6 +1043,8 @@ public:
|
||||
/** The currently-connected chain of blocks. */
|
||||
extern CChain chainActive;
|
||||
|
||||
/** The currently best known chain of headers (some of which may be invalid). */
|
||||
extern CChain chainMostWork;
|
||||
|
||||
/** Global variable that points to the active CCoinsView (protected by cs_main) */
|
||||
extern CCoinsViewCache *pcoinsTip;
|
||||
|
||||
Reference in New Issue
Block a user