Skip to content

Commit

Permalink
Fix for ProRegTx transaction conflict (#1124)
Browse files Browse the repository at this point in the history
* Don't allow collateral spend in same block as proreg tx

* Fix to MN check condition

* Don't let miner include ProRegTx and transaction spending collateral into one block

* Version bump
  • Loading branch information
psolstice authored Jan 12, 2022
1 parent 02fff91 commit 2e2c2ff
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 14)
define(_CLIENT_VERSION_REVISION, 9)
define(_CLIENT_VERSION_BUILD, 2)
define(_CLIENT_VERSION_BUILD, 3)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2022)
define(_COPYRIGHT_HOLDERS,[The %s developers])
Expand Down
2 changes: 1 addition & 1 deletion src/clientversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define CLIENT_VERSION_MAJOR 0
#define CLIENT_VERSION_MINOR 14
#define CLIENT_VERSION_REVISION 9
#define CLIENT_VERSION_BUILD 2
#define CLIENT_VERSION_BUILD 3

//! Set to true for release, false for prerelease or test build
#define CLIENT_VERSION_IS_RELEASE true
Expand Down
4 changes: 4 additions & 0 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,10 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
for (const auto& in : tx.vin) {
auto dmn = newList.GetMNByCollateral(in.prevout);
if (dmn && dmn->collateralOutpoint == in.prevout) {
// can't spend collateral funded by proreg tx in the same block
if (dmn->pdmnState && dmn->collateralOutpoint.hash == dmn->proTxHash && dmn->pdmnState->nRegisteredHeight == nHeight)
return _state.DoS(100, false, REJECT_CONFLICT, "bad-protx-collateral-spend");

newList.RemoveMN(dmn->proTxHash);

if (debugLogs) {
Expand Down
27 changes: 21 additions & 6 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,27 @@ void BlockAssembler::FillBlackListForBlockTemplate() {

if (tx.nVersion >= 3 && tx.nType == TRANSACTION_PROVIDER_REGISTER) {
CProRegTx proTx;
if (GetTxPayload(tx, proTx) && !proTx.collateralOutpoint.hash.IsNull() &&
// ProRegTx referencing external collateral can't be in same block with the collateral itself
(mempool.get(proTx.collateralOutpoint.hash) ||
// ProRegTx cannot be in the same block as transaction spending external collateral
mempool.isSpent(proTx.collateralOutpoint)))
mempool.CalculateDescendants(mi, txBlackList);
if (GetTxPayload(tx, proTx)) {
if (!proTx.collateralOutpoint.hash.IsNull()) {
if (
// ProRegTx referencing external collateral can't be in same block with the collateral itself
mempool.get(proTx.collateralOutpoint.hash) ||
// ProRegTx cannot be in the same block as transaction spending external collateral
mempool.isSpent(proTx.collateralOutpoint))
mempool.CalculateDescendants(mi, txBlackList);
}
else {
COutPoint fundedCollateral(mi->GetTx().GetHash(), proTx.collateralOutpoint.n);
if (mempool.isSpent(fundedCollateral)) {
// Transaction spending collateral funded by ProRegTx cannot be in the same block
// We need to blacklist spending tx otherwise two transactions will stuck in the mempool forever.
// Easiest way to do it is to block all the descendants (spending transaction is technically a
// descendant here) but let the ProRegTx into the block.
mempool.CalculateDescendants(mi, txBlackList);
txBlackList.erase(mi);
}
}
}
}

if (tx.nVersion >= 3 && tx.nType == TRANSACTION_SPORK) {
Expand Down

0 comments on commit 2e2c2ff

Please sign in to comment.