aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-11-16 19:28:24 +0100
committerPieter Wuille <pieter.wuille@gmail.com>2014-01-27 21:20:41 +0100
commit75f51f2a63e0ebe34ab290c2b7141dd240b98c3b (patch)
treeed9be9e3acbcd9d9df9f67264042109b8cd7db98 /src/main.h
parent0ec16f35d6b8d9f1fe876f1405f105f6e5aa0933 (diff)
downloadbitcoin-75f51f2a63e0ebe34ab290c2b7141dd240b98c3b.tar.xz
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).
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/main.h b/src/main.h
index 60e733b23a..ba353a885b 100644
--- a/src/main.h
+++ b/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;