diff options
author | Riccardo Spagni <ric@spagni.net> | 2014-09-06 21:57:37 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2014-09-06 21:57:37 +0200 |
commit | 3c2b74215b7c2d78f2bdcb46883eb104916be985 (patch) | |
tree | 16d8fcae07e2d617406565e05d96a8e44b6e8d19 /src/cryptonote_core | |
parent | Override for block hashing for block 202612 (diff) | |
parent | fix checkpoints (diff) | |
download | monero-3c2b74215b7c2d78f2bdcb46883eb104916be985.tar.xz |
Merge pull request #121 from fluffypony/masterv0.8.8.3
Fix tree_hash, patch for bad block 202612
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/blockchain_storage.cpp | 25 | ||||
-rw-r--r-- | src/cryptonote_core/checkpoints_create.h | 4 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.cpp | 23 |
3 files changed, 48 insertions, 4 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index e47c35ea5..c41b50204 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -88,7 +88,28 @@ bool blockchain_storage::init(const std::string& config_folder) m_config_folder = config_folder; LOG_PRINT_L0("Loading blockchain..."); const std::string filename = m_config_folder + "/" CRYPTONOTE_BLOCKCHAINDATA_FILENAME; - if(!tools::unserialize_obj_from_file(*this, filename)) + if(tools::unserialize_obj_from_file(*this, filename)) + { + + // checkpoints + + // mainchain + for (size_t height=0; height < m_blocks.size(); ++height) + { + CHECK_AND_ASSERT_MES((!m_checkpoints.is_in_checkpoint_zone(height)) || m_checkpoints.check_block(height,get_block_hash(m_blocks[height].bl)),false,"checkpoint fail, blockchain.bin invalid"); + } + + // check alt chains + #if 0 + // doesn't work when a checkpoint is added and there are already alt chains. However, the rest of the blockchain code suffers from the same issue, so ignore for now + // see issue #118 + BOOST_FOREACH(blocks_ext_by_hash::value_type& alt_block, m_alternative_chains) + { + CHECK_AND_ASSERT_MES(m_checkpoints.is_alternative_block_allowed(m_blocks.size()-1,alt_block.second.height),false,"stored alternative block not allowed, blockchain.bin invalid"); + } + #endif + } + else { LOG_PRINT_L0("Can't load blockchain storage from file, generating genesis block."); block bl = boost::value_initialized<block>(); @@ -743,7 +764,7 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto:: return false; } - //block is not related with head of main chain + //Block is not related with head of main chain //first of all - look in alternative chains container auto it_main_prev = m_blocks_index.find(b.prev_id); auto it_prev = m_alternative_chains.find(b.prev_id); diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 932f31da0..9d65dc243 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -42,6 +42,10 @@ namespace cryptonote { ADD_CHECKPOINT(29556, "53c484a8ed91e4da621bb2fa88106dbde426fe90d7ef07b9c1e5127fb6f3a7f6"); ADD_CHECKPOINT(50000, "0fe8758ab06a8b9cb35b7328fd4f757af530a5d37759f9d3e421023231f7b31c"); ADD_CHECKPOINT(80000, "a62dcd7b536f22e003ebae8726e9e7276f63d594e264b6f0cd7aab27b66e75e3"); + ADD_CHECKPOINT(202612, "bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698"); + ADD_CHECKPOINT(202613, "e2aa337e78df1f98f462b3b1e560c6b914dec47b610698b7b7d1e3e86b6197c2"); // from chainradar; verify this + ADD_CHECKPOINT(202614, "c29e3dc37d8da3e72e506e31a213a58771b24450144305bcba9e70fa4d6ea6fb"); // from chainradar; verify this + ADD_CHECKPOINT(205000, "5d3d7a26e6dc7535e34f03def711daa8c263785f73ec1fadef8a45880fde8063"); // from chainradar; verify this return true; } } diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 8b9f42376..d023561c3 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -635,10 +635,22 @@ namespace cryptonote if (string_tools::pod_to_hex(block_blob_hash) == correct_blob_hash_202612) { - res = string_tools::hex_to_pod(existing_block_id_202612); + string_tools::hex_to_pod(existing_block_id_202612, res); return true; } - return get_object_hash(get_block_hashing_blob(b), res); + bool hash_result = get_object_hash(get_block_hashing_blob(b), res); + + if (hash_result) + { + // make sure that we aren't looking at a block with the 202612 block id but not the correct blobdata + if (string_tools::pod_to_hex(res) == existing_block_id_202612) + { + LOG_ERROR("Block with block id for 202612 but incorrect block blob hash found!"); + res = null_hash; + return false; + } + } + return hash_result; } //--------------------------------------------------------------- crypto::hash get_block_hash(const block& b) @@ -677,6 +689,13 @@ namespace cryptonote //--------------------------------------------------------------- bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) { + // block 202612 bug workaround + const std::string longhash_202612 = "84f64766475d51837ac9efbef1926486e58563c95a19fef4aec3254f03000000"; + if (height == 202612) + { + string_tools::hex_to_pod(longhash_202612, res); + return true; + } block b_local = b; //workaround to avoid const errors with do_serialize blobdata bd = get_block_hashing_blob(b); crypto::cn_slow_hash(bd.data(), bd.size(), res); |