diff options
| author | Thomas Winget <tewinget@gmail.com> | 2014-09-29 16:30:47 -0400 |
|---|---|---|
| committer | Thomas Winget <tewinget@gmail.com> | 2014-09-30 16:21:37 -0400 |
| commit | f0b4138f1f6ecb86c971dd7edf72a92d54e22721 (patch) | |
| tree | f185f6e4ddd42d55615ec3d047acce488ad8fc57 /src/cryptonote_core/blockchain_storage.cpp | |
| parent | 7568f89c5559a667c53dfaa6d1bef27fe3b4ae86 (diff) | |
| download | monzero-core-f0b4138f1f6ecb86c971dd7edf72a92d54e22721.tar.gz monzero-core-f0b4138f1f6ecb86c971dd7edf72a92d54e22721.tar.xz monzero-core-f0b4138f1f6ecb86c971dd7edf72a92d54e22721.zip | |
various changes to runtime checkpoint updating
json checkpoints will be checked every 10 minutes, dns every 60.
json checkpoints always enforced, dns still with flag.
conflicting checkpoints is hard fail, but soft if dns enforce flag not
set and dns checkpoints are wonky.
Diffstat (limited to 'src/cryptonote_core/blockchain_storage.cpp')
| -rw-r--r-- | src/cryptonote_core/blockchain_storage.cpp | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index 1165a9035..6f1b4121c 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -1782,16 +1782,11 @@ bool blockchain_storage::add_new_block(const block& bl_, block_verification_cont return handle_block_to_main_chain(bl, id, bvc); } //------------------------------------------------------------------ -bool blockchain_storage::update_checkpoints(const std::string& file_path) +void blockchain_storage::check_against_checkpoints(checkpoints& points, bool enforce) { - if (!cryptonote::load_new_checkpoints(m_checkpoints, file_path)) - { - return false; - } - - const auto& points = m_checkpoints.get_points(); + const auto& pts = points.get_points(); - for (const auto& pt : points) + for (const auto& pt : pts) { // if the checkpoint is for a block we don't have yet, move on if (pt.first >= m_blocks.size()) @@ -1801,8 +1796,8 @@ bool blockchain_storage::update_checkpoints(const std::string& file_path) if (!m_checkpoints.check_block(pt.first, get_block_hash(m_blocks[pt.first].bl))) { - // if we're enforcing dns checkpoints, roll back to a couple of blocks before the checkpoint - if (m_enforce_dns_checkpoints) + // if asked to enforce checkpoints, roll back to a couple of blocks before the checkpoint + if (enforce) { LOG_ERROR("Checkpoint failed when adding new checkpoints, rolling back!"); std::list<block> empty; @@ -1814,8 +1809,46 @@ bool blockchain_storage::update_checkpoints(const std::string& file_path) } } } +} +//------------------------------------------------------------------ +// returns false if any of the checkpoints loading returns false. +// That should happen only if a checkpoint is added that conflicts +// 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)) + { + 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)) + { + return false; + } + } + else if (check_dns) + { + checkpoints dns_points; + cryptonote::load_checkpoints_from_dns(dns_points); + if (m_checkpoints.check_for_conflicts(dns_points)) + { + check_against_checkpoints(dns_points, false); + } + else + { + LOG_PRINT_L0("One or more checkpoints fetched from DNS conflicted with existing checkpoints!"); + } + } + + check_against_checkpoints(m_checkpoints, true); + return true; } +//------------------------------------------------------------------ void blockchain_storage::set_enforce_dns_checkpoints(bool enforce_checkpoints) { m_enforce_dns_checkpoints = enforce_checkpoints; |
