mirror of
https://github.com/monero-project/monero.git
synced 2025-07-27 22:05:27 -04:00
parent
34da7d852b
commit
f5df0e272e
17 changed files with 185 additions and 113 deletions
|
@ -53,6 +53,9 @@
|
|||
#include "ringct/rctSigs.h"
|
||||
#include "common/perf_timer.h"
|
||||
#include "common/notify.h"
|
||||
#if defined(PER_BLOCK_CHECKPOINT)
|
||||
#include "blocks/blocks.h"
|
||||
#endif
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "blockchain"
|
||||
|
@ -338,7 +341,7 @@ uint64_t Blockchain::get_current_blockchain_height() const
|
|||
//------------------------------------------------------------------
|
||||
//FIXME: possibly move this into the constructor, to avoid accidentally
|
||||
// dereferencing a null BlockchainDB pointer
|
||||
bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline, const cryptonote::test_options *test_options, difficulty_type fixed_difficulty, const GetCheckpointsCallback get_checkpoints/* = nullptr*/)
|
||||
bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline, const cryptonote::test_options *test_options, difficulty_type fixed_difficulty)
|
||||
{
|
||||
LOG_PRINT_L3("Blockchain::" << __func__);
|
||||
CRITICAL_REGION_LOCAL(m_tx_pool);
|
||||
|
@ -436,7 +439,7 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
|
|||
|
||||
#if defined(PER_BLOCK_CHECKPOINT)
|
||||
if (m_nettype != FAKECHAIN)
|
||||
load_compiled_in_block_hashes(get_checkpoints);
|
||||
load_compiled_in_block_hashes();
|
||||
#endif
|
||||
|
||||
MINFO("Blockchain initialized. last block: " << m_db->height() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block());
|
||||
|
@ -4401,21 +4404,19 @@ void Blockchain::cancel()
|
|||
|
||||
#if defined(PER_BLOCK_CHECKPOINT)
|
||||
static const char expected_block_hashes_hash[] = "954cb2bbfa2fe6f74b2cdd22a1a4c767aea249ad47ad4f7c9445f0f03260f511";
|
||||
void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback get_checkpoints)
|
||||
void Blockchain::load_compiled_in_block_hashes()
|
||||
{
|
||||
if (get_checkpoints == nullptr || !m_fast_sync)
|
||||
const bool testnet = m_nettype == TESTNET;
|
||||
const bool stagenet = m_nettype == STAGENET;
|
||||
if (m_fast_sync && get_blocks_dat_start(testnet, stagenet) != nullptr && get_blocks_dat_size(testnet, stagenet) > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const epee::span<const unsigned char> checkpoints = get_checkpoints(m_nettype);
|
||||
if (!checkpoints.empty())
|
||||
{
|
||||
MINFO("Loading precomputed blocks (" << checkpoints.size() << " bytes)");
|
||||
MINFO("Loading precomputed blocks (" << get_blocks_dat_size(testnet, stagenet) << " bytes)");
|
||||
|
||||
if (m_nettype == MAINNET)
|
||||
{
|
||||
// first check hash
|
||||
crypto::hash hash;
|
||||
if (!tools::sha256sum(checkpoints.data(), checkpoints.size(), hash))
|
||||
if (!tools::sha256sum(get_blocks_dat_start(testnet, stagenet), get_blocks_dat_size(testnet, stagenet), hash))
|
||||
{
|
||||
MERROR("Failed to hash precomputed blocks data");
|
||||
return;
|
||||
|
@ -4435,9 +4436,9 @@ void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback get_
|
|||
}
|
||||
}
|
||||
|
||||
if (checkpoints.size() > 4)
|
||||
if (get_blocks_dat_size(testnet, stagenet) > 4)
|
||||
{
|
||||
const unsigned char *p = checkpoints.data();
|
||||
const unsigned char *p = get_blocks_dat_start(testnet, stagenet);
|
||||
const uint32_t nblocks = *p | ((*(p+1))<<8) | ((*(p+2))<<16) | ((*(p+3))<<24);
|
||||
if (nblocks > (std::numeric_limits<uint32_t>::max() - 4) / sizeof(hash))
|
||||
{
|
||||
|
@ -4445,7 +4446,7 @@ void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback get_
|
|||
return;
|
||||
}
|
||||
const size_t size_needed = 4 + nblocks * sizeof(crypto::hash);
|
||||
if(nblocks > 0 && nblocks > (m_db->height() + HASH_OF_HASHES_STEP - 1) / HASH_OF_HASHES_STEP && checkpoints.size() >= size_needed)
|
||||
if(nblocks > 0 && nblocks > (m_db->height() + HASH_OF_HASHES_STEP - 1) / HASH_OF_HASHES_STEP && get_blocks_dat_size(testnet, stagenet) >= size_needed)
|
||||
{
|
||||
p += sizeof(uint32_t);
|
||||
m_blocks_hash_of_hashes.reserve(nblocks);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue