Support for forknote (BCN, ...) v2 and v3 Blocks

This commit is contained in:
wallet42
2016-05-21 18:16:47 -05:00
parent e87d0672b0
commit bf202c86c4
6 changed files with 41 additions and 29 deletions
+14 -8
View File
@@ -456,11 +456,17 @@ namespace cryptonote
BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
if(major_version > BLOCK_MAJOR_VERSION_2) return false;
if(major_version > BLOCK_MAJOR_VERSION_3) return false;
VARINT_FIELD(minor_version)
VARINT_FIELD(timestamp)
if (BLOCK_MAJOR_VERSION_1 == major_version)
{
VARINT_FIELD(timestamp)
}
FIELD(prev_id)
FIELD(nonce)
if (BLOCK_MAJOR_VERSION_1 == major_version)
{
FIELD(nonce)
}
END_SERIALIZE()
};
@@ -473,11 +479,11 @@ namespace cryptonote
BEGIN_SERIALIZE_OBJECT()
FIELDS(*static_cast<block_header *>(this))
// if (BLOCK_MAJOR_VERSION_2 <= major_version)
// {
// auto sbb = make_serializable_bytecoin_block(*this, false, false);
// FIELD_N("parent_block", sbb);
// }
if (BLOCK_MAJOR_VERSION_2 <= major_version)
{
auto sbb = make_serializable_bytecoin_block(*this, false, false);
FIELD_N("parent_block", sbb);
}
FIELD(miner_tx)
FIELD(tx_hashes)
END_SERIALIZE()
+14 -12
View File
@@ -650,15 +650,15 @@ namespace cryptonote
if (!get_block_hashing_blob(b, blob))
return false;
// if (BLOCK_MAJOR_VERSION_2 <= b.major_version)
// {
// blobdata parent_blob;
// auto sbb = make_serializable_bytecoin_block(b, true, false);
// if (!t_serializable_object_to_blob(sbb, parent_blob))
// return false;
if (BLOCK_MAJOR_VERSION_2 <= b.major_version)
{
blobdata parent_blob;
auto sbb = make_serializable_bytecoin_block(b, true, false);
if (!t_serializable_object_to_blob(sbb, parent_blob))
return false;
// blob.append(parent_blob);
// }
blob.append(parent_blob);
}
return get_object_hash(blob, res);
}
@@ -851,8 +851,8 @@ namespace cryptonote
//---------------------------------------------------------------
bool check_proof_of_work_v1(const block& bl, difficulty_type current_diffic, crypto::hash& proof_of_work)
{
// if (BLOCK_MAJOR_VERSION_1 != bl.major_version)
// return false;
if (BLOCK_MAJOR_VERSION_1 != bl.major_version)
return false;
proof_of_work = get_block_longhash(bl, 0);
return check_hash(proof_of_work, current_diffic);
@@ -860,7 +860,8 @@ 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)
if (BLOCK_MAJOR_VERSION_2 != bl.major_version ||
BLOCK_MAJOR_VERSION_3 != bl.major_version)
return false;
if (!get_bytecoin_block_longhash(bl, proof_of_work))
@@ -899,7 +900,8 @@ namespace cryptonote
switch (bl.major_version)
{
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_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);
}
CHECK_AND_ASSERT_MES(false, false, "unknown block major version: " << bl.major_version << "." << bl.minor_version);