mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-13 12:33:42 +02:00
Refactor IsPAKValid to not magically acquire chainparams
This commit is contained in:
parent
ecdefc5cb0
commit
e2be2356dd
4 changed files with 12 additions and 13 deletions
|
|
@ -199,21 +199,20 @@ CPAKList GetActivePAKList(const CBlockIndex* pblockindex, const Consensus::Param
|
|||
return CreatePAKListFromExtensionSpace(ComputeNextBlockFullCurrentParameters(pblockindex, params).m_extension_space);
|
||||
}
|
||||
|
||||
bool IsPAKValidOutput(const CTxOut& txout, const CPAKList& paklist)
|
||||
bool IsPAKValidOutput(const CTxOut& txout, const CPAKList& paklist, const uint256& parent_gen_hash, const CAsset& peg_asset)
|
||||
{
|
||||
const CChainParams& params = Params();
|
||||
if (txout.scriptPubKey.IsPegoutScript(params.ParentGenesisBlockHash()) &&
|
||||
txout.nAsset.IsExplicit() && txout.nAsset.GetAsset() == params.GetConsensus().pegged_asset &&
|
||||
(!ScriptHasValidPAKProof(txout.scriptPubKey, params.ParentGenesisBlockHash(), paklist))) {
|
||||
if (txout.scriptPubKey.IsPegoutScript(parent_gen_hash) &&
|
||||
txout.nAsset.IsExplicit() && txout.nAsset.GetAsset() == peg_asset &&
|
||||
(!ScriptHasValidPAKProof(txout.scriptPubKey, parent_gen_hash, paklist))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsPAKValidTx(const CTransaction& tx, const CPAKList& paklist)
|
||||
bool IsPAKValidTx(const CTransaction& tx, const CPAKList& paklist, const uint256& parent_gen_hash, const CAsset& peg_asset)
|
||||
{
|
||||
for (const auto& txout : tx.vout) {
|
||||
if (!IsPAKValidOutput(txout, paklist)) {
|
||||
if (!IsPAKValidOutput(txout, paklist, parent_gen_hash, peg_asset)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ CPAKList CreatePAKListFromExtensionSpace(const std::vector<std::vector<unsigned
|
|||
|
||||
CPAKList GetActivePAKList(const CBlockIndex* pblockindex, const Consensus::Params& params);
|
||||
|
||||
bool IsPAKValidOutput(const CTxOut& txout, const CPAKList& paklist);
|
||||
bool IsPAKValidOutput(const CTxOut& txout, const CPAKList& paklist, const uint256& parent_gen_hash, const CAsset& peg_asset);
|
||||
|
||||
bool IsPAKValidTx(const CTransaction& tx, const CPAKList& paklist);
|
||||
bool IsPAKValidTx(const CTransaction& tx, const CPAKList& paklist, const uint256& parent_gen_hash, const CAsset& peg_asset);
|
||||
|
||||
#endif // BITCOIN_PRIMITIVES_PAK_H
|
||||
|
|
|
|||
|
|
@ -529,7 +529,7 @@ void CTxMemPool::removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMem
|
|||
|
||||
// Little hack to quickly check if any outputs are PAK ones
|
||||
// by sending in empty(reject) list.
|
||||
if (!IsPAKValidTx(tx, CPAKList())) {
|
||||
if (!IsPAKValidTx(tx, CPAKList(), Params().ParentGenesisBlockHash(), Params().GetConsensus().pegged_asset)) {
|
||||
txToRemove.insert(it);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -604,7 +604,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
|
|||
std::vector<CTransactionRef> tx_to_remove;
|
||||
for (const auto& entry : mapTx) {
|
||||
const CTransaction& tx = entry.GetTx();
|
||||
if (chainparams.GetEnforcePak() && !IsPAKValidTx(tx, enforced_paklist)) {
|
||||
if (chainparams.GetEnforcePak() && !IsPAKValidTx(tx, enforced_paklist, chainparams.ParentGenesisBlockHash(), chainparams.GetConsensus().pegged_asset)) {
|
||||
tx_to_remove.push_back(MakeTransactionRef(tx));
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
|
|||
|
||||
// And now do PAK checks. Filtered by next blocks' enforced list
|
||||
if (chainparams.GetEnforcePak()) {
|
||||
if (!IsPAKValidTx(tx, GetActivePAKList(chainActive.Tip(), chainparams.GetConsensus()))) {
|
||||
if (!IsPAKValidTx(tx, GetActivePAKList(chainActive.Tip(), chainparams.GetConsensus()), chainparams.ParentGenesisBlockHash(), chainparams.GetConsensus().pegged_asset)) {
|
||||
return state.DoS(0, false, REJECT_NONSTANDARD, "invalid-pegout-proof");
|
||||
}
|
||||
}
|
||||
|
|
@ -2135,7 +2135,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
|||
// GetActivePAKList computes for the following block, so use previous index
|
||||
CPAKList paklist = GetActivePAKList(pindex->pprev, chainparams.GetConsensus());
|
||||
for (const auto& tx : block.vtx) {
|
||||
if (!IsPAKValidTx(*tx, paklist)) {
|
||||
if (!IsPAKValidTx(*tx, paklist, chainparams.ParentGenesisBlockHash(), chainparams.GetConsensus().pegged_asset)) {
|
||||
return state.DoS(100, error("ConnectBlock(): Bad PAK transaction"), REJECT_INVALID, "bad-pak-tx");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue