mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
Move checkpoint functions into checkpoints class
The functions in src/cryptonote_core/checkpoints_create.{h,cpp} should be member functions of the checkpoints class, if nothing else for the sake of keeping their documentation together. This commit covers moving those functions to be member functions of the checkpoints class as well as documenting those functions.
This commit is contained in:
parent
1b0c98e7e9
commit
540a76c5c2
@ -31,7 +31,6 @@ set(cryptonote_core_sources
|
||||
blockchain_storage.cpp
|
||||
blockchain.cpp
|
||||
checkpoints.cpp
|
||||
checkpoints_create.cpp
|
||||
cryptonote_basic_impl.cpp
|
||||
cryptonote_core.cpp
|
||||
cryptonote_format_utils.cpp
|
||||
@ -49,7 +48,6 @@ set(cryptonote_core_private_headers
|
||||
blockchain_storage_boost_serialization.h
|
||||
blockchain.h
|
||||
checkpoints.h
|
||||
checkpoints_create.h
|
||||
connection_context.h
|
||||
cryptonote_basic.h
|
||||
cryptonote_basic_impl.h
|
||||
|
@ -49,7 +49,7 @@
|
||||
#include "common/boost_serialization_helper.h"
|
||||
#include "warnings.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "cryptonote_core/checkpoints_create.h"
|
||||
#include "cryptonote_core/checkpoints.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#if defined(PER_BLOCK_CHECKPOINT)
|
||||
#include "blocks/blocks.h"
|
||||
@ -2860,16 +2860,16 @@ void Blockchain::check_against_checkpoints(const checkpoints& points, bool enfor
|
||||
// with an existing checkpoint.
|
||||
bool Blockchain::update_checkpoints(const std::string& file_path, bool check_dns)
|
||||
{
|
||||
if (!cryptonote::load_checkpoints_from_json(m_checkpoints, file_path))
|
||||
if (!m_checkpoints.load_checkpoints_from_json(file_path))
|
||||
{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we're checking both dns and json, load checkpoints from dns.
|
||||
// if we're not hard-enforcing dns checkpoints, handle accordingly
|
||||
if (m_enforce_dns_checkpoints && check_dns)
|
||||
{
|
||||
if (!cryptonote::load_checkpoints_from_dns(m_checkpoints))
|
||||
if (!m_checkpoints.load_checkpoints_from_dns())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -2877,7 +2877,7 @@ bool Blockchain::update_checkpoints(const std::string& file_path, bool check_dns
|
||||
else if (check_dns)
|
||||
{
|
||||
checkpoints dns_points;
|
||||
cryptonote::load_checkpoints_from_dns(dns_points);
|
||||
dns_points.load_checkpoints_from_dns();
|
||||
if (m_checkpoints.check_for_conflicts(dns_points))
|
||||
{
|
||||
check_against_checkpoints(dns_points, false);
|
||||
|
@ -48,7 +48,7 @@
|
||||
#include "common/boost_serialization_helper.h"
|
||||
#include "warnings.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "cryptonote_core/checkpoints_create.h"
|
||||
#include "cryptonote_core/checkpoints.h"
|
||||
//#include "serialization/json_archive.h"
|
||||
#include "../../contrib/otshell_utils/utils.hpp"
|
||||
#include "../../src/p2p/data_logger.hpp"
|
||||
@ -1854,7 +1854,7 @@ void blockchain_storage::check_against_checkpoints(const checkpoints& points, bo
|
||||
// with an existing checkpoint.
|
||||
bool blockchain_storage::update_checkpoints(const std::string& file_path, bool check_dns)
|
||||
{
|
||||
if (!cryptonote::load_checkpoints_from_json(m_checkpoints, file_path))
|
||||
if (!m_checkpoints.load_checkpoints_from_json(file_path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1863,7 +1863,7 @@ bool blockchain_storage::update_checkpoints(const std::string& file_path, bool c
|
||||
// if we're not hard-enforcing dns checkpoints, handle accordingly
|
||||
if (m_enforce_dns_checkpoints && check_dns)
|
||||
{
|
||||
if (!cryptonote::load_checkpoints_from_dns(m_checkpoints))
|
||||
if (!m_checkpoints.load_checkpoints_from_dns())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -1871,7 +1871,7 @@ bool blockchain_storage::update_checkpoints(const std::string& file_path, bool c
|
||||
else if (check_dns)
|
||||
{
|
||||
checkpoints dns_points;
|
||||
cryptonote::load_checkpoints_from_dns(dns_points, m_testnet);
|
||||
dns_points.load_checkpoints_from_dns(m_testnet);
|
||||
if (m_checkpoints.check_for_conflicts(dns_points))
|
||||
{
|
||||
check_against_checkpoints(dns_points, false);
|
||||
|
@ -1,21 +1,21 @@
|
||||
// Copyright (c) 2014-2016, The Monero Project
|
||||
//
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
@ -25,14 +25,44 @@
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#include "include_base_utils.h"
|
||||
|
||||
using namespace epee;
|
||||
|
||||
#include "checkpoints.h"
|
||||
|
||||
#include "common/dns_utils.h"
|
||||
#include "include_base_utils.h"
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool dns_records_match(const std::vector<std::string>& a, const std::vector<std::string>& b)
|
||||
{
|
||||
if (a.size() != b.size()) return false;
|
||||
|
||||
for (const auto& record_in_a : a)
|
||||
{
|
||||
bool ok = false;
|
||||
for (const auto& record_in_b : b)
|
||||
{
|
||||
if (record_in_a == record_in_b)
|
||||
{
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ok) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
namespace cryptonote
|
||||
{
|
||||
//---------------------------------------------------------------------------
|
||||
@ -125,4 +155,206 @@ namespace cryptonote
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkpoints::init_default_checkpoints()
|
||||
{
|
||||
ADD_CHECKPOINT(1, "771fbcd656ec1464d3a02ead5e18644030007a0fc664c0a964d30922821a8148");
|
||||
ADD_CHECKPOINT(10, "c0e3b387e47042f72d8ccdca88071ff96bff1ac7cde09ae113dbb7ad3fe92381");
|
||||
ADD_CHECKPOINT(100, "ac3e11ca545e57c49fca2b4e8c48c03c23be047c43e471e1394528b1f9f80b2d");
|
||||
ADD_CHECKPOINT(1000, "5acfc45acffd2b2e7345caf42fa02308c5793f15ec33946e969e829f40b03876");
|
||||
ADD_CHECKPOINT(10000, "c758b7c81f928be3295d45e230646de8b852ec96a821eac3fea4daf3fcac0ca2");
|
||||
ADD_CHECKPOINT(22231, "7cb10e29d67e1c069e6e11b17d30b809724255fee2f6868dc14cfc6ed44dfb25");
|
||||
ADD_CHECKPOINT(29556, "53c484a8ed91e4da621bb2fa88106dbde426fe90d7ef07b9c1e5127fb6f3a7f6");
|
||||
ADD_CHECKPOINT(50000, "0fe8758ab06a8b9cb35b7328fd4f757af530a5d37759f9d3e421023231f7b31c");
|
||||
ADD_CHECKPOINT(80000, "a62dcd7b536f22e003ebae8726e9e7276f63d594e264b6f0cd7aab27b66e75e3");
|
||||
ADD_CHECKPOINT(202612, "bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698");
|
||||
ADD_CHECKPOINT(202613, "e2aa337e78df1f98f462b3b1e560c6b914dec47b610698b7b7d1e3e86b6197c2");
|
||||
ADD_CHECKPOINT(202614, "c29e3dc37d8da3e72e506e31a213a58771b24450144305bcba9e70fa4d6ea6fb");
|
||||
ADD_CHECKPOINT(205000, "5d3d7a26e6dc7535e34f03def711daa8c263785f73ec1fadef8a45880fde8063");
|
||||
ADD_CHECKPOINT(220000, "9613f455933c00e3e33ac315cc6b455ee8aa0c567163836858c2d9caff111553");
|
||||
ADD_CHECKPOINT(230300, "bae7a80c46859db355556e3a9204a337ae8f24309926a1312323fdecf1920e61");
|
||||
ADD_CHECKPOINT(230700, "93e631240ceac831da1aebfc5dac8f722c430463024763ebafa888796ceaeedf");
|
||||
ADD_CHECKPOINT(231350, "b5add137199b820e1ea26640e5c3e121fd85faa86a1e39cf7e6cc097bdeb1131");
|
||||
ADD_CHECKPOINT(232150, "955de8e6b6508af2c24f7334f97beeea651d78e9ade3ab18fec3763be3201aa8");
|
||||
ADD_CHECKPOINT(249380, "654fb0a81ce3e5caf7e3264a70f447d4bd07586c08fa50f6638cc54da0a52b2d");
|
||||
ADD_CHECKPOINT(460000, "75037a7aed3e765db96c75bcf908f59d690a5f3390baebb9edeafd336a1c4831");
|
||||
ADD_CHECKPOINT(500000, "2428f0dbe49796be05ed81b347f53e1f7f44aed0abf641446ec2b94cae066b02");
|
||||
ADD_CHECKPOINT(600000, "f5828ebf7d7d1cb61762c4dfe3ccf4ecab2e1aad23e8113668d981713b7a54c5");
|
||||
ADD_CHECKPOINT(700000, "12be9b3d210b93f574d2526abb9c1ab2a881b479131fd0d4f7dac93875f503cd");
|
||||
ADD_CHECKPOINT(825000, "56503f9ad766774b575be3aff73245e9d159be88132c93d1754764f28da2ff60");
|
||||
ADD_CHECKPOINT(900000, "d9958d0e7dcf91a5a7b11de225927bf7efc6eb26240315ce12372be902cc1337");
|
||||
ADD_CHECKPOINT(913193, "5292d5d56f6ba4de33a58d9a34d263e2cb3c6fee0aed2286fd4ac7f36d53c85f");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkpoints::load_checkpoints_from_json(const std::string json_hashfile_fullpath)
|
||||
{
|
||||
boost::system::error_code errcode;
|
||||
if (! (boost::filesystem::exists(json_hashfile_fullpath, errcode)))
|
||||
{
|
||||
LOG_PRINT_L1("Blockchain checkpoints file not found");
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_PRINT_L1("Adding checkpoints from blockchain hashfile");
|
||||
|
||||
uint64_t prev_max_height = get_max_height();
|
||||
LOG_PRINT_L1("Hard-coded max checkpoint height is " << prev_max_height);
|
||||
t_hash_json hashes;
|
||||
epee::serialization::load_t_from_json_file(hashes, json_hashfile_fullpath);
|
||||
for (std::vector<t_hashline>::const_iterator it = hashes.hashlines.begin(); it != hashes.hashlines.end(); )
|
||||
{
|
||||
uint64_t height;
|
||||
height = it->height;
|
||||
if (height <= prev_max_height) {
|
||||
LOG_PRINT_L1("ignoring checkpoint height " << height);
|
||||
} else {
|
||||
std::string blockhash = it->hash;
|
||||
LOG_PRINT_L1("Adding checkpoint height " << height << ", hash=" << blockhash);
|
||||
ADD_CHECKPOINT(height, blockhash);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkpoints::load_checkpoints_from_dns(bool testnet)
|
||||
{
|
||||
// All four MoneroPulse domains have DNSSEC on and valid
|
||||
static const std::vector<std::string> dns_urls = { "checkpoints.moneropulse.se"
|
||||
, "checkpoints.moneropulse.org"
|
||||
, "checkpoints.moneropulse.net"
|
||||
, "checkpoints.moneropulse.co"
|
||||
};
|
||||
|
||||
static const std::vector<std::string> testnet_dns_urls = { "testpoints.moneropulse.se"
|
||||
, "testpoints.moneropulse.org"
|
||||
, "testpoints.moneropulse.net"
|
||||
, "testpoints.moneropulse.co"
|
||||
};
|
||||
|
||||
std::vector<std::vector<std::string> > records;
|
||||
records.resize(dns_urls.size());
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<int> dis(0, dns_urls.size() - 1);
|
||||
size_t first_index = dis(gen);
|
||||
|
||||
bool avail, valid;
|
||||
size_t cur_index = first_index;
|
||||
do
|
||||
{
|
||||
std::string url;
|
||||
if (testnet)
|
||||
{
|
||||
url = testnet_dns_urls[cur_index];
|
||||
}
|
||||
else
|
||||
{
|
||||
url = dns_urls[cur_index];
|
||||
}
|
||||
|
||||
records[cur_index] = tools::DNSResolver::instance().get_txt_record(url, avail, valid);
|
||||
if (!avail)
|
||||
{
|
||||
records[cur_index].clear();
|
||||
LOG_PRINT_L2("DNSSEC not available for checkpoint update at URL: " << url << ", skipping.");
|
||||
}
|
||||
if (!valid)
|
||||
{
|
||||
records[cur_index].clear();
|
||||
LOG_PRINT_L2("DNSSEC validation failed for checkpoint update at URL: " << url << ", skipping.");
|
||||
}
|
||||
|
||||
cur_index++;
|
||||
if (cur_index == dns_urls.size())
|
||||
{
|
||||
cur_index = 0;
|
||||
}
|
||||
records[cur_index].clear();
|
||||
} while (cur_index != first_index);
|
||||
|
||||
size_t num_valid_records = 0;
|
||||
|
||||
for( const auto& record_set : records)
|
||||
{
|
||||
if (record_set.size() != 0)
|
||||
{
|
||||
num_valid_records++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_valid_records < 2)
|
||||
{
|
||||
LOG_PRINT_L0("WARNING: no two valid MoneroPulse DNS checkpoint records were received");
|
||||
return true;
|
||||
}
|
||||
|
||||
int good_records_index = -1;
|
||||
for (size_t i = 0; i < records.size() - 1; ++i)
|
||||
{
|
||||
if (records[i].size() == 0) continue;
|
||||
|
||||
for (size_t j = i + 1; j < records.size(); ++j)
|
||||
{
|
||||
if (dns_records_match(records[i], records[j]))
|
||||
{
|
||||
good_records_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (good_records_index >= 0) break;
|
||||
}
|
||||
|
||||
if (good_records_index < 0)
|
||||
{
|
||||
LOG_PRINT_L0("WARNING: no two MoneroPulse DNS checkpoint records matched");
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto& record : records[good_records_index])
|
||||
{
|
||||
auto pos = record.find(":");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
uint64_t height;
|
||||
crypto::hash hash;
|
||||
|
||||
// parse the first part as uint64_t,
|
||||
// if this fails move on to the next record
|
||||
std::stringstream ss(record.substr(0, pos));
|
||||
if (!(ss >> height))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// parse the second part as crypto::hash,
|
||||
// if this fails move on to the next record
|
||||
std::string hashStr = record.substr(pos + 1);
|
||||
if (!epee::string_tools::parse_tpod_from_hex_string(hashStr, hash))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ADD_CHECKPOINT(height, hashStr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkpoints::load_new_checkpoints(const std::string json_hashfile_fullpath, bool testnet, bool dns)
|
||||
{
|
||||
bool result;
|
||||
|
||||
result = load_checkpoints_from_json(json_hashfile_fullpath);
|
||||
if (dns)
|
||||
{
|
||||
result &= load_checkpoints_from_dns(testnet);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
// Copyright (c) 2014-2016, The Monero Project
|
||||
//
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
@ -25,13 +25,18 @@
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "cryptonote_basic_impl.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "storages/portable_storage_template_helper.h" // epee json include
|
||||
|
||||
#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(add_checkpoint(h, hash), false);
|
||||
#define JSON_HASH_FILE_NAME "checkpoints.json"
|
||||
|
||||
|
||||
namespace cryptonote
|
||||
@ -88,8 +93,8 @@ namespace cryptonote
|
||||
* @param h the hash to be checked
|
||||
* @param is_a_checkpoint return-by-reference if there is a checkpoint at the given height
|
||||
*
|
||||
* @return true if there is no checkpoint at the given height,
|
||||
* true if the passed parameters match the stored checkpoint,
|
||||
* @return true if there is no checkpoint at the given height,
|
||||
* true if the passed parameters match the stored checkpoint,
|
||||
* false otherwise
|
||||
*/
|
||||
bool check_block(uint64_t height, const crypto::hash& h, bool& is_a_checkpoint) const;
|
||||
@ -110,7 +115,7 @@ namespace cryptonote
|
||||
* @param blockchain_height the current blockchain height
|
||||
* @param block_height the height of the block to be added as alternate
|
||||
*
|
||||
* @return true if alternate blocks are allowed given the parameters,
|
||||
* @return true if alternate blocks are allowed given the parameters,
|
||||
* otherwise false
|
||||
*/
|
||||
bool is_alternative_block_allowed(uint64_t blockchain_height, uint64_t block_height) const;
|
||||
@ -141,9 +146,71 @@ namespace cryptonote
|
||||
*/
|
||||
bool check_for_conflicts(const checkpoints& other) const;
|
||||
|
||||
/**
|
||||
* @brief loads the default main chain checkpoints
|
||||
*
|
||||
* @return true unless adding a checkpoint fails
|
||||
*/
|
||||
bool init_default_checkpoints();
|
||||
|
||||
/**
|
||||
* @brief load new checkpoints
|
||||
*
|
||||
* Loads new checkpoints from the specified json file, as well as
|
||||
* (optionally) from DNS.
|
||||
*
|
||||
* @param json_hashfile_fullpath path to the json checkpoints file
|
||||
* @param testnet whether to load testnet checkpoints or mainnet
|
||||
* @param dns whether or not to load DNS checkpoints
|
||||
*
|
||||
* @return true if loading successful and no conflicts
|
||||
*/
|
||||
bool load_new_checkpoints(const std::string json_hashfile_fullpath, bool testnet=false, bool dns=true);
|
||||
|
||||
/**
|
||||
* @brief load new checkpoints from json
|
||||
*
|
||||
* @param json_hashfile_fullpath path to the json checkpoints file
|
||||
*
|
||||
* @return true if loading successful and no conflicts
|
||||
*/
|
||||
bool load_checkpoints_from_json(const std::string json_hashfile_fullpath);
|
||||
|
||||
/**
|
||||
* @brief load new checkpoints from DNS
|
||||
*
|
||||
* @param testnet whether to load testnet checkpoints or mainnet
|
||||
*
|
||||
* @return true if loading successful and no conflicts
|
||||
*/
|
||||
bool load_checkpoints_from_dns(bool testnet = false);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
/**
|
||||
* @brief struct for loading a checkpoint from json
|
||||
*/
|
||||
struct t_hashline
|
||||
{
|
||||
uint64_t height; //!< the height of the checkpoint
|
||||
std::string hash; //!< the hash for the checkpoint
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(height)
|
||||
KV_SERIALIZE(hash)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief struct for loading many checkpoints from json
|
||||
*/
|
||||
struct t_hash_json {
|
||||
std::vector<t_hashline> hashlines; //!< the checkpoint lines from the file
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(hashlines)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
std::map<uint64_t, crypto::hash> m_points; //!< the checkpoints container
|
||||
|
||||
};
|
||||
|
@ -1,280 +0,0 @@
|
||||
// Copyright (c) 2014-2016, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#include "checkpoints_create.h"
|
||||
#include "common/dns_utils.h"
|
||||
#include "include_base_utils.h"
|
||||
#include <sstream>
|
||||
#include <random>
|
||||
#include "storages/portable_storage_template_helper.h" // epee json include
|
||||
|
||||
namespace
|
||||
{
|
||||
bool dns_records_match(const std::vector<std::string>& a, const std::vector<std::string>& b)
|
||||
{
|
||||
if (a.size() != b.size()) return false;
|
||||
|
||||
for (const auto& record_in_a : a)
|
||||
{
|
||||
bool ok = false;
|
||||
for (const auto& record_in_b : b)
|
||||
{
|
||||
if (record_in_a == record_in_b)
|
||||
{
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ok) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
namespace cryptonote
|
||||
{
|
||||
|
||||
struct t_hashline
|
||||
{
|
||||
uint64_t height;
|
||||
std::string hash;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(height)
|
||||
KV_SERIALIZE(hash)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct t_hash_json {
|
||||
std::vector<t_hashline> hashlines;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(hashlines)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
bool create_checkpoints(cryptonote::checkpoints& checkpoints)
|
||||
{
|
||||
ADD_CHECKPOINT(1, "771fbcd656ec1464d3a02ead5e18644030007a0fc664c0a964d30922821a8148");
|
||||
ADD_CHECKPOINT(10, "c0e3b387e47042f72d8ccdca88071ff96bff1ac7cde09ae113dbb7ad3fe92381");
|
||||
ADD_CHECKPOINT(100, "ac3e11ca545e57c49fca2b4e8c48c03c23be047c43e471e1394528b1f9f80b2d");
|
||||
ADD_CHECKPOINT(1000, "5acfc45acffd2b2e7345caf42fa02308c5793f15ec33946e969e829f40b03876");
|
||||
ADD_CHECKPOINT(10000, "c758b7c81f928be3295d45e230646de8b852ec96a821eac3fea4daf3fcac0ca2");
|
||||
ADD_CHECKPOINT(22231, "7cb10e29d67e1c069e6e11b17d30b809724255fee2f6868dc14cfc6ed44dfb25");
|
||||
ADD_CHECKPOINT(29556, "53c484a8ed91e4da621bb2fa88106dbde426fe90d7ef07b9c1e5127fb6f3a7f6");
|
||||
ADD_CHECKPOINT(50000, "0fe8758ab06a8b9cb35b7328fd4f757af530a5d37759f9d3e421023231f7b31c");
|
||||
ADD_CHECKPOINT(80000, "a62dcd7b536f22e003ebae8726e9e7276f63d594e264b6f0cd7aab27b66e75e3");
|
||||
ADD_CHECKPOINT(202612, "bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698");
|
||||
ADD_CHECKPOINT(202613, "e2aa337e78df1f98f462b3b1e560c6b914dec47b610698b7b7d1e3e86b6197c2");
|
||||
ADD_CHECKPOINT(202614, "c29e3dc37d8da3e72e506e31a213a58771b24450144305bcba9e70fa4d6ea6fb");
|
||||
ADD_CHECKPOINT(205000, "5d3d7a26e6dc7535e34f03def711daa8c263785f73ec1fadef8a45880fde8063");
|
||||
ADD_CHECKPOINT(220000, "9613f455933c00e3e33ac315cc6b455ee8aa0c567163836858c2d9caff111553");
|
||||
ADD_CHECKPOINT(230300, "bae7a80c46859db355556e3a9204a337ae8f24309926a1312323fdecf1920e61");
|
||||
ADD_CHECKPOINT(230700, "93e631240ceac831da1aebfc5dac8f722c430463024763ebafa888796ceaeedf");
|
||||
ADD_CHECKPOINT(231350, "b5add137199b820e1ea26640e5c3e121fd85faa86a1e39cf7e6cc097bdeb1131");
|
||||
ADD_CHECKPOINT(232150, "955de8e6b6508af2c24f7334f97beeea651d78e9ade3ab18fec3763be3201aa8");
|
||||
ADD_CHECKPOINT(249380, "654fb0a81ce3e5caf7e3264a70f447d4bd07586c08fa50f6638cc54da0a52b2d");
|
||||
ADD_CHECKPOINT(300000, "0c1cd46df6ccff90ec4ab493281f2583c344cd62216c427628990fe9db1bb8b6");
|
||||
ADD_CHECKPOINT(400000, "1b2b0e7a30e59691491529a3d506d1ba3d6052d0f6b52198b7330b28a6f1b6ac");
|
||||
ADD_CHECKPOINT(450000, "4d098b511ca97723e81737c448343cfd4e6dadb3d8a0e757c6e4d595e6e48357");
|
||||
ADD_CHECKPOINT(460000, "75037a7aed3e765db96c75bcf908f59d690a5f3390baebb9edeafd336a1c4831");
|
||||
ADD_CHECKPOINT(500000, "2428f0dbe49796be05ed81b347f53e1f7f44aed0abf641446ec2b94cae066b02");
|
||||
ADD_CHECKPOINT(600000, "f5828ebf7d7d1cb61762c4dfe3ccf4ecab2e1aad23e8113668d981713b7a54c5");
|
||||
ADD_CHECKPOINT(700000, "12be9b3d210b93f574d2526abb9c1ab2a881b479131fd0d4f7dac93875f503cd");
|
||||
ADD_CHECKPOINT(825000, "56503f9ad766774b575be3aff73245e9d159be88132c93d1754764f28da2ff60");
|
||||
ADD_CHECKPOINT(900000, "d9958d0e7dcf91a5a7b11de225927bf7efc6eb26240315ce12372be902cc1337");
|
||||
ADD_CHECKPOINT(913193, "5292d5d56f6ba4de33a58d9a34d263e2cb3c6fee0aed2286fd4ac7f36d53c85f");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath)
|
||||
{
|
||||
boost::system::error_code errcode;
|
||||
if (! (boost::filesystem::exists(json_hashfile_fullpath, errcode)))
|
||||
{
|
||||
LOG_PRINT_L1("Blockchain checkpoints file not found");
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_PRINT_L1("Adding checkpoints from blockchain hashfile");
|
||||
|
||||
uint64_t prev_max_height = checkpoints.get_max_height();
|
||||
LOG_PRINT_L1("Hard-coded max checkpoint height is " << prev_max_height);
|
||||
t_hash_json hashes;
|
||||
epee::serialization::load_t_from_json_file(hashes, json_hashfile_fullpath);
|
||||
for (std::vector<t_hashline>::const_iterator it = hashes.hashlines.begin(); it != hashes.hashlines.end(); )
|
||||
{
|
||||
uint64_t height;
|
||||
height = it->height;
|
||||
if (height <= prev_max_height) {
|
||||
LOG_PRINT_L1("ignoring checkpoint height " << height);
|
||||
} else {
|
||||
std::string blockhash = it->hash;
|
||||
LOG_PRINT_L1("Adding checkpoint height " << height << ", hash=" << blockhash);
|
||||
ADD_CHECKPOINT(height, blockhash);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, bool testnet)
|
||||
{
|
||||
// All four MoneroPulse domains have DNSSEC on and valid
|
||||
static const std::vector<std::string> dns_urls = { "checkpoints.moneropulse.se"
|
||||
, "checkpoints.moneropulse.org"
|
||||
, "checkpoints.moneropulse.net"
|
||||
, "checkpoints.moneropulse.co"
|
||||
};
|
||||
|
||||
static const std::vector<std::string> testnet_dns_urls = { "testpoints.moneropulse.se"
|
||||
, "testpoints.moneropulse.org"
|
||||
, "testpoints.moneropulse.net"
|
||||
, "testpoints.moneropulse.co"
|
||||
};
|
||||
|
||||
std::vector<std::vector<std::string> > records;
|
||||
records.resize(dns_urls.size());
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<int> dis(0, dns_urls.size() - 1);
|
||||
size_t first_index = dis(gen);
|
||||
|
||||
bool avail, valid;
|
||||
size_t cur_index = first_index;
|
||||
do
|
||||
{
|
||||
std::string url;
|
||||
if (testnet)
|
||||
{
|
||||
url = testnet_dns_urls[cur_index];
|
||||
}
|
||||
else
|
||||
{
|
||||
url = dns_urls[cur_index];
|
||||
}
|
||||
|
||||
records[cur_index] = tools::DNSResolver::instance().get_txt_record(url, avail, valid);
|
||||
if (!avail)
|
||||
{
|
||||
records[cur_index].clear();
|
||||
LOG_PRINT_L2("DNSSEC not available for checkpoint update at URL: " << url << ", skipping.");
|
||||
}
|
||||
if (!valid)
|
||||
{
|
||||
records[cur_index].clear();
|
||||
LOG_PRINT_L2("DNSSEC validation failed for checkpoint update at URL: " << url << ", skipping.");
|
||||
}
|
||||
|
||||
cur_index++;
|
||||
if (cur_index == dns_urls.size())
|
||||
{
|
||||
cur_index = 0;
|
||||
}
|
||||
records[cur_index].clear();
|
||||
} while (cur_index != first_index);
|
||||
|
||||
size_t num_valid_records = 0;
|
||||
|
||||
for( const auto& record_set : records)
|
||||
{
|
||||
if (record_set.size() != 0)
|
||||
{
|
||||
num_valid_records++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_valid_records < 2)
|
||||
{
|
||||
LOG_PRINT_L0("WARNING: no two valid MoneroPulse DNS checkpoint records were received");
|
||||
return true;
|
||||
}
|
||||
|
||||
int good_records_index = -1;
|
||||
for (size_t i = 0; i < records.size() - 1; ++i)
|
||||
{
|
||||
if (records[i].size() == 0) continue;
|
||||
|
||||
for (size_t j = i + 1; j < records.size(); ++j)
|
||||
{
|
||||
if (dns_records_match(records[i], records[j]))
|
||||
{
|
||||
good_records_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (good_records_index >= 0) break;
|
||||
}
|
||||
|
||||
if (good_records_index < 0)
|
||||
{
|
||||
LOG_PRINT_L0("WARNING: no two MoneroPulse DNS checkpoint records matched");
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto& record : records[good_records_index])
|
||||
{
|
||||
auto pos = record.find(":");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
uint64_t height;
|
||||
crypto::hash hash;
|
||||
|
||||
// parse the first part as uint64_t,
|
||||
// if this fails move on to the next record
|
||||
std::stringstream ss(record.substr(0, pos));
|
||||
if (!(ss >> height))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// parse the second part as crypto::hash,
|
||||
// if this fails move on to the next record
|
||||
std::string hashStr = record.substr(pos + 1);
|
||||
if (!epee::string_tools::parse_tpod_from_hex_string(hashStr, hash))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ADD_CHECKPOINT(height, hashStr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool load_new_checkpoints(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath)
|
||||
{
|
||||
// TODO: replace hard-coded url with const string or #define
|
||||
return (load_checkpoints_from_json(checkpoints, json_hashfile_fullpath) && load_checkpoints_from_dns(checkpoints));
|
||||
}
|
||||
|
||||
} // namespace cryptonote
|
@ -1,48 +0,0 @@
|
||||
// Copyright (c) 2014-2016, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "checkpoints.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(checkpoints.add_checkpoint(h, hash), false);
|
||||
#define JSON_HASH_FILE_NAME "checkpoints.json"
|
||||
|
||||
namespace cryptonote
|
||||
{
|
||||
|
||||
bool create_checkpoints(cryptonote::checkpoints& checkpoints);
|
||||
|
||||
bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath);
|
||||
bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, bool testnet = false);
|
||||
bool load_new_checkpoints(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath);
|
||||
|
||||
} // namespace cryptonote
|
@ -42,7 +42,7 @@ using namespace epee;
|
||||
#include "cryptonote_format_utils.h"
|
||||
#include "misc_language.h"
|
||||
#include <csignal>
|
||||
#include "cryptonote_core/checkpoints_create.h"
|
||||
#include "cryptonote_core/checkpoints.h"
|
||||
#include "blockchain_db/blockchain_db.h"
|
||||
#include "blockchain_db/lmdb/db_lmdb.h"
|
||||
#if defined(BERKELEY_DB)
|
||||
@ -159,7 +159,7 @@ namespace cryptonote
|
||||
if (!m_testnet && !m_fakechain)
|
||||
{
|
||||
cryptonote::checkpoints checkpoints;
|
||||
if (!cryptonote::create_checkpoints(checkpoints))
|
||||
if (!checkpoints.init_default_checkpoints())
|
||||
{
|
||||
throw std::runtime_error("Failed to initialize checkpoints");
|
||||
}
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cryptonote_core/checkpoints_create.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
#include "cryptonote_protocol/cryptonote_protocol_handler.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
Loading…
Reference in New Issue
Block a user