Sync with latest Komodo changes

This commit is contained in:
Michael Toutonghi
2018-08-06 12:52:22 -07:00
150 changed files with 10076 additions and 2162 deletions

View File

@@ -87,7 +87,8 @@ uint256 CBlockHeader::GetVerusEntropyHash(int32_t height) const
return GetHash();
}
uint256 CBlock::BuildMerkleTree(bool* fMutated) const
uint256 BuildMerkleTree(bool* fMutated, const std::vector<uint256> leaves,
std::vector<uint256> &vMerkleTree)
{
/* WARNING! If you're reading this because you're learning about crypto
and/or designing a new system that will use merkle trees, keep in mind
@@ -100,10 +101,10 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
transactions leading to the same merkle root. For example, these two
trees:
A A
/ \ / \
B C B C
/ \ | / \ / \
A A
/ \ / \
B C B C
/ \ \ / \ / \
D E F D E F F
/ \ / \ / \ / \ / \ / \ / \
1 2 3 4 5 6 1 2 3 4 5 6 5 6
@@ -124,13 +125,14 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
known ways of changing the transactions without affecting the merkle
root.
*/
vMerkleTree.clear();
vMerkleTree.reserve(vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes.
for (std::vector<CTransaction>::const_iterator it(vtx.begin()); it != vtx.end(); ++it)
vMerkleTree.push_back(it->GetHash());
vMerkleTree.reserve(leaves.size() * 2 + 16); // Safe upper bound for the number of total nodes.
for (std::vector<uint256>::const_iterator it(leaves.begin()); it != leaves.end(); ++it)
vMerkleTree.push_back(*it);
int j = 0;
bool mutated = false;
for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
for (int nSize = leaves.size(); nSize > 1; nSize = (nSize + 1) / 2)
{
for (int i = 0; i < nSize; i += 2)
{
@@ -150,13 +152,20 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const
return (vMerkleTree.empty() ? uint256() : vMerkleTree.back());
}
std::vector<uint256> CBlock::GetMerkleBranch(int nIndex) const
uint256 CBlock::BuildMerkleTree(bool* fMutated) const
{
std::vector<uint256> leaves;
for (int i=0; i<vtx.size(); i++) leaves.push_back(vtx[i].GetHash());
return ::BuildMerkleTree(fMutated, leaves, vMerkleTree);
}
std::vector<uint256> GetMerkleBranch(int nIndex, int nLeaves, const std::vector<uint256> &vMerkleTree)
{
if (vMerkleTree.empty())
BuildMerkleTree();
std::vector<uint256> vMerkleBranch;
int j = 0;
for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
for (int nSize = nLeaves; nSize > 1; nSize = (nSize + 1) / 2)
{
int i = std::min(nIndex^1, nSize-1);
vMerkleBranch.push_back(vMerkleTree[j+i]);
@@ -166,6 +175,15 @@ std::vector<uint256> CBlock::GetMerkleBranch(int nIndex) const
return vMerkleBranch;
}
std::vector<uint256> CBlock::GetMerkleBranch(int nIndex) const
{
if (vMerkleTree.empty())
BuildMerkleTree();
return ::GetMerkleBranch(nIndex, vtx.size(), vMerkleTree);
}
uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex)
{
if (nIndex == -1)

View File

@@ -229,6 +229,12 @@ public:
};
uint256 BuildMerkleTree(bool* fMutated, const std::vector<uint256> leaves,
std::vector<uint256> &vMerkleTree);
std::vector<uint256> GetMerkleBranch(int nIndex, int nLeaves, const std::vector<uint256> &vMerkleTree);
/**
* Custom serializer for CBlockHeader that omits the nonce and solution, for use
* as input to Equihash.

View File

@@ -232,11 +232,26 @@ CAmount CTransaction::GetJoinSplitValueIn() const
{
// NB: vpub_new "gives" money to the value pool just as inputs do
nValue += it->vpub_new;
if (!MoneyRange(it->vpub_new) || !MoneyRange(nValue))
throw std::runtime_error("CTransaction::GetJoinSplitValueIn(): value out of range");
}
return nValue;
}
CAmount CTransaction::GetJoinSplitValueOut() const
{
CAmount nValue = 0;
for (std::vector<JSDescription>::const_iterator it(vjoinsplit.begin()); it != vjoinsplit.end(); ++it)
{
// NB: vpub_new "gives" money to the value pool just as inputs do
nValue += it->vpub_old;
if (!MoneyRange(it->vpub_old) || !MoneyRange(nValue))
throw std::runtime_error("CTransaction::GetJoinSplitValueOut(): value out of range");
}
return nValue;
}

View File

@@ -450,6 +450,8 @@ public:
// Return sum of JoinSplit vpub_new
CAmount GetJoinSplitValueIn() const;
// Return sum of JoinSplit vpub_old
CAmount GetJoinSplitValueOut() const;
// Compute priority, given priority of inputs and (optionally) tx size
double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const;
@@ -457,6 +459,11 @@ public:
// Compute modified tx size for priority calculation (optionally given tx size)
unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const;
bool IsMint() const
{
return IsCoinImport() || IsCoinBase();
}
bool IsCoinBase() const
{
return (vin.size() == 1 && vin[0].prevout.IsNull());
@@ -464,6 +471,11 @@ public:
int64_t UnlockTime(uint32_t voutNum) const;
bool IsCoinImport() const
{
return (vin.size() == 1 && vin[0].prevout.n == 10e8);
}
friend bool operator==(const CTransaction& a, const CTransaction& b)
{
return a.hash == b.hash;