2014-08-13 10:38:35 +00:00
|
|
|
// Copyright (c) 2012-2014, The CryptoNote developers, The Bytecoin developers
|
|
|
|
//
|
|
|
|
// This file is part of Bytecoin.
|
|
|
|
//
|
|
|
|
// Bytecoin is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Bytecoin is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-03 22:07:58 +00:00
|
|
|
|
|
|
|
#include "include_base_utils.h"
|
|
|
|
using namespace epee;
|
|
|
|
|
|
|
|
#include "checkpoints.h"
|
|
|
|
|
|
|
|
namespace cryptonote
|
|
|
|
{
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
checkpoints::checkpoints()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool checkpoints::add_checkpoint(uint64_t height, const std::string& hash_str)
|
|
|
|
{
|
|
|
|
crypto::hash h = null_hash;
|
|
|
|
bool r = epee::string_tools::parse_tpod_from_hex_string(hash_str, h);
|
|
|
|
CHECK_AND_ASSERT_MES(r, false, "WRONG HASH IN CHECKPOINTS!!!");
|
|
|
|
CHECK_AND_ASSERT_MES(0 == m_points.count(height), false, "WRONG HASH IN CHECKPOINTS!!!");
|
|
|
|
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-15 16:40:40 +00:00
|
|
|
bool checkpoints::check_block(uint64_t height, const crypto::hash& h, bool& is_a_checkpoint) const
|
2014-03-03 22:07:58 +00:00
|
|
|
{
|
|
|
|
auto it = m_points.find(height);
|
2014-05-15 16:40:40 +00:00
|
|
|
is_a_checkpoint = it != m_points.end();
|
|
|
|
if(!is_a_checkpoint)
|
2014-03-03 22:07:58 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if(it->second == h)
|
|
|
|
{
|
|
|
|
LOG_PRINT_GREEN("CHECKPOINT PASSED FOR HEIGHT " << height << " " << h, LOG_LEVEL_0);
|
|
|
|
return true;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
LOG_ERROR("CHECKPOINT FAILED FOR HEIGHT " << height << ". EXPECTED HASH: " << it->second << ", FETCHED HASH: " << h);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-05-15 16:40:40 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
bool checkpoints::check_block(uint64_t height, const crypto::hash& h) const
|
|
|
|
{
|
|
|
|
bool ignored;
|
|
|
|
return check_block(height, h, ignored);
|
|
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
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-03-03 22:07:58 +00:00
|
|
|
}
|