Skip to content

Commit

Permalink
Updated to work with block major version 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
sumlnoether committed Mar 26, 2018
1 parent 3ba1fe1 commit b4b6caf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define BLOCK_MAJOR_VERSION_1 1
#define BLOCK_MAJOR_VERSION_2 2
#define BLOCK_MAJOR_VERSION_3 3
#define BLOCK_MAJOR_VERSION_4 4

#define COIN ((uint64_t)100000000) // pow(10, 8)
#define DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6)
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_core/cryptonote_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ namespace cryptonote

BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
if(major_version > BLOCK_MAJOR_VERSION_3) return false;
if(major_version > BLOCK_MAJOR_VERSION_4) return false;
VARINT_FIELD(minor_version)
if (BLOCK_MAJOR_VERSION_1 == major_version)
{
Expand Down
11 changes: 9 additions & 2 deletions src/cryptonote_core/cryptonote_format_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,13 @@ namespace cryptonote
blobdata bd;
if(!get_bytecoin_block_hashing_blob(b, bd))
return false;
crypto::cn_slow_hash(bd.data(), bd.size(), res);
if (b.major_version == BLOCK_MAJOR_VERSION_3) {
crypto::cn_slow_hash(bd.data(), bd.size(), res);
}
else if (b.major_version == BLOCK_MAJOR_VERSION_4) {
// TODO: Integrate the Cryptonight v7 variant. (OPTIONAL)
// This is not required for the node-cryptonote-utils package.
}
return true;
}
//---------------------------------------------------------------
Expand Down Expand Up @@ -860,7 +866,7 @@ namespace cryptonote
//---------------------------------------------------------------
bool check_proof_of_work_v2(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work)
{
if (BLOCK_MAJOR_VERSION_2 != bl.major_version || BLOCK_MAJOR_VERSION_3 != bl.major_version)
if (BLOCK_MAJOR_VERSION_2 != bl.major_version || BLOCK_MAJOR_VERSION_3 != bl.major_version || BLOCK_MAJOR_VERSION_4 != bl.major_version)
return false;

if (!get_bytecoin_block_longhash(bl, proof_of_work))
Expand Down Expand Up @@ -901,6 +907,7 @@ namespace cryptonote
case BLOCK_MAJOR_VERSION_1: return check_proof_of_work_v1(bl, current_diffic, proof_of_work);
case BLOCK_MAJOR_VERSION_2: return check_proof_of_work_v2(bl, current_diffic, proof_of_work);
case BLOCK_MAJOR_VERSION_3: return check_proof_of_work_v2(bl, current_diffic, proof_of_work);
case BLOCK_MAJOR_VERSION_4: return check_proof_of_work_v2(bl, current_diffic, proof_of_work);
}

CHECK_AND_ASSERT_MES(false, false, "unknown block major version: " << bl.major_version << "." << bl.minor_version);
Expand Down
9 changes: 9 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ NAN_METHOD(construct_block_blob) {
if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
}
if (b.major_version == BLOCK_MAJOR_VERSION_4) {
block parent_block;
b.parent_block.nonce = nonce;
if (!construct_parent_block(b, parent_block))
return THROW_ERROR_EXCEPTION("Failed to construct parent block");

if (!mergeBlocks(parent_block, b, std::vector<crypto::hash>()))
return THROW_ERROR_EXCEPTION("Failed to postprocess mining block");
}

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

1 comment on commit b4b6caf

@vitorgamer58
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to forknote#1

Please sign in to comment.