Optimize mempool by removing unnecessary sprout checks
This commit is contained in:
@@ -127,11 +127,6 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry,
|
|||||||
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
|
mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
|
|
||||||
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
|
|
||||||
mapSproutNullifiers[nf] = &tx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
||||||
mapSaplingNullifiers[spendDescription.nullifier] = &tx;
|
mapSaplingNullifiers[spendDescription.nullifier] = &tx;
|
||||||
}
|
}
|
||||||
@@ -332,9 +327,8 @@ bool CTxMemPool::removeSpentIndex(const uint256 txhash)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& removed, bool fRecursive)
|
// Remove transaction from memory pool
|
||||||
{
|
void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& removed, bool fRecursive) {
|
||||||
// Remove transaction from memory pool
|
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
std::deque<uint256> txToRemove;
|
std::deque<uint256> txToRemove;
|
||||||
@@ -369,11 +363,8 @@ void CTxMemPool::remove(const CTransaction &origTx, std::list<CTransaction>& rem
|
|||||||
mapRecentlyAddedTx.erase(hash);
|
mapRecentlyAddedTx.erase(hash);
|
||||||
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
||||||
mapNextTx.erase(txin.prevout);
|
mapNextTx.erase(txin.prevout);
|
||||||
BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) {
|
|
||||||
BOOST_FOREACH(const uint256& nf, joinsplit.nullifiers) {
|
// remove each Sapling nullifier associated with this shielded spend
|
||||||
mapSproutNullifiers.erase(nf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
||||||
mapSaplingNullifiers.erase(spendDescription.nullifier);
|
mapSaplingNullifiers.erase(spendDescription.nullifier);
|
||||||
}
|
}
|
||||||
@@ -440,14 +431,6 @@ void CTxMemPool::removeWithAnchor(const uint256 &invalidRoot, ShieldedType type)
|
|||||||
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
|
for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) {
|
||||||
const CTransaction& tx = it->GetTx();
|
const CTransaction& tx = it->GetTx();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SPROUT:
|
|
||||||
BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) {
|
|
||||||
if (joinsplit.anchor == invalidRoot) {
|
|
||||||
transactionsToRemove.push_back(tx);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SAPLING:
|
case SAPLING:
|
||||||
BOOST_FOREACH(const SpendDescription& spendDescription, tx.vShieldedSpend) {
|
BOOST_FOREACH(const SpendDescription& spendDescription, tx.vShieldedSpend) {
|
||||||
if (spendDescription.anchor == invalidRoot) {
|
if (spendDescription.anchor == invalidRoot) {
|
||||||
@@ -484,17 +467,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list<CTransaction>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
|
// remove conflicting Sapling z2z tx's
|
||||||
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
|
|
||||||
std::map<uint256, const CTransaction*>::iterator it = mapSproutNullifiers.find(nf);
|
|
||||||
if (it != mapSproutNullifiers.end()) {
|
|
||||||
const CTransaction &txConflict = *it->second;
|
|
||||||
if (txConflict != tx) {
|
|
||||||
remove(txConflict, removed, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
||||||
std::map<uint256, const CTransaction*>::iterator it = mapSaplingNullifiers.find(spendDescription.nullifier);
|
std::map<uint256, const CTransaction*>::iterator it = mapSaplingNullifiers.find(spendDescription.nullifier);
|
||||||
if (it != mapSaplingNullifiers.end()) {
|
if (it != mapSaplingNullifiers.end()) {
|
||||||
@@ -639,30 +612,6 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
boost::unordered_map<uint256, SproutMerkleTree, CCoinsKeyHasher> intermediates;
|
|
||||||
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
|
|
||||||
BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) {
|
|
||||||
assert(!pcoins->GetNullifier(nf, SPROUT));
|
|
||||||
}
|
|
||||||
|
|
||||||
SproutMerkleTree tree;
|
|
||||||
auto it = intermediates.find(joinsplit.anchor);
|
|
||||||
if (it != intermediates.end()) {
|
|
||||||
tree = it->second;
|
|
||||||
} else {
|
|
||||||
assert(pcoins->GetSproutAnchorAt(joinsplit.anchor, tree));
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FOREACH(const uint256& commitment, joinsplit.commitments)
|
|
||||||
{
|
|
||||||
tree.append(commitment);
|
|
||||||
}
|
|
||||||
|
|
||||||
intermediates.insert(std::make_pair(tree.root(), tree));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
for (const SpendDescription &spendDescription : tx.vShieldedSpend) {
|
||||||
SaplingMerkleTree tree;
|
SaplingMerkleTree tree;
|
||||||
|
|
||||||
@@ -706,7 +655,6 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
|
|||||||
assert(it->first == it->second.ptx->vin[it->second.n].prevout);
|
assert(it->first == it->second.ptx->vin[it->second.n].prevout);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkNullifiers(SPROUT);
|
|
||||||
checkNullifiers(SAPLING);
|
checkNullifiers(SAPLING);
|
||||||
|
|
||||||
assert(totalTxSize == checkTotal);
|
assert(totalTxSize == checkTotal);
|
||||||
@@ -717,9 +665,6 @@ void CTxMemPool::checkNullifiers(ShieldedType type) const
|
|||||||
{
|
{
|
||||||
const std::map<uint256, const CTransaction*>* mapToUse;
|
const std::map<uint256, const CTransaction*>* mapToUse;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SPROUT:
|
|
||||||
mapToUse = &mapSproutNullifiers;
|
|
||||||
break;
|
|
||||||
case SAPLING:
|
case SAPLING:
|
||||||
mapToUse = &mapSaplingNullifiers;
|
mapToUse = &mapSaplingNullifiers;
|
||||||
break;
|
break;
|
||||||
@@ -839,8 +784,6 @@ bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const
|
|||||||
bool CTxMemPool::nullifierExists(const uint256& nullifier, ShieldedType type) const
|
bool CTxMemPool::nullifierExists(const uint256& nullifier, ShieldedType type) const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SPROUT:
|
|
||||||
return mapSproutNullifiers.count(nullifier);
|
|
||||||
case SAPLING:
|
case SAPLING:
|
||||||
return mapSaplingNullifiers.count(nullifier);
|
return mapSaplingNullifiers.count(nullifier);
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user