From 9f5cc03f94de86c2e89d7e4f1d403752ec48bb10 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Mon, 17 Dec 2018 11:39:54 -0500 Subject: [PATCH] Read PAK list from connected blocks, save list, and boot transactions not conforming --- src/txmempool.cpp | 23 +++++++++++++++++++++-- src/txmempool.h | 2 +- src/validation.cpp | 17 ++++++++++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index f9dd8488c7..b125c37ed2 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -17,6 +17,7 @@ #include #include #include +#include // removeForBlock paklist transition CTxMemPoolEntry::CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee, int64_t _nTime, unsigned int _entryHeight, @@ -569,7 +570,7 @@ void CTxMemPool::removeConflicts(const CTransaction &tx) /** * Called when a block is connected. Removes from mempool and updates the miner fee estimator. */ -void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, const std::set>& setPeginsSpent) +void CTxMemPool::removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, const std::set>& setPeginsSpent, bool pak_transition) { LOCK(cs); std::vector entries; @@ -611,7 +612,25 @@ void CTxMemPool::removeForBlock(const std::vector& vtx, unsigne ClearPrioritisation(tx_id); } } - + // Eject any newly-invalid peg-outs based on changing block commitment + const CChainParams& chainparams = Params(); + if (pak_transition && !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard())) { + for (const auto& entry : mapTx) { + for (const auto& out : entry.GetTx().vout) { + if (out.scriptPubKey.IsPegoutScript(Params().ParentGenesisBlockHash()) && + !ScriptHasValidPAKProof(out.scriptPubKey, Params().ParentGenesisBlockHash())) { + txiter it = mapTx.find(entry.GetTx().GetHash()); + const CTransaction& tx = it->GetTx(); + setEntries stage; + stage.insert(it); + RemoveStaged(stage, true, MemPoolRemovalReason::BLOCK); + removeRecursive(tx, MemPoolRemovalReason::BLOCK); + ClearPrioritisation(tx.GetHash()); + break; + } + } + } + } lastRollingFeeUpdate = GetTime(); blockSinceLastRollingFeeBump = true; } diff --git a/src/txmempool.h b/src/txmempool.h index adad69b6c9..1352188fd6 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -552,7 +552,7 @@ public: void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags); void removeConflicts(const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(cs); void removeForBlock(const std::vector& vtx, unsigned int nBlockHeight, - const std::set>& setPeginsSpent); + const std::set>& setPeginsSpent, bool pak_transition=false); void clear(); void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs); //lock free diff --git a/src/validation.cpp b/src/validation.cpp index 83b369ba65..31589d395c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2585,10 +2585,25 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp // Write the chain state to disk, if necessary. if (!FlushStateToDisk(chainparams, state, FlushStateMode::IF_NEEDED)) return false; + + // Get PAK commitment from coinbase, if it exists + boost::optional paklist = GetPAKKeysFromCommitment(*blockConnecting.vtx[0]); + if (paklist) { + std::vector > offline_keys; + std::vector > online_keys; + bool is_reject; + paklist->ToBytes(offline_keys, online_keys, is_reject); + pblocktree->WritePAKList(offline_keys, online_keys, is_reject); + g_paklist_blockchain = *paklist; + } + int64_t nTime5 = GetTimeMicros(); nTimeChainState += nTime5 - nTime4; LogPrint(BCLog::BENCH, " - Writing chainstate: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime5 - nTime4) * MILLI, nTimeChainState * MICRO, nTimeChainState * MILLI / nBlocksTotal); // Remove conflicting transactions from the mempool.; - mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, setPeginsSpent); + // ELEMENTS: We also eject now-invalid peg-outs based on block transition if not config list set + // If config is set, this means all peg-outs have been filtered for that list already and other + // functionaries aren't matching your list. Operator should restart with no list or new matching list. + mempool.removeForBlock(blockConnecting.vtx, pindexNew->nHeight, setPeginsSpent, (paklist && !g_paklist_config)); disconnectpool.removeForBlock(blockConnecting.vtx); // Update chainActive & related variables. chainActive.SetTip(pindexNew);