aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/cryptonote_core.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2014-10-02 16:48:01 +0200
committerRiccardo Spagni <ric@spagni.net>2014-10-02 16:48:05 +0200
commit1cf22b27a6b95e1e44c35157f5c5ccb73efec9da (patch)
tree770a470c84cd8c7c7ef816dd2c34078d5aebbc7a /src/cryptonote_core/cryptonote_core.cpp
parent0e777d0e6587b41b139f8c8105c3855994584e95 (diff)
parentc0bdd511c3309e78488051f6a21b0b30ed25af44 (diff)
downloadmonzero-core-1cf22b27a6b95e1e44c35157f5c5ccb73efec9da.tar.gz
monzero-core-1cf22b27a6b95e1e44c35157f5c5ccb73efec9da.tar.xz
monzero-core-1cf22b27a6b95e1e44c35157f5c5ccb73efec9da.zip
Merge pull request #165
c0bdd51 Daemon should now exit on conflicting checkpoints (Thomas Winget) f0b4138 various changes to runtime checkpoint updating (Thomas Winget) 7568f89 Fixed segfault with checkpoints loading (Thomas Winget) b261d92 DNS checkpoint updating added, and daemon flag to enforce them (Thomas Winget) 30caebf reload checkpoints file every ~hr and print if any fail (Thomas Winget) 0e14491 updated DNSResolver/things that use it for DNSSEC (Thomas Winget) 6f2c2e1 Adding an identical existing checkpoint should not error (Thomas Winget)
Diffstat (limited to 'src/cryptonote_core/cryptonote_core.cpp')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp52
1 files changed, 51 insertions, 1 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 964d61e2f..d9d8a7faf 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -41,6 +41,7 @@ using namespace epee;
#include "cryptonote_config.h"
#include "cryptonote_format_utils.h"
#include "misc_language.h"
+#include <csignal>
DISABLE_VS_WARNINGS(4355)
@@ -54,7 +55,10 @@ namespace cryptonote
m_miner(this),
m_miner_address(boost::value_initialized<account_public_address>()),
m_starter_message_showed(false),
- m_target_blockchain_height(0)
+ m_target_blockchain_height(0),
+ m_checkpoints_path(""),
+ m_last_dns_checkpoints_update(0),
+ m_last_json_checkpoints_update(0)
{
set_cryptonote_protocol(pprotocol);
}
@@ -71,6 +75,39 @@ namespace cryptonote
m_blockchain_storage.set_checkpoints(std::move(chk_pts));
}
//-----------------------------------------------------------------------------------
+ void core::set_checkpoints_file_path(const std::string& path)
+ {
+ m_checkpoints_path = path;
+ }
+ //-----------------------------------------------------------------------------------
+ void core::set_enforce_dns_checkpoints(bool enforce_dns)
+ {
+ m_blockchain_storage.set_enforce_dns_checkpoints(enforce_dns);
+ }
+ //-----------------------------------------------------------------------------------------------
+ bool core::update_checkpoints()
+ {
+ bool res = true;
+ if (time(NULL) - m_last_dns_checkpoints_update >= 3600)
+ {
+ res = m_blockchain_storage.update_checkpoints(m_checkpoints_path, true);
+ m_last_dns_checkpoints_update = time(NULL);
+ 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);
+ }
+
+ // if anything fishy happened getting new checkpoints, bring down the house
+ if (!res)
+ {
+ graceful_exit();
+ }
+ return res;
+ }
+ //-----------------------------------------------------------------------------------
void core::init_options(boost::program_options::options_description& /*desc*/)
{
}
@@ -127,6 +164,10 @@ namespace cryptonote
r = m_blockchain_storage.init(m_config_folder, testnet);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
+ // load json & DNS 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.");
+
r = m_miner.init(vm, testnet);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
@@ -418,6 +459,10 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool core::handle_incoming_block(const blobdata& block_blob, block_verification_context& bvc, bool update_miner_blocktemplate)
{
+ // load json & DNS 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.");
+
bvc = boost::value_initialized<block_verification_context>();
if(block_blob.size() > get_max_block_size())
{
@@ -545,4 +590,9 @@ namespace cryptonote
uint64_t core::get_target_blockchain_height() const {
return m_target_blockchain_height;
}
+ //-----------------------------------------------------------------------------------------------
+ void core::graceful_exit()
+ {
+ raise(SIGTERM);
+ }
}