-
-
Notifications
You must be signed in to change notification settings - Fork 369
Evo: handle validation failures gracefully #1931
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
Open
navidR
wants to merge
1
commit into
firoorg:master
Choose a base branch
from
navidR:dev/navidr/graceful-evo-validation-failures
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // Copyright (c) 2026 The Firo Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include "test/test_bitcoin.h" | ||
|
|
||
| #include "chainparams.h" | ||
| #include "compat/endian.h" | ||
| #include "consensus/validation.h" | ||
| #include "evo/cbtx.h" | ||
| #include "evo/deterministicmns.h" | ||
| #include "evo/evodb.h" | ||
| #include "llmq/quorums_blockprocessor.h" | ||
| #include "primitives/block.h" | ||
| #include "primitives/transaction.h" | ||
| #include "validation.h" | ||
|
|
||
| #include <array> | ||
| #include <boost/test/unit_test.hpp> | ||
| #include <cstdint> | ||
| #include <limits> | ||
| #include <string> | ||
| #include <tuple> | ||
|
|
||
| namespace | ||
| { | ||
|
|
||
| struct EvoValidationTestingSetup : BasicTestingSetup { | ||
| std::array<uint256, 101> blockHashes; | ||
| std::array<CBlockIndex, 101> blockIndexes; | ||
| llmq::CQuorumBlockProcessor processor; | ||
| llmq::CQuorumBlockProcessor* previousProcessor; | ||
|
|
||
| EvoValidationTestingSetup() : BasicTestingSetup(CBaseChainParams::REGTEST), | ||
| processor(*evoDb), | ||
| previousProcessor(llmq::quorumBlockProcessor) | ||
| { | ||
| for (size_t i = 0; i < blockIndexes.size(); ++i) { | ||
| const uint32_t encodedHeight = static_cast<uint32_t>(i + 1); | ||
| for (size_t byte = 0; byte < sizeof(encodedHeight); ++byte) { | ||
| blockHashes[i].begin()[byte] = static_cast<unsigned char>(encodedHeight >> (byte * 8)); | ||
| } | ||
|
|
||
| blockIndexes[i].nHeight = static_cast<int>(i); | ||
| blockIndexes[i].pprev = i == 0 ? nullptr : &blockIndexes[i - 1]; | ||
| blockIndexes[i].phashBlock = &blockHashes[i]; | ||
| blockIndexes[i].BuildSkip(); | ||
| } | ||
|
|
||
| llmq::quorumBlockProcessor = &processor; | ||
| } | ||
|
|
||
| ~EvoValidationTestingSetup() | ||
| { | ||
| llmq::quorumBlockProcessor = previousProcessor; | ||
| } | ||
|
|
||
| const CBlockIndex* Tip() const | ||
| { | ||
| return &blockIndexes.back(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| BOOST_AUTO_TEST_SUITE(evo_validation_tests) | ||
|
|
||
| static CTransactionRef MakeMalformedSpecialTx(int32_t type) | ||
| { | ||
| CMutableTransaction tx; | ||
| tx.nVersion = 3; | ||
| tx.nType = type; | ||
| return MakeTransactionRef(tx); | ||
| } | ||
|
|
||
| static CBlock MakeMalformedSpecialTxBlock(int32_t type) | ||
| { | ||
| CBlock block; | ||
| block.vtx.emplace_back(MakeTransactionRef(CMutableTransaction())); | ||
| block.vtx.emplace_back(MakeMalformedSpecialTx(type)); | ||
| return block; | ||
| } | ||
|
|
||
| BOOST_FIXTURE_TEST_CASE(evo_helpers_reject_invalid_state_without_asserting, EvoValidationTestingSetup) | ||
| { | ||
| const CBlockIndex* pindexPrev = Tip(); | ||
|
|
||
| const std::array<int32_t, 5> specialTxTypes{ | ||
| TRANSACTION_PROVIDER_REGISTER, | ||
| TRANSACTION_PROVIDER_UPDATE_SERVICE, | ||
| TRANSACTION_PROVIDER_UPDATE_REGISTRAR, | ||
| TRANSACTION_PROVIDER_UPDATE_REVOKE, | ||
| TRANSACTION_QUORUM_COMMITMENT, | ||
| }; | ||
|
|
||
| for (const int32_t type : specialTxTypes) { | ||
| CValidationState state; | ||
| CDeterministicMNList list; | ||
| const CBlock block = MakeMalformedSpecialTxBlock(type); | ||
| bool result; | ||
| { | ||
| LOCK(deterministicMNManager->cs); | ||
| result = deterministicMNManager->BuildNewListFromBlock(block, pindexPrev, state, list, false); | ||
| } | ||
|
|
||
| BOOST_CHECK(!result); | ||
| BOOST_CHECK(state.IsInvalid()); | ||
| BOOST_CHECK_EQUAL(state.GetRejectReason(), type == TRANSACTION_QUORUM_COMMITMENT ? "bad-qc-payload" : "bad-protx-payload"); | ||
| } | ||
|
|
||
| { | ||
| CValidationState state; | ||
| uint256 merkleRoot; | ||
| const CBlock block = MakeMalformedSpecialTxBlock(TRANSACTION_QUORUM_COMMITMENT); | ||
|
|
||
| BOOST_CHECK(!CalcCbTxMerkleRootQuorums(block, pindexPrev, merkleRoot, state)); | ||
| BOOST_CHECK(state.IsInvalid()); | ||
| BOOST_CHECK_EQUAL(state.GetRejectReason(), "bad-qc-payload"); | ||
| } | ||
|
|
||
| const auto llmqType = Params().GetConsensus().llmqs.begin()->first; | ||
| const uint32_t minedHeight = static_cast<uint32_t>(pindexPrev->nHeight); | ||
| const auto inverseHeightKey = std::make_tuple( | ||
| std::string("q_mcih"), | ||
| static_cast<uint8_t>(llmqType), | ||
| htobe32(std::numeric_limits<uint32_t>::max() - minedHeight)); | ||
| BOOST_REQUIRE(!evoDb->Exists(inverseHeightKey)); | ||
|
|
||
| auto dbTransaction = evoDb->BeginTransaction(); | ||
| evoDb->Write(inverseHeightKey, 0); | ||
|
|
||
| CValidationState state; | ||
| uint256 merkleRoot; | ||
| CBlock block; | ||
| BOOST_CHECK(!CalcCbTxMerkleRootQuorums(block, pindexPrev, merkleRoot, state)); | ||
| BOOST_CHECK(state.IsInvalid()); | ||
| BOOST_CHECK_EQUAL(state.GetRejectReason(), "commitment-not-found"); | ||
| dbTransaction->Rollback(); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_SUITE_END() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the Evo DB's inverse-height index points to a missing commitment record—the exact local inconsistency constructed by the new regression test—this failure is unrelated to the candidate block or its sending peer. Returning
state.DoS(100, ...)makesCheckCbTxMerkleRootsclassify an otherwise valid block as consensus-invalid and allowsBlockCheckedto penalize the peer; it can also leave the block marked invalid until manual recovery. Report this asstate.Error(...)so the node surfaces its local database failure without blaming network input.Useful? React with 👍 / 👎.