Browse Source

move things around and some debugging code for odd issues

pull/4/head
miketout 6 years ago
parent
commit
185b2d4f2f
  1. 7
      src/cc/CoinbaseGuard.cpp
  2. 39
      src/cc/CoinbaseGuard.h
  3. 16
      src/komodo_bitcoind.h
  4. 39
      src/script/standard.h

7
src/cc/CoinbaseGuard.cpp

@ -255,10 +255,13 @@ bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTr
uint256 utxo = hw.GetHash();
uint32_t height = 0;
for (int i = 0; i < ccp.vData[2].size(); i++)
int i, dataLen = ccp.vData[2].size();
for (i = dataLen - 1; i >= 0; i--)
{
height = height << 8 + ccp.vData[2][i];
height = (height << 8) + ccp.vData[2][i];
}
// strange issue
printf("iterator: %d, height: %d, datalen: %d\n", i, height, dataLen);
if (utxo == uint256(ccp.vData[0]))
{

39
src/cc/CoinbaseGuard.h

@ -20,45 +20,6 @@
#define DEFAULT_STAKE_TXFEE 0
class CStakeParams
{
public:
static const uint32_t STAKE_MINPARAMS = 4;
static const uint32_t STAKE_MAXPARAMS = 5;
uint32_t srcHeight;
uint32_t blkHeight;
uint256 prevHash;
CPubKey pk;
CStakeParams() : srcHeight(0), blkHeight(0), prevHash(), pk() {}
CStakeParams(const std::vector<std::vector<unsigned char>> &vData);
CStakeParams(uint32_t _srcHeight, uint32_t _blkHeight, const uint256 &_prevHash, const CPubKey &_pk) :
srcHeight(_srcHeight), blkHeight(_blkHeight), prevHash(_prevHash), pk(_pk) {}
std::vector<unsigned char> AsVector()
{
std::vector<unsigned char> ret;
CScript scr = CScript();
scr << OPRETTYPE_STAKEPARAMS;
scr << srcHeight;
scr << blkHeight;
scr << std::vector<unsigned char>(prevHash.begin(), prevHash.end());
if (pk.IsValid())
{
scr << std::vector<unsigned char>(pk.begin(), pk.end());
}
ret = std::vector<unsigned char>(scr.begin(), scr.end());
return ret;
}
bool IsValid() { return srcHeight != 0; }
};
bool UnpackStakeOpRet(const CTransaction &stakeTx, std::vector<std::vector<unsigned char>> &vData);
bool GetStakeParams(const CTransaction &stakeTx, CStakeParams &stakeParams);

16
src/komodo_bitcoind.h

@ -20,6 +20,7 @@
#include "primitives/nonce.h"
#include "consensus/params.h"
#include "komodo_defs.h"
#include "script/standard.h"
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp);
@ -1454,6 +1455,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_
return(isPoS != 0);
}
bool GetStakeParams(const CTransaction &stakeTx, CStakeParams &stakeParams);
bool ValidateMatchingStake(const CTransaction &ccTx, uint32_t voutNum, const CTransaction &stakeTx, bool &cheating);
// for now, we will ignore slowFlag in the interest of keeping success/fail simpler for security purposes
@ -1510,6 +1512,20 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
{
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 (p.prevHash != pblock->hashPrevBlock || p.blkHeight != height)
{
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;
}
}
}
}
}
if (validHash)

39
src/script/standard.h

@ -106,6 +106,45 @@ class COptCCParams
std::vector<unsigned char> AsVector();
};
class CStakeParams
{
public:
static const uint32_t STAKE_MINPARAMS = 4;
static const uint32_t STAKE_MAXPARAMS = 5;
uint32_t srcHeight;
uint32_t blkHeight;
uint256 prevHash;
CPubKey pk;
CStakeParams() : srcHeight(0), blkHeight(0), prevHash(), pk() {}
CStakeParams(const std::vector<std::vector<unsigned char>> &vData);
CStakeParams(uint32_t _srcHeight, uint32_t _blkHeight, const uint256 &_prevHash, const CPubKey &_pk) :
srcHeight(_srcHeight), blkHeight(_blkHeight), prevHash(_prevHash), pk(_pk) {}
std::vector<unsigned char> AsVector()
{
std::vector<unsigned char> ret;
CScript scr = CScript();
scr << OPRETTYPE_STAKEPARAMS;
scr << srcHeight;
scr << blkHeight;
scr << std::vector<unsigned char>(prevHash.begin(), prevHash.end());
if (pk.IsValid())
{
scr << std::vector<unsigned char>(pk.begin(), pk.end());
}
ret = std::vector<unsigned char>(scr.begin(), scr.end());
return ret;
}
bool IsValid() { return srcHeight != 0; }
};
/** Check whether a CTxDestination is a CNoDestination. */
bool IsValidDestination(const CTxDestination& dest);

Loading…
Cancel
Save