Skip to content

Commit

Permalink
Make fork warning use version bit masking, on the assumption that fro…
Browse files Browse the repository at this point in the history
…m this point on all changes will be triggered by a bit in nVersion rather than an incrementing integer.
  • Loading branch information
mikehearn authored and Braydon Fuller committed Dec 3, 2015
1 parent fadcd7d commit 463db05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
15 changes: 14 additions & 1 deletion qa/rpc-tests/forknotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,29 @@ def setup_network(self):
with open(self.alert_filename, 'w') as f:
pass # Just open then close to create zero-length file
self.nodes.append(start_node(0, self.options.tmpdir,
["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]))
["-blockversion=3", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]))
# Node1 mines block.version=211 blocks
self.nodes.append(start_node(1, self.options.tmpdir,
["-blockversion=211"]))
connect_nodes(self.nodes[1], 0)

# Node2 mines block.version=0x20000007 blocks
self.nodes.append(start_node(2, self.options.tmpdir,
["-blockversion=%d"%(0x20000007,)]))
connect_nodes(self.nodes[2], 0)

self.is_network_split = False
self.sync_all()

def run_test(self):
# Should be no alerts if nodes 0 or 2 mine:
self.nodes[0].generate(1)
self.sync_all()
self.nodes[2].generate(1)
self.sync_all()
if os.stat(self.alert_filename).st_size > 0:
raise AssertionError("Erroneous up-version alert")

# Mine 51 up-version blocks
self.nodes[1].generate(51)
self.sync_all()
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2230,12 +2230,12 @@ void static UpdateTip(CBlockIndex *pindexNew) {
const CBlockIndex* pindex = chainActive.Tip();
for (int i = 0; i < 100 && pindex != NULL; i++)
{
if (pindex->nVersion > CBlock::CURRENT_VERSION)
if ((pindex->nVersion & ~CBlock::UNDERSTOOD_VERSIONS) != 0)
++nUpgraded;
pindex = pindex->pprev;
}
if (nUpgraded > 0)
LogPrintf("%s: %d of last 100 blocks above version %d\n", __func__, nUpgraded, (int)CBlock::CURRENT_VERSION);
LogPrintf("%s: %d of last 100 blocks contain unknown version feature bit\n", __func__, nUpgraded);
if (nUpgraded > 100/2)
{
// strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user:
Expand Down
5 changes: 4 additions & 1 deletion src/primitives/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ const unsigned int SIZE_FORK_VERSION = 0x20000007;
class CBlockHeader
{
public:
// header
static const int32_t CURRENT_VERSION=SIZE_FORK_VERSION;
// This code knows the rules for these block versions:
static const int32_t UNDERSTOOD_VERSIONS = (SIZE_FORK_VERSION | 3 | 2 | 1);

// header
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
Expand Down

0 comments on commit 463db05

Please sign in to comment.