aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorTomer Konforty <tomerk@kon40.com>2014-09-24 17:36:04 +0300
committerRiccardo Spagni <ric@spagni.net>2014-09-25 00:00:44 +0200
commit06a4578bf253cfde6f0ab352994b3aadf61ec372 (patch)
treec96190c1c5b4b112f7086a9071ac4d7f2eeb6b30 /src/cryptonote_core
parentcheckpoint (diff)
downloadmonero-06a4578bf253cfde6f0ab352994b3aadf61ec372.tar.xz
Added ability to read chechpoint hashes from json file in data folder
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/checkpoints.cpp9
-rw-r--r--src/cryptonote_core/checkpoints.h1
-rw-r--r--src/cryptonote_core/checkpoints_create.h50
3 files changed, 60 insertions, 0 deletions
diff --git a/src/cryptonote_core/checkpoints.cpp b/src/cryptonote_core/checkpoints.cpp
index 3669a7217..c76a23841 100644
--- a/src/cryptonote_core/checkpoints.cpp
+++ b/src/cryptonote_core/checkpoints.cpp
@@ -93,4 +93,13 @@ namespace cryptonote
uint64_t checkpoint_height = it->first;
return checkpoint_height < block_height;
}
+ uint64_t checkpoints::get_max_height()
+ {
+ std::map< uint64_t, crypto::hash >::const_iterator highest =
+ std::max_element( m_points.begin(), m_points.end(),
+ ( boost::bind(&std::map< uint64_t, crypto::hash >::value_type::first, _1) <
+ boost::bind(&std::map< uint64_t, crypto::hash >::value_type::first, _2 ) ) );
+ return highest->first;
+ }
+
}
diff --git a/src/cryptonote_core/checkpoints.h b/src/cryptonote_core/checkpoints.h
index 11c4b5eb7..3dee48682 100644
--- a/src/cryptonote_core/checkpoints.h
+++ b/src/cryptonote_core/checkpoints.h
@@ -44,6 +44,7 @@ namespace cryptonote
bool check_block(uint64_t height, const crypto::hash& h) const;
bool check_block(uint64_t height, const crypto::hash& h, bool& is_a_checkpoint) const;
bool is_alternative_block_allowed(uint64_t blockchain_height, uint64_t block_height) const;
+ uint64_t get_max_height();
private:
std::map<uint64_t, crypto::hash> m_points;
diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h
index f75829aba..7512ddd95 100644
--- a/src/cryptonote_core/checkpoints_create.h
+++ b/src/cryptonote_core/checkpoints_create.h
@@ -34,6 +34,24 @@
#include "misc_log_ex.h"
#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(checkpoints.add_checkpoint(h, hash), false);
+#define JSON_HASH_FILE_NAME "checkpoints.json"
+
+struct t_hashline
+{
+ uint64_t height;
+ std::string hash;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(height)
+ KV_SERIALIZE(hash)
+ END_KV_SERIALIZE_MAP()
+};
+
+struct t_hash_json {
+ std::vector<t_hashline> hashlines;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(hashlines)
+ END_KV_SERIALIZE_MAP()
+};
namespace cryptonote {
inline bool create_checkpoints(cryptonote::checkpoints& checkpoints)
@@ -59,4 +77,36 @@ namespace cryptonote {
return true;
}
+
+ inline bool load_checkpoins_from_json(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath)
+ {
+ boost::system::error_code errcode;
+ if (! (boost::filesystem::exists(json_hashfile_fullpath, errcode)))
+ {
+ LOG_PRINT_L0("Blockchain checkpoints file not found");
+ return true;
+ }
+
+ LOG_PRINT_L0("Adding checkpoints from blockchain hashfile");
+
+ uint64_t prev_max_height = checkpoints.get_max_height();
+ LOG_PRINT_L0("Hard-coded max checkpoint height is " << prev_max_height);
+ t_hash_json hashes;
+ epee::serialization::load_t_from_json_file(hashes, json_hashfile_fullpath);
+ for (std::vector<t_hashline>::const_iterator it = hashes.hashlines.begin(); it != hashes.hashlines.end(); )
+ {
+ uint64_t height;
+ height = it->height;
+ if (height <= prev_max_height) {
+ LOG_PRINT_L0("ignoring checkpoint height " << height);
+ } else {
+ std::string blockhash = it->hash;
+ LOG_PRINT_L0("Adding checkpoint height " << height << ", hash=" << blockhash);
+ ADD_CHECKPOINT(height, blockhash);
+ }
+ ++it;
+ }
+
+ return true;
+ }
}