Skip to content
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

Headers-first synchronization #4468

Merged
merged 11 commits into from
Oct 17, 2014
2 changes: 1 addition & 1 deletion qa/pull-tester/run-bitcoind-for-test.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ touch "$DATADIR/regtest/debug.log"
tail -q -n 1 -F "$DATADIR/regtest/debug.log" | grep -m 1 -q "Done loading" &
WAITER=$!
PORT=`expr 10000 + $$ % 55536`
"@abs_top_builddir@/src/bitcoind@EXEEXT@" -connect=0.0.0.0 -datadir="$DATADIR" -rpcuser=user -rpcpassword=pass -listen -keypool=3 -debug -debug=net -logtimestamps -port=$PORT -whitelist=127.0.0.1 -regtest -rpcport=`expr $PORT + 1` &
"@abs_top_builddir@/src/bitcoind@EXEEXT@" -connect=0.0.0.0 -datadir="$DATADIR" -rpcuser=user -rpcpassword=pass -listen -keypool=3 -debug -debug=net -logtimestamps -checkmempool=0 -port=$PORT -whitelist=127.0.0.1 -regtest -rpcport=`expr $PORT + 1` &
BITCOIND=$!

#Install a watchdog.
Expand Down
32 changes: 25 additions & 7 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,29 @@ struct CDiskBlockPos
};

enum BlockStatus {
// Unused.
BLOCK_VALID_UNKNOWN = 0,
BLOCK_VALID_HEADER = 1, // parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future
BLOCK_VALID_TREE = 2, // parent found, difficulty matches, timestamp >= median previous, checkpoint
BLOCK_VALID_TRANSACTIONS = 3, // only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid, no duplicate txids, sigops, size, merkle root
BLOCK_VALID_CHAIN = 4, // outputs do not overspend inputs, no double spends, coinbase output ok, immature coinbase spends, BIP30
BLOCK_VALID_SCRIPTS = 5, // scripts/signatures ok

// Parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future
BLOCK_VALID_HEADER = 1,

// All parent headers found, difficulty matches, timestamp >= median previous, checkpoint. Implies all parents
// are also at least TREE.
BLOCK_VALID_TREE = 2,

// Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid, no duplicate txids,
// sigops, size, merkle root. Implies all parents are at least TREE but not necessarily TRANSACTIONS. When all
// parent blocks also have TRANSACTIONS, CBlockIndex::nChainTx will be set.
BLOCK_VALID_TRANSACTIONS = 3,

// Outputs do not overspend inputs, no double spends, coinbase output ok, immature coinbase spends, BIP30.
// Implies all parents are also at least CHAIN.
BLOCK_VALID_CHAIN = 4,

// Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
BLOCK_VALID_SCRIPTS = 5,

// All validity bits.
BLOCK_VALID_MASK = BLOCK_VALID_HEADER | BLOCK_VALID_TREE | BLOCK_VALID_TRANSACTIONS |
BLOCK_VALID_CHAIN | BLOCK_VALID_SCRIPTS,

Expand Down Expand Up @@ -103,7 +120,8 @@ class CBlockIndex
// Note: in a potential headers-first mode, this number cannot be relied upon
unsigned int nTx;

// (memory only) Number of transactions in the chain up to and including this block
// (memory only) Number of transactions in the chain up to and including this block.
// This value will be non-zero only if and only if transactions for this block and all its parents are available.
unsigned int nChainTx; // change to 64-bit type when necessary; won't happen before 2030

// Verification status of this block. See enum BlockStatus
Expand Down Expand Up @@ -146,7 +164,7 @@ class CBlockIndex
SetNull();
}

CBlockIndex(CBlockHeader& block)
CBlockIndex(const CBlockHeader& block)
{
SetNull();

Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ bool AppInit2(boost::thread_group& threadGroup)

// If the loaded chain has a wrong genesis, bail out immediately
// (we're likely using a testnet datadir, or the other way around).
if (!mapBlockIndex.empty() && chainActive.Genesis() == NULL)
if (!mapBlockIndex.empty() && mapBlockIndex.count(Params().HashGenesisBlock()) == 0)
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));

// Initialize the block index (no-op if non-empty database was already loaded)
Expand Down
Loading