After a reorg, boot all peg-ins and peg-outs from mempool

This commit is contained in:
Gregory Sanders 2019-06-19 13:05:41 -04:00
parent 6000752a92
commit 50a2b599ca
2 changed files with 22 additions and 0 deletions

View file

@ -521,6 +521,24 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
if (!validLP) {
mapTx.modify(it, update_lock_points(lp));
}
// On re-org, remove *all* peg-in and PAK-based peg-outs due to possible
// invalidity from dynafed transitions
// TODO: Only boot out now-invalid transactions. Re-orgs are very rare in
// federated systems but can occasionally happen due to consensus algorithm.
// Little hack to quickly check if any outputs are PAK ones
// by sending in empty(reject) list.
if (!IsPAKValidTx(tx, CPAKList())) {
txToRemove.insert(it);
continue;
}
for (const auto& input : tx.vin) {
if (input.m_is_pegin) {
txToRemove.insert(it);
break;
}
}
}
setEntries setAllRemoves;
for (txiter it : txToRemove) {

View file

@ -294,6 +294,10 @@ class FedPegTest(BitcoinTestFramework):
if sidechain.gettransaction(pegtxid1)["confirmations"] != 0:
raise Exception("Peg-in didn't unconfirm after invalidateblock call.")
# Re-org causes peg-ins to get booted(wallet will resubmit in 10 minutes)
assert_equal(sidechain.getrawmempool(), [])
sidechain.sendrawtransaction(tx1["hex"])
# Create duplicate claim, put it in block along with current one in mempool
# to test duplicate-in-block claims between two txs that are in the same block.
raw_pegin = sidechain.createrawpegin(raw, proof)["hex"]