-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: simplify asset lock validation code #7284
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
| #include <memory> | ||
| #include <stack> | ||
|
|
||
| using node::BlockManager; | ||
| using node::ReadBlockFromDisk; | ||
|
|
||
| // Forward declaration to prevent a new circular dependencies through masternode/payments.h | ||
|
|
@@ -248,8 +247,7 @@ CCreditPoolManager::~CCreditPoolManager() = default; | |
|
|
||
| CCreditPoolDiff::CCreditPoolDiff(CCreditPool starter, const CBlockIndex* pindexPrev, | ||
| const Consensus::Params& consensusParams, const CAmount blockSubsidy) : | ||
| pool(std::move(starter)), | ||
| pindexPrev(pindexPrev) | ||
| pool(std::move(starter)) | ||
| { | ||
| assert(pindexPrev); | ||
|
|
||
|
|
@@ -297,15 +295,9 @@ bool CCreditPoolDiff::Unlock(const CTransaction& tx, TxValidationState& state) | |
| return true; | ||
| } | ||
|
|
||
| bool CCreditPoolDiff::ProcessLockUnlockTransaction(const BlockManager& blockman, const llmq::CQuorumManager& qman, const CTransaction& tx, TxValidationState& state) | ||
| bool CCreditPoolDiff::ProcessLockUnlockTransaction(const CTransaction& tx, TxValidationState& state) | ||
| { | ||
| if (!tx.IsSpecialTxVersion()) return true; | ||
| if (tx.nType != TRANSACTION_ASSET_LOCK && tx.nType != TRANSACTION_ASSET_UNLOCK) return true; | ||
|
|
||
| if (!CheckAssetLockUnlockTx(blockman, qman, tx, pindexPrev, pool.indexes, state)) { | ||
| // pass the state returned by the function above | ||
| return false; | ||
| } | ||
|
|
||
|
knst marked this conversation as resolved.
|
||
| try { | ||
|
knst marked this conversation as resolved.
knst marked this conversation as resolved.
|
||
| switch (tx.nType) { | ||
|
Comment on lines
300
to
303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Credit pool related checks are still there: mempool validate all other consensus relevant conditions such as pre-v24 activation ; wrong OP_RETURN utxo, etc.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate with #7284 (comment) resolved block assembly |
||
|
|
@@ -322,7 +314,7 @@ bool CCreditPoolDiff::ProcessLockUnlockTransaction(const BlockManager& blockman, | |
| } | ||
|
Comment on lines
302
to
314
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick: try/catch in ProcessLockUnlockTransaction is now effectively dead With source: ['claude'] |
||
| } | ||
|
Comment on lines
298
to
315
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking: Mining path loses height/quorum-sensitive asset unlock validation
source: ['codex'] 🤖 Fix this with AI agents
Comment on lines
298
to
315
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: Implicit invariant: ProcessLockUnlockTransaction now relies on caller-side validation After this PR, ProcessLockUnlockTransaction no longer calls CheckAssetLockTx/CheckAssetUnlockTx. Correctness depends on the caller having validated the transaction beforehand: ConnectBlock validates via CheckSpecialTxInner (specialtxman.cpp) before CheckCreditPoolDiffForBlock; the miner relies on mempool acceptance for ASSET_LOCK and re-checks ASSET_UNLOCK explicitly in addPackageTxs. This is a non-obvious precondition. A short comment above ProcessLockUnlockTransaction documenting that callers must ensure CheckAssetLockTx/CheckAssetUnlockTx has run would prevent future regressions where a new caller skips the upstream validation. source: ['claude'] 🤖 Fix this with AI agents |
||
|
|
||
| std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, const BlockManager& blockman, const llmq::CQuorumManager& qman, | ||
| std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpoolman, | ||
| const CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams, | ||
| const CAmount blockSubsidy, BlockValidationState& state) | ||
| { | ||
|
|
@@ -333,7 +325,7 @@ std::optional<CCreditPoolDiff> GetCreditPoolDiffForBlock(CCreditPoolManager& cpo | |
| for (size_t i = 1; i < block.vtx.size(); ++i) { | ||
| const auto& tx = *block.vtx[i]; | ||
| TxValidationState tx_state; | ||
| if (!creditPoolDiff.ProcessLockUnlockTransaction(blockman, qman, tx, tx_state)) { | ||
| if (!creditPoolDiff.ProcessLockUnlockTransaction(tx, tx_state)) { | ||
| assert(tx_state.GetResult() == TxValidationResult::TX_CONSENSUS); | ||
| state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, tx_state.GetRejectReason(), | ||
| strprintf("Process Lock/Unlock Transaction failed at Credit Pool (tx hash %s) %s", tx.GetHash().ToString(), tx_state.GetDebugMessage())); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.