From 44486c7a8085491e0d6b0bac842279cdd51bd604 Mon Sep 17 00:00:00 2001 From: Bohdan Vanieiev Date: Tue, 21 Jan 2020 16:22:35 +0200 Subject: [PATCH 1/7] Fix num pop tx --- configure.ac | 5 +- src/Makefile.am | 4 +- src/Makefile.bench.include | 4 +- src/Makefile.qt.include | 2 +- src/Makefile.qttest.include | 2 +- src/Makefile.test.include | 2 +- src/Makefile.test_util.include | 2 +- src/bitcoind.cpp | 2 - src/init.cpp | 2 + src/qt/bitcoin.cpp | 10 +++ src/test/util/setup_common.cpp | 12 ++- src/test/util/setup_common.h | 3 + src/validation.cpp | 13 ++- src/vbk/pop_service/pop_service_impl.cpp | 15 +++- src/vbk/test/integration/Makefile.include | 2 +- src/vbk/test/unit/block_validation_tests.cpp | 90 ++++++++++++++++---- src/vbk/test/unit/pop_reward_tests.cpp | 2 +- 17 files changed, 135 insertions(+), 37 deletions(-) diff --git a/configure.ac b/configure.ac index d058f58d2233e..8b783270e75f0 100644 --- a/configure.ac +++ b/configure.ac @@ -359,10 +359,13 @@ if test "x$CXXFLAGS_overridden" = "xno"; then fi # fakeit does not work with GCC's devirtualization, which is enabled with -O2 or higher -FAKEIT_CXXFLAGS= +THIRD_PARTY_INCLUDE="-isystem ../third_party/include" + +FAKEIT_CXXFLAGS=$THIRD_PARTY_INCLUDE AX_CHECK_COMPILE_FLAG([-fno-devirtualize],[FAKEIT_CXXFLAGS="$FAKEIT_CXXFLAGS -fno-devirtualize"]) AX_CHECK_COMPILE_FLAG([-Wno-ignored-optimization-argument],[FAKEIT_CXXFLAGS="$FAKEIT_CXXFLAGS -Wno-ignored-optimization-argument"]) AC_SUBST(FAKEIT_CXXFLAGS) +CXXFLAGS="$CXXFLAGS $FAKEIT_CXXFLAGS" enable_hwcrc32=no enable_sse41=no diff --git a/src/Makefile.am b/src/Makefile.am index 5085a58946d50..c66b08d441999 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,9 +10,7 @@ AM_CPPFLAGS = $(DEBUG_CPPFLAGS) $(HARDENED_CPPFLAGS) AM_LIBTOOLFLAGS = --preserve-dup-deps EXTRA_LIBRARIES = -FAKEIT_DIR = $(top_srcdir)/third_party/include -FAKEIT_HEADER = $(FAKEIT_DIR)/fakeit.hpp -THIRD_PARTY_INCLUDE = -isystem $(FAKEIT_DIR) + if EMBEDDED_UNIVALUE LIBUNIVALUE = univalue/libunivalue.la diff --git a/src/Makefile.bench.include b/src/Makefile.bench.include index a9827623cfc0c..0eb3d610904a4 100644 --- a/src/Makefile.bench.include +++ b/src/Makefile.bench.include @@ -2,8 +2,6 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -THIRD_PARTY_INCLUDE = -isystem $(top_srcdir)/third_party/include - bin_PROGRAMS += bench/bench_bitcoin BENCH_SRCDIR = bench BENCH_BINARY = bench/bench_bitcoin$(EXEEXT) @@ -46,7 +44,7 @@ bench_bench_bitcoin_SOURCES = \ nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES) bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/ -bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(THIRD_PARTY_INCLUDE) +bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(FAKEIT_CXXFLAGS) bench_bench_bitcoin_LDADD = \ $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_WALLET) \ diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index cf09eee2cbdfb..fb6479caf8dfc 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -314,7 +314,7 @@ qt_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) endif qt_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) \ $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \ - $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) + $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GRPC_LIBS) qt_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) qt_bitcoin_qt_LIBTOOLFLAGS = $(AM_LIBTOOLFLAGS) --tag CXX diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index 8c47fabad9f41..b79bebdc66619 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -56,7 +56,7 @@ endif qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) \ $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(QR_LIBS) $(BDB_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) \ - $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) + $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(GRPC_LIBS) qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) qt_test_test_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 0cf99149d9359..5da8f123fbd32 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -233,7 +233,7 @@ BITCOIN_TEST_SUITE += \ endif test_test_bitcoin_SOURCES = $(BITCOIN_TEST_SUITE) $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) -test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS) $(THIRD_PARTY_INCLUDE) +test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS) $(FAKEIT_CXXFLAGS) test_test_bitcoin_LDADD = $(LIBTEST_UTIL) if ENABLE_WALLET test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET) diff --git a/src/Makefile.test_util.include b/src/Makefile.test_util.include index f72ed7897d4ab..e6b4449baecc3 100644 --- a/src/Makefile.test_util.include +++ b/src/Makefile.test_util.include @@ -16,7 +16,7 @@ TEST_UTIL_H = \ test/util/transaction_utils.h \ test/util/wallet.h -libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS) $(THIRD_PARTY_INCLUDE) +libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS) $(FAKEIT_CXXFLAGS) libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(FAKEIT_CXXFLAGS) libtest_util_a_SOURCES = \ test/util/blockfilter.cpp \ diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 09689e2d2b9b8..1b0dde2ede2de 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -155,8 +155,6 @@ static bool AppInit(int argc, char* argv[]) return false; } fRet = AppInitMain(node); - // connman is initialized in AppInitMain - VeriBlock::InitRpcService(node.connman.get()); } catch (const std::exception& e) { PrintExceptionContinue(&e, "AppInit()"); diff --git a/src/init.cpp b/src/init.cpp index eeca48c4c2773..d7280ad9e892a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1321,6 +1321,8 @@ bool AppInitMain(NodeContext& node) assert(!node.connman); node.connman = std::unique_ptr(new CConnman(GetRand(std::numeric_limits::max()), GetRand(std::numeric_limits::max()))); + VeriBlock::InitRpcService(node.connman.get()); + node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), scheduler)); RegisterValidationInterface(node.peer_logic.get()); diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 0021c3dbc7986..aab5e3766f352 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -6,6 +6,9 @@ #include #endif +#include +#include + #include #include @@ -406,6 +409,8 @@ int GuiMain(int argc, char* argv[]) util::WinCmdLineArgs winArgs; std::tie(argc, argv) = winArgs.get(); #endif + VeriBlock::InitUtilService(); + VeriBlock::InitConfig(); SetupEnvironment(); util::ThreadSetInternalName("main"); @@ -521,6 +526,11 @@ int GuiMain(int argc, char* argv[]) PaymentServer::ipcParseCommandLine(*node, argc, argv); #endif + VeriBlock::InitPopService( + gArgs.GetArg("-althost", "127.0.0.1"), + gArgs.GetArg("-altport", "19012"), + gArgs.GetBoolArg("-altautoconfig", true)); + QScopedPointer networkStyle(NetworkStyle::instantiate(Params().NetworkIDString())); assert(!networkStyle.isNull()); // Allow for separate UI settings for testnets diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 4cd9d687df22f..13686de80b9ad 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -176,7 +176,11 @@ TestChain100Setup::TestChain100Setup() // Create a new block with just given transactions, coinbase paying to // scriptPubKey, and try to add it to the current chain. -CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector& txns, const CScript& scriptPubKey) +CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector& txns, const CScript& scriptPubKey) { + return this->CreateAndProcessBlock(txns, scriptPubKey, nullptr); +} + +CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector& txns, const CScript& scriptPubKey, bool* isBlockValid) { const CChainParams& chainparams = Params(); std::unique_ptr pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey); @@ -196,7 +200,11 @@ CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector shared_pblock = std::make_shared(block); - ProcessNewBlock(chainparams, shared_pblock, true, nullptr); + + bool isValid = ProcessNewBlock(chainparams, shared_pblock, true, nullptr); + if(isBlockValid != nullptr) { + *isBlockValid = isValid; + } CBlock result = block; return result; diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 9248c8e8a9da0..69287bb3cee80 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -123,6 +123,9 @@ struct TestChain100Setup : public RegTestingSetup { CBlock CreateAndProcessBlock(const std::vector& txns, const CScript& scriptPubKey); + CBlock CreateAndProcessBlock(const std::vector& txns, + const CScript& scriptPubKey, bool* isBlockValid); + ~TestChain100Setup() override; std::vector m_coinbase_txns; // For convenience, coinbase transactions diff --git a/src/validation.cpp b/src/validation.cpp index 064b160ace251..6fa64674b2ca7 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3328,9 +3328,20 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu // First transaction must be coinbase, the rest must not be if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-missing", "first tx is not coinbase"); - for (unsigned int i = 1; i < block.vtx.size(); i++) + + size_t totalPopTxes = 0; + for (unsigned int i = 1; i < block.vtx.size(); i++) { + if(VeriBlock::isPopTx(*block.vtx[i])) + ++totalPopTxes; + if (block.vtx[i]->IsCoinBase()) return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-cb-multiple", "more than one coinbase"); + } + + auto& config = VeriBlock::getService(); + if(totalPopTxes > config.max_pop_tx_amount) { + return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "too many pop txes", "number of pop vtx in a block is too high"); + } // Check transactions // Must check for duplicate inputs (see CVE-2018-17144) diff --git a/src/vbk/pop_service/pop_service_impl.cpp b/src/vbk/pop_service/pop_service_impl.cpp index 5938bafaae07e..5fdc0b8270f8a 100644 --- a/src/vbk/pop_service/pop_service_impl.cpp +++ b/src/vbk/pop_service/pop_service_impl.cpp @@ -499,7 +499,8 @@ bool blockPopValidationImpl(PopServiceImpl& pop, const CBlock& block, const CBlo { bool isValid = true; const auto& config = getService(); - + size_t numOfPubTxes = 0; + size_t numOfCtxTxes = 0; std::string error_message; LOCK(mempool.cs); @@ -522,6 +523,7 @@ bool blockPopValidationImpl(PopServiceImpl& pop, const CBlock& block, const CBlo switch (type) { case PopTxType::CONTEXT: { + ++numOfCtxTxes; try { pop.updateContext(context.vbk, context.btc); } catch (const PopServiceException& e) { @@ -534,6 +536,7 @@ bool blockPopValidationImpl(PopServiceImpl& pop, const CBlock& block, const CBlo } case PopTxType::PUBLICATIONS: { + ++numOfPubTxes; PublicationData popEndorsement; pop.getPublicationsData(publications, popEndorsement); @@ -604,6 +607,16 @@ bool blockPopValidationImpl(PopServiceImpl& pop, const CBlock& block, const CBlo } } + if(numOfCtxTxes > config.max_update_context_tx_amount) { + pop.removePayloads(block, pindexPrev.nHeight + 1); + return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "too-many-update-ctx-txes", strprintf("too many 'updatecontext' transactions: actual %d > %d expected", numOfCtxTxes, config.max_update_context_tx_amount)); + } + + if(numOfCtxTxes + numOfPubTxes > config.max_pop_tx_amount) { + pop.removePayloads(block, pindexPrev.nHeight + 1); + return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "too-many-pop-txes", strprintf("too many PoP transactions: actual %d > %d expected", numOfPubTxes + numOfCtxTxes, config.max_pop_tx_amount)); + } + if (!isValid) { pop.removePayloads(block, pindexPrev.nHeight + 1); return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, strprintf("blockPopValidation(): pop check is failed"), "bad pop data \n" + error_message); diff --git a/src/vbk/test/integration/Makefile.include b/src/vbk/test/integration/Makefile.include index fdc0ff5c13c62..402f66ccd4e69 100644 --- a/src/vbk/test/integration/Makefile.include +++ b/src/vbk/test/integration/Makefile.include @@ -20,7 +20,7 @@ VBK_INTEGRATION_TESTS = \ vbk_test_integration_test_int_vbk_SOURCES = $(VBK_INTEGRATION_TEST_SUITE) $(VBK_INTEGRATION_TESTS) -vbk_test_integration_test_int_vbk_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS) $(THIRD_PARTY_INCLUDE) +vbk_test_integration_test_int_vbk_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS) $(FAKEIT_CXXFLAGS) vbk_test_integration_test_int_vbk_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) $(FAKEIT_CXXFLAGS) vbk_test_integration_test_int_vbk_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) \ diff --git a/src/vbk/test/unit/block_validation_tests.cpp b/src/vbk/test/unit/block_validation_tests.cpp index af150b69580d8..e2f68a5a3f619 100644 --- a/src/vbk/test/unit/block_validation_tests.cpp +++ b/src/vbk/test/unit/block_validation_tests.cpp @@ -34,7 +34,7 @@ struct BlockValidationFixture : public TestChain100Setup { BlockValidationFixture() { - VeriBlock::InitConfig(); + auto& config = VeriBlock::InitConfig(); VeriBlock::InitUtilService(); CBlockIndex* endorsedBlockIndex = ChainActive().Tip()->pprev; @@ -43,6 +43,25 @@ struct BlockValidationFixture : public TestChain100Setup { stream = std::make_shared(SER_NETWORK, PROTOCOL_VERSION); *stream << endorsedBlock.GetBlockHeader(); + + When(OverloadedMethod(pop_impl_mock, getPublicationsData, void(const VeriBlock::Publications&, VeriBlock::PublicationData&))) + .Do([&](const VeriBlock::Publications& pub, VeriBlock::PublicationData& publicationData) { + publicationData.set_identifier(config.index.unwrap()); + publicationData.set_header(stream->data(), stream->size()); + }); + When(Method(pop_impl_mock, parsePopTx)).AlwaysDo([](const CTransactionRef& tx, VeriBlock::Publications* pub, VeriBlock::Context* ctx, VeriBlock::PopTxType* type) -> bool { + std::vector> stack; + return VeriBlock::EvalScriptImpl(tx->vin[0].scriptSig, stack, nullptr, pub, ctx, type, false); + }); + When(Method(pop_impl_mock, determineATVPlausibilityWithBTCRules)).AlwaysReturn(true); + Fake(Method(pop_impl_mock, addPayloads)); + Fake(Method(pop_impl_mock, updateContext)); + + When(Method(pop_service_mock, checkVTBinternally)).AlwaysReturn(true); + When(Method(pop_service_mock, checkATVinternally)).AlwaysReturn(true); + When(Method(pop_service_mock, blockPopValidation)).AlwaysDo([&](const CBlock& block, const CBlockIndex& pindexPrev, const Consensus::Params& params, BlockValidationState& state) -> bool { + return VeriBlock::blockPopValidationImpl(pop_impl_mock.get(), block, pindexPrev, params, state); + }); }; std::shared_ptr stream; @@ -50,30 +69,65 @@ struct BlockValidationFixture : public TestChain100Setup { BOOST_AUTO_TEST_SUITE(block_validation_tests) +BOOST_FIXTURE_TEST_CASE(BlockWith256PublicationTxes, BlockValidationFixture) +{ + std::vector pubs; + for (size_t i = 0; i < 256 /* more than 50 */; ++i) { + CScript script; + script << std::vector{(uint8_t)i}; + pubs.emplace_back(VeriBlock::MakePopTx(script)); + } + + bool isBlockValid = true; + auto block = CreateAndProcessBlock(pubs, cbKey, &isBlockValid); + BOOST_CHECK(!isBlockValid); +} -BOOST_FIXTURE_TEST_CASE(BlockWithBothPopTxes, BlockValidationFixture) +BOOST_FIXTURE_TEST_CASE(BlockWithMaxNumberOfPublicationTxes, BlockValidationFixture) { auto& config = VeriBlock::getService(); + std::vector pubs; + for (size_t i = 0; i < std::min(config.max_pop_tx_amount, 256u); ++i) { + CScript script; + script << std::vector{(uint8_t)i}; + pubs.emplace_back(VeriBlock::MakePopTx(script)); + } + + bool isBlockValid = true; + auto block = CreateAndProcessBlock(pubs, cbKey, &isBlockValid); + BOOST_CHECK(isBlockValid); + BOOST_CHECK(block.vtx.size() == config.max_pop_tx_amount + 1 /* coinbase */); +} - When(OverloadedMethod(pop_impl_mock, getPublicationsData, void(const VeriBlock::Publications&, VeriBlock::PublicationData&))) - .Do([&](const VeriBlock::Publications& pub, VeriBlock::PublicationData& publicationData) { - publicationData.set_identifier(config.index.unwrap()); - publicationData.set_header(stream->data(), stream->size()); - }); - When(Method(pop_impl_mock, parsePopTx)).AlwaysDo([](const CTransactionRef& tx, VeriBlock::Publications* pub, VeriBlock::Context* ctx, VeriBlock::PopTxType* type) -> bool { - std::vector> stack; - return VeriBlock::EvalScriptImpl(tx->vin[0].scriptSig, stack, nullptr, pub, ctx, type, false); +BOOST_FIXTURE_TEST_CASE(BlockWith1000ContextTxes, BlockValidationFixture) +{ + std::vector pubs; + std::generate_n(std::back_inserter(pubs), 1000, [&]() { + return VeriBlock::MakePopTx(ctxscript); }); - When(Method(pop_impl_mock, determineATVPlausibilityWithBTCRules)).AlwaysReturn(true); - Fake(Method(pop_impl_mock, addPayloads)); - Fake(Method(pop_impl_mock, updateContext)); - - When(Method(pop_service_mock, checkVTBinternally)).AlwaysReturn(true); - When(Method(pop_service_mock, checkATVinternally)).AlwaysReturn(true); - When(Method(pop_service_mock, blockPopValidation)).AlwaysDo([&](const CBlock& block, const CBlockIndex& pindexPrev, const Consensus::Params& params, BlockValidationState& state) -> bool { - return VeriBlock::blockPopValidationImpl(pop_impl_mock.get(), block, pindexPrev, params, state); + + bool isBlockValid = true; + auto block = CreateAndProcessBlock(pubs, cbKey, &isBlockValid); + BOOST_CHECK(!isBlockValid); +} + +BOOST_FIXTURE_TEST_CASE(BlockWithMaxContextTxes, BlockValidationFixture) +{ + auto& config = VeriBlock::getService(); + std::vector pubs; + std::generate_n(std::back_inserter(pubs), config.max_update_context_tx_amount, [&]() { + return VeriBlock::MakePopTx(ctxscript); }); + bool isBlockValid = true; + auto block = CreateAndProcessBlock(pubs, cbKey, &isBlockValid); + BOOST_CHECK(isBlockValid); + BOOST_CHECK(block.vtx.size() == config.max_update_context_tx_amount + 1 /* coinbase */); +} + + +BOOST_FIXTURE_TEST_CASE(BlockWithBothPopTxes, BlockValidationFixture) +{ VeriBlock::Context ctx; ctx.btc.push_back(btc_header); ctx.vbk.push_back(vbk_header); diff --git a/src/vbk/test/unit/pop_reward_tests.cpp b/src/vbk/test/unit/pop_reward_tests.cpp index 72e44c456d142..e344d50bec37e 100644 --- a/src/vbk/test/unit/pop_reward_tests.cpp +++ b/src/vbk/test/unit/pop_reward_tests.cpp @@ -152,7 +152,7 @@ BOOST_FIXTURE_TEST_CASE(check_wallet_balance_with_pop_reward, PopRewardsTestFixt { CWallet wallet(&chain, WalletLocation(), WalletDatabase::CreateDummy()); { - LOCK(wallet.cs_wallet); + LOCK(wallet.GetLegacyScriptPubKeyMan()->cs_wallet); // add Pubkey to wallet BOOST_REQUIRE(wallet.GetLegacyScriptPubKeyMan()->AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey())); } From 075acd4a99248a11317d936dddd9875280c35ba0 Mon Sep 17 00:00:00 2001 From: Bohdan Vanieiev Date: Wed, 22 Jan 2020 18:15:15 +0200 Subject: [PATCH 2/7] Add tests --- src/vbk/test/unit/block_validation_tests.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vbk/test/unit/block_validation_tests.cpp b/src/vbk/test/unit/block_validation_tests.cpp index e2f68a5a3f619..33f8fb573f50b 100644 --- a/src/vbk/test/unit/block_validation_tests.cpp +++ b/src/vbk/test/unit/block_validation_tests.cpp @@ -45,7 +45,7 @@ struct BlockValidationFixture : public TestChain100Setup { *stream << endorsedBlock.GetBlockHeader(); When(OverloadedMethod(pop_impl_mock, getPublicationsData, void(const VeriBlock::Publications&, VeriBlock::PublicationData&))) - .Do([&](const VeriBlock::Publications& pub, VeriBlock::PublicationData& publicationData) { + .AlwaysDo([&](const VeriBlock::Publications& pub, VeriBlock::PublicationData& publicationData) { publicationData.set_identifier(config.index.unwrap()); publicationData.set_header(stream->data(), stream->size()); }); @@ -74,7 +74,7 @@ BOOST_FIXTURE_TEST_CASE(BlockWith256PublicationTxes, BlockValidationFixture) std::vector pubs; for (size_t i = 0; i < 256 /* more than 50 */; ++i) { CScript script; - script << std::vector{(uint8_t)i}; + script << std::vector{10, (uint8_t)i} << OP_CHECKATV << OP_CHECKPOP; pubs.emplace_back(VeriBlock::MakePopTx(script)); } @@ -89,7 +89,7 @@ BOOST_FIXTURE_TEST_CASE(BlockWithMaxNumberOfPublicationTxes, BlockValidationFixt std::vector pubs; for (size_t i = 0; i < std::min(config.max_pop_tx_amount, 256u); ++i) { CScript script; - script << std::vector{(uint8_t)i}; + script << std::vector{10, (uint8_t)i} << OP_CHECKATV << OP_CHECKPOP; pubs.emplace_back(VeriBlock::MakePopTx(script)); } From 11f28d5ecb5589b73db64f121b23099a32a2eeb4 Mon Sep 17 00:00:00 2001 From: Bohdan Vanieiev Date: Wed, 22 Jan 2020 18:15:55 +0200 Subject: [PATCH 3/7] Make autoconfig false by default --- src/bitcoind.cpp | 2 +- src/qt/bitcoin.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 1b0dde2ede2de..91fb24adc2c58 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -111,7 +111,7 @@ static bool AppInit(int argc, char* argv[]) VeriBlock::InitPopService( gArgs.GetArg("-althost", "127.0.0.1"), gArgs.GetArg("-altport", "19012"), - gArgs.GetBoolArg("-altautoconfig", true)); + gArgs.GetBoolArg("-altautoconfig", false)); if (!AppInitBasicSetup()) { diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index aab5e3766f352..642aec3512d4d 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -529,7 +529,7 @@ int GuiMain(int argc, char* argv[]) VeriBlock::InitPopService( gArgs.GetArg("-althost", "127.0.0.1"), gArgs.GetArg("-altport", "19012"), - gArgs.GetBoolArg("-altautoconfig", true)); + gArgs.GetBoolArg("-altautoconfig", false)); QScopedPointer networkStyle(NetworkStyle::instantiate(Params().NetworkIDString())); assert(!networkStyle.isNull()); From 00298145480ef743cb848c1b9dd9ea9252c90529 Mon Sep 17 00:00:00 2001 From: Bohdan Vanieiev Date: Wed, 22 Jan 2020 18:21:46 +0200 Subject: [PATCH 4/7] Disable CD on pull requests --- .github/workflows/cd.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 27c4b4dae2644..4c16ba997c34a 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -6,10 +6,6 @@ on: - master - develop - feature/* - pull_request: - branches: - - master - - develop jobs: build: From 372beb145ad2be1054c41cc56b554fc303b1d7bd Mon Sep 17 00:00:00 2001 From: Bohdan Vanieiev Date: Wed, 22 Jan 2020 19:11:27 +0200 Subject: [PATCH 5/7] Refactor a bit --- src/vbk/pop_service/pop_service_impl.cpp | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/vbk/pop_service/pop_service_impl.cpp b/src/vbk/pop_service/pop_service_impl.cpp index 5fdc0b8270f8a..e54d053377528 100644 --- a/src/vbk/pop_service/pop_service_impl.cpp +++ b/src/vbk/pop_service/pop_service_impl.cpp @@ -14,8 +14,8 @@ #include