mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +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);
|
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(parent_gen_hash) &&
|
||||||
if (txout.scriptPubKey.IsPegoutScript(params.ParentGenesisBlockHash()) &&
|
txout.nAsset.IsExplicit() && txout.nAsset.GetAsset() == peg_asset &&
|
||||||
txout.nAsset.IsExplicit() && txout.nAsset.GetAsset() == params.GetConsensus().pegged_asset &&
|
(!ScriptHasValidPAKProof(txout.scriptPubKey, parent_gen_hash, paklist))) {
|
||||||
(!ScriptHasValidPAKProof(txout.scriptPubKey, params.ParentGenesisBlockHash(), paklist))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
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) {
|
for (const auto& txout : tx.vout) {
|
||||||
if (!IsPAKValidOutput(txout, paklist)) {
|
if (!IsPAKValidOutput(txout, paklist, parent_gen_hash, peg_asset)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,8 @@ CPAKList CreatePAKListFromExtensionSpace(const std::vector<std::vector<unsigned
|
||||||
|
|
||||||
CPAKList GetActivePAKList(const CBlockIndex* pblockindex, const Consensus::Params& params);
|
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
|
#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
|
// Little hack to quickly check if any outputs are PAK ones
|
||||||
// by sending in empty(reject) list.
|
// by sending in empty(reject) list.
|
||||||
if (!IsPAKValidTx(tx, CPAKList())) {
|
if (!IsPAKValidTx(tx, CPAKList(), Params().ParentGenesisBlockHash(), Params().GetConsensus().pegged_asset)) {
|
||||||
txToRemove.insert(it);
|
txToRemove.insert(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -604,7 +604,7 @@ void CTxMemPool::removeForBlock(const std::vector<CTransactionRef>& vtx, unsigne
|
||||||
std::vector<CTransactionRef> tx_to_remove;
|
std::vector<CTransactionRef> tx_to_remove;
|
||||||
for (const auto& entry : mapTx) {
|
for (const auto& entry : mapTx) {
|
||||||
const CTransaction& tx = entry.GetTx();
|
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));
|
tx_to_remove.push_back(MakeTransactionRef(tx));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -611,7 +611,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
|
||||||
|
|
||||||
// And now do PAK checks. Filtered by next blocks' enforced list
|
// And now do PAK checks. Filtered by next blocks' enforced list
|
||||||
if (chainparams.GetEnforcePak()) {
|
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");
|
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
|
// GetActivePAKList computes for the following block, so use previous index
|
||||||
CPAKList paklist = GetActivePAKList(pindex->pprev, chainparams.GetConsensus());
|
CPAKList paklist = GetActivePAKList(pindex->pprev, chainparams.GetConsensus());
|
||||||
for (const auto& tx : block.vtx) {
|
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");
|
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