Skip to content

Commit 9f5cc03

Browse files
committed
Read PAK list from connected blocks, save list, and boot transactions not conforming
1 parent 86fbc24 commit 9f5cc03

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/txmempool.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <util.h>
1818
#include <utilmoneystr.h>
1919
#include <utiltime.h>
20+
#include <chainparams.h> // removeForBlock paklist transition
2021

2122
CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
2223
int64_t _nTime, unsigned int _entryHeight,
@@ -569,7 +570,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx)
569570
/**
570571
* Called when a block is connected. Removes from mempool and updates the miner fee estimator.
571572
*/
572-
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent)
573+
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, bool pak_transition)
573574
{
574575
LOCK(cs);
575576
std::vector<const CTxMemPoolEntry*> entries;
@@ -611,7 +612,25 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
611612
ClearPrioritisation(tx_id);
612613
}
613614
}
614-
615+
// Eject any newly-invalid peg-outs based on changing block commitment
616+
const CChainParams& chainparams = Params();
617+
if (pak_transition && !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard())) {
618+
for (const auto& entry : mapTx) {
619+
for (const auto& out : entry.GetTx().vout) {
620+
if (out.scriptPubKey.IsPegoutScript(Params().ParentGenesisBlockHash()) &&
621+
!ScriptHasValidPAKProof(out.scriptPubKey, Params().ParentGenesisBlockHash())) {
622+
txiter it = mapTx.find(entry.GetTx().GetHash());
623+
const CTransaction& tx = it->GetTx();
624+
setEntries stage;
625+
stage.insert(it);
626+
RemoveStaged(stage, true, MemPoolRemovalReason::BLOCK);
627+
removeRecursive(tx, MemPoolRemovalReason::BLOCK);
628+
ClearPrioritisation(tx.GetHash());
629+
break;
630+
}
631+
}
632+
}
633+
}
615634
lastRollingFeeUpdate = GetTime();
616635
blockSinceLastRollingFeeBump = true;
617636
}

src/txmempool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ class CTxMemPool
552552
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
553553
void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
554554
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight,
555-
const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent);
555+
const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, bool pak_transition=false);
556556

557557
void clear();
558558
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs); //lock free

src/validation.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2585,10 +2585,25 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
25852585
// Write the chain state to disk, if necessary.
25862586
if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED))
25872587
return false;
2588+
2589+
// Get PAK commitment from coinbase, if it exists
2590+
boost::optional<CPAKList> paklist = GetPAKKeysFromCommitment(*blockConnecting.vtx[0]);
2591+
if (paklist) {
2592+
std::vector<std::vector<unsigned char> > offline_keys;
2593+
std::vector<std::vector<unsigned char> > online_keys;
2594+
bool is_reject;
2595+
paklist->ToBytes(offline_keys, online_keys, is_reject);
2596+
pblocktree->WritePAKList(offline_keys, online_keys, is_reject);
2597+
g_paklist_blockchain = *paklist;
2598+
}
2599+
25882600
int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4;
25892601
LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * MILLI, nTimeChainState * MICRO, nTimeChainState * MILLI / nBlocksTotal);
25902602
// Remove conflicting transactions from the mempool.;
2591-
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, setPeginsSpent);
2603+
// ELEMENTS: We also eject now-invalid peg-outs based on block transition if not config list set
2604+
// If config is set, this means all peg-outs have been filtered for that list already and other
2605+
// functionaries aren't matching your list. Operator should restart with no list or new matching list.
2606+
mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, setPeginsSpent, (paklist && !g_paklist_config));
25922607
disconnectpool.removeForBlock(blockConnecting.vtx);
25932608
// Update chainActive & related variables.
25942609
chainActive.SetTip(pindexNew);

0 commit comments

Comments
 (0)