From 50a2b599caae1d131479df39e2a0f342eb3298c0 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Wed, 19 Jun 2019 13:05:41 -0400 Subject: [PATCH] After a reorg, boot all peg-ins and peg-outs from mempool --- src/txmempool.cpp | 18 ++++++++++++++++++ test/functional/feature_fedpeg.py | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index a4c5f1dee4..037e9a890c 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -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) { diff --git a/test/functional/feature_fedpeg.py b/test/functional/feature_fedpeg.py index dcbcdaa35b..faa13276db 100755 --- a/test/functional/feature_fedpeg.py +++ b/test/functional/feature_fedpeg.py @@ -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"]