Monero
Loading...
Searching...
No Matches
core_proxy.h
Go to the documentation of this file.
1// Copyright (c) 2014-2022, 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 <boost/program_options/variables_map.hpp>
34
38#include <unordered_map>
39
40namespace tests
41{
42 struct block_index {
43 size_t height;
48 std::list<cryptonote::transaction> txes;
49
50 block_index() : height(0), id(crypto::null_hash), longhash(crypto::null_hash) { }
51 block_index(size_t _height, const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob, const std::list<cryptonote::transaction> &_txes)
52 : height(_height), id(_id), longhash(_longhash), blk(_blk), blob(_blob), txes(_txes) { }
53 };
54
56 {
58 std::list<crypto::hash> m_known_block_list;
59 std::unordered_map<crypto::hash, block_index> m_hash2blkidx;
60
62 std::list<cryptonote::transaction> txes;
63
64 bool add_block(const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob);
65 void build_short_history(std::list<crypto::hash> &m_history, const crypto::hash &m_start);
66
67
68 public:
69 virtual bool is_synchronized() const final { return true; }
71 void safesyncmode(const bool){}
72 virtual uint64_t get_current_blockchain_height() const final {return 1;}
74 bool init(const boost::program_options::variables_map& vm);
75 bool deinit(){return true;}
76 bool get_short_chain_history(std::list<crypto::hash>& ids);
77 bool have_block(const crypto::hash& id, int *where = NULL);
78 bool have_block_unlocked(const crypto::hash& id, int *where = NULL);
79 void get_blockchain_top(uint64_t& height, crypto::hash& top_id);
81 bool handle_incoming_txs(const std::vector<cryptonote::tx_blob_entry>& tx_blobs, std::vector<cryptonote::tx_verification_context>& tvc, cryptonote::relay_method tx_relay, bool relayed);
82 bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true);
83 void pause_mine(){}
84 void resume_mine(){}
85 bool on_idle(){return true;}
86 bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, bool clip_pruned, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp){return true;}
88 cryptonote::Blockchain &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class proxy_core."); }
89 bool get_test_drop_download() {return true;}
90 bool get_test_drop_download_height() {return true;}
91 bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks_entry, std::vector<cryptonote::block> &blocks) { return true; }
92 bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; }
93 bool update_checkpoints(const bool skip_dns = false) { return true; }
98 bool get_pool_transaction(const crypto::hash& id, cryptonote::blobdata& tx_blob, cryptonote::relay_category tx_category) const { return false; }
99 bool pool_has_tx(const crypto::hash &txid) const { return false; }
100 bool get_blocks(uint64_t start_offset, size_t count, std::vector<std::pair<cryptonote::blobdata, cryptonote::block>>& blocks, std::vector<cryptonote::blobdata>& txs) const { return false; }
101 bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::vector<cryptonote::transaction>& txs, std::vector<crypto::hash>& missed_txs) const { return false; }
102 bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan = NULL) const { return false; }
104 uint8_t get_ideal_hard_fork_version(uint64_t height) const { return 0; }
105 uint8_t get_hard_fork_version(uint64_t height) const { return 0; }
108 bool fluffy_blocks_enabled() const { return false; }
109 uint64_t prevalidate_block_hashes(uint64_t height, const std::vector<crypto::hash> &hashes, const std::vector<uint64_t> &weights) { return 0; }
110 bool has_block_weights(uint64_t height, uint64_t nblocks) const { return false; }
111 bool is_within_compiled_block_hash_area(uint64_t height) const { return false; }
112 bool pad_transactions() const { return false; }
114 bool prune_blockchain(uint32_t pruning_seed) const { return true; }
115 bool get_txpool_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes) { return false; }
116 bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs, bool include_unrelayed_txes = true) const { return false; }
118 };
119}
static uint64_t h
Definition: blockchain_stats.cpp:55
Definition: blockchain.h:100
Non-owning sequence of data. Does not deep copy.
Definition: span.h:55
Definition: core_proxy.h:56
void set_target_blockchain_height(uint64_t)
Definition: core_proxy.h:73
bool has_block_weights(uint64_t height, uint64_t nblocks) const
Definition: core_proxy.h:110
bool get_transactions(const std::vector< crypto::hash > &txs_ids, std::vector< cryptonote::transaction > &txs, std::vector< crypto::hash > &missed_txs) const
Definition: core_proxy.h:101
bool fluffy_blocks_enabled() const
Definition: core_proxy.h:108
bool handle_incoming_tx(const cryptonote::tx_blob_entry &tx_blob, cryptonote::tx_verification_context &tvc, cryptonote::relay_method tx_relay, bool relayed)
Definition: core_proxy.cpp:162
bool get_test_drop_download_height()
Definition: core_proxy.h:90
uint8_t get_ideal_hard_fork_version(uint64_t height) const
Definition: core_proxy.h:104
uint8_t get_hard_fork_version(uint64_t height) const
Definition: core_proxy.h:105
bool get_block_by_hash(const crypto::hash &h, cryptonote::block &blk, bool *orphan=NULL) const
Definition: core_proxy.h:102
bool prepare_handle_incoming_blocks(const std::vector< cryptonote::block_complete_entry > &blocks_entry, std::vector< cryptonote::block > &blocks)
Definition: core_proxy.h:91
bool cleanup_handle_incoming_blocks(bool force_sync=false)
Definition: core_proxy.h:92
bool get_txpool_complement(const std::vector< crypto::hash > &hashes, std::vector< cryptonote::blobdata > &txes)
Definition: core_proxy.h:115
bool handle_incoming_txs(const std::vector< cryptonote::tx_blob_entry > &tx_blobs, std::vector< cryptonote::tx_verification_context > &tvc, cryptonote::relay_method tx_relay, bool relayed)
Definition: core_proxy.cpp:192
virtual void on_transactions_relayed(epee::span< const cryptonote::blobdata > tx_blobs, cryptonote::relay_method tx_relay)
Definition: core_proxy.h:96
virtual uint64_t get_current_blockchain_height() const final
Definition: core_proxy.h:72
std::unordered_map< crypto::hash, block_index > m_hash2blkidx
Definition: core_proxy.h:59
void build_short_history(std::list< crypto::hash > &m_history, const crypto::hash &m_start)
Definition: core_proxy.cpp:259
void get_blockchain_top(uint64_t &height, crypto::hash &top_id)
Definition: core_proxy.cpp:236
void on_synchronized()
Definition: core_proxy.h:70
bool handle_get_objects(cryptonote::NOTIFY_REQUEST_GET_OBJECTS::request &arg, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request &rsp, cryptonote::cryptonote_connection_context &context)
Definition: core_proxy.h:87
bool get_blocks(uint64_t start_offset, size_t count, std::vector< std::pair< cryptonote::blobdata, cryptonote::block > > &blocks, std::vector< cryptonote::blobdata > &txs) const
Definition: core_proxy.h:100
std::list< cryptonote::transaction > txes
Definition: core_proxy.h:62
bool get_pool_transaction(const crypto::hash &id, cryptonote::blobdata &tx_blob, cryptonote::relay_category tx_category) const
Definition: core_proxy.h:98
cryptonote::network_type get_nettype() const
Definition: core_proxy.h:97
std::list< crypto::hash > m_known_block_list
Definition: core_proxy.h:58
size_t get_block_sync_size(uint64_t height) const
Definition: core_proxy.h:95
void resume_mine()
Definition: core_proxy.h:84
uint64_t prevalidate_block_hashes(uint64_t height, const std::vector< crypto::hash > &hashes, const std::vector< uint64_t > &weights)
Definition: core_proxy.h:109
bool pool_has_tx(const crypto::hash &txid) const
Definition: core_proxy.h:99
bool handle_incoming_block(const cryptonote::blobdata &block_blob, const cryptonote::block *block, cryptonote::block_verification_context &bvc, bool update_miner_blocktemplate=true)
Definition: core_proxy.cpp:205
cryptonote::difficulty_type get_block_cumulative_difficulty(uint64_t height) const
Definition: core_proxy.h:107
bool add_block(const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob)
Definition: core_proxy.cpp:274
bool get_test_drop_download()
Definition: core_proxy.h:89
bool find_blockchain_supplement(const std::list< crypto::hash > &qblock_ids, bool clip_pruned, cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request &resp)
Definition: core_proxy.h:86
crypto::hash get_block_id_by_height(uint64_t height) const
Definition: core_proxy.h:117
bool deinit()
Definition: core_proxy.h:75
bool get_short_chain_history(std::list< crypto::hash > &ids)
Definition: core_proxy.cpp:231
cryptonote::Blockchain & get_blockchain_storage()
Definition: core_proxy.h:88
uint64_t get_target_blockchain_height() const
Definition: core_proxy.h:94
uint8_t get_ideal_hard_fork_version() const
Definition: core_proxy.h:103
crypto::hash m_lastblk
Definition: core_proxy.h:61
uint64_t get_earliest_ideal_height_for_version(uint8_t version) const
Definition: core_proxy.h:106
bool is_within_compiled_block_hash_area(uint64_t height) const
Definition: core_proxy.h:111
bool have_block_unlocked(const crypto::hash &id, int *where=NULL)
Definition: core_proxy.cpp:248
cryptonote::block m_genesis
Definition: core_proxy.h:57
bool pad_transactions() const
Definition: core_proxy.h:112
bool update_checkpoints(const bool skip_dns=false)
Definition: core_proxy.h:93
virtual bool is_synchronized() const final
Definition: core_proxy.h:69
bool have_block(const crypto::hash &id, int *where=NULL)
Definition: core_proxy.cpp:255
void safesyncmode(const bool)
Definition: core_proxy.h:71
void pause_mine()
Definition: core_proxy.h:83
bool get_pool_transaction_hashes(std::vector< crypto::hash > &txs, bool include_unrelayed_txes=true) const
Definition: core_proxy.h:116
bool prune_blockchain(uint32_t pruning_seed) const
Definition: core_proxy.h:114
uint32_t get_blockchain_pruning_seed() const
Definition: core_proxy.h:113
bool on_idle()
Definition: core_proxy.h:85
#define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT
Definition: cryptonote_config.h:98
int * count
Definition: gmock_stress_test.cc:176
#define const
Definition: ipfrdr.c:80
relay_method tx_relay
Definition: levin_notify.cpp:545
static void init()
Definition: logging.cpp:38
static int version
Definition: mdb_load.c:29
Definition: blocks.cpp:13
crypto namespace.
Definition: crypto.cpp:60
static constexpr crypto::hash null_hash
Definition: hash.h:92
POD_CLASS hash
Definition: hash.h:48
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:41
network_type
Definition: cryptonote_config.h:289
@ MAINNET
Definition: cryptonote_config.h:290
relay_category
Definition: blockchain_db.h:110
relay_method
Methods tracking how a tx was received and relayed.
Definition: enums.h:37
std::string blobdata
Definition: blobdatatype.h:39
Definition: core_proxy.h:41
unsigned int uint32_t
Definition: stdint.h:126
unsigned char uint8_t
Definition: stdint.h:124
unsigned __int64 uint64_t
Definition: stdint.h:136
Definition: argon2_core.h:74
Definition: verification_context.h:59
Definition: cryptonote_basic.h:475
Definition: connection_context.h:43
Definition: i_core_events.h:38
Definition: cryptonote_protocol_defs.h:122
Definition: verification_context.h:41
Definition: misc_language.h:104
Definition: core_proxy.h:42
block_index()
Definition: core_proxy.h:50
crypto::hash id
Definition: core_proxy.h:44
crypto::hash longhash
Definition: core_proxy.h:45
cryptonote::blobdata blob
Definition: core_proxy.h:47
cryptonote::block blk
Definition: core_proxy.h:46
std::list< cryptonote::transaction > txes
Definition: core_proxy.h:48
block_index(size_t _height, const crypto::hash &_id, const crypto::hash &_longhash, const cryptonote::block &_blk, const cryptonote::blobdata &_blob, const std::list< cryptonote::transaction > &_txes)
Definition: core_proxy.h:51
size_t height
Definition: core_proxy.h:43
struct hash_func hashes[]
randomx_vm * vm
Definition: tests.cpp:20