aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp24
-rw-r--r--src/cryptonote_core/blockchain.h5
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp38
-rw-r--r--src/cryptonote_core/blockchain_storage.h5
-rw-r--r--src/cryptonote_core/cryptonote_basic.h4
-rw-r--r--src/cryptonote_core/hardfork.cpp21
6 files changed, 88 insertions, 9 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 28df3629f..a594a1b05 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1033,8 +1033,8 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m
CRITICAL_REGION_BEGIN(m_blockchain_lock);
height = m_db->height();
- b.major_version = m_hardfork->get_ideal_version();
- b.minor_version = 0;
+ b.major_version = m_hardfork->get_current_version();
+ b.minor_version = m_hardfork->get_ideal_version();
b.prev_id = get_tail_id();
b.timestamp = time(NULL);
@@ -3199,3 +3199,23 @@ bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, ui
{
return m_hardfork->get_voting_info(version, window, votes, threshold, voting);
}
+
+bool Blockchain::for_all_key_images(std::function<bool(const crypto::key_image&)> f) const
+{
+ return m_db->for_all_key_images(f);
+}
+
+bool Blockchain::for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)> f) const
+{
+ return m_db->for_all_blocks(f);
+}
+
+bool Blockchain::for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)> f) const
+{
+ return m_db->for_all_transactions(f);
+}
+
+bool Blockchain::for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const
+{
+ return m_db->for_all_outputs(f);;
+}
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 3a663a342..21bbfb447 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -165,6 +165,11 @@ namespace cryptonote
uint8_t get_ideal_hard_fork_version() const { return m_hardfork->get_ideal_version(); }
bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const;
+ bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const;
+ bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const block&)>) const;
+ bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const;
+ bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)>) const;
+
BlockchainDB& get_db()
{
return *m_db;
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index b2d4f5ac1..6d2b33bda 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -1890,3 +1890,41 @@ void blockchain_storage::set_enforce_dns_checkpoints(bool enforce_checkpoints)
{
m_enforce_dns_checkpoints = enforce_checkpoints;
}
+//------------------------------------------------------------------
+bool blockchain_storage::for_all_key_images(std::function<bool(const crypto::key_image&)> f) const
+{
+ for (key_images_container::const_iterator i = m_spent_keys.begin(); i != m_spent_keys.end(); ++i) {
+ if (!f(*i))
+ return false;
+ }
+ return true;
+}
+//------------------------------------------------------------------
+bool blockchain_storage::for_all_blocks(std::function<bool(uint64_t, const block&)> f) const
+{
+ for (blocks_container::const_iterator i = m_blocks.begin(); i != m_blocks.end(); ++i) {
+ if (!f(i->height, i->bl))
+ return false;
+ }
+ return true;
+}
+//------------------------------------------------------------------
+bool blockchain_storage::for_all_transactions(std::function<bool(const transaction&)> f) const
+{
+ for (transactions_container::const_iterator i = m_transactions.begin(); i != m_transactions.end(); ++i) {
+ if (!f(i->second.tx))
+ return false;
+ }
+ return true;
+}
+//------------------------------------------------------------------
+bool blockchain_storage::for_all_outputs(std::function<bool(uint64_t, const crypto::hash&, size_t)> f) const
+{
+ for (outputs_container::const_iterator i = m_outputs.begin(); i != m_outputs.end(); ++i) {
+ for (size_t n = 0; n < i->second.size(); ++n) {
+ if (!f(i->first, i->second[n].first, i->second[n].second))
+ return false;
+ }
+ }
+ return true;
+}
diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h
index 2a4cfcd49..4a4fc14c2 100644
--- a/src/cryptonote_core/blockchain_storage.h
+++ b/src/cryptonote_core/blockchain_storage.h
@@ -185,6 +185,11 @@ namespace cryptonote
difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return m_blocks[height].cumulative_difficulty; }
uint64_t get_block_coins_generated(uint64_t height) const { return m_blocks[height].already_generated_coins; }
+ bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const;
+ bool for_all_blocks(std::function<bool(uint64_t height, const block&)>) const;
+ bool for_all_transactions(std::function<bool(const transaction&)>) const;
+ bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)>) const;
+
// use for testing only
bool debug_pop_block_from_blockchain() { return pop_block_from_blockchain(); }
diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h
index d3db50068..94887b5a0 100644
--- a/src/cryptonote_core/cryptonote_basic.h
+++ b/src/cryptonote_core/cryptonote_basic.h
@@ -277,8 +277,8 @@ namespace cryptonote
/************************************************************************/
struct block_header
{
- uint8_t major_version; // now used as a voting mechanism, rather than how this particular block is built
- uint8_t minor_version;
+ uint8_t major_version;
+ uint8_t minor_version; // now used as a voting mechanism, rather than how this particular block is built
uint64_t timestamp;
crypto::hash prev_id;
uint32_t nonce;
diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp
index 77839678c..6ecaff056 100644
--- a/src/cryptonote_core/hardfork.cpp
+++ b/src/cryptonote_core/hardfork.cpp
@@ -35,6 +35,17 @@
using namespace cryptonote;
+static uint8_t get_block_vote(const cryptonote::block &b)
+{
+ // Pre-hardfork blocks have a minor version hardcoded to 0.
+ // For the purposes of voting, we consider 0 to refer to
+ // version number 1, which is what all blocks from the genesis
+ // block are. It makes things simpler.
+ if (b.minor_version == 0)
+ return 1;
+ return b.minor_version;
+}
+
HardFork::HardFork(cryptonote::BlockchainDB &db, uint8_t original_version, uint64_t original_version_till_height, time_t forked_time, time_t update_time, uint64_t window_size, int threshold_percent):
db(db),
original_version(original_version),
@@ -87,7 +98,7 @@ bool HardFork::do_check(uint8_t version) const
bool HardFork::check(const cryptonote::block &block) const
{
CRITICAL_REGION_LOCAL(lock);
- return do_check(block.major_version);
+ return do_check(get_block_vote(block));
}
bool HardFork::add(uint8_t block_version, uint64_t height)
@@ -125,7 +136,7 @@ bool HardFork::add(uint8_t block_version, uint64_t height)
bool HardFork::add(const cryptonote::block &block, uint64_t height)
{
- return add(block.major_version, height);
+ return add(get_block_vote(block), height);
}
void HardFork::init()
@@ -168,7 +179,7 @@ uint8_t HardFork::get_block_version(uint64_t height) const
return original_version;
const cryptonote::block &block = db.get_block_from_height(height);
- return block.major_version;
+ return get_block_vote(block);
}
bool HardFork::reorganize_from_block_height(uint64_t height)
@@ -192,7 +203,7 @@ bool HardFork::reorganize_from_block_height(uint64_t height)
}
for (uint64_t h = rescan_height; h <= height; ++h) {
cryptonote::block b = db.get_block_from_height(h);
- const uint8_t v = get_effective_version(b.major_version);
+ const uint8_t v = get_effective_version(get_block_vote(b));
last_versions[v]++;
versions.push_back(v);
}
@@ -236,7 +247,7 @@ bool HardFork::rescan_from_block_height(uint64_t height)
const uint64_t rescan_height = height >= (window_size - 1) ? height - (window_size -1) : 0;
for (uint64_t h = rescan_height; h <= height; ++h) {
cryptonote::block b = db.get_block_from_height(h);
- const uint8_t v = get_effective_version(b.major_version);
+ const uint8_t v = get_effective_version(get_block_vote(b));
last_versions[v]++;
versions.push_back(v);
}