Skip to content

Commit a7dc478

Browse files
committed
After a reorg, boot all peg-ins and peg-outs from mempool
1 parent 9a3b9b9 commit a7dc478

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/txmempool.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,24 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
521521
if (!validLP) {
522522
mapTx.modify(it, update_lock_points(lp));
523523
}
524+
525+
// On re-org, remove *all* peg-in and PAK-based peg-outs due to possible
526+
// invalidity from dynafed transitions
527+
// TODO: Only boot out now-invalid transactions. Re-orgs are very rare in
528+
// federated systems but can occasionally happen due to consensus algorithm.
529+
530+
// Little hack to quickly check if any outputs are PAK ones
531+
// by sending in empty(reject) list.
532+
if (!IsPAKValidTx(tx, CPAKList())) {
533+
txToRemove.insert(it);
534+
continue;
535+
}
536+
for (const auto& input : tx.vin) {
537+
if (input.m_is_pegin) {
538+
txToRemove.insert(it);
539+
break;
540+
}
541+
}
524542
}
525543
setEntries setAllRemoves;
526544
for (txiter it : txToRemove) {

test/functional/feature_fedpeg.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ def run_test(self):
294294
if sidechain.gettransaction(pegtxid1)["confirmations"] != 0:
295295
raise Exception("Peg-in didn't unconfirm after invalidateblock call.")
296296

297+
# Re-org causes peg-ins to get booted(wallet will resubmit in 10 minutes)
298+
assert_equal(sidechain.getrawmempool(), [])
299+
sidechain.sendrawtransaction(tx1["hex"])
300+
297301
# Create duplicate claim, put it in block along with current one in mempool
298302
# to test duplicate-in-block claims between two txs that are in the same block.
299303
raw_pegin = sidechain.createrawpegin(raw, proof)["hex"]

0 commit comments

Comments
 (0)