2018-01-07 00:05:16 -05:00
|
|
|
// Copyright (c) 2014-2018, The Monero Project
|
2016-03-25 02:22:06 -04:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// All rights reserved.
|
2016-03-25 02:22:06 -04:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
2016-03-25 02:22:06 -04:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
2016-03-25 02:22:06 -04:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// 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.
|
2016-03-25 02:22:06 -04:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// 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.
|
2016-03-25 02:22:06 -04:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// 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.
|
2016-03-25 02:22:06 -04:00
|
|
|
//
|
2014-07-23 09:03:52 -04:00
|
|
|
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
2014-03-03 17:07:58 -05:00
|
|
|
|
|
|
|
#include "include_base_utils.h"
|
2016-03-25 02:22:06 -04:00
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
using namespace epee;
|
|
|
|
|
|
|
|
#include "checkpoints.h"
|
|
|
|
|
2016-03-25 02:22:06 -04:00
|
|
|
#include "common/dns_utils.h"
|
|
|
|
#include "include_base_utils.h"
|
2017-11-25 17:25:05 -05:00
|
|
|
#include "string_tools.h"
|
2017-09-10 12:35:59 -04:00
|
|
|
#include "storages/portable_storage_template_helper.h" // epee json include
|
2017-11-25 17:25:05 -05:00
|
|
|
#include "serialization/keyvalue_serialization.h"
|
2016-03-25 02:22:06 -04:00
|
|
|
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
|
|
|
#define MONERO_DEFAULT_LOG_CATEGORY "checkpoints"
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
namespace cryptonote
|
|
|
|
{
|
2017-11-25 17:25:05 -05:00
|
|
|
/**
|
|
|
|
* @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()
|
|
|
|
};
|
|
|
|
|
2014-03-03 17:07:58 -05:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
checkpoints::checkpoints()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool checkpoints::add_checkpoint(uint64_t height, const std::string& hash_str)
|
|
|
|
{
|
2017-09-10 12:35:59 -04:00
|
|
|
crypto::hash h = crypto::null_hash;
|
2014-03-03 17:07:58 -05:00
|
|
|
bool r = epee::string_tools::parse_tpod_from_hex_string(hash_str, h);
|
2014-09-24 18:43:03 -04:00
|
|
|
CHECK_AND_ASSERT_MES(r, false, "Failed to parse checkpoint hash string into binary representation!");
|
|
|
|
|
|
|
|
// return false if adding at a height we already have AND the hash is different
|
|
|
|
if (m_points.count(height))
|
|
|
|
{
|
|
|
|
CHECK_AND_ASSERT_MES(h == m_points[height], false, "Checkpoint at given height already exists, and hash for new checkpoint was different!");
|
|
|
|
}
|
2014-03-03 17:07:58 -05:00
|
|
|
m_points[height] = h;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool checkpoints::is_in_checkpoint_zone(uint64_t height) const
|
|
|
|
{
|
|
|
|
return !m_points.empty() && (height <= (--m_points.end())->first);
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
2014-05-25 13:06:40 -04:00
|
|
|
bool checkpoints::check_block(uint64_t height, const crypto::hash& h, bool& is_a_checkpoint) const
|
2014-03-03 17:07:58 -05:00
|
|
|
{
|
|
|
|
auto it = m_points.find(height);
|
2014-05-25 13:06:40 -04:00
|
|
|
is_a_checkpoint = it != m_points.end();
|
|
|
|
if(!is_a_checkpoint)
|
2014-03-03 17:07:58 -05:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if(it->second == h)
|
|
|
|
{
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MINFO("CHECKPOINT PASSED FOR HEIGHT " << height << " " << h);
|
2014-03-03 17:07:58 -05:00
|
|
|
return true;
|
|
|
|
}else
|
|
|
|
{
|
Change logging to easylogging++
This replaces the epee and data_loggers logging systems with
a single one, and also adds filename:line and explicit severity
levels. Categories may be defined, and logging severity set
by category (or set of categories). epee style 0-4 log level
maps to a sensible severity configuration. Log files now also
rotate when reaching 100 MB.
To select which logs to output, use the MONERO_LOGS environment
variable, with a comma separated list of categories (globs are
supported), with their requested severity level after a colon.
If a log matches more than one such setting, the last one in
the configuration string applies. A few examples:
This one is (mostly) silent, only outputting fatal errors:
MONERO_LOGS=*:FATAL
This one is very verbose:
MONERO_LOGS=*:TRACE
This one is totally silent (logwise):
MONERO_LOGS=""
This one outputs all errors and warnings, except for the
"verify" category, which prints just fatal errors (the verify
category is used for logs about incoming transactions and
blocks, and it is expected that some/many will fail to verify,
hence we don't want the spam):
MONERO_LOGS=*:WARNING,verify:FATAL
Log levels are, in decreasing order of priority:
FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
Subcategories may be added using prefixes and globs. This
example will output net.p2p logs at the TRACE level, but all
other net* logs only at INFO:
MONERO_LOGS=*:ERROR,net*:INFO,net.p2p:TRACE
Logs which are intended for the user (which Monero was using
a lot through epee, but really isn't a nice way to go things)
should use the "global" category. There are a few helper macros
for using this category, eg: MGINFO("this shows up by default")
or MGINFO_RED("this is red"), to try to keep a similar look
and feel for now.
Existing epee log macros still exist, and map to the new log
levels, but since they're used as a "user facing" UI element
as much as a logging system, they often don't map well to log
severities (ie, a log level 0 log may be an error, or may be
something we want the user to see, such as an important info).
In those cases, I tried to use the new macros. In other cases,
I left the existing macros in. When modifying logs, it is
probably best to switch to the new macros with explicit levels.
The --log-level options and set_log commands now also accept
category settings, in addition to the epee style log levels.
2017-01-01 11:34:23 -05:00
|
|
|
MWARNING("CHECKPOINT FAILED FOR HEIGHT " << height << ". EXPECTED HASH: " << it->second << ", FETCHED HASH: " << h);
|
2014-03-03 17:07:58 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-05-25 13:06:40 -04:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool checkpoints::check_block(uint64_t height, const crypto::hash& h) const
|
|
|
|
{
|
|
|
|
bool ignored;
|
|
|
|
return check_block(height, h, ignored);
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
2016-03-25 02:22:06 -04:00
|
|
|
//FIXME: is this the desired behavior?
|
2014-05-25 13:06:40 -04:00
|
|
|
bool checkpoints::is_alternative_block_allowed(uint64_t blockchain_height, uint64_t block_height) const
|
|
|
|
{
|
|
|
|
if (0 == block_height)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto it = m_points.upper_bound(blockchain_height);
|
|
|
|
// Is blockchain_height before the first checkpoint?
|
|
|
|
if (it == m_points.begin())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
--it;
|
|
|
|
uint64_t checkpoint_height = it->first;
|
|
|
|
return checkpoint_height < block_height;
|
|
|
|
}
|
2014-09-25 01:15:28 -04:00
|
|
|
//---------------------------------------------------------------------------
|
2014-12-06 17:46:51 -05:00
|
|
|
uint64_t checkpoints::get_max_height() const
|
2014-09-24 10:36:04 -04:00
|
|
|
{
|
|
|
|
std::map< uint64_t, crypto::hash >::const_iterator highest =
|
|
|
|
std::max_element( m_points.begin(), m_points.end(),
|
|
|
|
( boost::bind(&std::map< uint64_t, crypto::hash >::value_type::first, _1) <
|
|
|
|
boost::bind(&std::map< uint64_t, crypto::hash >::value_type::first, _2 ) ) );
|
|
|
|
return highest->first;
|
|
|
|
}
|
2014-09-25 01:15:28 -04:00
|
|
|
//---------------------------------------------------------------------------
|
2014-12-06 17:46:51 -05:00
|
|
|
const std::map<uint64_t, crypto::hash>& checkpoints::get_points() const
|
2014-09-25 01:15:28 -04:00
|
|
|
{
|
|
|
|
return m_points;
|
|
|
|
}
|
2014-09-24 10:36:04 -04:00
|
|
|
|
2014-12-06 17:46:51 -05:00
|
|
|
bool checkpoints::check_for_conflicts(const checkpoints& other) const
|
2014-09-29 16:30:47 -04:00
|
|
|
{
|
|
|
|
for (auto& pt : other.get_points())
|
|
|
|
{
|
|
|
|
if (m_points.count(pt.first))
|
|
|
|
{
|
2014-12-06 17:46:51 -05:00
|
|
|
CHECK_AND_ASSERT_MES(pt.second == m_points.at(pt.first), false, "Checkpoint at given height already exists, and hash for new checkpoint was different!");
|
2014-09-29 16:30:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-25 02:22:06 -04:00
|
|
|
|
2018-02-16 06:04:04 -05:00
|
|
|
bool checkpoints::init_default_checkpoints(network_type nettype)
|
2016-03-25 02:22:06 -04:00
|
|
|
{
|
2018-02-16 06:04:04 -05:00
|
|
|
if (nettype == TESTNET)
|
2017-09-11 11:32:46 -04:00
|
|
|
{
|
|
|
|
ADD_CHECKPOINT(0, "48ca7cd3c8de5b6a4d53d2861fbdaedca141553559f9be9520068053cda8430b");
|
2017-11-11 06:16:48 -05:00
|
|
|
ADD_CHECKPOINT(1000000, "46b690b710a07ea051bc4a6b6842ac37be691089c0f7758cfeec4d5fc0b4a258");
|
2017-09-11 11:32:46 -04:00
|
|
|
return true;
|
|
|
|
}
|
2018-02-16 06:04:04 -05:00
|
|
|
if (nettype == STAGENET)
|
|
|
|
{
|
|
|
|
ADD_CHECKPOINT(0, "76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb");
|
|
|
|
ADD_CHECKPOINT(10000, "1f8b0ce313f8b9ba9a46108bfd285c45ad7c2176871fd41c3a690d4830ce2fd5");
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-25 02:22:06 -04:00
|
|
|
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");
|
2016-09-18 12:40:43 -04:00
|
|
|
ADD_CHECKPOINT(1000000, "a886ef5149902d8342475fee9bb296341b891ac67c4842f47a833f23c00ed721");
|
|
|
|
ADD_CHECKPOINT(1100000, "3fd720c5c8b3072fc1ccda922dec1ef25f9ed88a1e6ad4103d0fe00b180a5903");
|
2016-12-12 17:24:48 -05:00
|
|
|
ADD_CHECKPOINT(1150000, "1dd16f626d18e1e988490dfd06de5920e22629c972c58b4d8daddea0038627b2");
|
|
|
|
ADD_CHECKPOINT(1200000, "fa7d13a90850882060479d100141ff84286599ae39c3277c8ea784393f882d1f");
|
2017-09-06 03:18:46 -04:00
|
|
|
ADD_CHECKPOINT(1300000, "31b34272343a44a9f4ac7de7a8fcf3b7d8a3124d7d6870affd510d2f37e74cd0");
|
|
|
|
ADD_CHECKPOINT(1390000, "a8f5649dd4ded60eedab475f2bec8c934681c07e3cf640e9be0617554f13ff6c");
|
2018-03-18 10:44:36 -04:00
|
|
|
ADD_CHECKPOINT(1450000, "ac94e8860093bc7c83e4e91215cba1d663421ecf4067a0ae609c3a8b52bcfac2");
|
|
|
|
ADD_CHECKPOINT(1530000, "01759bce497ec38e63c78b1038892169203bb78f87e488172f6b854fcd63ba7e");
|
2016-12-12 17:24:48 -05:00
|
|
|
|
2016-03-25 02:22:06 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:05:48 -05:00
|
|
|
bool checkpoints::load_checkpoints_from_json(const std::string &json_hashfile_fullpath)
|
2016-03-25 02:22:06 -04:00
|
|
|
{
|
|
|
|
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;
|
2017-12-10 10:06:04 -05:00
|
|
|
if (!epee::serialization::load_t_from_json_file(hashes, json_hashfile_fullpath))
|
|
|
|
{
|
|
|
|
MERROR("Error loading checkpoints from " << json_hashfile_fullpath);
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-25 02:22:06 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-16 06:04:04 -05:00
|
|
|
bool checkpoints::load_checkpoints_from_dns(network_type nettype)
|
2016-03-25 02:22:06 -04:00
|
|
|
{
|
2017-02-16 15:03:26 -05:00
|
|
|
std::vector<std::string> records;
|
|
|
|
|
2016-03-25 02:22:06 -04:00
|
|
|
// 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"
|
|
|
|
};
|
|
|
|
|
2018-02-16 06:04:04 -05:00
|
|
|
static const std::vector<std::string> stagenet_dns_urls = { "stagenetpoints.moneropulse.se"
|
|
|
|
, "stagenetpoints.moneropulse.org"
|
|
|
|
, "stagenetpoints.moneropulse.net"
|
|
|
|
, "stagenetpoints.moneropulse.co"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!tools::dns_utils::load_txt_records_from_dns(records, nettype == TESTNET ? testnet_dns_urls : nettype == STAGENET ? stagenet_dns_urls : dns_urls))
|
2017-02-16 15:03:26 -05:00
|
|
|
return true; // why true ?
|
2016-03-25 02:22:06 -04:00
|
|
|
|
2017-02-16 15:03:26 -05:00
|
|
|
for (const auto& record : records)
|
2016-03-25 02:22:06 -04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-16 06:04:04 -05:00
|
|
|
bool checkpoints::load_new_checkpoints(const std::string &json_hashfile_fullpath, network_type nettype, bool dns)
|
2016-03-25 02:22:06 -04:00
|
|
|
{
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
result = load_checkpoints_from_json(json_hashfile_fullpath);
|
|
|
|
if (dns)
|
|
|
|
{
|
2018-02-16 06:04:04 -05:00
|
|
|
result &= load_checkpoints_from_dns(nettype);
|
2016-03-25 02:22:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2014-03-03 17:07:58 -05:00
|
|
|
}
|