mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Read PAK list from connected blocks, save list, and boot transactions not conforming
This commit is contained in:
parent
86fbc2418f
commit
9f5cc03f94
3 changed files with 38 additions and 4 deletions
|
|
@ -17,6 +17,7 @@
|
|||
#include <util.h>
|
||||
#include <utilmoneystr.h>
|
||||
#include <utiltime.h>
|
||||
#include <chainparams.h> // 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<CTransactionRef>& vtx, unsigned int nBlockHeight, const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent)
|
||||
void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight, const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, bool pak_transition)
|
||||
{
|
||||
LOCK(cs);
|
||||
std::vector<const CTxMemPoolEntry*> entries;
|
||||
|
|
@ -611,7 +612,25 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<CTransactionRef>& vtx, unsigned int nBlockHeight,
|
||||
const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent);
|
||||
const std::set<std::pair<uint256, COutPoint>>& setPeginsSpent, bool pak_transition=false);
|
||||
|
||||
void clear();
|
||||
void _clear() EXCLUSIVE_LOCKS_REQUIRED(cs); //lock free
|
||||
|
|
|
|||
|
|
@ -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<CPAKList> paklist = GetPAKKeysFromCommitment(*blockConnecting.vtx[0]);
|
||||
if (paklist) {
|
||||
std::vector<std::vector<unsigned char> > offline_keys;
|
||||
std::vector<std::vector<unsigned char> > 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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue