From 65d2644f5033ac8b2eee6333ca4000afbe21c341 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Wed, 4 Nov 2015 00:00:01 -0500 Subject: [PATCH 1/4] change default peer address, fix crash in claim trie --- share/seeds/nodes_main.txt | 2 +- src/chainparams.cpp | 2 ++ src/chainparamsseeds.h | 2 +- src/main.cpp | 2 +- src/ncctrie.cpp | 3 ++- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/share/seeds/nodes_main.txt b/share/seeds/nodes_main.txt index e25ee3584..83ef1ffae 100644 --- a/share/seeds/nodes_main.txt +++ b/share/seeds/nodes_main.txt @@ -1 +1 @@ -104.236.42.182 +52.27.78.56 diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 392869511..c295d0b5c 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -115,6 +115,8 @@ public: vSeeds.clear(); vFixedSeeds.clear(); + vSeeds.push_back(CDNSSeedData("lbrycrd.lbry.io", "testseed.lbrycrd.lbry.io")); // lbry.io + base58Prefixes[PUBKEY_ADDRESS] = std::vector(1,0); base58Prefixes[SCRIPT_ADDRESS] = std::vector(1,5); base58Prefixes[SECRET_KEY] = std::vector(1,128); diff --git a/src/chainparamsseeds.h b/src/chainparamsseeds.h index 619b3d007..34affb8c7 100644 --- a/src/chainparamsseeds.h +++ b/src/chainparamsseeds.h @@ -8,7 +8,7 @@ * IPv4 as well as onion addresses are wrapped inside a IPv6 address accordingly. */ static SeedSpec6 pnSeed6_main[] = { - {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x68,0xec,0x2a,0xb6}, 8333} + {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x34,0x1b,0x4e,0x38}, 8333} }; static SeedSpec6 pnSeed6_test[] = { diff --git a/src/main.cpp b/src/main.cpp index 68dcc9f97..cf81a0731 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3628,7 +3628,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) } // process in case the block isn't known yet - if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) { + if (hash != chainparams.GetConsensus().hashGenesisBlock && (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0)) { CValidationState state; if (ProcessNewBlock(state, NULL, &block, true, dbp)) nLoaded++; diff --git a/src/ncctrie.cpp b/src/ncctrie.cpp index 065c303fc..34e6b4871 100644 --- a/src/ncctrie.cpp +++ b/src/ncctrie.cpp @@ -573,7 +573,8 @@ bool CNCCTrie::updateHash(const std::string& name, uint256& hash) void CNCCTrie::BatchWriteNode(CLevelDBBatch& batch, const std::string& name, const CNCCTrieNode* pNode) const { - LogPrintf("%s: Writing %s to disk with %d values\n", __func__, name, pNode->values.size()); + if (pNode) + LogPrintf("%s: Writing %s to disk with %d values\n", __func__, name, pNode->values.size()); if (pNode) batch.Write(std::make_pair('n', name), *pNode); else From a1c1d813aed8ee6372943c1f3f651aca8f4893c6 Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Thu, 12 Nov 2015 13:54:46 -0500 Subject: [PATCH 2/4] change bitcoin to lbrycrd in binaries and default data directories --- .gitignore | 7 ++----- src/Makefile.qttest.include | 28 ++++++++++++++-------------- src/Makefile.test.include | 28 ++++++++++++++-------------- src/util.cpp | 4 ++-- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 2b9a06f40..f83fa8c64 100644 --- a/.gitignore +++ b/.gitignore @@ -2,14 +2,11 @@ *.exe src/bitcoin -src/bitcoind src/lbrycrdd -src/bitcoin-cli src/lbrycrd-cli -src/bitcoin-tx src/lbrycrd-tx -src/test/test_bitcoin -src/qt/test/test_bitcoin-qt +src/test/test_lbrycrd +src/qt/test/test_lbrycrd-qt # autoreconf Makefile.in diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index c5392cf30..e79682179 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -1,5 +1,5 @@ -bin_PROGRAMS += qt/test/test_bitcoin-qt -TESTS += qt/test/test_bitcoin-qt +bin_PROGRAMS += qt/test/test_lbrycrd-qt +TESTS += qt/test/test_lbrycrd-qt TEST_QT_MOC_CPP = qt/test/moc_uritests.cpp @@ -12,37 +12,37 @@ TEST_QT_H = \ qt/test/paymentrequestdata.h \ qt/test/paymentservertests.h -qt_test_test_bitcoin_qt_CPPFLAGS = $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \ +qt_test_test_lbrycrd_qt_CPPFLAGS = $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \ $(QT_INCLUDES) $(QT_TEST_INCLUDES) $(PROTOBUF_CFLAGS) -qt_test_test_bitcoin_qt_SOURCES = \ +qt_test_test_lbrycrd_qt_SOURCES = \ qt/test/test_main.cpp \ qt/test/uritests.cpp \ $(TEST_QT_H) if ENABLE_WALLET -qt_test_test_bitcoin_qt_SOURCES += \ +qt_test_test_lbrycrd_qt_SOURCES += \ qt/test/paymentservertests.cpp endif -nodist_qt_test_test_bitcoin_qt_SOURCES = $(TEST_QT_MOC_CPP) +nodist_qt_test_test_lbrycrd_qt_SOURCES = $(TEST_QT_MOC_CPP) -qt_test_test_bitcoin_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER) +qt_test_test_lbrycrd_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER) if ENABLE_WALLET -qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET) +qt_test_test_lbrycrd_qt_LDADD += $(LIBBITCOIN_WALLET) endif -qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) \ +qt_test_test_lbrycrd_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) \ $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) -qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) +qt_test_test_lbrycrd_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno CLEANFILES += $(CLEAN_BITCOIN_QT_TEST) -test_bitcoin_qt : qt/test/test_bitcoin-qt$(EXEEXT) +test_lbrycrd_qt : qt/test/test_lbrycrd-qt$(EXEEXT) -test_bitcoin_qt_check : qt/test/test_bitcoin-qt$(EXEEXT) FORCE +test_lbrycrd_qt_check : qt/test/test_lbrycrd-qt$(EXEEXT) FORCE $(MAKE) check-TESTS TESTS=$^ -test_bitcoin_qt_clean: FORCE - rm -f $(CLEAN_BITCOIN_QT_TEST) $(qt_test_test_bitcoin_qt_OBJECTS) +test_lbrycrd_qt_clean: FORCE + rm -f $(CLEAN_BITCOIN_QT_TEST) $(qt_test_test_lbrycrd_qt_OBJECTS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index af2640d91..a5d485957 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -1,7 +1,7 @@ -TESTS += test/test_bitcoin -bin_PROGRAMS += test/test_bitcoin +TESTS += test/test_lbrycrd +bin_PROGRAMS += test/test_lbrycrd TEST_SRCDIR = test -TEST_BINARY=test/test_bitcoin$(EXEEXT) +TEST_BINARY=test/test_lbrycrd$(EXEEXT) EXTRA_DIST += \ @@ -85,18 +85,18 @@ BITCOIN_TESTS += \ test/rpc_wallet_tests.cpp endif -test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) -test_test_bitcoin_CPPFLAGS = $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) -test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ +test_test_lbrycrd_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) +test_test_lbrycrd_CPPFLAGS = $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) +test_test_lbrycrd_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) if ENABLE_WALLET -test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET) +test_test_lbrycrd_LDADD += $(LIBBITCOIN_WALLET) endif -test_test_bitcoin_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) -test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static +test_test_lbrycrd_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) +test_test_lbrycrd_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static -nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES) +nodist_test_test_lbrycrd_SOURCES = $(GENERATED_TEST_FILES) $(BITCOIN_TESTS): $(GENERATED_TEST_FILES) @@ -104,13 +104,13 @@ CLEAN_BITCOIN_TEST = test/*.gcda test/*.gcno $(GENERATED_TEST_FILES) CLEANFILES += $(CLEAN_BITCOIN_TEST) -bitcoin_test: $(TEST_BINARY) +lbrycrd_test: $(TEST_BINARY) -bitcoin_test_check: $(TEST_BINARY) FORCE +lbrycrd_test_check: $(TEST_BINARY) FORCE $(MAKE) check-TESTS TESTS=$^ -bitcoin_test_clean : FORCE - rm -f $(CLEAN_BITCOIN_TEST) $(test_test_bitcoin_OBJECTS) $(TEST_BINARY) +lbrycrd_test_clean : FORCE + rm -f $(CLEAN_BITCOIN_TEST) $(test_test_lbrycrd_OBJECTS) $(TEST_BINARY) check-local: @echo "Running test/bitcoin-util-test.py..." diff --git a/src/util.cpp b/src/util.cpp index 5d09a9157..8dd4a5d17 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -401,7 +401,7 @@ boost::filesystem::path GetDefaultDataDir() // Unix: ~/.lbrycrd #ifdef WIN32 // Windows - return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin"; + return GetSpecialFolderPath(CSIDL_APPDATA) / "lbrycrd"; #else fs::path pathRet; char* pszHome = getenv("HOME"); @@ -413,7 +413,7 @@ boost::filesystem::path GetDefaultDataDir() // Mac pathRet /= "Library/Application Support"; TryCreateDirectory(pathRet); - return pathRet / "Bitcoin"; + return pathRet / "lbrycrd"; #else // Unix return pathRet / ".lbrycrd"; From 4873a2833b76e0832fa2adb52cb0622a07d1f28c Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Wed, 18 Nov 2015 17:52:20 -0500 Subject: [PATCH 3/4] change the message start bytes --- src/chainparams.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c295d0b5c..9ce8bbaed 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -45,10 +45,10 @@ public: * The characters are rarely used upper ASCII, not valid as UTF-8, and produce * a large 32-bit integer with any alignment. */ - pchMessageStart[0] = 0xf9; - pchMessageStart[1] = 0xbe; - pchMessageStart[2] = 0xb4; - pchMessageStart[3] = 0xd9; + pchMessageStart[0] = 0xc8; + pchMessageStart[1] = 0xef; + pchMessageStart[2] = 0xd9; + pchMessageStart[3] = 0xbe; //pchMessageStart[0] = 0xfa; //pchMessageStart[1] = 0xe4; //pchMessageStart[2] = 0xaa; From c5b589c33d1f4d197fa8c38936fe2ad514710f4d Mon Sep 17 00:00:00 2001 From: Jimmy Kiselak Date: Wed, 9 Dec 2015 15:16:13 -0500 Subject: [PATCH 4/4] handle situation where expired claim is spent correctly --- src/miner.cpp | 3 +- src/ncctrie.cpp | 2 +- src/test/ncctrie_tests.cpp | 168 ++++++++++++++++++++++++++++++++++++- 3 files changed, 167 insertions(+), 6 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bb2030f6b..f8eb9bb90 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -313,8 +313,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) assert(vvchParams.size() == 2); std::string name(vvchParams[0].begin(), vvchParams[0].end()); int throwaway; - if (!trieCache.spendClaim(name, txin.prevout.hash, txin.prevout.n, coins->nHeight, throwaway)) - LogPrintf("%s: Something went wrong removing the name\n", __func__); + trieCache.spendClaim(name, txin.prevout.hash, txin.prevout.n, coins->nHeight, throwaway); std::pair val(txin.prevout.hash, txin.prevout.n); std::pair >entry(name, val); spentClaims.insert(entry); diff --git a/src/ncctrie.cpp b/src/ncctrie.cpp index 34e6b4871..d49538a6e 100644 --- a/src/ncctrie.cpp +++ b/src/ncctrie.cpp @@ -904,12 +904,12 @@ bool CNCCTrieCache::removeClaimFromTrie(const std::string name, uint256 txhash, if (!success) { LogPrintf("%s: Removing a value was unsuccessful. name = %s, txhash = %s, nOut = %d", __func__, name.c_str(), txhash.GetHex(), nOut); + return false; } else { nValidAtHeight = val.nValidAtHeight; } - assert(success); if (fChanged) { for (std::string::const_iterator itCur = name.begin(); itCur != name.end(); ++itCur) diff --git a/src/test/ncctrie_tests.cpp b/src/test/ncctrie_tests.cpp index f363072cd..847b69c46 100644 --- a/src/test/ncctrie_tests.cpp +++ b/src/test/ncctrie_tests.cpp @@ -140,7 +140,28 @@ const unsigned int expire_nonces[] = { 11252, 21975, 35712, 7510, 1534, 44727, 143860, 47305, 27722, 175266, 43248, 225233, 11955, 88368, 168603, 124807, 69459, 31880, 49456, 355451, 79880, 128749, 65667, 10897, 14131, 4409, 10523, 8720, 112240, 71025, - 95521, 103635, 39284, 63443, 66790, 52473, 80317, 118192, 76604,}; + 95521, 103635, 39284, 63443, 66790, 52473, 80317, 118192, 76604, 42631, + 124855, 28023, 52448, 140048, 15594, 192785, 5973, 40950, 37768, 94673, + 82233, 7635, 172419, 88992, 5259, 59021, 94380, 38724, 287534, 8261, + 3699, 52757, 83678, 134701, 109758, 11209, 52740, 44356, 56768, 22635, + 28090, 28563, 92925, 32423, 11457, 3837, 13992, 41831, 35708, 3784, + 29034, 29481, 29843, 48043, 69674, 20555, 38391, 26421, 10631, 92622, + 20304, 27564, 10952, 128072, 19793, 21355, 12599, 17296, 51064, 139138, + 22038, 6035, 3012, 43928, 110504, 1708, 10164, 79900, 21204, 78917, + 8746, 61911, 45844, 1885, 13413, 11197, 58423, 24607, 142379, 28543, + 57602, 298725, 6766, 82398, 31727, 87268, 13744, 35847, 123645, 106809, + 10275, 23769, 91704, 20887, 74599, 95506, 188778, 56997, 36100, 72149, + 69856, 117184, 11810, 65634, 18767, 30398, 30976, 62762, 54996, 5967, + 102018, 7538, 117803, 13328, 98490, 18573, 254, 110552, 4154, 152476, + 102240, 3962, 33563, 95590, 182191, 12839, 13578, 15032, 1445, 4095, + 92483, 21161, 1623, 22039, 67635, 61451, 62277, 154696, 195002, 15911, + 3103, 5683, 15840, 4474, 68755, 4592, 8261, 81237, 120883, 41460, + 11793, 125524, 280727, 326875, 12209, 24251, 101730, 4289, 91666, 1238, + 24388, 34929, 43158, 88433, 39474, 19966, 12112, 150581, 46709, 5426, + 78896, 28203, 60363, 139941, 62739, 133675, 148176, 125234, 221557, 15251, + 2323, 21270, 15099, 18092, 11211, 170844, 2169, 33698, 66588, 62719, + 120057, 8823, 5430, 44579, 61385, 84720, 64857, 70478, 116285, 8904, + 63423}; BOOST_FIXTURE_TEST_SUITE(ncctrie_tests, TestingSetup) @@ -892,13 +913,16 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration) tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP << OP_TRUE; CMutableTransaction tx2 = BuildTransaction(tx1); tx2.vout[0].scriptPubKey = CScript() << OP_TRUE; + CMutableTransaction tx3 = BuildTransaction(coinbases[1]); + tx3.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue << OP_2DROP << OP_DROP << OP_TRUE; + tx3.vout[0].nValue = tx1.vout[0].nValue >> 1; std::vector blocks_to_invalidate; // set expiration time to 100 blocks after the block becomes valid. pnccTrie->setExpirationTime(200); - // create a claim. verify no expiration event has been scheduled. + // create a claim. verify the expiration event has been scheduled. AddToMempool(tx1); @@ -913,7 +937,7 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration) BOOST_CHECK(!pnccTrie->queueEmpty()); BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); - // advance until the claim is valid. verify the expiration event is scheduled. + // advance until the claim is valid. BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); @@ -1178,6 +1202,144 @@ BOOST_AUTO_TEST_CASE(ncctrie_claim_expiration) BOOST_CHECK(pnccTrie->queueEmpty()); BOOST_CHECK(pnccTrie->expirationQueueEmpty()); BOOST_CHECK(blocks_to_invalidate.empty()); + + // Make sure that when a claim expires, a lesser claim for the same name takes over + + CNodeValue val; + + // create one claims for the name + + AddToMempool(tx1); + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate->block.vtx.size() == 2); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock); + delete pblocktemplate; + + BOOST_CHECK(pnccTrie->empty()); + BOOST_CHECK(!pnccTrie->queueEmpty()); + BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); + + // advance a little while and insert the second claim + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + for (unsigned int i = 1; i < 50; ++i) + { + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + } + delete pblocktemplate; + + AddToMempool(tx3); + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate->block.vtx.size() == 2); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + delete pblocktemplate; + + BOOST_CHECK(pnccTrie->empty()); + BOOST_CHECK(!pnccTrie->queueEmpty()); + BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); + + // advance until tx1 is valid + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + for (unsigned int i = 1; i < 50; ++i) + { + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + } + delete pblocktemplate; + + BOOST_CHECK(pnccTrie->empty()); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + delete pblocktemplate; + + BOOST_CHECK(!pnccTrie->empty()); + BOOST_CHECK(!pnccTrie->queueEmpty()); + BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); + + // advance until tx3 is valid, ensure tx1 is winning + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + for (unsigned int i = 1; i < 50; ++i) + { + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + } + delete pblocktemplate; + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + delete pblocktemplate; + + BOOST_CHECK(!pnccTrie->empty()); + BOOST_CHECK(pnccTrie->queueEmpty()); + BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); + BOOST_CHECK(pnccTrie->getInfoForName(sName, val)); + BOOST_CHECK(val.txhash == tx1.GetHash()); + + // advance until the expiration event occurs. verify the expiration event occurs on time. + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + for (unsigned int i = 1; i < 50; ++i) + { + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + if (i == 1) + blocks_to_invalidate.push_back(pblocktemplate->block.hashPrevBlock); + } + delete pblocktemplate; + + BOOST_CHECK(!pnccTrie->empty()); + BOOST_CHECK(pnccTrie->queueEmpty()); + BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + delete pblocktemplate; + + BOOST_CHECK(!pnccTrie->empty()); + BOOST_CHECK(pnccTrie->queueEmpty()); + BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); + BOOST_CHECK(pnccTrie->getInfoForName(sName, val)); + BOOST_CHECK(val.txhash == tx3.GetHash()); + + // spend tx1 + + AddToMempool(tx2); + + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + pblocktemplate->block.hashPrevBlock = chainActive.Tip()->GetBlockHash(); + BOOST_CHECK(CreateBlock(pblocktemplate, find_nonces, expire_nonces[block_counter++])); + delete pblocktemplate; + + // roll back to when tx1 and tx3 are in the trie and tx1 is winning + + BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back())); + blocks_to_invalidate.pop_back(); + BOOST_CHECK(!pnccTrie->empty()); + BOOST_CHECK(pnccTrie->queueEmpty()); + BOOST_CHECK(!pnccTrie->expirationQueueEmpty()); + BOOST_CHECK(pnccTrie->getInfoForName(sName, val)); + BOOST_CHECK(val.txhash == tx1.GetHash()); + + // roll all the way back + + BOOST_CHECK(RemoveBlock(blocks_to_invalidate.back())); + blocks_to_invalidate.pop_back(); + BOOST_CHECK(pnccTrie->empty()); + BOOST_CHECK(pnccTrie->queueEmpty()); + BOOST_CHECK(pnccTrie->expirationQueueEmpty()); + BOOST_CHECK(blocks_to_invalidate.empty()); + } BOOST_AUTO_TEST_CASE(ncctrienode_serialize_unserialize)