Skip to content

Commit 23a47f7

Browse files
committed
Apply some Fork changes
Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com>
1 parent 3591b34 commit 23a47f7

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

Client.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@ std::vector<uint8_t> BlockHeader::toV8() const {
1818
for (uint32_t i(0) ; i < 4 ; i++) v8.push_back(reinterpret_cast<const uint8_t*>(&version)[i]);
1919
v8.insert(v8.end(), previousblockhash.begin(), previousblockhash.end());
2020
v8.insert(v8.end(), merkleRoot.begin(), merkleRoot.end());
21-
for (uint32_t i(0) ; i < 8 ; i++) v8.push_back(reinterpret_cast<const uint8_t*>(&curtime)[i]); // In Riecoin, nBits and nTime need to be swapped before hashing
21+
for (uint32_t i(0) ; i < 8 ; i++) v8.push_back(reinterpret_cast<const uint8_t*>(&curtime)[i]);
2222
for (uint32_t i(0) ; i < 4 ; i++) v8.push_back(reinterpret_cast<const uint8_t*>(&bits)[i]);
2323
v8.insert(v8.end(), nOffset.begin(), nOffset.end());
2424
return v8;
2525
}
2626

27-
std::array<uint8_t, 32> BlockHeader::powHash() const {
28-
std::array<uint8_t, 80> bhForPow;
29-
*reinterpret_cast<uint32_t*>(&bhForPow) = version;
30-
std::copy(previousblockhash.begin(), previousblockhash.end(), bhForPow.begin() + 4);
31-
std::copy(merkleRoot.begin(), merkleRoot.end(), bhForPow.begin() + 36);
32-
*reinterpret_cast<uint32_t*>(&bhForPow[68]) = bits; // In Riecoin, nBits and nTime need to be swapped before hashing
33-
*reinterpret_cast<uint64_t*>(&bhForPow[72]) = curtime;
34-
return sha256sha256(bhForPow.data(), 80);
27+
std::array<uint8_t, 32> BlockHeader::powHash(const int32_t powVersion) const {
28+
if (powVersion == -1) { // "Legacy" PoW: the hash is done after swapping nTime and nBits
29+
std::array<uint8_t, 80> bhForPow;
30+
*reinterpret_cast<uint32_t*>(&bhForPow) = version;
31+
std::copy(previousblockhash.begin(), previousblockhash.end(), bhForPow.begin() + 4);
32+
std::copy(merkleRoot.begin(), merkleRoot.end(), bhForPow.begin() + 36);
33+
*reinterpret_cast<uint32_t*>(&bhForPow[68]) = bits;
34+
*reinterpret_cast<uint64_t*>(&bhForPow[72]) = curtime;
35+
return sha256sha256(bhForPow.data(), 80);
36+
}
37+
else
38+
return sha256sha256(toV8().data(), 80);
3539
}
3640

3741
mpz_class BlockHeader::target(const int32_t powVersion) const {
@@ -46,7 +50,7 @@ mpz_class BlockHeader::target(const int32_t powVersion) const {
4650
else
4751
return 0;
4852

49-
const std::array<uint8_t, 32> hash(powHash());
53+
const std::array<uint8_t, 32> hash(powHash(powVersion));
5054
for (uint64_t i(0) ; i < 256 ; i++) {
5155
target <<= 1;
5256
if ((hash[i/8] >> (i % 8)) & 1)

Client.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ struct BlockHeader { // The fields are named according to the GetBlockTemplate l
2222

2323
BlockHeader() : version(0), previousblockhash{0}, merkleRoot{0}, curtime(0), bits(0), nOffset{0} {}
2424
std::vector<uint8_t> toV8() const;
25-
std::array<uint8_t, 32> powHash() const;
26-
mpz_class target(const int32_t powVersion) const;
25+
std::array<uint8_t, 32> powHash(const int32_t) const;
26+
mpz_class target(const int32_t) const;
2727
};
2828

2929
// Stores all the information needed for the miner and submissions

GBTClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ bool GBTClient::_fetchWork() {
176176
*jsonGbt_Res_Txs(json_object_get(jsonGbt_Res, "transactions")),
177177
*jsonGbt_Res_Rules(json_object_get(jsonGbt_Res, "rules")),
178178
*jsonGbt_Res_Dwc(json_object_get(jsonGbt_Res, "default_witness_commitment")),
179-
*jsonGbt_Res_Patterns(json_object_get(jsonGbt_Res, "constellations"));
179+
*jsonGbt_Res_Patterns(json_object_get(jsonGbt_Res, "patterns"));
180180

181181
// Failure to GetBlockTemplate (or invalid response)
182182
if (jsonGbt == nullptr || jsonGbt_Res == nullptr || jsonGbt_Res_Txs == nullptr || jsonGbt_Res_Rules == nullptr || jsonGbt_Res_Dwc == nullptr || json_array_size(jsonGbt_Res_Patterns) == 0) {

0 commit comments

Comments
 (0)