Remove loading checkpoints from DNS (#570)

* Remove loading checkpoints from DNS code

* Remove DNS code from blockchain utilities

* Fix grammar in json checkpoint comments
This commit is contained in:
Doyle 2019-04-26 13:16:56 +10:00 committed by GitHub
parent ab2333d60e
commit 47522768f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 125 deletions

View file

@ -760,7 +760,6 @@ int main(int argc, char* argv[])
try
{
core.disable_dns_checkpoints(true);
#if defined(PER_BLOCK_CHECKPOINT)
const GetCheckpointsCallback& get_checkpoints = blocks::GetCheckpointsData;
#else

View file

@ -339,34 +339,16 @@ namespace cryptonote
uint64_t height;
height = it->height;
if (height <= prev_max_height) {
LOG_PRINT_L1("ignoring checkpoint height " << 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);
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(network_type nettype)
{
return true;
}
bool checkpoints::load_new_checkpoints(const std::string &json_hashfile_fullpath, network_type nettype, bool dns)
{
bool result;
result = load_checkpoints_from_json(json_hashfile_fullpath);
if (dns)
{
result &= load_checkpoints_from_dns(nettype);
}
return result;
}
}

View file

@ -161,20 +161,6 @@ namespace cryptonote
*/
bool init_default_checkpoints(network_type nettype);
/**
* @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 nettype network type
* @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, network_type nettype=MAINNET, bool dns=true);
/**
* @brief load new checkpoints from json
*
@ -184,15 +170,6 @@ namespace cryptonote
*/
bool load_checkpoints_from_json(const std::string &json_hashfile_fullpath);
/**
* @brief load new checkpoints from DNS
*
* @param nettype network type
*
* @return true if loading successful and no conflicts
*/
bool load_checkpoints_from_dns(network_type nettype = MAINNET);
private:
std::unordered_map<uint64_t, std::vector<checkpoint_t>> m_staging_points; // Incomplete service node checkpoints being voted on
std::map<uint64_t, checkpoint_t> m_points; //!< the checkpoints container

View file

@ -126,7 +126,7 @@ static const hard_fork_record stagenet_hard_forks[] =
//------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool, service_nodes::service_node_list& service_node_list, service_nodes::deregister_vote_pool& deregister_vote_pool):
m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_weight_limit(0), m_current_block_cumul_weight_median(0),
m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_sync_on_blocks(true), m_db_sync_threshold(1), m_db_sync_mode(db_async), m_db_default_sync(false), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_bytes_to_sync(0), m_cancel(false),
m_max_prepare_blocks_threads(4), m_db_sync_on_blocks(true), m_db_sync_threshold(1), m_db_sync_mode(db_async), m_db_default_sync(false), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_bytes_to_sync(0), m_cancel(false),
m_long_term_block_weights_window(CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE),
m_long_term_effective_median_block_weight(0),
m_difficulty_for_next_block_top_hash(crypto::null_hash),
@ -3972,36 +3972,10 @@ void Blockchain::check_against_checkpoints(const checkpoints& points, bool enfor
// 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::update_checkpoints(const std::string& file_path, bool check_dns)
bool Blockchain::update_checkpoints(const std::string& file_path)
{
if (!m_checkpoints.load_checkpoints_from_json(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 && !m_offline)
{
if (!m_checkpoints.load_checkpoints_from_dns())
{
return false;
}
}
else if (check_dns && !m_offline)
{
checkpoints dns_points;
dns_points.load_checkpoints_from_dns();
if (m_checkpoints.check_for_conflicts(dns_points))
{
check_against_checkpoints(dns_points, false);
}
else
{
MERROR("One or more checkpoints fetched from DNS conflicted with existing checkpoints!");
}
}
return false;
check_against_checkpoints(m_checkpoints, true);
return true;
}
@ -4020,12 +3994,6 @@ bool Blockchain::add_checkpoint_vote(service_nodes::checkpoint_vote const &vote)
m_checkpoints.add_checkpoint_vote(vote);
return true;
}
//------------------------------------------------------------------
void Blockchain::set_enforce_dns_checkpoints(bool enforce_checkpoints)
{
m_enforce_dns_checkpoints = enforce_checkpoints;
}
//------------------------------------------------------------------
void Blockchain::block_longhash_worker(uint64_t height, const epee::span<const block> &blocks, std::unordered_map<crypto::hash, crypto::hash> &map) const
{

View file

@ -761,14 +761,13 @@ namespace cryptonote
void set_enforce_dns_checkpoints(bool enforce);
/**
* @brief loads new checkpoints from a file and optionally from DNS
* @brief loads new checkpoints from a file
*
* @param file_path the path of the file to look for and load checkpoints from
* @param check_dns whether or not to check for new DNS-based checkpoints
*
* @return false if any enforced checkpoint type fails to load, otherwise true
*/
bool update_checkpoints(const std::string& file_path, bool check_dns);
bool update_checkpoints(const std::string& file_path);
// TODO(doyle): CHECKPOINTING(doyle):
struct service_node_checkpoint_pool_entry
@ -1157,8 +1156,6 @@ namespace cryptonote
std::vector<ValidateMinerTxHook*> m_validate_miner_tx_hooks;
checkpoints m_checkpoints;
bool m_enforce_dns_checkpoints;
HardFork *m_hardfork;
network_type m_nettype;

View file

@ -108,10 +108,6 @@ namespace cryptonote
"offline"
, "Do not listen for peers, nor connect to any"
};
const command_line::arg_descriptor<bool> arg_disable_dns_checkpoints = {
"disable-dns-checkpoints"
, "Do not retrieve checkpoints from DNS"
};
const command_line::arg_descriptor<size_t> arg_block_download_max_size = {
"block-download-max-size"
, "Set maximum size of block download queue in bytes (0 for default)"
@ -132,11 +128,6 @@ namespace cryptonote
, "Sleep time in ms, defaults to 0 (off), used to debug before/after locking mutex. Values 100 to 1000 are good for tests."
, 0
};
static const command_line::arg_descriptor<bool> arg_dns_checkpoints = {
"enforce-dns-checkpointing"
, "checkpoints from DNS server will be enforced"
, false
};
static const command_line::arg_descriptor<uint64_t> arg_fast_block_sync = {
"fast-block-sync"
, "Sync up most of the way by using embedded, known block hashes."
@ -227,9 +218,7 @@ namespace cryptonote
m_starter_message_showed(false),
m_target_blockchain_height(0),
m_checkpoints_path(""),
m_last_dns_checkpoints_update(0),
m_last_json_checkpoints_update(0),
m_disable_dns_checkpoints(false),
m_update_download(0),
m_nettype(UNDEFINED),
m_update_available(false),
@ -248,23 +237,15 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool core::update_checkpoints()
{
if (m_nettype != MAINNET || m_disable_dns_checkpoints) return true;
if (m_nettype != MAINNET) return true;
if (m_checkpoints_updating.test_and_set()) return true;
bool res = true;
if (time(NULL) - m_last_dns_checkpoints_update >= 3600)
if (time(NULL) - m_last_json_checkpoints_update >= 600)
{
res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, true);
m_last_dns_checkpoints_update = time(NULL);
res = m_blockchain_storage.update_checkpoints(m_checkpoints_path);
m_last_json_checkpoints_update = time(NULL);
}
else if (time(NULL) - m_last_json_checkpoints_update >= 600)
{
res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, false);
m_last_json_checkpoints_update = time(NULL);
}
m_checkpoints_updating.clear();
// if anything fishy happened getting new checkpoints, bring down the house
@ -301,7 +282,6 @@ namespace cryptonote
command_line::add_arg(desc, arg_stagenet_on);
command_line::add_arg(desc, arg_regtest_on);
command_line::add_arg(desc, arg_fixed_difficulty);
command_line::add_arg(desc, arg_dns_checkpoints);
command_line::add_arg(desc, arg_prep_blocks_threads);
command_line::add_arg(desc, arg_fast_block_sync);
command_line::add_arg(desc, arg_show_time_stats);
@ -311,7 +291,6 @@ namespace cryptonote
command_line::add_arg(desc, arg_no_fluffy_blocks);
command_line::add_arg(desc, arg_test_dbg_lock_sleep);
command_line::add_arg(desc, arg_offline);
command_line::add_arg(desc, arg_disable_dns_checkpoints);
command_line::add_arg(desc, arg_block_download_max_size);
command_line::add_arg(desc, arg_max_txpool_weight);
command_line::add_arg(desc, arg_service_node);
@ -359,12 +338,10 @@ namespace cryptonote
m_checkpoints_path = checkpoint_json_hashfile_fullpath.string();
}
m_blockchain_storage.set_enforce_dns_checkpoints(command_line::get_arg(vm, arg_dns_checkpoints));
test_drop_download_height(command_line::get_arg(vm, arg_test_drop_download_height));
m_fluffy_blocks_enabled = !get_arg(vm, arg_no_fluffy_blocks);
m_pad_transactions = get_arg(vm, arg_pad_transactions);
m_offline = get_arg(vm, arg_offline);
m_disable_dns_checkpoints = get_arg(vm, arg_disable_dns_checkpoints);
if (!command_line::is_arg_defaulted(vm, arg_fluffy_blocks))
MWARNING(arg_fluffy_blocks.name << " is obsolete, it is now default");
@ -700,9 +677,9 @@ namespace cryptonote
MGINFO("Loading checkpoints");
// load json & DNS checkpoints, and verify them
// load json checkpoints and verify them
// with respect to what blocks we already have
CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json conflicted with existing checkpoints.");
// DNS versions checking
if (check_updates_string == "disabled")
@ -1577,9 +1554,9 @@ namespace cryptonote
{
TRY_ENTRY();
// load json & DNS checkpoints every 10min/hour respectively,
// load json checkpoints every 10min/hour respectively,
// and verify them with respect to what blocks we already have
CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json or dns conflicted with existing checkpoints.");
CHECK_AND_ASSERT_MES(update_checkpoints(), false, "One or more checkpoints loaded from json conflicted with existing checkpoints.");
bvc = boost::value_initialized<block_verification_context>();
if(block_blob.size() > get_max_block_size())

View file

@ -410,13 +410,6 @@ namespace cryptonote
*/
void set_cryptonote_protocol(i_cryptonote_protocol* pprotocol);
/**
* @brief set whether or not to enable or disable DNS checkpoints
*
* @param disble whether to disable DNS checkpoints
*/
void disable_dns_checkpoints(bool disable = true) { m_disable_dns_checkpoints = disable; }
/**
* @copydoc tx_memory_pool::have_tx
*
@ -1158,11 +1151,9 @@ namespace cryptonote
std::atomic<bool> m_update_available;
std::string m_checkpoints_path; //!< path to json checkpoints file
time_t m_last_dns_checkpoints_update; //!< time when dns checkpoints were last updated
time_t m_last_json_checkpoints_update; //!< time when json checkpoints were last updated
std::atomic_flag m_checkpoints_updating; //!< set if checkpoints are currently updating to avoid multiple threads attempting to update at once
bool m_disable_dns_checkpoints;
bool m_service_node;
crypto::secret_key m_service_node_key;