mirror of
https://github.com/GOSTSec/gostcoin
synced 2025-03-12 21:31:05 +00:00
initial changes for hard fork 1
This commit is contained in:
parent
17b06ad37a
commit
53c91d4039
19
src/hash.h
19
src/hash.h
@ -55,7 +55,7 @@ public:
|
||||
}
|
||||
|
||||
// invalidates the object
|
||||
uint256 GetHash() {
|
||||
uint256 GetHash() { // shouldn't be called after hard fork 1
|
||||
uint8_t hash1[64];
|
||||
i2p::crypto::GOSTR3411_2012_512 ((uint8_t *)ctx.str ().c_str (), ctx.str ().length (), hash1);
|
||||
uint256 hash2;
|
||||
@ -63,6 +63,12 @@ public:
|
||||
return hash2;
|
||||
}
|
||||
|
||||
uint256 GetHashHF1()
|
||||
{
|
||||
const uint8_t * buf = (const uint8_t *)ctx.str ().c_str ();
|
||||
return Hash (buf, buf + ctx.str ().length ());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CHashWriter& operator<<(const T& obj) {
|
||||
// Serialize to this stream
|
||||
@ -73,7 +79,7 @@ public:
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline uint256 Hash(const T1 p1begin, const T1 p1end,
|
||||
const T2 p2begin, const T2 p2end)
|
||||
const T2 p2begin, const T2 p2end) // shouldn't be called after hard fork 1
|
||||
{
|
||||
static unsigned char pblank[1];
|
||||
size_t s1 = (p1end - p1begin) * sizeof(p1begin[0]),
|
||||
@ -94,12 +100,21 @@ uint256 Hash (const uint256& left, const uint256& right); // for Merkle tree
|
||||
|
||||
template<typename T>
|
||||
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
||||
// shouldn't be called after hard fork 1
|
||||
{
|
||||
CHashWriter ss(nType, nVersion);
|
||||
ss << obj;
|
||||
return ss.GetHash();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
uint256 SerializeHashHF1(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
||||
{
|
||||
CHashWriter ss(nType, nVersion);
|
||||
ss << obj;
|
||||
return ss.GetHashHF1();
|
||||
}
|
||||
|
||||
template<typename T1>
|
||||
inline uint160 Hash160(const T1 pbegin, const T1 pend)
|
||||
{
|
||||
|
35
src/main.h
35
src/main.h
@ -26,6 +26,8 @@ class CNode;
|
||||
|
||||
struct CBlockIndexWorkComparator;
|
||||
|
||||
static const int HARDFORK_BLOCK1 = 100000000; // TODO: set actual block # when ready
|
||||
|
||||
/** The maximum allowed size for a serialized block, in bytes (network rule) */
|
||||
static const unsigned int MAX_BLOCK_SIZE = 1000000; // 1000KB block hard limit
|
||||
/** The maximum size for mined blocks */
|
||||
@ -423,7 +425,7 @@ public:
|
||||
|
||||
uint256 GetHash() const
|
||||
{
|
||||
return SerializeHash(*this);
|
||||
return (nBestHeight >= HARDFORK_BLOCK1) ? SerializeHashHF1(*this) : SerializeHash(*this);
|
||||
}
|
||||
|
||||
friend bool operator==(const CTxOut& a, const CTxOut& b)
|
||||
@ -504,7 +506,7 @@ public:
|
||||
|
||||
uint256 GetHash() const
|
||||
{
|
||||
return SerializeHash(*this);
|
||||
return (nBestHeight >= HARDFORK_BLOCK1) ? SerializeHashHF1(*this) : SerializeHash(*this);
|
||||
}
|
||||
|
||||
bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
|
||||
@ -794,7 +796,7 @@ public:
|
||||
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
|
||||
hasher << hashBlock;
|
||||
hasher << *this;
|
||||
fileout << hasher.GetHash();
|
||||
fileout << (nBestHeight >= HARDFORK_BLOCK1) ? hasher.GetHashHF1 () : hasher.GetHash();
|
||||
|
||||
// Flush stdio buffers and commit to disk before returning
|
||||
fflush(fileout);
|
||||
@ -825,7 +827,7 @@ public:
|
||||
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
|
||||
hasher << hashBlock;
|
||||
hasher << *this;
|
||||
if (hashChecksum != hasher.GetHash())
|
||||
if (hashChecksum != ((nBestHeight >= HARDFORK_BLOCK1) ? hasher.GetHashHF1 () : hasher.GetHash()))
|
||||
return error("CBlockUndo::ReadFromDisk() : checksum mismatch");
|
||||
|
||||
return true;
|
||||
@ -1377,8 +1379,11 @@ public:
|
||||
for (int i = 0; i < nSize; i += 2)
|
||||
{
|
||||
int i2 = std::min(i+1, nSize-1);
|
||||
vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]), END(vMerkleTree[j+i]),
|
||||
BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
|
||||
if (nBestHeight >= HARDFORK_BLOCK1)
|
||||
vMerkleTree.push_back(Hash (vMerkleTree[j+i], vMerkleTree[j+i2]));
|
||||
else
|
||||
vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]), END(vMerkleTree[j+i]),
|
||||
BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
|
||||
}
|
||||
j += nSize;
|
||||
}
|
||||
@ -1413,10 +1418,20 @@ public:
|
||||
return 0;
|
||||
BOOST_FOREACH(const uint256& otherside, vMerkleBranch)
|
||||
{
|
||||
if (nIndex & 1)
|
||||
hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
|
||||
else
|
||||
hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
|
||||
if (nBestHeight >= HARDFORK_BLOCK1)
|
||||
{
|
||||
if (nIndex & 1)
|
||||
hash = Hash(otherside, hash);
|
||||
else
|
||||
hash = Hash(hash, otherside);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nIndex & 1)
|
||||
hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
|
||||
else
|
||||
hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
|
||||
}
|
||||
nIndex >>= 1;
|
||||
}
|
||||
return hash;
|
||||
|
Loading…
x
Reference in New Issue
Block a user