diff options
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 4 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 11 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 10 | ||||
-rw-r--r-- | src/cryptonote_core/tx_pool.cpp | 42 | ||||
-rw-r--r-- | src/cryptonote_core/tx_sanity_check.cpp | 16 | ||||
-rw-r--r-- | src/cryptonote_core/tx_sanity_check.h | 6 |
6 files changed, 27 insertions, 62 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index a8683a531..5578f519e 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3423,7 +3423,7 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const if (version >= HF_VERSION_PER_BYTE_FEE) { const bool use_long_term_median_in_fee = version >= HF_VERSION_LONG_TERM_BLOCK_WEIGHT; - uint64_t fee_per_byte = get_dynamic_base_fee(base_reward, use_long_term_median_in_fee ? m_long_term_effective_median_block_weight : median, version); + uint64_t fee_per_byte = get_dynamic_base_fee(base_reward, use_long_term_median_in_fee ? std::min<uint64_t>(median, m_long_term_effective_median_block_weight) : median, version); MDEBUG("Using " << print_money(fee_per_byte) << "/byte fee"); needed_fee = tx_weight * fee_per_byte; // quantize fee up to 8 decimals @@ -3481,7 +3481,7 @@ uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const uint64_t already_generated_coins = db_height ? m_db->get_block_already_generated_coins(db_height - 1) : 0; uint64_t base_reward; - if (!get_block_reward(median, 1, already_generated_coins, base_reward, version)) + if (!get_block_reward(m_current_block_cumul_weight_limit / 2, 1, already_generated_coins, base_reward, version)) { MERROR("Failed to determine block reward, using placeholder " << print_money(BLOCK_REWARD_OVERESTIMATE) << " as a high bound"); base_reward = BLOCK_REWARD_OVERESTIMATE; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index de60367e6..212616af8 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1056,17 +1056,6 @@ namespace cryptonote return handle_incoming_txs({std::addressof(tx_blob), 1}, {std::addressof(tvc), 1}, tx_relay, relayed); } //----------------------------------------------------------------------------------------------- - bool core::get_stat_info(core_stat_info& st_inf) const - { - st_inf.mining_speed = m_miner.get_speed(); - st_inf.alternative_blocks = m_blockchain_storage.get_alternative_blocks_count(); - st_inf.blockchain_height = m_blockchain_storage.get_current_blockchain_height(); - st_inf.tx_pool_size = m_mempool.get_transactions_count(); - st_inf.top_block_id_str = epee::string_tools::pod_to_hex(m_blockchain_storage.get_tail_id()); - return true; - } - - //----------------------------------------------------------------------------------------------- bool core::check_tx_semantic(const transaction& tx, bool keeped_by_block) const { if(!tx.vin.size()) diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 6fb2f68ab..79a846de1 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -45,7 +45,6 @@ #include "blockchain.h" #include "cryptonote_basic/miner.h" #include "cryptonote_basic/connection_context.h" -#include "cryptonote_basic/cryptonote_stat_info.h" #include "warnings.h" #include "crypto/hash.h" #include "span.h" @@ -556,15 +555,6 @@ namespace cryptonote 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_count) const; /** - * @brief gets some stats about the daemon - * - * @param st_inf return-by-reference container for the stats requested - * - * @return true - */ - bool get_stat_info(core_stat_info& st_inf) const; - - /** * @copydoc Blockchain::get_tx_outputs_gindexs * * @note see Blockchain::get_tx_outputs_gindexs diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 8c8e43c90..05cbf14a8 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -38,6 +38,7 @@ #include "cryptonote_basic/cryptonote_boost_serialization.h" #include "cryptonote_config.h" #include "blockchain.h" +#include "blockchain_db/locked_txn.h" #include "blockchain_db/blockchain_db.h" #include "common/boost_serialization_helper.h" #include "int-util.h" @@ -88,25 +89,6 @@ namespace cryptonote else return get_min_block_weight(version) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE; } - - // This class is meant to create a batch when none currently exists. - // If a batch exists, it can't be from another thread, since we can - // only be called with the txpool lock taken, and it is held during - // the whole prepare/handle/cleanup incoming block sequence. - class LockedTXN { - public: - LockedTXN(Blockchain &b): m_blockchain(b), m_batch(false), m_active(false) { - m_batch = m_blockchain.get_db().batch_start(); - m_active = true; - } - void commit() { try { if (m_batch && m_active) { m_blockchain.get_db().batch_stop(); m_active = false; } } catch (const std::exception &e) { MWARNING("LockedTXN::commit filtering exception: " << e.what()); } } - void abort() { try { if (m_batch && m_active) { m_blockchain.get_db().batch_abort(); m_active = false; } } catch (const std::exception &e) { MWARNING("LockedTXN::abort filtering exception: " << e.what()); } } - ~LockedTXN() { abort(); } - private: - Blockchain &m_blockchain; - bool m_batch; - bool m_active; - }; } //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- @@ -256,7 +238,7 @@ namespace cryptonote if (kept_by_block) m_parsed_tx_cache.insert(std::make_pair(id, tx)); CRITICAL_REGION_LOCAL1(m_blockchain); - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); if (!insert_key_images(tx, id, tx_relay)) return false; @@ -301,7 +283,7 @@ namespace cryptonote if (kept_by_block) m_parsed_tx_cache.insert(std::make_pair(id, tx)); CRITICAL_REGION_LOCAL1(m_blockchain); - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); m_blockchain.remove_txpool_tx(id); if (!insert_key_images(tx, id, tx_relay)) return false; @@ -362,7 +344,7 @@ namespace cryptonote if (bytes == 0) bytes = m_txpool_max_weight; CRITICAL_REGION_LOCAL1(m_blockchain); - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); bool changed = false; // this will never remove the first one, but we don't care @@ -494,7 +476,7 @@ namespace cryptonote try { - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); txpool_tx_meta_t meta; if (!m_blockchain.get_txpool_tx_meta(id, meta)) { @@ -549,7 +531,7 @@ namespace cryptonote try { - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); txpool_tx_meta_t meta; if (!m_blockchain.get_txpool_tx_meta(txid, meta)) { @@ -671,7 +653,7 @@ namespace cryptonote if (!remove.empty()) { - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); for (const std::pair<crypto::hash, uint64_t> &entry: remove) { const crypto::hash &txid = entry.first; @@ -742,7 +724,7 @@ namespace cryptonote CRITICAL_REGION_LOCAL(m_transactions_lock); CRITICAL_REGION_LOCAL1(m_blockchain); const time_t now = time(NULL); - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); for (const auto& hash : hashes) { try @@ -1219,7 +1201,7 @@ namespace cryptonote CRITICAL_REGION_LOCAL(m_transactions_lock); CRITICAL_REGION_LOCAL1(m_blockchain); bool changed = false; - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); for(size_t i = 0; i!= tx.vin.size(); i++) { CHECKED_GET_SPECIFIC_VARIANT(tx.vin[i], const txin_to_key, itk, void()); @@ -1311,7 +1293,7 @@ namespace cryptonote LOG_PRINT_L2("Filling block template, median weight " << median_weight << ", " << m_txs_by_fee_and_receive_time.size() << " txes in the pool"); - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); auto sorted_it = m_txs_by_fee_and_receive_time.begin(); for (; sorted_it != m_txs_by_fee_and_receive_time.end(); ++sorted_it) @@ -1448,7 +1430,7 @@ namespace cryptonote size_t n_removed = 0; if (!remove.empty()) { - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); for (const crypto::hash &txid: remove) { try @@ -1528,7 +1510,7 @@ namespace cryptonote } if (!remove.empty()) { - LockedTXN lock(m_blockchain); + LockedTXN lock(m_blockchain.get_db()); for (const auto &txid: remove) { try diff --git a/src/cryptonote_core/tx_sanity_check.cpp b/src/cryptonote_core/tx_sanity_check.cpp index 03cbb5c26..e99982def 100644 --- a/src/cryptonote_core/tx_sanity_check.cpp +++ b/src/cryptonote_core/tx_sanity_check.cpp @@ -28,7 +28,7 @@ #include <stdint.h> #include <vector> -#include "cryptonote_basic/cryptonote_basic_impl.h" +#include "cryptonote_basic/cryptonote_basic.h" #include "cryptonote_basic/cryptonote_format_utils.h" #include "blockchain.h" #include "tx_sanity_check.h" @@ -39,7 +39,7 @@ namespace cryptonote { -bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob) +bool tx_sanity_check(const cryptonote::blobdata &tx_blob, uint64_t rct_outs_available) { cryptonote::transaction tx; @@ -70,14 +70,18 @@ bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob n_indices += in_to_key.key_offsets.size(); } + return tx_sanity_check(rct_indices, n_indices, rct_outs_available); +} + +bool tx_sanity_check(const std::set<uint64_t> &rct_indices, size_t n_indices, uint64_t rct_outs_available) +{ if (n_indices <= 10) { MDEBUG("n_indices is only " << n_indices << ", not checking"); return true; } - uint64_t n_available = blockchain.get_num_mature_outputs(0); - if (n_available < 10000) + if (rct_outs_available < 10000) return true; if (rct_indices.size() < n_indices * 8 / 10) @@ -88,9 +92,9 @@ bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob std::vector<uint64_t> offsets(rct_indices.begin(), rct_indices.end()); uint64_t median = epee::misc_utils::median(offsets); - if (median < n_available * 6 / 10) + if (median < rct_outs_available * 6 / 10) { - MERROR("median offset index is too low (median is " << median << " out of total " << n_available << "offsets). Transactions should contain a higher fraction of recent outputs."); + MERROR("median offset index is too low (median is " << median << " out of total " << rct_outs_available << "offsets). Transactions should contain a higher fraction of recent outputs."); return false; } diff --git a/src/cryptonote_core/tx_sanity_check.h b/src/cryptonote_core/tx_sanity_check.h index c12d1b0b1..4a469462f 100644 --- a/src/cryptonote_core/tx_sanity_check.h +++ b/src/cryptonote_core/tx_sanity_check.h @@ -26,11 +26,11 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include <set> #include "cryptonote_basic/blobdatatype.h" namespace cryptonote { - class Blockchain; - - bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob); + bool tx_sanity_check(const cryptonote::blobdata &tx_blob, uint64_t rct_outs_available); + bool tx_sanity_check(const std::set<uint64_t> &rct_indices, size_t n_indices, uint64_t rct_outs_available); } |