Cleanup nonce changes
This commit is contained in:
@@ -271,6 +271,7 @@ libbitcoin_server_a_SOURCES = \
|
|||||||
crypto/haraka.h \
|
crypto/haraka.h \
|
||||||
crypto/haraka_portable.h \
|
crypto/haraka_portable.h \
|
||||||
crypto/verus_hash.h \
|
crypto/verus_hash.h \
|
||||||
|
crypto/verus_hash.cpp \
|
||||||
deprecation.cpp \
|
deprecation.cpp \
|
||||||
httprpc.cpp \
|
httprpc.cpp \
|
||||||
httpserver.cpp \
|
httpserver.cpp \
|
||||||
@@ -410,6 +411,7 @@ libbitcoin_common_a_SOURCES = \
|
|||||||
crypto/haraka.h \
|
crypto/haraka.h \
|
||||||
crypto/haraka_portable.h \
|
crypto/haraka_portable.h \
|
||||||
crypto/verus_hash.h \
|
crypto/verus_hash.h \
|
||||||
|
crypto/verus_hash.cpp \
|
||||||
hash.cpp \
|
hash.cpp \
|
||||||
key.cpp \
|
key.cpp \
|
||||||
keystore.cpp \
|
keystore.cpp \
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class CVerusHash
|
|||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
|
|
||||||
CVerusHash() {}
|
CVerusHash() { }
|
||||||
|
|
||||||
CVerusHash &Write(const unsigned char *data, size_t len);
|
CVerusHash &Write(const unsigned char *data, size_t len);
|
||||||
|
|
||||||
@@ -37,6 +37,7 @@ class CVerusHash
|
|||||||
result = buf2;
|
result = buf2;
|
||||||
curPos = 0;
|
curPos = 0;
|
||||||
std::fill(buf1, buf1 + sizeof(buf1), 0);
|
std::fill(buf1, buf1 + sizeof(buf1), 0);
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); }
|
int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); }
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ public:
|
|||||||
int nType;
|
int nType;
|
||||||
int nVersion;
|
int nVersion;
|
||||||
|
|
||||||
CVerusHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn), state() {}
|
CVerusHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn), state() { }
|
||||||
|
|
||||||
CVerusHashWriter& write(const char *pch, size_t size) {
|
CVerusHashWriter& write(const char *pch, size_t size) {
|
||||||
state.Write((const unsigned char*)pch, size);
|
state.Write((const unsigned char*)pch, size);
|
||||||
|
|||||||
@@ -1271,7 +1271,12 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height)
|
|||||||
CTransaction tx;
|
CTransaction tx;
|
||||||
|
|
||||||
if (!pblock->IsVerusPOSBlock())
|
if (!pblock->IsVerusPOSBlock())
|
||||||
|
{
|
||||||
|
printf("%s, height %d not POS block\n", pblock->nNonce.GetHex().c_str(), height);
|
||||||
|
pblock->nNonce.SetPOSTarget(pblock->nNonce.GetPOSTarget());
|
||||||
|
printf("%s after setting POS target\n", pblock->nNonce.GetHex().c_str());
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
char voutaddr[64], destaddr[64], cbaddr[64];
|
char voutaddr[64], destaddr[64], cbaddr[64];
|
||||||
|
|
||||||
|
|||||||
@@ -462,9 +462,9 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, bool isStake)
|
|||||||
{
|
{
|
||||||
uint32_t nBitsPOS;
|
uint32_t nBitsPOS;
|
||||||
arith_uint256 posHash;
|
arith_uint256 posHash;
|
||||||
|
|
||||||
siglen = verus_staked(pblock, key, txStaked, nBitsPOS, posHash, utxosig);
|
siglen = verus_staked(pblock, key, txStaked, nBitsPOS, posHash, utxosig);
|
||||||
blocktime = GetAdjustedTime();
|
blocktime = GetAdjustedTime();
|
||||||
pblock->SetVerusPOSTarget(nBitsPOS);
|
|
||||||
|
|
||||||
// change the scriptPubKeyIn to the same output script exactly as the staking transaction
|
// change the scriptPubKeyIn to the same output script exactly as the staking transaction
|
||||||
if (siglen > 0)
|
if (siglen > 0)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public:
|
|||||||
return (int64_t)nTime;
|
return (int64_t)nTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t GetVerusPOSTarget() const
|
uint32_t GetVerusPOSTarget() const
|
||||||
{
|
{
|
||||||
uint32_t nBits = 0;
|
uint32_t nBits = 0;
|
||||||
|
|
||||||
@@ -112,19 +112,22 @@ public:
|
|||||||
return nNonce.IsPOSNonce();
|
return nNonce.IsPOSNonce();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetVerusPOSTarget(int32_t nBits)
|
void SetVerusPOSTarget(uint32_t nBits)
|
||||||
{
|
{
|
||||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
uint256 hash;
|
|
||||||
arith_uint256 tmpNonce;
|
|
||||||
|
|
||||||
arith_uint256 arNonce = UintToArith256(nNonce);
|
arith_uint256 arNonce = UintToArith256(nNonce);
|
||||||
arNonce = ((arNonce >> 32) << 32) | nBits;
|
|
||||||
|
|
||||||
tmpNonce = ((arNonce << 128) >> 128);
|
// printf("before svpt: %s\n", ArithToUint256(arNonce).GetHex().c_str());
|
||||||
hashWriter << ArithToUint256(tmpNonce);
|
|
||||||
|
|
||||||
nNonce = ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce);
|
arNonce = (arNonce & CPOSNonce::entropyMask) | nBits;
|
||||||
|
|
||||||
|
// printf("after clear: %s\n", ArithToUint256(arNonce).GetHex().c_str());
|
||||||
|
|
||||||
|
hashWriter << ArithToUint256(arNonce);
|
||||||
|
nNonce = CPOSNonce(ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | arNonce));
|
||||||
|
|
||||||
|
// printf(" after svpt: %s\n", nNonce.GetHex().c_str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
extern char ASSETCHAINS_SYMBOL[65];
|
extern char ASSETCHAINS_SYMBOL[65];
|
||||||
|
|
||||||
|
arith_uint256 CPOSNonce::entropyMask = UintToArith256(uint256S("00000000000000000000000000000000ffffffffffffffffffffffff00000000"));
|
||||||
|
arith_uint256 CPOSNonce::posDiffMask = UintToArith256(uint256S("00000000000000000000000000000000000000000000000000000000ffffffff"));
|
||||||
|
|
||||||
bool CPOSNonce::NewPOSActive(int32_t height)
|
bool CPOSNonce::NewPOSActive(int32_t height)
|
||||||
{
|
{
|
||||||
if ((strcmp(ASSETCHAINS_SYMBOL, "VRSC") == 0) && (height < (96480 + 100)))
|
if ((strcmp(ASSETCHAINS_SYMBOL, "VRSC") == 0) && (height < (96480 + 100)))
|
||||||
@@ -38,13 +41,17 @@ void CPOSNonce::SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t vou
|
|||||||
hashWriter << txid;
|
hashWriter << txid;
|
||||||
hashWriter << voutNum;
|
hashWriter << voutNum;
|
||||||
|
|
||||||
arith_uint256 arNonce = (UintToArith256(*this) & 0xffffffff) |
|
arith_uint256 arNonce = (UintToArith256(*this) & posDiffMask) |
|
||||||
((UintToArith256(hashWriter.GetHash()) & UintToArith256(uint256S("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))) << 32);
|
(UintToArith256(hashWriter.GetHash()) & entropyMask);
|
||||||
|
|
||||||
hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
// printf("before %s\n", ArithToUint256(arNonce).GetHex().c_str());
|
||||||
hashWriter << ArithToUint256(arNonce);
|
|
||||||
|
|
||||||
*this = CPOSNonce(ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | arNonce));
|
CVerusHashWriter newWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
|
newWriter << ArithToUint256(arNonce);
|
||||||
|
|
||||||
|
*this = CPOSNonce(ArithToUint256((UintToArith256(newWriter.GetHash()) << 128) | arNonce));
|
||||||
|
|
||||||
|
// printf("after %s\n", this->GetHex().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPOSNonce::CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum)
|
bool CPOSNonce::CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum)
|
||||||
@@ -57,8 +64,8 @@ bool CPOSNonce::CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t v
|
|||||||
hashWriter << txid;
|
hashWriter << txid;
|
||||||
hashWriter << voutNum;
|
hashWriter << voutNum;
|
||||||
|
|
||||||
arith_uint256 arNonce = (UintToArith256(*this) & 0xffffffff) |
|
arith_uint256 arNonce = (UintToArith256(*this) & posDiffMask) |
|
||||||
((UintToArith256(hashWriter.GetHash()) & UintToArith256(uint256S("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))) << 32);
|
(UintToArith256(hashWriter.GetHash()) & entropyMask);
|
||||||
|
|
||||||
hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
hashWriter << ArithToUint256(arNonce);
|
hashWriter << ArithToUint256(arNonce);
|
||||||
|
|||||||
@@ -19,9 +19,12 @@ public:
|
|||||||
static bool NewPOSActive(int32_t height);
|
static bool NewPOSActive(int32_t height);
|
||||||
static bool NewNonceActive(int32_t height);
|
static bool NewNonceActive(int32_t height);
|
||||||
|
|
||||||
CPOSNonce() {}
|
static arith_uint256 entropyMask;
|
||||||
CPOSNonce(const base_blob<256> &b) : uint256(b) {}
|
static arith_uint256 posDiffMask;
|
||||||
CPOSNonce(const std::vector<unsigned char> &vch) : uint256(vch) {}
|
|
||||||
|
CPOSNonce() : uint256() { }
|
||||||
|
CPOSNonce(const base_blob<256> &b) : uint256(b) { }
|
||||||
|
CPOSNonce(const std::vector<unsigned char> &vch) : uint256(vch) { }
|
||||||
|
|
||||||
int32_t GetPOSTarget() const
|
int32_t GetPOSTarget() const
|
||||||
{
|
{
|
||||||
@@ -44,18 +47,14 @@ public:
|
|||||||
return (*this == ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce));
|
return (*this == ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPOSTarget(int32_t nBits)
|
void SetPOSTarget(uint32_t nBits)
|
||||||
{
|
{
|
||||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
arith_uint256 tmpNonce;
|
|
||||||
|
|
||||||
arith_uint256 arNonce = UintToArith256(*this);
|
arith_uint256 arNonce = (UintToArith256(*this) & entropyMask) | nBits;
|
||||||
arNonce = ((arNonce >> 32) << 32) | nBits;
|
hashWriter << ArithToUint256(arNonce);
|
||||||
|
|
||||||
tmpNonce = ((arNonce << 128) >> 128);
|
(uint256 &)(*this) = ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | arNonce);
|
||||||
hashWriter << ArithToUint256(tmpNonce);
|
|
||||||
|
|
||||||
(uint256 &)(*this) = ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum);
|
void SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum);
|
||||||
|
|||||||
@@ -998,7 +998,7 @@ CWallet::TxItems CWallet::OrderedTxItems(std::list<CAccountingEntry>& acentries,
|
|||||||
// UTXO with the smallest coin age if there is more than one, as larger coin age will win more often and is worth saving
|
// UTXO with the smallest coin age if there is more than one, as larger coin age will win more often and is worth saving
|
||||||
// each attempt consists of taking a VerusHash of the following values:
|
// each attempt consists of taking a VerusHash of the following values:
|
||||||
// ASSETCHAINS_MAGIC, nHeight, txid, voutNum
|
// ASSETCHAINS_MAGIC, nHeight, txid, voutNum
|
||||||
bool CWallet::VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult, CTransaction &stakeSource, int32_t &voutNum, int32_t nHeight, uint32_t bnTarget) const
|
bool CWallet::VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult, CTransaction &stakeSource, int32_t &voutNum, int32_t nHeight, uint32_t &bnTarget) const
|
||||||
{
|
{
|
||||||
arith_uint256 target;
|
arith_uint256 target;
|
||||||
arith_uint256 curHash;
|
arith_uint256 curHash;
|
||||||
@@ -1017,6 +1017,7 @@ bool CWallet::VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult,
|
|||||||
{
|
{
|
||||||
CBlockHeader bh = pastBlockIndex->GetBlockHeader();
|
CBlockHeader bh = pastBlockIndex->GetBlockHeader();
|
||||||
uint256 pastHash = bh.GetVerusEntropyHash(nHeight);
|
uint256 pastHash = bh.GetVerusEntropyHash(nHeight);
|
||||||
|
CPOSNonce curNonce;
|
||||||
|
|
||||||
BOOST_FOREACH(COutput &txout, vecOutputs)
|
BOOST_FOREACH(COutput &txout, vecOutputs)
|
||||||
{
|
{
|
||||||
@@ -1026,19 +1027,21 @@ bool CWallet::VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult,
|
|||||||
if (Solver(txout.tx->vout[txout.i].scriptPubKey, whichType, vSolutions) && (whichType == TX_PUBKEY || whichType == TX_PUBKEYHASH) &&
|
if (Solver(txout.tx->vout[txout.i].scriptPubKey, whichType, vSolutions) && (whichType == TX_PUBKEY || whichType == TX_PUBKEYHASH) &&
|
||||||
(!pwinner || pwinner->tx->vout[pwinner->i].nValue > txout.tx->vout[txout.i].nValue))
|
(!pwinner || pwinner->tx->vout[pwinner->i].nValue > txout.tx->vout[txout.i].nValue))
|
||||||
pwinner = &txout;
|
pwinner = &txout;
|
||||||
|
curNonce = pBlock->nNonce;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pwinner)
|
if (pwinner)
|
||||||
{
|
{
|
||||||
stakeSource = *(pwinner->tx);
|
stakeSource = *(pwinner->tx);
|
||||||
voutNum = pwinner->i;
|
voutNum = pwinner->i;
|
||||||
|
pBlock->nNonce = curNonce;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNew, uint32_t bnTarget, arith_uint256 &hashResult, uint8_t *utxosig) const
|
int32_t CWallet::VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &bnTarget, arith_uint256 &hashResult, uint8_t *utxosig) const
|
||||||
{
|
{
|
||||||
CTransaction stakeSource;
|
CTransaction stakeSource;
|
||||||
int32_t voutNum, siglen = 0;
|
int32_t voutNum, siglen = 0;
|
||||||
|
|||||||
@@ -1149,8 +1149,8 @@ public:
|
|||||||
bool ignoreUnspendable=true);
|
bool ignoreUnspendable=true);
|
||||||
|
|
||||||
// staking functions
|
// staking functions
|
||||||
bool VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult, CTransaction &stakeSource, int32_t &voutNum, int32_t nHeight, uint32_t bnTarget) const;
|
bool VerusSelectStakeOutput(CBlock *pBlock, arith_uint256 &hashResult, CTransaction &stakeSource, int32_t &voutNum, int32_t nHeight, uint32_t &bnTarget) const;
|
||||||
int32_t VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNew, uint32_t bnTarget, arith_uint256 &hashResult, uint8_t *utxosig) const;
|
int32_t VerusStakeTransaction(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &bnTarget, arith_uint256 &hashResult, uint8_t *utxosig) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A key allocated from the key pool. */
|
/** A key allocated from the key pool. */
|
||||||
|
|||||||
Reference in New Issue
Block a user