From f1e0d4459a09c18b50312efa7b94bf817d7253f2 Mon Sep 17 00:00:00 2001 From: Alexey Poghilenkov Date: Mon, 3 Feb 2020 11:50:14 +0900 Subject: [PATCH 1/2] change the endorsedBlock validation --- src/vbk/pop_service/pop_service_impl.cpp | 4 ++-- src/vbk/test/unit/pop_service_tests.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/vbk/pop_service/pop_service_impl.cpp b/src/vbk/pop_service/pop_service_impl.cpp index 2c01d04696978..fe4904e336b22 100644 --- a/src/vbk/pop_service/pop_service_impl.cpp +++ b/src/vbk/pop_service/pop_service_impl.cpp @@ -597,8 +597,8 @@ bool txPopValidation(PopServiceImpl& pop, const CTransactionRef& tx, const CBloc AssertLockHeld(cs_main); const CBlockIndex* popEndorsementIdnex = LookupBlockIndex(popEndorsementHeader.GetHash()); - if (popEndorsementIdnex == nullptr || pindexPrev.GetAncestor(popEndorsementIdnex->nHeight) == nullptr) { - return state.Invalid(TxValidationResult::TX_BAD_POP_DATA, "pop-tx-endorsed-block-not-from-this-chain", strprintf("[%s] can not find endorsed block in this chain: %s", tx->GetHash().ToString(), popEndorsementHeader.GetHash().ToString())); + if (popEndorsementIdnex == nullptr || !ChainActive().Contains(popEndorsementIdnex)) { + return state.Invalid(TxValidationResult::TX_BAD_POP_DATA, "pop-tx-endorsed-block-not-from-this-main-chain", strprintf("[%s] can not find endorsed block in this chain: %s", tx->GetHash().ToString(), popEndorsementHeader.GetHash().ToString())); } CBlock popEndorsementBlock; diff --git a/src/vbk/test/unit/pop_service_tests.cpp b/src/vbk/test/unit/pop_service_tests.cpp index c62fbb7a20baf..77aaf6b120743 100644 --- a/src/vbk/test/unit/pop_service_tests.cpp +++ b/src/vbk/test/unit/pop_service_tests.cpp @@ -107,7 +107,7 @@ BOOST_FIXTURE_TEST_CASE(blockPopValidation_test_wrong_index, PopServiceFixture) Verify_Method(Method(pop_service_impl_mock, removePayloads)).Once(); } -BOOST_FIXTURE_TEST_CASE(blockPopValidation_test_wrong_ancestor, PopServiceFixture) +BOOST_FIXTURE_TEST_CASE(blockPopValidation_test_endorsed_block_not_from_main_chain, PopServiceFixture) { CBlockIndex* endorsedBlockIndex = ChainActive().Tip()->pprev->pprev->pprev; CBlock endorsedBlock; @@ -123,7 +123,6 @@ BOOST_FIXTURE_TEST_CASE(blockPopValidation_test_wrong_ancestor, PopServiceFixtur BlockValidationState state; InvalidateBlock(state, Params(), endorsedBlockIndex); ActivateBestChain(state, Params()); - ChainstateActive().ActivateBestChain(state, Params(), nullptr); BOOST_CHECK(ChainActive().Height() < prevHeight); CBlock block = createBlockWithPopTx(*this); From 24c6e8de89ff9117c01f9551ca952d35a4e9b12b Mon Sep 17 00:00:00 2001 From: Alexey Poghilenkov Date: Mon, 3 Feb 2020 11:51:50 +0900 Subject: [PATCH 2/2] fix --- src/vbk/pop_service/pop_service_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vbk/pop_service/pop_service_impl.cpp b/src/vbk/pop_service/pop_service_impl.cpp index fe4904e336b22..5c02fe993287c 100644 --- a/src/vbk/pop_service/pop_service_impl.cpp +++ b/src/vbk/pop_service/pop_service_impl.cpp @@ -598,7 +598,7 @@ bool txPopValidation(PopServiceImpl& pop, const CTransactionRef& tx, const CBloc AssertLockHeld(cs_main); const CBlockIndex* popEndorsementIdnex = LookupBlockIndex(popEndorsementHeader.GetHash()); if (popEndorsementIdnex == nullptr || !ChainActive().Contains(popEndorsementIdnex)) { - return state.Invalid(TxValidationResult::TX_BAD_POP_DATA, "pop-tx-endorsed-block-not-from-this-main-chain", strprintf("[%s] can not find endorsed block in this chain: %s", tx->GetHash().ToString(), popEndorsementHeader.GetHash().ToString())); + return state.Invalid(TxValidationResult::TX_BAD_POP_DATA, "pop-tx-endorsed-block-not-from-this-main-chain", strprintf("[%s] can not find endorsed block in the main chain: %s", tx->GetHash().ToString(), popEndorsementHeader.GetHash().ToString())); } CBlock popEndorsementBlock;