| 1 | // Copyright (c) 2014-2022, The Monero Project |
| 2 | // |
| 3 | // All rights reserved. |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without modification, are |
| 6 | // permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of |
| 9 | // conditions and the following disclaimer. |
| 10 | // |
| 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 12 | // of conditions and the following disclaimer in the documentation and/or other |
| 13 | // materials provided with the distribution. |
| 14 | // |
| 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be |
| 16 | // used to endorse or promote products derived from this software without specific |
| 17 | // prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
| 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers |
| 30 | |
| 31 | #include "checkpoints.h" |
| 32 | |
| 33 | #include "common/dns_utils.h" |
| 34 | #include "string_tools.h" |
| 35 | #include "storages/portable_storage_template_helper.h" // epee json include |
| 36 | #include "serialization/keyvalue_serialization.h" |
| 37 | #include <boost/system/error_code.hpp> |
| 38 | #include <boost/filesystem.hpp> |
| 39 | #include <functional> |
| 40 | #include <vector> |
| 41 | |
| 42 | using namespace epee; |
| 43 | |
| 44 | #undef MONERO_DEFAULT_LOG_CATEGORY |
| 45 | #define MONERO_DEFAULT_LOG_CATEGORY "checkpoints" |
| 46 | |
| 47 | namespace cryptonote |
| 48 | { |
| 49 | /** |
| 50 | * @brief struct for loading a checkpoint from json |
| 51 | */ |
| 52 | struct t_hashline |
| 53 | { |
| 54 | uint64_t height; //!< the height of the checkpoint |
| 55 | std::string hash; //!< the hash for the checkpoint |
| 56 | BEGIN_KV_SERIALIZE_MAP() |
| 57 | KV_SERIALIZE(height) |
| 58 | KV_SERIALIZE(hash) |
| 59 | END_KV_SERIALIZE_MAP() |
| 60 | }; |
| 61 | |
| 62 | /** |
| 63 | * @brief struct for loading many checkpoints from json |
| 64 | */ |
| 65 | struct t_hash_json { |
| 66 | std::vector<t_hashline> hashlines; //!< the checkpoint lines from the file |
| 67 | BEGIN_KV_SERIALIZE_MAP() |
| 68 | KV_SERIALIZE(hashlines) |
| 69 | END_KV_SERIALIZE_MAP() |
| 70 | }; |
| 71 | |
| 72 | //--------------------------------------------------------------------------- |
| 73 | checkpoints::checkpoints() |
| 74 | { |
| 75 | } |
| 76 | //--------------------------------------------------------------------------- |
| 77 | bool checkpoints::add_checkpoint(uint64_t height, const std::string& hash_str, const std::string& difficulty_str) |
| 78 | { |
| 79 | crypto::hash h = crypto::null_hash; |
| 80 | bool r = epee::string_tools::hex_to_pod(hash_str, h); |
| 81 | CHECK_AND_ASSERT_MES(r, false, "Failed to parse checkpoint hash string into binary representation!"); |
| 82 | |
| 83 | // return false if adding at a height we already have AND the hash is different |
| 84 | if (m_points.count(height)) |
| 85 | { |
| 86 | CHECK_AND_ASSERT_MES(h == m_points[height], false, "Checkpoint at given height already exists, and hash for new checkpoint was different!"); |
| 87 | } |
| 88 | m_points[height] = h; |
| 89 | if (!difficulty_str.empty()) |
| 90 | { |
| 91 | try |
| 92 | { |
| 93 | difficulty_type difficulty(difficulty_str); |
| 94 | if (m_difficulty_points.count(height)) |
| 95 | { |
| 96 | CHECK_AND_ASSERT_MES(difficulty == m_difficulty_points[height], false, "Difficulty checkpoint at given height already exists, and difficulty for new checkpoint was different!"); |
| 97 | } |
| 98 | m_difficulty_points[height] = difficulty; |
| 99 | } |
| 100 | catch (...) |
| 101 | { |
| 102 | LOG_ERROR("Failed to parse difficulty checkpoint: " << difficulty_str); |
| 103 | return false; |
| 104 | } |
| 105 | } |
| 106 | return true; |
| 107 | } |
| 108 | //--------------------------------------------------------------------------- |
| 109 | bool checkpoints::is_in_checkpoint_zone(uint64_t height) const |
| 110 | { |
| 111 | return !m_points.empty() && (height <= (--m_points.end())->first); |
| 112 | } |
| 113 | //--------------------------------------------------------------------------- |
| 114 | bool checkpoints::check_block(uint64_t height, const crypto::hash& h, bool& is_a_checkpoint) const |
| 115 | { |
| 116 | auto it = m_points.find(height); |
| 117 | is_a_checkpoint = it != m_points.end(); |
| 118 | if(!is_a_checkpoint) |
| 119 | return true; |
| 120 | |
| 121 | if(it->second == h) |
| 122 | { |
| 123 | MINFO("CHECKPOINT PASSED FOR HEIGHT " << height << " " << h); |
| 124 | return true; |
| 125 | }else |
| 126 | { |
| 127 | MWARNING("CHECKPOINT FAILED FOR HEIGHT " << height << ". EXPECTED HASH: " << it->second << ", FETCHED HASH: " << h); |
| 128 | return false; |
| 129 | } |
| 130 | } |
| 131 | //--------------------------------------------------------------------------- |
| 132 | bool checkpoints::check_block(uint64_t height, const crypto::hash& h) const |
| 133 | { |
| 134 | bool ignored; |
| 135 | return check_block(height, h, ignored); |
| 136 | } |
| 137 | //--------------------------------------------------------------------------- |
| 138 | //FIXME: is this the desired behavior? |
| 139 | bool checkpoints::is_alternative_block_allowed(uint64_t blockchain_height, uint64_t block_height) const |
| 140 | { |
| 141 | if (0 == block_height) |
| 142 | return false; |
| 143 | |
| 144 | auto it = m_points.upper_bound(blockchain_height); |
| 145 | // Is blockchain_height before the first checkpoint? |
| 146 | if (it == m_points.begin()) |
| 147 | return true; |
| 148 | |
| 149 | --it; |
| 150 | uint64_t checkpoint_height = it->first; |
| 151 | return checkpoint_height < block_height; |
| 152 | } |
| 153 | //--------------------------------------------------------------------------- |
| 154 | uint64_t checkpoints::get_max_height() const |
| 155 | { |
| 156 | if (m_points.empty()) |
| 157 | return 0; |
| 158 | return m_points.rbegin()->first; |
| 159 | } |
| 160 | //--------------------------------------------------------------------------- |
| 161 | const std::map<uint64_t, crypto::hash>& checkpoints::get_points() const |
| 162 | { |
| 163 | return m_points; |
| 164 | } |
| 165 | //--------------------------------------------------------------------------- |
| 166 | const std::map<uint64_t, difficulty_type>& checkpoints::get_difficulty_points() const |
| 167 | { |
| 168 | return m_difficulty_points; |
| 169 | } |
| 170 | |
| 171 | bool checkpoints::check_for_conflicts(const checkpoints& other) const |
| 172 | { |
| 173 | for (auto& pt : other.get_points()) |
| 174 | { |
| 175 | if (m_points.count(pt.first)) |
| 176 | { |
| 177 | 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!"); |
| 178 | } |
| 179 | } |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | bool checkpoints::init_default_checkpoints(network_type nettype) |
| 184 | { |
| 185 | if (nettype == TESTNET) |
| 186 | { |
| 187 | ADD_CHECKPOINT2(0, "48ca7cd3c8de5b6a4d53d2861fbdaedca141553559f9be9520068053cda8430b", "0x1"); |
| 188 | ADD_CHECKPOINT2(1000000, "46b690b710a07ea051bc4a6b6842ac37be691089c0f7758cfeec4d5fc0b4a258", "0x7aaad7153"); |
| 189 | ADD_CHECKPOINT2(1058600, "12904f6b4d9e60fd875674e07147d2c83d6716253f046af7b894c3e81da7e1bd", "0x971efd119"); |
| 190 | ADD_CHECKPOINT2(1450000, "87562ca6786f41556b8d5b48067303a57dc5ca77155b35199aedaeca1550f5a0", "0xa639e2930e"); |
| 191 | return true; |
| 192 | } |
| 193 | if (nettype == STAGENET) |
| 194 | { |
| 195 | ADD_CHECKPOINT2(0, "76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb", "0x1"); |
| 196 | ADD_CHECKPOINT2(10000, "1f8b0ce313f8b9ba9a46108bfd285c45ad7c2176871fd41c3a690d4830ce2fd5", "0x1d73ba"); |
| 197 | ADD_CHECKPOINT2(550000, "409f68cddd8e74b37469b41c1e61250d81c5776b42264f416d5d27c4626383ed", "0x5f3d4d03e"); |
| 198 | return true; |
| 199 | } |
| 200 | ADD_CHECKPOINT2(1, "771fbcd656ec1464d3a02ead5e18644030007a0fc664c0a964d30922821a8148", "0x2"); |
| 201 | ADD_CHECKPOINT2(10, "c0e3b387e47042f72d8ccdca88071ff96bff1ac7cde09ae113dbb7ad3fe92381", "0x2a974"); |
| 202 | ADD_CHECKPOINT2(100, "ac3e11ca545e57c49fca2b4e8c48c03c23be047c43e471e1394528b1f9f80b2d", "0x35d14b"); |
| 203 | ADD_CHECKPOINT2(1000, "5acfc45acffd2b2e7345caf42fa02308c5793f15ec33946e969e829f40b03876", "0x36a0373"); |
| 204 | ADD_CHECKPOINT2(10000, "c758b7c81f928be3295d45e230646de8b852ec96a821eac3fea4daf3fcac0ca2", "0x60a91390"); |
| 205 | ADD_CHECKPOINT2(22231, "7cb10e29d67e1c069e6e11b17d30b809724255fee2f6868dc14cfc6ed44dfb25", "0x1e288793d"); |
| 206 | ADD_CHECKPOINT2(29556, "53c484a8ed91e4da621bb2fa88106dbde426fe90d7ef07b9c1e5127fb6f3a7f6", "0x71f64cce8"); |
| 207 | ADD_CHECKPOINT2(50000, "0fe8758ab06a8b9cb35b7328fd4f757af530a5d37759f9d3e421023231f7b31c", "0x893044b400"); |
| 208 | ADD_CHECKPOINT2(80000, "a62dcd7b536f22e003ebae8726e9e7276f63d594e264b6f0cd7aab27b66e75e3", "0x5cc113f1076"); |
| 209 | ADD_CHECKPOINT2(202612, "bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698", "0x73310a259eb2"); |
| 210 | ADD_CHECKPOINT2(202613, "e2aa337e78df1f98f462b3b1e560c6b914dec47b610698b7b7d1e3e86b6197c2", "0x733154039b97"); |
| 211 | ADD_CHECKPOINT2(202614, "c29e3dc37d8da3e72e506e31a213a58771b24450144305bcba9e70fa4d6ea6fb", "0x73319dc90cb6"); |
| 212 | ADD_CHECKPOINT2(205000, "5d3d7a26e6dc7535e34f03def711daa8c263785f73ec1fadef8a45880fde8063", "0x75fcc3d85123"); |
| 213 | ADD_CHECKPOINT2(220000, "9613f455933c00e3e33ac315cc6b455ee8aa0c567163836858c2d9caff111553", "0x89cfed0cae3c"); |
| 214 | ADD_CHECKPOINT2(230300, "bae7a80c46859db355556e3a9204a337ae8f24309926a1312323fdecf1920e61", "0x967d13e5baa9"); |
| 215 | ADD_CHECKPOINT2(230700, "93e631240ceac831da1aebfc5dac8f722c430463024763ebafa888796ceaeedf", "0x96fb9663ebe7"); |
| 216 | ADD_CHECKPOINT2(231350, "b5add137199b820e1ea26640e5c3e121fd85faa86a1e39cf7e6cc097bdeb1131", "0x97b9919177bf"); |
| 217 | ADD_CHECKPOINT2(232150, "955de8e6b6508af2c24f7334f97beeea651d78e9ade3ab18fec3763be3201aa8", "0x98a038b612e8"); |
| 218 | ADD_CHECKPOINT2(249380, "654fb0a81ce3e5caf7e3264a70f447d4bd07586c08fa50f6638cc54da0a52b2d", "0xac9739634e6d"); |
| 219 | ADD_CHECKPOINT2(460000, "75037a7aed3e765db96c75bcf908f59d690a5f3390baebb9edeafd336a1c4831", "0x167799549bdda"); |
| 220 | ADD_CHECKPOINT2(500000, "2428f0dbe49796be05ed81b347f53e1f7f44aed0abf641446ec2b94cae066b02", "0x188ce145e4ba9"); |
| 221 | ADD_CHECKPOINT2(600000, "f5828ebf7d7d1cb61762c4dfe3ccf4ecab2e1aad23e8113668d981713b7a54c5", "0x1d9f3759e1554"); |
| 222 | ADD_CHECKPOINT2(700000, "12be9b3d210b93f574d2526abb9c1ab2a881b479131fd0d4f7dac93875f503cd", "0x2201e4ee39c2c"); |
| 223 | ADD_CHECKPOINT2(825000, "56503f9ad766774b575be3aff73245e9d159be88132c93d1754764f28da2ff60", "0x27565a442d5df"); |
| 224 | ADD_CHECKPOINT2(900000, "d9958d0e7dcf91a5a7b11de225927bf7efc6eb26240315ce12372be902cc1337", "0x2a6334031546e"); |
| 225 | ADD_CHECKPOINT2(913193, "5292d5d56f6ba4de33a58d9a34d263e2cb3c6fee0aed2286fd4ac7f36d53c85f", "0x2aefe7f40f5ea"); |
| 226 | ADD_CHECKPOINT2(1000000, "a886ef5149902d8342475fee9bb296341b891ac67c4842f47a833f23c00ed721", "0x2edd71370f0e5"); |
| 227 | ADD_CHECKPOINT2(1100000, "3fd720c5c8b3072fc1ccda922dec1ef25f9ed88a1e6ad4103d0fe00b180a5903", "0x390eb0035c53a"); |
| 228 | ADD_CHECKPOINT2(1150000, "1dd16f626d18e1e988490dfd06de5920e22629c972c58b4d8daddea0038627b2", "0x422d5662e9e37"); |
| 229 | ADD_CHECKPOINT2(1200000, "fa7d13a90850882060479d100141ff84286599ae39c3277c8ea784393f882d1f", "0x4c73503fc4aa3"); |
| 230 | ADD_CHECKPOINT2(1300000, "31b34272343a44a9f4ac7de7a8fcf3b7d8a3124d7d6870affd510d2f37e74cd0", "0x723f49bc249d5"); |
| 231 | ADD_CHECKPOINT2(1390000, "a8f5649dd4ded60eedab475f2bec8c934681c07e3cf640e9be0617554f13ff6c", "0xb4bba65e2841b"); |
| 232 | ADD_CHECKPOINT2(1450000, "ac94e8860093bc7c83e4e91215cba1d663421ecf4067a0ae609c3a8b52bcfac2", "0x11a4aabdca9511"); |
| 233 | ADD_CHECKPOINT2(1530000, "01759bce497ec38e63c78b1038892169203bb78f87e488172f6b854fcd63ba7e", "0x2819ce9f9e91e5"); |
| 234 | ADD_CHECKPOINT2(1579000, "7d0d7a2346373afd41ed1e744a939fc5d474a7dbaa257be5c6fff4009e789241", "0x357a590e7dda83"); |
| 235 | ADD_CHECKPOINT2(1668900, "ac2dcaf3d2f58ffcf8391639f0f1ebafcb8eac43c49479c7c37f611868d07568", "0x474226e475cc3b"); |
| 236 | ADD_CHECKPOINT2(1775600, "1c6e01c661dc22cab939e79ec6a5272190624ce8356d2f7b958e4f9a57fdb05e", "0x5e3b9d206a27c6"); |
| 237 | ADD_CHECKPOINT2(1856000, "9b57f17f29c71a3acd8a7904b93c41fa6eb8d2b7c73936ce4f1702d14880ba29", "0x6bde5e1caccee1"); |
| 238 | ADD_CHECKPOINT2(1958000, "98a5d6e51afdf3146e0eefb10a66e8648d8d4d5c2742be8835e976ba217c9bb2", "0x79dd46d2a0971a"); |
| 239 | ADD_CHECKPOINT2(2046000, "5e867f0b8baefed9244a681df97fc885d8ab36c3dfcd24c7a3abf3b8ac8b8314", "0x9cb8b6ff2978c6"); |
| 240 | ADD_CHECKPOINT2(2092500, "c4e00820c9c7989b49153d5e90ae095a18a11d990e82fcc3be54e6ed785472b5", "0xb4e585a31369cb"); |
| 241 | ADD_CHECKPOINT2(2182500, "0d22b5f81982eff21d094af9e821dc2007e6342069e3b1a37b15d97646353124", "0xead4a874083492"); |
| 242 | ADD_CHECKPOINT2(2661600, "41c9060e8426012238e8a26da26fcb90797436896cc70886a894c2c560bcccf2", "0x2e0d87526ff161f"); |
| 243 | ADD_CHECKPOINT2(2677000, "1b9fee6246eeb176bd17d637bf252e9af54a4218675f01b4449cc0901867f9eb", "0x2f165bc1a5163ba"); |
| 244 | ADD_CHECKPOINT2(2706000, "d8eb144c5e1fe6b329ecc900ec95e7792fccff84175fb23a25ed59d7299a511c", "0x310f7d89372f705"); |
| 245 | ADD_CHECKPOINT2(2720000, "b19fb41dff15bd1016afbee9f8469f05aab715c9e5d1b974466a11fd58ecbb86", "0x3216b5851ddbb61"); |
| 246 | ADD_CHECKPOINT2(2817000, "39726d19ccaac01d150bec827b877ffae710b516bd633503662036ef4422e577", "0x3900669561954c1"); |
| 247 | ADD_CHECKPOINT2(2844000, "28fc7b446dfef5b469f5778eb72ddf32a307a5f5a9823d1c394e772349e05d40", "0x3af384ec0e97d12"); |
| 248 | ADD_CHECKPOINT2(2851000, "5bf0e47fc782263191a33f63a67db6c711781dc2a3c442e17ed901ec401be5c9", "0x3b6cd8a8ed610e8"); |
| 249 | ADD_CHECKPOINT2(2971000, "3d4cac5ac515eeabd18769ab943af85f36db51d28720def0d0e6effc2c8f5ce3", "0x436e532738b8b5b"); |
| 250 | ADD_CHECKPOINT2(2985000, "08f5e6b7301c1b6ed88268a28f8677a06e8ff943b3f9e48d3080f71f9c134bfb", "0x444b7b42a633c96"); |
| 251 | ADD_CHECKPOINT2(3088000, "bddf8ca09110d33d6d497f13a113630c2b6af1c84d4f3a6f35cb1446f2604ade", "0x4aed3615c2f8c3e"); |
| 252 | ADD_CHECKPOINT2(3102800, "083f4a34f9490403b564286e7f13fd1ed45c52c86fa47195f151594e5bc87504", "0x4bbed52d4da5dfb"); |
| 253 | ADD_CHECKPOINT2(3198000, "1d685b39be51e4e84e0af69fa78e023c7cb21de7d33acd012d0371d5f78712d5", "0x517d415fee3a816"); |
| 254 | ADD_CHECKPOINT2(3375700, "96ef57b830ef7a7ccb61ada8595a4670765b6954d8cbf45c6cf583700a676302", "0x61209b7da8a0fa6"); |
| 255 | ADD_CHECKPOINT2(3451000, "0cbc912e06e1adae11f6c9cb675d3159d225b4b04d4a6c61defe50ae1816dd60", "0x6aa5fc4226bab97"); |
| 256 | ADD_CHECKPOINT2(3482000, "629071b10ddad67bdc6156102aba8e008a754c91da252eede852fff9175a9f0a", "0x6f1063da7e70c0e"); |
| 257 | ADD_CHECKPOINT2(3516300, "fa08acbcda99fcc3cd94a749364a29fa6de9501a023cb6673d0c68fdf988b7c3", "0x738f0af4d65d459"); |
| 258 | ADD_CHECKPOINT2(3541000, "74c457bed9ceef40f31f43bb8fab804077519d45c910dcad2acf4dd8556195c7", "0x76ff158c682d218"); |
| 259 | ADD_CHECKPOINT2(3576000, "5da4891bfd06be270193bd949f2a623a2b0cb0ebfaad21c70a6cb18e418e5b6a", "0x7cb2e203e867b57"); |
| 260 | ADD_CHECKPOINT2(3609000, "2c49c7eb40959b4d7a452dcec64e65c59a8b1ebec12ffe0af42bc9468eddae56", "0x823db8bb8f45661"); |
| 261 | ADD_CHECKPOINT2(3661900, "ac392757a92123f68d63cd72f0d1410f63df1102a53b5d39fc4d53d0998b20a3", "0x8a38f2195826a97"); |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | bool checkpoints::load_checkpoints_from_json(const std::string &json_hashfile_fullpath) |
| 266 | { |
| 267 | boost::system::error_code errcode; |
| 268 | if (! (boost::filesystem::exists(json_hashfile_fullpath, errcode))) |
| 269 | { |
| 270 | LOG_PRINT_L1("Blockchain checkpoints file not found"); |
| 271 | return true; |
| 272 | } |
| 273 | |
| 274 | LOG_PRINT_L1("Adding checkpoints from blockchain hashfile"); |
| 275 | |
| 276 | uint64_t prev_max_height = get_max_height(); |
| 277 | LOG_PRINT_L1("Hard-coded max checkpoint height is " << prev_max_height); |
| 278 | t_hash_json hashes; |
| 279 | if (!epee::serialization::load_t_from_json_file(hashes, json_hashfile_fullpath)) |
| 280 | { |
| 281 | MERROR("Error loading checkpoints from " << json_hashfile_fullpath); |
| 282 | return false; |
| 283 | } |
| 284 | for (std::vector<t_hashline>::const_iterator it = hashes.hashlines.begin(); it != hashes.hashlines.end(); ) |
| 285 | { |
| 286 | uint64_t height; |
| 287 | height = it->height; |
| 288 | if (height <= prev_max_height) { |
| 289 | LOG_PRINT_L1("ignoring checkpoint height " << height); |
| 290 | } else { |
| 291 | std::string blockhash = it->hash; |
| 292 | LOG_PRINT_L1("Adding checkpoint height " << height << ", hash=" << blockhash); |
| 293 | ADD_CHECKPOINT(height, blockhash); |
| 294 | } |
| 295 | ++it; |
| 296 | } |
| 297 | |
| 298 | return true; |
| 299 | } |
| 300 | |
| 301 | bool checkpoints::load_checkpoints_from_dns(network_type nettype) |
| 302 | { |
| 303 | std::vector<std::string> records; |
| 304 | |
| 305 | // All four MoneroPulse domains have DNSSEC on and valid |
| 306 | static const std::vector<std::string> dns_urls = { "checkpoints.moneropulse.se" |
| 307 | , "checkpoints.moneropulse.org" |
| 308 | , "checkpoints.moneropulse.net" |
| 309 | , "checkpoints.moneropulse.co" |
| 310 | }; |
| 311 | |
| 312 | static const std::vector<std::string> testnet_dns_urls = { "testpoints.moneropulse.se" |
| 313 | , "testpoints.moneropulse.org" |
| 314 | , "testpoints.moneropulse.net" |
| 315 | , "testpoints.moneropulse.co" |
| 316 | }; |
| 317 | |
| 318 | static const std::vector<std::string> stagenet_dns_urls = { "stagenetpoints.moneropulse.se" |
| 319 | , "stagenetpoints.moneropulse.org" |
| 320 | , "stagenetpoints.moneropulse.net" |
| 321 | , "stagenetpoints.moneropulse.co" |
| 322 | }; |
| 323 | |
| 324 | if (!tools::dns_utils::load_txt_records_from_dns(records, nettype == TESTNET ? testnet_dns_urls : nettype == STAGENET ? stagenet_dns_urls : dns_urls)) |
| 325 | return true; // why true ? |
| 326 | |
| 327 | for (const auto& record : records) |
| 328 | { |
| 329 | auto pos = record.find(":"); |
| 330 | if (pos != std::string::npos) |
| 331 | { |
| 332 | uint64_t height; |
| 333 | crypto::hash hash; |
| 334 | |
| 335 | // parse the first part as uint64_t, |
| 336 | // if this fails move on to the next record |
| 337 | std::stringstream ss(record.substr(0, pos)); |
| 338 | if (!(ss >> height)) |
| 339 | { |
| 340 | continue; |
| 341 | } |
| 342 | |
| 343 | // parse the second part as crypto::hash, |
| 344 | // if this fails move on to the next record |
| 345 | std::string hashStr = record.substr(pos + 1); |
| 346 | if (!epee::string_tools::hex_to_pod(hashStr, hash)) |
| 347 | { |
| 348 | continue; |
| 349 | } |
| 350 | |
| 351 | ADD_CHECKPOINT(height, hashStr); |
| 352 | } |
| 353 | } |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | bool checkpoints::load_new_checkpoints(const std::string &json_hashfile_fullpath, network_type nettype, bool dns) |
| 358 | { |
| 359 | bool result; |
| 360 | |
| 361 | result = load_checkpoints_from_json(json_hashfile_fullpath); |
| 362 | if (dns) |
| 363 | { |
| 364 | result &= load_checkpoints_from_dns(nettype); |
| 365 | } |
| 366 | |
| 367 | return result; |
| 368 | } |
| 369 | } |