Monero
cryptonote_core.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2020, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30 
31 #pragma once
32 
33 #include <ctime>
34 
35 #include <boost/function.hpp>
36 #include <boost/program_options/options_description.hpp>
37 #include <boost/program_options/variables_map.hpp>
38 
39 #include "cryptonote_basic/fwd.h"
43 #include "storages/portable_storage_template_helper.h"
44 #include "common/download.h"
45 #include "common/command_line.h"
46 #include "tx_pool.h"
47 #include "blockchain.h"
48 #include "cryptonote_basic/miner.h"
50 #include "warnings.h"
51 #include "crypto/hash.h"
52 #include "span.h"
53 #include "rpc/fwd.h"
54 
57 
59 
60 namespace cryptonote
61 {
62  struct test_options {
63  const std::pair<uint8_t, uint64_t> *hard_forks;
65  };
66 
75 
76  /************************************************************************/
77  /* */
78  /************************************************************************/
79 
87  class core final: public i_miner_handler, public i_core_events
88  {
89  public:
90 
98  core(i_cryptonote_protocol* pprotocol);
99 
107 
115  bool on_idle();
116 
130  bool handle_incoming_tx(const tx_blob_entry& tx_blob, tx_verification_context& tvc, relay_method tx_relay, bool relayed);
131 
147  bool handle_incoming_txs(epee::span<const tx_blob_entry> tx_blobs, epee::span<tx_verification_context> tvc, relay_method tx_relay, bool relayed);
148 
162  bool handle_incoming_txs(const std::vector<tx_blob_entry>& tx_blobs, std::vector<tx_verification_context>& tvc, relay_method tx_relay, bool relayed)
163  {
164  tvc.resize(tx_blobs.size());
165  return handle_incoming_txs(epee::to_span(tx_blobs), epee::to_mut_span(tvc), tx_relay, relayed);
166  }
167 
183  bool handle_incoming_block(const blobdata& block_blob, const block *b, block_verification_context& bvc, bool update_miner_blocktemplate = true);
184 
190  bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks);
191 
197  bool cleanup_handle_incoming_blocks(bool force_sync = false);
198 
206  bool check_incoming_block_size(const blobdata& block_blob) const;
207 
214 
215  //-------------------- i_miner_handler -----------------------
216 
230 
236  virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
237  virtual bool get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash);
238 
243  virtual void on_transactions_relayed(epee::span<const cryptonote::blobdata> tx_blobs, relay_method tx_relay) final;
244 
245 
251  miner& get_miner(){return m_miner;}
252 
258  const miner& get_miner()const{return m_miner;}
259 
268  static void init_options(boost::program_options::options_description& desc);
269 
282  bool init(const boost::program_options::variables_map& vm, const test_options *test_options = NULL, const GetCheckpointsCallback& get_checkpoints = nullptr);
283 
289  bool set_genesis_block(const block& b);
290 
298  bool deinit();
299 
303  void test_drop_download();
304 
310  void test_drop_download_height(uint64_t height);
311 
317  bool get_test_drop_download() const;
318 
327  bool get_test_drop_download_height() const;
328 
334  virtual uint64_t get_current_blockchain_height() const final;
335 
342  void get_blockchain_top(uint64_t& height, crypto::hash& top_id) const;
343 
349  bool get_blocks(uint64_t start_offset, size_t count, std::vector<std::pair<cryptonote::blobdata,block>>& blocks, std::vector<cryptonote::blobdata>& txs) const;
350 
356  bool get_blocks(uint64_t start_offset, size_t count, std::vector<std::pair<cryptonote::blobdata,block>>& blocks) const;
357 
363  bool get_blocks(uint64_t start_offset, size_t count, std::vector<block>& blocks) const;
364 
370  template<class t_ids_container, class t_blocks_container, class t_missed_container>
371  bool get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs) const
372  {
373  return m_blockchain_storage.get_blocks(block_ids, blocks, missed_bs);
374  }
375 
381  crypto::hash get_block_id_by_height(uint64_t height) const;
382 
388  bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::vector<cryptonote::blobdata>& txs, std::vector<crypto::hash>& missed_txs) const;
389 
395  bool get_split_transactions_blobs(const std::vector<crypto::hash>& txs_ids, std::vector<std::tuple<crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata>>& txs, std::vector<crypto::hash>& missed_txs) const;
396 
402  bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::vector<transaction>& txs, std::vector<crypto::hash>& missed_txs) const;
403 
409  bool get_block_by_hash(const crypto::hash &h, block &blk, bool *orphan = NULL) const;
410 
416  bool get_alternative_blocks(std::vector<block>& blocks) const;
417 
423  size_t get_alternative_blocks_count() const;
424 
431 
437  void set_checkpoints(checkpoints&& chk_pts);
438 
444  void set_checkpoints_file_path(const std::string& path);
445 
451  void set_enforce_dns_checkpoints(bool enforce_dns);
452 
458  void set_txpool_listener(boost::function<void(std::vector<txpool_event>)> zmq_pub);
459 
465  void disable_dns_checkpoints(bool disable = true) { m_disable_dns_checkpoints = disable; }
466 
472  bool pool_has_tx(const crypto::hash &txid) const;
473 
480  bool get_pool_transactions(std::vector<transaction>& txs, bool include_sensitive_txes = false) const;
481 
488  bool get_txpool_backlog(std::vector<tx_backlog_entry>& backlog, bool include_sensitive_txes = false) const;
489 
496  bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs, bool include_sensitive_txes = false) const;
497 
504  bool get_pool_transaction_stats(struct txpool_stats& stats, bool include_sensitive_txes = false) const;
505 
511  bool get_pool_transaction(const crypto::hash& id, cryptonote::blobdata& tx, relay_category tx_category) const;
512 
519  bool get_pool_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos, bool include_sensitive_txes = false) const;
520 
526  bool get_pool_for_rpc(std::vector<cryptonote::rpc::tx_in_pool>& tx_infos, cryptonote::rpc::key_images_with_tx_hashes& key_image_infos) const;
527 
534  size_t get_pool_transactions_count(bool include_sensitive_txes = false) const;
535 
541  size_t get_blockchain_total_transactions() const;
542 
548  bool have_block_unlocked(const crypto::hash& id, int *where = NULL) const;
549  bool have_block(const crypto::hash& id, int *where = NULL) const;
550 
556  bool get_short_chain_history(std::list<crypto::hash>& ids) const;
557 
563  bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, bool clip_pruned, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp) const;
564 
570  bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_block_count, size_t max_tx_count) const;
571 
577  bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs) const;
578  bool get_tx_outputs_gindexs(const crypto::hash& tx_id, size_t n_txes, std::vector<std::vector<uint64_t>>& indexs) const;
579 
585  crypto::hash get_tail_id() const;
586 
592  difficulty_type get_block_cumulative_difficulty(uint64_t height) const;
593 
600 
606  bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) const;
607 
613  void pause_mine();
614 
620  void resume_mine();
621 
628 
635 
641  std::string print_pool(bool short_format) const;
642 
648  virtual bool is_synchronized() const final;
649 
655  void on_synchronized();
656 
662  void safesyncmode(const bool onoff);
663 
669  void set_target_blockchain_height(uint64_t target_blockchain_height);
670 
677 
684 
690  uint8_t get_ideal_hard_fork_version(uint64_t height) const;
691 
697  uint8_t get_hard_fork_version(uint64_t height) const;
698 
705 
710  std::time_t get_start_time() const;
711 
722  bool update_checkpoints(const bool skip_dns = false);
723 
730  void graceful_exit();
731 
737  void stop();
738 
745 
756  bool are_key_images_spent(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const;
757 
766  bool are_key_images_spent_in_pool(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const;
767 
773  size_t get_block_sync_size(uint64_t height) const;
774 
780  std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t> get_coinbase_tx_sum(const uint64_t start_offset, const size_t count);
781 
787  network_type get_nettype() const { return m_nettype; };
788 
797  bool is_update_available() const { return m_update_available; }
798 
805 
811  uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes, const std::vector<uint64_t> &weights);
812 
818  uint64_t get_free_space() const;
819 
825  bool offline() const { return m_offline; }
826 
832  uint32_t get_blockchain_pruning_seed() const;
833 
841  bool prune_blockchain(uint32_t pruning_seed = 0);
842 
849 
856 
862  bool is_within_compiled_block_hash_area(uint64_t height) const;
863 
867  bool has_block_weights(uint64_t height, uint64_t nblocks) const;
868 
872  void flush_bad_txs_cache();
873 
877  void flush_invalid_blocks();
878 
886  bool get_txpool_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes);
887 
888  private:
889 
900  bool add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, relay_method tx_relay, bool relayed);
901 
916  bool add_new_tx(transaction& tx, tx_verification_context& tvc, relay_method tx_relay, bool relayed);
917 
923  bool add_new_block(const block& b, block_verification_context& bvc);
924 
932  bool load_state_data();
933 
939  bool parse_tx_from_blob(transaction& tx, crypto::hash& tx_hash, const blobdata& blob) const;
940 
951  bool check_tx_syntax(const transaction& tx) const;
952 
969  bool check_tx_semantic(const transaction& tx, bool keeped_by_block) const;
970  void set_semantics_failed(const crypto::hash &tx_hash);
971 
975  bool handle_incoming_tx_accumulated_batch(std::vector<tx_verification_batch_info> &tx_info, bool keeped_by_block);
976 
985 
993  bool handle_command_line(const boost::program_options::variables_map& vm);
994 
1002  bool check_tx_inputs_keyimages_diff(const transaction& tx) const;
1003 
1011  bool check_tx_inputs_ring_members_diff(const transaction& tx) const;
1012 
1021  bool check_tx_inputs_keyimages_domain(const transaction& tx) const;
1022 
1029 
1035  bool check_updates();
1036 
1042  bool check_disk_space();
1043 
1049  bool check_block_rate();
1050 
1056  bool recalculate_difficulties();
1057 
1058  bool m_test_drop_download = true;
1059 
1061 
1064 
1066 
1067  epee::critical_section m_incoming_tx_lock;
1068 
1069  //m_miner and m_miner_addres are probably temporary here
1071 
1072  std::string m_config_folder;
1073 
1075 
1076  epee::math_helper::once_a_time_seconds<60*60*12, false> m_store_blockchain_interval;
1077  epee::math_helper::once_a_time_seconds<60*60*2, true> m_fork_moaner;
1078  epee::math_helper::once_a_time_seconds<60*60*12, true> m_check_updates_interval;
1079  epee::math_helper::once_a_time_seconds<60*10, true> m_check_disk_space_interval;
1080  epee::math_helper::once_a_time_seconds<90, false> m_block_rate_interval;
1081  epee::math_helper::once_a_time_seconds<60*60*5, true> m_blockchain_pruning_interval;
1082  epee::math_helper::once_a_time_seconds<60*60*24*7, false> m_diff_recalc_interval;
1083 
1084  std::atomic<bool> m_starter_message_showed;
1085 
1087 
1089 
1090  std::atomic<bool> m_update_available;
1091 
1092  std::string m_checkpoints_path;
1095 
1096  std::atomic_flag m_checkpoints_updating;
1098 
1100 
1101  time_t start_time;
1102 
1103  std::unordered_set<crypto::hash> bad_semantics_txes[2];
1105 
1106  enum {
1112 
1115  boost::mutex m_update_mutex;
1116 
1119 
1120  /* `boost::function` is used because the implementation never allocates if
1121  the callable object has a single `std::shared_ptr` or `std::weap_ptr`
1122  internally. Whereas, the libstdc++ `std::function` will allocate. */
1123 
1124  std::shared_ptr<tools::Notify> m_block_rate_notify;
1125  boost::function<void(std::vector<txpool_event>)> m_zmq_pub;
1126  };
1127 }
1128 
1129 POP_WARNINGS
Definition: blockchain.h:96
bool get_blocks(uint64_t start_offset, size_t count, std::vector< std::pair< cryptonote::blobdata, block >> &blocks, std::vector< cryptonote::blobdata > &txs) const
get blocks and transactions from blocks based on start height and count
Definition: blockchain.cpp:2090
A container for blockchain checkpoints.
Definition: checkpoints.h:53
handles core cryptonote functionality
Definition: cryptonote_core.h:88
epee::math_helper::once_a_time_seconds< 60 *60 *5, true > m_blockchain_pruning_interval
interval for incremental blockchain pruning
Definition: cryptonote_core.h:1081
size_t block_sync_size
Definition: cryptonote_core.h:1099
bool handle_incoming_tx_pre(const tx_blob_entry &tx_blob, tx_verification_context &tvc, cryptonote::transaction &tx, crypto::hash &tx_hash)
Definition: cryptonote_core.cpp:779
bool pool_has_tx(const crypto::hash &txid) const
checks if the pool has a transaction with the given hash
Definition: cryptonote_core.cpp:1671
bool handle_incoming_tx(const tx_blob_entry &tx_blob, tx_verification_context &tvc, relay_method tx_relay, bool relayed)
handles an incoming transaction
Definition: cryptonote_core.cpp:1088
bool check_updates()
checks DNS versions
Definition: cryptonote_core.cpp:1769
void safesyncmode(const bool onoff)
Put DB in safe sync mode.
Definition: cryptonote_core.cpp:1523
bool update_blockchain_pruning()
incrementally prunes blockchain
Definition: cryptonote_core.cpp:2006
bool check_tx_inputs_keyimages_domain(const transaction &tx) const
verify that each input key image in a transaction is in the valid domain
Definition: cryptonote_core.cpp:1288
virtual bool handle_block_found(block &b, block_verification_context &bvc)
stores and relays a block found by a miner
Definition: cryptonote_core.cpp:1458
bool is_within_compiled_block_hash_area(uint64_t height) const
checks whether a given block height is included in the precompiled block hash area
Definition: cryptonote_core.cpp:2048
bool m_offline
Definition: cryptonote_core.h:1118
tx_memory_pool m_mempool
transaction pool instance
Definition: cryptonote_core.h:1062
virtual void on_transactions_relayed(epee::span< const cryptonote::blobdata > tx_blobs, relay_method tx_relay) final
called when a transaction is relayed.
Definition: cryptonote_core.cpp:1377
bool handle_incoming_txs(epee::span< const tx_blob_entry > tx_blobs, epee::span< tx_verification_context > tvc, relay_method tx_relay, bool relayed)
handles a list of incoming transactions
Definition: cryptonote_core.cpp:973
void get_blockchain_top(uint64_t &height, crypto::hash &top_id) const
get the hash and height of the most recent block
Definition: cryptonote_core.cpp:405
bool handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request &arg, NOTIFY_RESPONSE_GET_OBJECTS::request &rsp, cryptonote_connection_context &context)
retrieves a set of blocks and their transactions, and possibly other transactions
Definition: cryptonote_core.cpp:1691
size_t get_alternative_blocks_count() const
returns the number of alternative blocks stored
Definition: cryptonote_core.cpp:456
uint64_t prevalidate_block_hashes(uint64_t height, const std::vector< crypto::hash > &hashes, const std::vector< uint64_t > &weights)
check a set of hashes against the precompiled hash set
Definition: cryptonote_core.cpp:2026
void stop()
stops the daemon running
Definition: cryptonote_core.cpp:304
bool parse_tx_from_blob(transaction &tx, crypto::hash &tx_hash, const blobdata &blob) const
Definition: cryptonote_core.cpp:1638
epee::math_helper::once_a_time_seconds< 60 *60 *2, true > m_fork_moaner
interval for checking HardFork status
Definition: cryptonote_core.h:1077
bool is_key_image_spent(const crypto::key_image &key_im) const
check if a key image is already spent on the blockchain
Definition: cryptonote_core.cpp:1169
bool has_block_weights(uint64_t height, uint64_t nblocks) const
checks whether block weights are known for the given range
Definition: cryptonote_core.cpp:2053
void set_cryptonote_protocol(i_cryptonote_protocol *pprotocol)
set the pointer to the cryptonote protocol object to use
Definition: cryptonote_core.cpp:245
uint8_t get_hard_fork_version(uint64_t height) const
return the hard fork version for a given block height
Definition: cryptonote_core.cpp:1759
bool check_disk_space()
checks free disk space
Definition: cryptonote_core.cpp:1899
static void init_options(boost::program_options::options_description &desc)
adds command line options to the given options set
Definition: cryptonote_core.cpp:319
bool get_transactions(const std::vector< crypto::hash > &txs_ids, std::vector< cryptonote::blobdata > &txs, std::vector< crypto::hash > &missed_txs) const
Definition: cryptonote_core.cpp:430
epee::math_helper::once_a_time_seconds< 60 *60 *12, true > m_check_updates_interval
interval for checking for new versions
Definition: cryptonote_core.h:1078
boost::function< void(std::vector< txpool_event >)> m_zmq_pub
Definition: cryptonote_core.h:1125
bool get_test_drop_download_height() const
gets whether or not to drop blocks
Definition: cryptonote_core.cpp:768
void pause_mine()
Definition: cryptonote_core.cpp:1434
std::shared_ptr< tools::Notify > m_block_rate_notify
Definition: cryptonote_core.h:1124
time_t m_last_json_checkpoints_update
time when json checkpoints were last updated
Definition: cryptonote_core.h:1094
bool handle_command_line(const boost::program_options::variables_map &vm)
act on a set of command line options given
Definition: cryptonote_core.cpp:355
bool update_miner_block_template()
Definition: cryptonote_core.cpp:1711
void flush_invalid_blocks()
flushes the invalid block cache
Definition: cryptonote_core.cpp:1996
bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, uint64_t &start_height, std::vector< uint64_t > &distribution, uint64_t &base) const
gets per block distribution of outputs of a given amount
Definition: cryptonote_core.cpp:1419
void graceful_exit()
tells the daemon to wind down operations and stop running
Definition: cryptonote_core.cpp:2063
void set_txpool_listener(boost::function< void(std::vector< txpool_event >)> zmq_pub)
set a listener for txes being added to the txpool
Definition: cryptonote_core.cpp:268
epee::math_helper::once_a_time_seconds< 90, false > m_block_rate_interval
interval for checking block rate
Definition: cryptonote_core.h:1080
void test_drop_download_height(uint64_t height)
sets to drop blocks downloaded below a certain height
Definition: cryptonote_core.cpp:758
bool get_short_chain_history(std::list< crypto::hash > &ids) const
gets the hashes for a subset of the blockchain
Definition: cryptonote_core.cpp:1686
void resume_mine()
Definition: cryptonote_core.cpp:1439
bool are_key_images_spent_in_pool(const std::vector< crypto::key_image > &key_im, std::vector< bool > &spent) const
check if multiple key images are spent in the transaction pool
Definition: cryptonote_core.cpp:1225
bool fluffy_blocks_enabled() const
get whether fluffy blocks are enabled
Definition: cryptonote_core.h:804
bool on_idle()
calls various idle routines
Definition: cryptonote_core.cpp:1717
uint64_t get_free_space() const
get free disk space on the blockchain partition
Definition: cryptonote_core.cpp:2031
uint32_t get_blockchain_pruning_seed() const
get the blockchain pruning seed
Definition: cryptonote_core.cpp:2038
network_type m_nettype
which network are we on?
Definition: cryptonote_core.h:1088
difficulty_type get_block_cumulative_difficulty(uint64_t height) const
Definition: cryptonote_core.cpp:1618
bool get_pool_transaction_hashes(std::vector< crypto::hash > &txs, bool include_sensitive_txes=false) const
get a list of all transactions in the pool
Definition: cryptonote_core.cpp:1654
bool get_blocks(uint64_t start_offset, size_t count, std::vector< std::pair< cryptonote::blobdata, block >> &blocks, std::vector< cryptonote::blobdata > &txs) const
Definition: cryptonote_core.cpp:410
bool is_update_available() const
check whether an update is known to be available or not
Definition: cryptonote_core.h:797
miner m_miner
miner instance
Definition: cryptonote_core.h:1070
Blockchain m_blockchain_storage
Blockchain instance.
Definition: cryptonote_core.h:1063
bool have_block(const crypto::hash &id, int *where=NULL) const
Definition: cryptonote_core.cpp:1633
bool get_pool_transactions(std::vector< transaction > &txs, bool include_sensitive_txes=false) const
get a list of all transactions in the pool
Definition: cryptonote_core.cpp:1648
std::string m_config_folder
folder to look in for configs and other files
Definition: cryptonote_core.h:1072
bool prepare_handle_incoming_blocks(const std::vector< block_complete_entry > &blocks_entry, std::vector< block > &blocks)
performs some preprocessing on a group of incoming blocks to speed up verification
Definition: cryptonote_core.cpp:1534
bool check_block_rate()
checks block rate, and warns if it's too slow
Definition: cryptonote_core.cpp:1942
uint64_t m_target_blockchain_height
blockchain height target
Definition: cryptonote_core.h:1086
bool set_genesis_block(const block &b)
clears the blockchain and starts a new one
Definition: cryptonote_core.cpp:734
Blockchain & get_blockchain_storage()
gets the Blockchain instance
Definition: cryptonote_core.h:627
bool get_split_transactions_blobs(const std::vector< crypto::hash > &txs_ids, std::vector< std::tuple< crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata >> &txs, std::vector< crypto::hash > &missed_txs) const
Definition: cryptonote_core.cpp:435
size_t get_blockchain_total_transactions() const
gets the total number of transactions on the main chain
Definition: cryptonote_core.cpp:1309
bool have_block_unlocked(const crypto::hash &id, int *where=NULL) const
Definition: cryptonote_core.cpp:1628
uint8_t get_ideal_hard_fork_version() const
returns the newest hardfork version known to the blockchain
Definition: cryptonote_core.cpp:1749
crypto::hash get_tail_id() const
get the hash of the most recent block on the blockchain
Definition: cryptonote_core.cpp:1613
bool get_test_drop_download() const
gets whether or not to drop blocks (for testing)
Definition: cryptonote_core.cpp:763
bool m_disable_dns_checkpoints
Definition: cryptonote_core.h:1097
bool cleanup_handle_incoming_blocks(bool force_sync=false)
incoming blocks post-processing, cleanup, and disk sync
Definition: cryptonote_core.cpp:1546
virtual uint64_t get_current_blockchain_height() const final
get the current height of the blockchain
Definition: cryptonote_core.cpp:400
std::atomic_flag m_checkpoints_updating
set if checkpoints are currently updating to avoid multiple threads attempting to update at once
Definition: cryptonote_core.h:1096
const miner & get_miner() const
gets the miner instance (const)
Definition: cryptonote_core.h:258
virtual bool is_synchronized() const final
gets the core synchronization status
Definition: cryptonote_core.cpp:1513
std::string m_checkpoints_path
path to json checkpoints file
Definition: cryptonote_core.h:1092
bool load_state_data()
load any core state stored on disk
Definition: cryptonote_core.cpp:739
epee::math_helper::once_a_time_seconds< 60 *60 *12, false > m_store_blockchain_interval
interval for manual storing of Blockchain, if enabled
Definition: cryptonote_core.h:1076
void set_checkpoints_file_path(const std::string &path)
set the file path to read from when loading checkpoints
Definition: cryptonote_core.cpp:258
bool check_blockchain_pruning()
checks the blockchain pruning if enabled
Definition: cryptonote_core.cpp:2011
void flush_bad_txs_cache()
flushes the bad txs cache
Definition: cryptonote_core.cpp:1988
size_t get_block_sync_size(uint64_t height) const
get the number of blocks to sync in one go
Definition: cryptonote_core.cpp:1184
bool offline() const
get whether the core is running offline
Definition: cryptonote_core.h:825
bool deinit()
performs safe shutdown steps for core and core components
Definition: cryptonote_core.cpp:745
void set_semantics_failed(const crypto::hash &tx_hash)
Definition: cryptonote_core.cpp:855
network_type get_nettype() const
get the network type we're on
Definition: cryptonote_core.h:787
core(i_cryptonote_protocol *pprotocol)
constructor
Definition: cryptonote_core.cpp:226
bool check_tx_semantic(const transaction &tx, bool keeped_by_block) const
validates some simple properties of a transaction
Definition: cryptonote_core.cpp:1093
std::time_t get_start_time() const
gets start_time
Definition: cryptonote_core.cpp:2058
uint64_t m_test_drop_download_height
height under which to drop incoming blocks, if doing so
Definition: cryptonote_core.h:1060
bool handle_incoming_tx_post(const tx_blob_entry &tx_blob, tx_verification_context &tvc, cryptonote::transaction &tx, crypto::hash &tx_hash)
Definition: cryptonote_core.cpp:843
void set_checkpoints(checkpoints &&chk_pts)
assign a set of blockchain checkpoint hashes
Definition: cryptonote_core.cpp:253
std::string print_pool(bool short_format) const
get a string containing human-readable pool information
Definition: cryptonote_core.cpp:1706
@ UPDATES_NOTIFY
Definition: cryptonote_core.h:1108
@ UPDATES_UPDATE
Definition: cryptonote_core.h:1110
@ UPDATES_DOWNLOAD
Definition: cryptonote_core.h:1109
@ UPDATES_DISABLED
Definition: cryptonote_core.h:1107
size_t get_pool_transactions_count(bool include_sensitive_txes=false) const
get the total number of transactions in the pool
Definition: cryptonote_core.cpp:1623
bool handle_incoming_block(const blobdata &block_blob, const block *b, block_verification_context &bvc, bool update_miner_blocktemplate=true)
handles an incoming block
Definition: cryptonote_core.cpp:1558
std::atomic< bool > m_starter_message_showed
has the "daemon will sync now" message been shown?
Definition: cryptonote_core.h:1084
void set_target_blockchain_height(uint64_t target_blockchain_height)
sets the target blockchain height
Definition: cryptonote_core.cpp:2016
bool get_outs(const COMMAND_RPC_GET_OUTPUTS_BIN::request &req, COMMAND_RPC_GET_OUTPUTS_BIN::response &res) const
gets specific outputs to mix with
Definition: cryptonote_core.cpp:1414
crypto::hash get_block_id_by_height(uint64_t height) const
gets a block's hash given a height
Definition: cryptonote_core.cpp:1696
bool get_pool_transaction(const crypto::hash &id, cryptonote::blobdata &tx, relay_category tx_category) const
get a specific transaction from the pool
Definition: cryptonote_core.cpp:1666
bool update_checkpoints(const bool skip_dns=false)
tells the Blockchain to update its checkpoints
Definition: cryptonote_core.cpp:275
i_cryptonote_protocol * get_protocol()
get the cryptonote protocol instance
Definition: cryptonote_core.h:213
uint64_t get_target_blockchain_height() const
gets the target blockchain height
Definition: cryptonote_core.cpp:2021
void on_synchronized()
Definition: cryptonote_core.cpp:1518
bool get_alternative_blocks(std::vector< block > &blocks) const
compiles a list of all blocks stored as alternative chains
Definition: cryptonote_core.cpp:451
bool recalculate_difficulties()
recalculate difficulties after the last difficulty checklpoint to circumvent the annoying 'difficulty...
Definition: cryptonote_core.cpp:1982
tools::download_async_handle m_update_download
Definition: cryptonote_core.h:1113
void set_enforce_dns_checkpoints(bool enforce_dns)
set whether or not we enforce DNS checkpoints
Definition: cryptonote_core.cpp:263
bool m_test_drop_download
whether or not to drop incoming blocks (for testing)
Definition: cryptonote_core.h:1058
bool check_incoming_block_size(const blobdata &block_blob) const
check the size of a block against the current maximum
Definition: cryptonote_core.cpp:1599
void disable_dns_checkpoints(bool disable=true)
set whether or not to enable or disable DNS checkpoints
Definition: cryptonote_core.h:465
epee::critical_section m_incoming_tx_lock
incoming transaction lock
Definition: cryptonote_core.h:1067
std::atomic< bool > m_update_available
Definition: cryptonote_core.h:1090
epee::math_helper::once_a_time_seconds< 60 *60 *24 *7, false > m_diff_recalc_interval
interval for recalculating difficulties
Definition: cryptonote_core.h:1082
bool get_pool_for_rpc(std::vector< cryptonote::rpc::tx_in_pool > &tx_infos, cryptonote::rpc::key_images_with_tx_hashes &key_image_infos) const
get information about all transactions and key images in the pool
Definition: cryptonote_core.cpp:1681
bool get_pool_transaction_stats(struct txpool_stats &stats, bool include_sensitive_txes=false) const
get a list of all transactions in the pool
Definition: cryptonote_core.cpp:1660
bool find_blockchain_supplement(const std::list< crypto::hash > &qblock_ids, bool clip_pruned, NOTIFY_RESPONSE_CHAIN_ENTRY::request &resp) const
Definition: cryptonote_core.cpp:1404
void test_drop_download()
sets to drop blocks downloaded (for testing)
Definition: cryptonote_core.cpp:753
miner & get_miner()
gets the miner instance
Definition: cryptonote_core.h:251
bool handle_incoming_tx_accumulated_batch(std::vector< tx_verification_batch_info > &tx_info, bool keeped_by_block)
Definition: cryptonote_core.cpp:878
size_t m_last_update_length
Definition: cryptonote_core.h:1114
boost::mutex bad_semantics_txes_lock
Definition: cryptonote_core.h:1104
bool get_pool_transactions_and_spent_keys_info(std::vector< tx_info > &tx_infos, std::vector< spent_key_image_info > &key_image_infos, bool include_sensitive_txes=false) const
Definition: cryptonote_core.cpp:1676
bool get_txpool_complement(const std::vector< crypto::hash > &hashes, std::vector< cryptonote::blobdata > &txes)
returns the set of transactions in the txpool which are not in the argument
Definition: cryptonote_core.cpp:2001
std::unordered_set< crypto::hash > bad_semantics_txes[2]
Definition: cryptonote_core.h:1103
bool prune_blockchain(uint32_t pruning_seed=0)
prune the blockchain
Definition: cryptonote_core.cpp:2043
uint64_t get_earliest_ideal_height_for_version(uint8_t version) const
return the earliest block a given version may activate
Definition: cryptonote_core.cpp:1764
bool get_block_by_hash(const crypto::hash &h, block &blk, bool *orphan=NULL) const
gets the block with a given hash
Definition: cryptonote_core.cpp:1701
i_cryptonote_protocol * m_pprotocol
cryptonote protocol instance
Definition: cryptonote_core.h:1065
bool add_new_block(const block &b, block_verification_context &bvc)
adds a block to the blockchain
Definition: cryptonote_core.cpp:1528
cryptonote_protocol_stub m_protocol_stub
cryptonote protocol stub instance
Definition: cryptonote_core.h:1074
bool are_key_images_spent(const std::vector< crypto::key_image > &key_im, std::vector< bool > &spent) const
check if multiple key images are spent
Definition: cryptonote_core.cpp:1174
bool check_tx_inputs_keyimages_diff(const transaction &tx) const
verify that each input key image in a transaction is unique
Definition: cryptonote_core.cpp:1260
epee::math_helper::once_a_time_seconds< 60 *10, true > m_check_disk_space_interval
interval for checking for disk space
Definition: cryptonote_core.h:1079
boost::mutex m_update_mutex
Definition: cryptonote_core.h:1115
virtual bool get_block_template(block &b, const account_public_address &adr, difficulty_type &diffic, uint64_t &height, uint64_t &expected_reward, const blobdata &ex_nonce, uint64_t &seed_height, crypto::hash &seed_hash)
creates a new block to mine against
Definition: cryptonote_core.cpp:1394
bool handle_incoming_txs(const std::vector< tx_blob_entry > &tx_blobs, std::vector< tx_verification_context > &tvc, relay_method tx_relay, bool relayed)
handles a list of incoming transactions
Definition: cryptonote_core.h:162
bool get_txpool_backlog(std::vector< tx_backlog_entry > &backlog, bool include_sensitive_txes=false) const
Definition: cryptonote_core.cpp:440
const Blockchain & get_blockchain_storage() const
gets the Blockchain instance (const)
Definition: cryptonote_core.h:634
time_t start_time
Definition: cryptonote_core.h:1101
time_t m_last_dns_checkpoints_update
time when dns checkpoints were last updated
Definition: cryptonote_core.h:1093
enum cryptonote::core::@8 check_updates_level
bool init(const boost::program_options::variables_map &vm, const test_options *test_options=NULL, const GetCheckpointsCallback &get_checkpoints=nullptr)
initializes the core as needed
Definition: cryptonote_core.cpp:461
bool add_new_tx(transaction &tx, const crypto::hash &tx_hash, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context &tvc, relay_method tx_relay, bool relayed)
Definition: cryptonote_core.cpp:1314
bool relay_txpool_transactions()
attempts to relay any transactions in the mempool which need it
Definition: cryptonote_core.cpp:1332
std::pair< boost::multiprecision::uint128_t, boost::multiprecision::uint128_t > get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
get the sum of coinbase tx amounts between blocks
Definition: cryptonote_core.cpp:1232
bool check_tx_syntax(const transaction &tx) const
check a transaction's syntax
Definition: cryptonote_core.cpp:1643
bool check_tx_inputs_ring_members_diff(const transaction &tx) const
verify that each ring uses distinct members
Definition: cryptonote_core.cpp:1272
bool m_fluffy_blocks_enabled
Definition: cryptonote_core.h:1117
bool get_tx_outputs_gindexs(const crypto::hash &tx_id, std::vector< uint64_t > &indexs) const
gets the global indices for outputs from a given transaction
Definition: cryptonote_core.cpp:1424
Definition: miner.h:61
Definition: cryptonote_basic.h:194
Transaction pool, handles transactions which are not part of a block.
Definition: tx_pool.h:98
@ HAVE_BLOCK_MAIN_CHAIN
Definition: cryptonote_core.h:58
@ HAVE_BLOCK_INVALID
Definition: cryptonote_core.h:58
@ HAVE_BLOCK_ALT_CHAIN
Definition: cryptonote_core.h:58
PUSH_WARNINGS
Definition: hash-ops.h:53
Definition: base.py:1
int b
Definition: base.py:1
Definition: blocks.cpp:13
Definition: unordered_containers_boost_serialization.h:38
const
Definition: build_protob.py:9
crypto namespace.
Definition: crypto.cpp:60
POD_CLASS key_image
Definition: crypto.h:87
POD_CLASS hash
Definition: hash.h:48
std::unordered_map< crypto::key_image, std::vector< crypto::hash > > key_images_with_tx_hashes
Definition: message_data_structs.h:107
Holds cryptonote related classes and helpers.
Definition: blockchain_db.cpp:45
const command_line::arg_descriptor< bool > arg_sync_pruned_blocks
Definition: cryptonote_core.cpp:125
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
Definition: cryptonote_core.cpp:99
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:41
network_type
Definition: cryptonote_config.h:273
const command_line::arg_descriptor< bool > arg_regtest_on
Definition: cryptonote_core.cpp:84
const command_line::arg_descriptor< bool > arg_offline
Definition: cryptonote_core.cpp:112
relay_category
Definition: blockchain_db.h:110
relay_method
Methods tracking how a tx was received and relayed.
Definition: enums.h:37
const command_line::arg_descriptor< difficulty_type > arg_fixed_difficulty
Definition: cryptonote_core.cpp:94
const command_line::arg_descriptor< bool, false > arg_testnet_on
Definition: cryptonote_core.cpp:74
const command_line::arg_descriptor< bool, false > arg_stagenet_on
Definition: cryptonote_core.cpp:79
std::string blobdata
Definition: blobdatatype.h:39
const command_line::arg_descriptor< size_t > arg_block_download_max_size
Definition: cryptonote_core.cpp:120
std::function< const epee::span< const unsigned char >cryptonote::network_type network)> GetCheckpointsCallback
Callback routine that returns checkpoints data for specific network type.
Definition: blockchain.h:90
mdb_size_t count(MDB_cursor *cur)
Definition: value_stream.cpp:39
version
Supported socks variants.
Definition: socks.h:58
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:105
Definition: blockchain_ancestry.cpp:72
std::shared_ptr< download_thread_control > download_async_handle
Definition: download.h:35
#define false
Definition: stdbool.h:37
epee::misc_utils::struct_init< request_t > request
Definition: core_rpc_server_commands_defs.h:487
epee::misc_utils::struct_init< response_t > response
Definition: core_rpc_server_commands_defs.h:515
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:227
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:316
epee::misc_utils::struct_init< request_t > request
Definition: cryptonote_protocol_defs.h:246
Definition: cryptonote_basic.h:501
Definition: verification_context.h:59
Definition: cryptonote_basic.h:464
Definition: cryptonote_core.h:974
const cryptonote::transaction * tx
Definition: cryptonote_core.h:974
tx_verification_context & tvc
Definition: cryptonote_core.h:974
crypto::hash tx_hash
Definition: cryptonote_core.h:974
bool & result
Definition: cryptonote_core.h:974
Definition: connection_context.h:43
Definition: cryptonote_protocol_handler_common.h:53
Definition: i_core_events.h:38
Definition: cryptonote_protocol_handler_common.h:42
Definition: miner.h:48
Definition: cryptonote_core.h:62
const size_t long_term_block_weight_window
Definition: cryptonote_core.h:64
const std::pair< uint8_t, uint64_t > * hard_forks
Definition: cryptonote_core.h:63
Definition: cryptonote_protocol_defs.h:122
Definition: core_rpc_server_commands_defs.h:1344
Definition: verification_context.h:41
Definition: core_rpc_server_commands_defs.h:1502
DISABLE_VS_WARNINGS(4244 4345 4503) using namespace crypto