aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.h
diff options
context:
space:
mode:
authorstoffu <stoffu@protonmail.ch>2020-05-15 10:56:23 +0900
committerstoffu <stoffu@protonmail.ch>2020-06-09 10:40:51 +0900
commit7bd66b01bfb62ecaf8ff02b20d14db3a77322abc (patch)
treec6a4db2a82193471570360734f4c4955271a69ba /src/cryptonote_core/blockchain.h
parentMerge pull request #6576 (diff)
downloadmonero-7bd66b01bfb62ecaf8ff02b20d14db3a77322abc.tar.xz
daemon: guard against rare 'difficulty drift' bug with checkpoints and recalculation
On startup, it checks against the difficulty checkpoints, and if any mismatch is found, recalculates all the blocks with wrong difficulties. Additionally, once a week it recalculates difficulties of blocks after the last difficulty checkpoint.
Diffstat (limited to 'src/cryptonote_core/blockchain.h')
-rw-r--r--src/cryptonote_core/blockchain.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 3a89cc5df..4dc2cea31 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -310,6 +310,22 @@ namespace cryptonote
difficulty_type get_difficulty_for_next_block();
/**
+ * @brief check currently stored difficulties against difficulty checkpoints
+ *
+ * @return {flag, height} flag: true if all difficulty checkpoints pass, height: the last checkpoint height before the difficulty drift bug starts
+ */
+ std::pair<bool, uint64_t> check_difficulty_checkpoints() const;
+
+ /**
+ * @brief recalculate difficulties for blocks after the last difficulty checkpoints to circumvent the annoying 'difficulty drift' bug
+ *
+ * @param start_height: if omitted, starts recalculation from the last difficulty checkpoint
+ *
+ * @return number of blocks whose difficulties got corrected
+ */
+ size_t recalculate_difficulties(boost::optional<uint64_t> start_height = boost::none);
+
+ /**
* @brief adds a block to the blockchain
*
* Adds a new block to the blockchain. If the block's parent is not the