Clean up POS checks
This commit is contained in:
@@ -65,14 +65,13 @@ bool CCheatList::IsCheatInList(const CTransaction &tx, CTransaction *cheatTx)
|
||||
range = indexedCheatCandidates.equal_range(utxo);
|
||||
for (auto it = range.first; it != range.second; it++)
|
||||
{
|
||||
// we assume height is valid, as we should have pruned the list before checking. since the tx came out of a valid block,
|
||||
// what matters is if the prior hash matches
|
||||
CTransaction &cTx = it->second->tx;
|
||||
printf("cTx::opret : %s\n", cTx.vout[1].scriptPubKey.ToString().c_str());
|
||||
|
||||
// need both parameters to check
|
||||
if (GetStakeParams(cTx, s))
|
||||
{
|
||||
if (p.prevHash != s.prevHash)
|
||||
if (p.prevHash != s.prevHash && s.blkHeight >= p.blkHeight)
|
||||
{
|
||||
cheatTx = &cTx;
|
||||
return true;
|
||||
@@ -85,7 +84,6 @@ bool CCheatList::IsCheatInList(const CTransaction &tx, CTransaction *cheatTx)
|
||||
|
||||
bool CCheatList::Add(CTxHolder &txh)
|
||||
{
|
||||
CVerusHashWriter hw = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
if (NetworkUpgradeActive(txh.height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING))
|
||||
{
|
||||
LOCK(cs_cheat);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "streams.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "script/script.h"
|
||||
#include "uint256.h"
|
||||
|
||||
@@ -34,6 +35,13 @@ class CTxHolder
|
||||
hw << tx.vin[0].prevout.n;
|
||||
utxo = hw.GetHash();
|
||||
}
|
||||
|
||||
CTxHolder& operator=(const CTxHolder& txh)
|
||||
{
|
||||
utxo = txh.utxo;
|
||||
height = txh.height;
|
||||
tx = txh.tx;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1492,31 +1492,13 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
|
||||
value = pblock->vtx[txn_count-1].vout[0].nValue;
|
||||
|
||||
{
|
||||
bool validHash = true;
|
||||
bool validHash = (value != 0);
|
||||
bool enablePOSNonce = CPOSNonce::NewPOSActive(height);
|
||||
bool newPOSEnforcement = enablePOSNonce && (Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight <= height);
|
||||
uint256 rawHash;
|
||||
arith_uint256 posHash;
|
||||
|
||||
// check without consequences if not enforced yet
|
||||
{
|
||||
if (pblock->GetRawVerusPOSHash(rawHash, height))
|
||||
{
|
||||
if (posHash > target)
|
||||
{
|
||||
posHash = UintToArith256(rawHash) / value;
|
||||
printf("PoS block\nblkHash: %s\nnNonce: %s\nrawHash: %s\nposHash: %s\nvalue: %lu\n",
|
||||
pblock->GetHash().GetHex().c_str(), pblock->nNonce.GetHex().c_str(), rawHash.GetHex().c_str(), posHash.GetHex().c_str(), value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("PoS block\nblkHash: %s\nnNonce: %s\nFAILED TO GET posHash\n",
|
||||
pblock->GetHash().GetHex().c_str(), pblock->nNonce.GetHex().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (newPOSEnforcement)
|
||||
if (validHash && newPOSEnforcement)
|
||||
{
|
||||
validHash = pblock->GetRawVerusPOSHash(rawHash, height);
|
||||
posHash = UintToArith256(rawHash) / value;
|
||||
@@ -1526,25 +1508,26 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
|
||||
printf("ERROR: invalid nonce value for PoS block\nnNonce: %s\nrawHash: %s\nposHash: %s\nvalue: %lu\n",
|
||||
pblock->nNonce.GetHex().c_str(), rawHash.GetHex().c_str(), posHash.GetHex().c_str(), value);
|
||||
}
|
||||
for (int i = 0; validHash && i < pblock->vtx[0].vout.size(); i++)
|
||||
// make sure prev block hash and block height are correct
|
||||
CStakeParams p;
|
||||
if (validHash && (validHash = GetStakeParams(pblock->vtx[txn_count-1], p)))
|
||||
{
|
||||
if (!ValidateMatchingStake(pblock->vtx[0], i, pblock->vtx[txn_count-1], validHash))
|
||||
for (int i = 0; validHash && i < pblock->vtx[0].vout.size(); i++)
|
||||
{
|
||||
validHash = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// make sure prev block hash and block height are correct
|
||||
CStakeParams p;
|
||||
if (validHash = GetStakeParams(pblock->vtx[txn_count-1], p))
|
||||
if (ValidateMatchingStake(pblock->vtx[0], i, pblock->vtx[txn_count-1], validHash) && !validHash)
|
||||
{
|
||||
if (p.prevHash != pblock->hashPrevBlock || p.blkHeight != height)
|
||||
if (p.prevHash == pblock->hashPrevBlock && p.blkHeight == height)
|
||||
{
|
||||
validHash = true;
|
||||
}
|
||||
{
|
||||
printf("ERROR: invalid block data for stake tx\nblkHash: %s\ntxBlkHash: %s\nblkHeight: %d\ntxBlkHeight: %d\n",
|
||||
pblock->hashPrevBlock.GetHex().c_str(), p.prevHash.GetHex().c_str(), height, p.blkHeight);
|
||||
validHash = false;
|
||||
}
|
||||
}
|
||||
else validHash = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3724,7 +3724,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
|
||||
ASSETCHAINS_LWMAPOS && (i == (block.vtx.size() - 1)) &&
|
||||
(block.IsVerusPOSBlock()))
|
||||
{
|
||||
CTxHolder txh(block.vtx[i], pindexDelete->GetHeight());
|
||||
CTxHolder txh = CTxHolder(block.vtx[i], pindexDelete->GetHeight());
|
||||
cheatList.Add(txh);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user