Remove mempool transactions which commit to an unmineable branch ID
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "consensus/upgrades.h"
|
||||
#include "main.h"
|
||||
#include "txmempool.h"
|
||||
#include "util.h"
|
||||
@@ -156,4 +157,59 @@ BOOST_AUTO_TEST_CASE(MempoolIndexingTest)
|
||||
BOOST_CHECK(it == pool.mapTx.get<1>().end());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(RemoveWithoutBranchId) {
|
||||
CTxMemPool pool(CFeeRate(0));
|
||||
TestMemPoolEntryHelper entry;
|
||||
entry.nFee = 10000LL;
|
||||
entry.hadNoDependencies = true;
|
||||
|
||||
// Add some Sprout transactions
|
||||
for (auto i = 1; i < 11; i++) {
|
||||
CMutableTransaction tx = CMutableTransaction();
|
||||
tx.vout.resize(1);
|
||||
tx.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||
tx.vout[0].nValue = i * COIN;
|
||||
pool.addUnchecked(tx.GetHash(), entry.BranchId(NetworkUpgradeInfo[Consensus::BASE_SPROUT].nBranchId).FromTx(tx));
|
||||
}
|
||||
BOOST_CHECK_EQUAL(pool.size(), 10);
|
||||
|
||||
// Check the pool only contains Sprout transactions
|
||||
for (CTxMemPool::indexed_transaction_set::const_iterator it = pool.mapTx.begin(); it != pool.mapTx.end(); it++) {
|
||||
BOOST_CHECK_EQUAL(it->GetValidatedBranchId(), NetworkUpgradeInfo[Consensus::BASE_SPROUT].nBranchId);
|
||||
}
|
||||
|
||||
// Add some dummy transactions
|
||||
for (auto i = 1; i < 11; i++) {
|
||||
CMutableTransaction tx = CMutableTransaction();
|
||||
tx.vout.resize(1);
|
||||
tx.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||
tx.vout[0].nValue = i * COIN + 100;
|
||||
pool.addUnchecked(tx.GetHash(), entry.BranchId(NetworkUpgradeInfo[Consensus::UPGRADE_TESTDUMMY].nBranchId).FromTx(tx));
|
||||
}
|
||||
BOOST_CHECK_EQUAL(pool.size(), 20);
|
||||
|
||||
// Add some Overwinter transactions
|
||||
for (auto i = 1; i < 11; i++) {
|
||||
CMutableTransaction tx = CMutableTransaction();
|
||||
tx.vout.resize(1);
|
||||
tx.vout[0].scriptPubKey = CScript() << OP_11 << OP_EQUAL;
|
||||
tx.vout[0].nValue = i * COIN + 200;
|
||||
pool.addUnchecked(tx.GetHash(), entry.BranchId(NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].nBranchId).FromTx(tx));
|
||||
}
|
||||
BOOST_CHECK_EQUAL(pool.size(), 30);
|
||||
|
||||
// Remove transactions that are not for Overwinter
|
||||
pool.removeWithoutBranchId(NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].nBranchId);
|
||||
BOOST_CHECK_EQUAL(pool.size(), 10);
|
||||
|
||||
// Check the pool only contains Overwinter transactions
|
||||
for (CTxMemPool::indexed_transaction_set::const_iterator it = pool.mapTx.begin(); it != pool.mapTx.end(); it++) {
|
||||
BOOST_CHECK_EQUAL(it->GetValidatedBranchId(), NetworkUpgradeInfo[Consensus::UPGRADE_OVERWINTER].nBranchId);
|
||||
}
|
||||
|
||||
// Roll back to Sprout
|
||||
pool.removeWithoutBranchId(NetworkUpgradeInfo[Consensus::BASE_SPROUT].nBranchId);
|
||||
BOOST_CHECK_EQUAL(pool.size(), 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -106,7 +106,8 @@ TestingSetup::~TestingSetup()
|
||||
|
||||
CTxMemPoolEntry TestMemPoolEntryHelper::FromTx(CMutableTransaction &tx, CTxMemPool *pool) {
|
||||
return CTxMemPoolEntry(tx, nFee, nTime, dPriority, nHeight,
|
||||
pool ? pool->HasNoInputsOf(tx) : hadNoDependencies, spendsCoinbase);
|
||||
pool ? pool->HasNoInputsOf(tx) : hadNoDependencies,
|
||||
spendsCoinbase, nBranchId);
|
||||
}
|
||||
|
||||
void Shutdown(void* parg)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef BITCOIN_TEST_TEST_BITCOIN_H
|
||||
#define BITCOIN_TEST_TEST_BITCOIN_H
|
||||
|
||||
#include "consensus/upgrades.h"
|
||||
#include "pubkey.h"
|
||||
#include "txdb.h"
|
||||
|
||||
@@ -48,10 +49,12 @@ struct TestMemPoolEntryHelper
|
||||
unsigned int nHeight;
|
||||
bool hadNoDependencies;
|
||||
bool spendsCoinbase;
|
||||
uint32_t nBranchId;
|
||||
|
||||
TestMemPoolEntryHelper() :
|
||||
nFee(0), nTime(0), dPriority(0.0), nHeight(1),
|
||||
hadNoDependencies(false), spendsCoinbase(false) { }
|
||||
hadNoDependencies(false), spendsCoinbase(false),
|
||||
nBranchId(SPROUT_BRANCH_ID) { }
|
||||
|
||||
CTxMemPoolEntry FromTx(CMutableTransaction &tx, CTxMemPool *pool = NULL);
|
||||
|
||||
@@ -62,5 +65,6 @@ struct TestMemPoolEntryHelper
|
||||
TestMemPoolEntryHelper &Height(unsigned int _height) { nHeight = _height; return *this; }
|
||||
TestMemPoolEntryHelper &HadNoDependencies(bool _hnd) { hadNoDependencies = _hnd; return *this; }
|
||||
TestMemPoolEntryHelper &SpendsCoinbase(bool _flag) { spendsCoinbase = _flag; return *this; }
|
||||
TestMemPoolEntryHelper &BranchId(uint32_t _branchId) { nBranchId = _branchId; return *this; }
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user