Changeset View
Changeset View
Standalone View
Standalone View
src/test/miner_tests.cpp
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | void TestPackageSelection(Config &config, CScript scriptPubKey, | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate = | std::unique_ptr<CBlockTemplate> pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetId() == parentTxId); | BOOST_CHECK(pblocktemplate->block.vtx[1]->GetId() == parentTxId); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetId() == highFeeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[2]->GetId() == highFeeTxId); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[3]->GetId() == mediumFeeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[3]->GetId() == mediumFeeTxId); | ||||
// Test that a package below the block min tx fee doesn't get included | // Test that a package below the block min tx fee doesn't get included | ||||
tx.vin[0].prevout = COutPoint(highFeeTxId, 0); | tx.vin[0].prevout = COutPoint(txFirst[2]->GetId(), 0); | ||||
// 0 fee. | // 0 fee. | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; | tx.vout[0].nValue = int64_t(5000000000LL - 1000 - 50000) * SATOSHI; | ||||
TxId freeTxId = tx.GetId(); | TxId freeTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(freeTxId, entry.Fee(Amount::zero()).FromTx(tx)); | g_mempool.addUnchecked(freeTxId, entry.Fee(Amount::zero()).FromTx(tx)); | ||||
size_t freeTxSize = CTransaction(tx).GetBillableSize(); | size_t freeTxSize = CTransaction(tx).GetBillableSize(); | ||||
// Calculate a fee on child transaction that will put the package just | // Calculate a fee on child transaction that will put the package just | ||||
// below the block min tx fee (assuming 1 child tx of the same size). | // below the block min tx fee (assuming 1 child tx of the same size). | ||||
Show All 20 Lines | void TestPackageSelection(Config &config, CScript scriptPubKey, | ||||
tx.vout[0].nValue -= 2 * SATOSHI; | tx.vout[0].nValue -= 2 * SATOSHI; | ||||
lowFeeTxId = tx.GetId(); | lowFeeTxId = tx.GetId(); | ||||
g_mempool.addUnchecked(lowFeeTxId, | g_mempool.addUnchecked(lowFeeTxId, | ||||
entry.Fee(feeToUse + 2 * SATOSHI).FromTx(tx)); | entry.Fee(feeToUse + 2 * SATOSHI).FromTx(tx)); | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetId() == freeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[4]->GetId() == freeTxId); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetId() == lowFeeTxId); | BOOST_CHECK(pblocktemplate->block.vtx[5]->GetId() == lowFeeTxId); | ||||
// Test that transaction selection properly updates ancestor fee | // Test that transaction selection properly updates ancestor fee | ||||
// calculations as ancestor transactions get included in a block. Add a | // calculations as ancestor transactions get included in a block. Add a | ||||
// 0-fee transaction that has 2 outputs. | // 0-fee transaction that has 2 outputs. | ||||
tx.vin[0].prevout = COutPoint(txFirst[2]->GetId(), 0); | tx.vin[0].prevout = COutPoint(txFirst[3]->GetId(), 0); | ||||
tx.vout.resize(2); | tx.vout.resize(2); | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI; | tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI; | ||||
// 1BCC output. | // 1BCC output. | ||||
tx.vout[1].nValue = 100000000 * SATOSHI; | tx.vout[1].nValue = 100000000 * SATOSHI; | ||||
TxId freeTxId2 = tx.GetId(); | TxId freeTxId2 = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
freeTxId2, entry.Fee(Amount::zero()).SpendsCoinbase(true).FromTx(tx)); | freeTxId2, entry.Fee(Amount::zero()).SpendsCoinbase(true).FromTx(tx)); | ||||
// This tx can't be mined by itself. | // This tx can't be mined by itself. | ||||
tx.vin[0].prevout = COutPoint(freeTxId2, 0); | tx.vin[0].prevout = COutPoint(freeTxId2, 0); | ||||
tx.vout.resize(1); | tx.vout.resize(1); | ||||
feeToUse = blockMinFeeRate.GetFee(freeTxSize); | feeToUse = blockMinFeeRate.GetFee(freeTxSize + 10); | ||||
tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI - feeToUse; | tx.vout[0].nValue = int64_t(5000000000LL - 100000000) * SATOSHI - feeToUse; | ||||
TxId lowFeeTxId2 = tx.GetId(); | TxId lowFeeTxId2 = tx.GetId(); | ||||
g_mempool.addUnchecked( | g_mempool.addUnchecked( | ||||
lowFeeTxId2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx)); | lowFeeTxId2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx)); | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | ||||
// Verify that this tx isn't selected. | // Verify that this tx isn't selected. | ||||
for (const auto &txn : pblocktemplate->block.vtx) { | for (const auto &txn : pblocktemplate->block.vtx) { | ||||
BOOST_CHECK(txn->GetId() != freeTxId2); | BOOST_CHECK(txn->GetId() != freeTxId2); | ||||
BOOST_CHECK(txn->GetId() != lowFeeTxId2); | BOOST_CHECK(txn->GetId() != lowFeeTxId2); | ||||
} | } | ||||
// This tx will be mineable, and should cause lowFeeTxId2 to be selected as | // This tx will be mineable, and could hypothetically cause lowFeeTxId2 to | ||||
// well. | // be selected but shouldn't since we don't continue to update packages, and | ||||
// have no way of knowing that its parent has been mined. | |||||
tx.vin[0].prevout = COutPoint(freeTxId2, 1); | tx.vin[0].prevout = COutPoint(freeTxId2, 1); | ||||
// 10k satoshi fee. | // 10k satoshi fee. | ||||
tx.vout[0].nValue = (100000000 - 10000) * SATOSHI; | tx.vout[0].nValue = (100000000 - 10000) * SATOSHI; | ||||
g_mempool.addUnchecked(tx.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx)); | g_mempool.addUnchecked(tx.GetId(), entry.Fee(10000 * SATOSHI).FromTx(tx)); | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | BlockAssembler(config, g_mempool).CreateNewBlock(scriptPubKey); | ||||
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetId() == lowFeeTxId2); | // Verify lowFeeTxID still didn't make it in, because we don't update | ||||
// packages on the fly. | |||||
for (const auto &txn : pblocktemplate->block.vtx) { | |||||
BOOST_CHECK(txn->GetId() != lowFeeTxId2); | |||||
} | |||||
} | } | ||||
void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg) { | void TestCoinbaseMessageEB(uint64_t eb, std::string cbmsg) { | ||||
GlobalConfig config; | GlobalConfig config; | ||||
config.SetMaxBlockSize(eb); | config.SetMaxBlockSize(eb); | ||||
CScript scriptPubKey = | CScript scriptPubKey = | ||||
CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909" | CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909" | ||||
▲ Show 20 Lines • Show All 603 Lines • Show Last 20 Lines |