|
|
@ -122,7 +122,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
|
|
|
|
uint256 hashHighFeeTx = tx.GetHash();
|
|
|
|
uint256 hashHighFeeTx = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey);
|
|
|
|
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
|
|
|
|
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 4U);
|
|
|
|
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 4U);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
|
|
|
@ -143,7 +143,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
|
|
|
|
tx.vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
|
|
|
|
tx.vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
|
|
|
|
uint256 hashLowFeeTx = tx.GetHash();
|
|
|
|
uint256 hashLowFeeTx = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(feeToUse).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(feeToUse).FromTx(tx));
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey);
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
|
|
|
|
// Verify that the free tx and the low fee tx didn't get selected
|
|
|
|
// Verify that the free tx and the low fee tx didn't get selected
|
|
|
|
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
|
|
|
|
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx);
|
|
|
@ -157,7 +157,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
|
|
|
|
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
|
|
|
|
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
|
|
|
|
hashLowFeeTx = tx.GetHash();
|
|
|
|
hashLowFeeTx = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(feeToUse+2).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(feeToUse+2).FromTx(tx));
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey);
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
|
|
|
|
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 6U);
|
|
|
|
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 6U);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);
|
|
|
@ -179,7 +179,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
|
|
|
|
tx.vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
|
|
|
|
tx.vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
|
|
|
|
uint256 hashLowFeeTx2 = tx.GetHash();
|
|
|
|
uint256 hashLowFeeTx2 = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey);
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
|
|
|
|
|
|
|
|
|
|
|
|
// Verify that this tx isn't selected.
|
|
|
|
// Verify that this tx isn't selected.
|
|
|
|
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
|
|
|
|
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
|
|
|
@ -192,7 +192,7 @@ void MinerTestingSetup::TestPackageSelection(const CChainParams& chainparams, co
|
|
|
|
tx.vin[0].prevout.n = 1;
|
|
|
|
tx.vin[0].prevout.n = 1;
|
|
|
|
tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
|
|
|
|
tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(10000).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(10000).FromTx(tx));
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey);
|
|
|
|
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
|
|
|
|
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 9U);
|
|
|
|
BOOST_REQUIRE_EQUAL(pblocktemplate->block.vtx.size(), 9U);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
|
|
|
|
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
fCheckpointsEnabled = false;
|
|
|
|
fCheckpointsEnabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Simple block creation, nothing special yet:
|
|
|
|
// Simple block creation, nothing special yet:
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
|
|
|
|
|
|
|
|
// We can't make transactions until we have inputs
|
|
|
|
// We can't make transactions until we have inputs
|
|
|
|
// Therefore, load 110 blocks :)
|
|
|
|
// Therefore, load 110 blocks :)
|
|
|
@ -252,7 +252,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
LOCK(m_node.mempool->cs);
|
|
|
|
LOCK(m_node.mempool->cs);
|
|
|
|
|
|
|
|
|
|
|
|
// Just to make sure we can still make simple blocks
|
|
|
|
// Just to make sure we can still make simple blocks
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
|
|
|
|
|
|
|
|
const CAmount BLOCKSUBSIDY = 50*COIN;
|
|
|
|
const CAmount BLOCKSUBSIDY = 50*COIN;
|
|
|
|
const CAmount LOWFEE = CENT;
|
|
|
|
const CAmount LOWFEE = CENT;
|
|
|
@ -277,7 +277,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
tx.vin[0].prevout.hash = hash;
|
|
|
|
tx.vin[0].prevout.hash = hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey), std::runtime_error, HasReason("bad-blk-sigops"));
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-blk-sigops"));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
|
|
|
|
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
|
|
|
@ -291,7 +291,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOpsCost(80).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOpsCost(80).FromTx(tx));
|
|
|
|
tx.vin[0].prevout.hash = hash;
|
|
|
|
tx.vin[0].prevout.hash = hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
// block size > limit
|
|
|
|
// block size > limit
|
|
|
@ -311,13 +311,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
|
|
|
|
tx.vin[0].prevout.hash = hash;
|
|
|
|
tx.vin[0].prevout.hash = hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
// orphan in *m_node.mempool, template creation fails
|
|
|
|
// orphan in *m_node.mempool, template creation fails
|
|
|
|
hash = tx.GetHash();
|
|
|
|
hash = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx));
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
// child with higher feerate than parent
|
|
|
|
// child with higher feerate than parent
|
|
|
@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
tx.vout[0].nValue = tx.vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE; //First txn output + fresh coinbase - new txn fee
|
|
|
|
tx.vout[0].nValue = tx.vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE; //First txn output + fresh coinbase - new txn fee
|
|
|
|
hash = tx.GetHash();
|
|
|
|
hash = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
// coinbase in *m_node.mempool, template creation fails
|
|
|
|
// coinbase in *m_node.mempool, template creation fails
|
|
|
@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
// give it a fee so it'll get mined
|
|
|
|
// give it a fee so it'll get mined
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
// Should throw bad-cb-multiple
|
|
|
|
// Should throw bad-cb-multiple
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey), std::runtime_error, HasReason("bad-cb-multiple"));
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-cb-multiple"));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
// double spend txn pair in *m_node.mempool, template creation fails
|
|
|
|
// double spend txn pair in *m_node.mempool, template creation fails
|
|
|
@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
tx.vout[0].scriptPubKey = CScript() << OP_2;
|
|
|
|
tx.vout[0].scriptPubKey = CScript() << OP_2;
|
|
|
|
hash = tx.GetHash();
|
|
|
|
hash = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("bad-txns-inputs-missingorspent"));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
// subsidy changing
|
|
|
|
// subsidy changing
|
|
|
@ -375,7 +375,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
next->BuildSkip();
|
|
|
|
next->BuildSkip();
|
|
|
|
::ChainActive().SetTip(next);
|
|
|
|
::ChainActive().SetTip(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
// Extend to a 210000-long block chain.
|
|
|
|
// Extend to a 210000-long block chain.
|
|
|
|
while (::ChainActive().Tip()->nHeight < 210000) {
|
|
|
|
while (::ChainActive().Tip()->nHeight < 210000) {
|
|
|
|
CBlockIndex* prev = ::ChainActive().Tip();
|
|
|
|
CBlockIndex* prev = ::ChainActive().Tip();
|
|
|
@ -387,7 +387,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
next->BuildSkip();
|
|
|
|
next->BuildSkip();
|
|
|
|
::ChainActive().SetTip(next);
|
|
|
|
::ChainActive().SetTip(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
|
|
|
|
|
|
|
|
// invalid p2sh txn in *m_node.mempool, template creation fails
|
|
|
|
// invalid p2sh txn in *m_node.mempool, template creation fails
|
|
|
|
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
|
|
|
|
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
|
|
|
@ -404,7 +404,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
hash = tx.GetHash();
|
|
|
|
hash = tx.GetHash();
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
m_node.mempool->addUnchecked(entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
|
|
|
|
// Should throw block-validation-failed
|
|
|
|
// Should throw block-validation-failed
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey), std::runtime_error, HasReason("block-validation-failed"));
|
|
|
|
BOOST_CHECK_EXCEPTION(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error, HasReason("block-validation-failed"));
|
|
|
|
m_node.mempool->clear();
|
|
|
|
m_node.mempool->clear();
|
|
|
|
|
|
|
|
|
|
|
|
// Delete the dummy blocks again.
|
|
|
|
// Delete the dummy blocks again.
|
|
|
@ -492,7 +492,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
|
|
|
|
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
|
|
|
|
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
|
|
|
|
BOOST_CHECK(!TestSequenceLocks(CTransaction(tx), flags)); // Sequence locks fail
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
|
|
|
|
|
|
|
|
// None of the of the absolute height/time locked tx should have made
|
|
|
|
// None of the of the absolute height/time locked tx should have made
|
|
|
|
// it into the template because we still check IsFinalTx in CreateNewBlock,
|
|
|
|
// it into the template because we still check IsFinalTx in CreateNewBlock,
|
|
|
@ -505,7 +505,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|
|
|
::ChainActive().Tip()->nHeight++;
|
|
|
|
::ChainActive().Tip()->nHeight++;
|
|
|
|
SetMockTime(::ChainActive().Tip()->GetMedianTimePast() + 1);
|
|
|
|
SetMockTime(::ChainActive().Tip()->GetMedianTimePast() + 1);
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(::ChainstateActive(), scriptPubKey));
|
|
|
|
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
|
|
|
|
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5U);
|
|
|
|
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5U);
|
|
|
|
|
|
|
|
|
|
|
|
::ChainActive().Tip()->nHeight--;
|
|
|
|
::ChainActive().Tip()->nHeight--;
|
|
|
|