Skip to content

Commit b4b6caf

Browse files
committed
Updated to work with block major version 4.
1 parent 3ba1fe1 commit b4b6caf

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/cryptonote_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define BLOCK_MAJOR_VERSION_1 1
99
#define BLOCK_MAJOR_VERSION_2 2
1010
#define BLOCK_MAJOR_VERSION_3 3
11+
#define BLOCK_MAJOR_VERSION_4 4
1112

1213
#define COIN ((uint64_t)100000000) // pow(10, 8)
1314
#define DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6)

src/cryptonote_core/cryptonote_basic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ namespace cryptonote
456456

457457
BEGIN_SERIALIZE()
458458
VARINT_FIELD(major_version)
459-
if(major_version > BLOCK_MAJOR_VERSION_3) return false;
459+
if(major_version > BLOCK_MAJOR_VERSION_4) return false;
460460
VARINT_FIELD(minor_version)
461461
if (BLOCK_MAJOR_VERSION_1 == major_version)
462462
{

src/cryptonote_core/cryptonote_format_utils.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,13 @@ namespace cryptonote
772772
blobdata bd;
773773
if(!get_bytecoin_block_hashing_blob(b, bd))
774774
return false;
775-
crypto::cn_slow_hash(bd.data(), bd.size(), res);
775+
if (b.major_version == BLOCK_MAJOR_VERSION_3) {
776+
crypto::cn_slow_hash(bd.data(), bd.size(), res);
777+
}
778+
else if (b.major_version == BLOCK_MAJOR_VERSION_4) {
779+
// TODO: Integrate the Cryptonight v7 variant. (OPTIONAL)
780+
// This is not required for the node-cryptonote-utils package.
781+
}
776782
return true;
777783
}
778784
//---------------------------------------------------------------
@@ -860,7 +866,7 @@ namespace cryptonote
860866
//---------------------------------------------------------------
861867
bool check_proof_of_work_v2(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work)
862868
{
863-
if (BLOCK_MAJOR_VERSION_2 != bl.major_version || BLOCK_MAJOR_VERSION_3 != bl.major_version)
869+
if (BLOCK_MAJOR_VERSION_2 != bl.major_version || BLOCK_MAJOR_VERSION_3 != bl.major_version || BLOCK_MAJOR_VERSION_4 != bl.major_version)
864870
return false;
865871

866872
if (!get_bytecoin_block_longhash(bl, proof_of_work))
@@ -901,6 +907,7 @@ namespace cryptonote
901907
case BLOCK_MAJOR_VERSION_1: return check_proof_of_work_v1(bl, current_diffic, proof_of_work);
902908
case BLOCK_MAJOR_VERSION_2: return check_proof_of_work_v2(bl, current_diffic, proof_of_work);
903909
case BLOCK_MAJOR_VERSION_3: return check_proof_of_work_v2(bl, current_diffic, proof_of_work);
910+
case BLOCK_MAJOR_VERSION_4: return check_proof_of_work_v2(bl, current_diffic, proof_of_work);
904911
}
905912

906913
CHECK_AND_ASSERT_MES(false, false, "unknown block major version: " << bl.major_version << "." << bl.minor_version);

src/main.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ NAN_METHOD(construct_block_blob) {
182182
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
183183
return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
184184
}
185+
if (b.major_version == BLOCK_MAJOR_VERSION_4) {
186+
block parent_block;
187+
b.parent_block.nonce = nonce;
188+
if (!construct_parent_block(b, parent_block))
189+
return THROW_ERROR_EXCEPTION("Failed to construct parent block");
190+
191+
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
192+
return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
193+
}
185194

186195
if (!block_to_blob(b, output))
187196
return THROW_ERROR_EXCEPTION("Failed to convert block to blob");

0 commit comments

Comments
 (0)