aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp11
-rw-r--r--src/cryptonote_core/blockchain.h5
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp29
-rw-r--r--src/cryptonote_core/cryptonote_core.h26
-rw-r--r--src/cryptonote_core/tx_pool.cpp75
-rw-r--r--src/cryptonote_core/tx_pool.h5
-rw-r--r--src/cryptonote_core/tx_sanity_check.cpp16
-rw-r--r--src/cryptonote_core/tx_sanity_check.h6
8 files changed, 106 insertions, 67 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 78893fdf2..5578f519e 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -2541,6 +2541,13 @@ bool Blockchain::add_block_as_invalid(const block_extended_info& bei, const cryp
return true;
}
//------------------------------------------------------------------
+void Blockchain::flush_invalid_blocks()
+{
+ LOG_PRINT_L3("Blockchain::" << __func__);
+ CRITICAL_REGION_LOCAL(m_blockchain_lock);
+ m_invalid_blocks.clear();
+}
+//------------------------------------------------------------------
bool Blockchain::have_block(const crypto::hash& id) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
@@ -3416,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
@@ -3474,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/blockchain.h b/src/cryptonote_core/blockchain.h
index 0aecdcb57..4ed7a2f02 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -1017,6 +1017,11 @@ namespace cryptonote
*/
bool has_block_weights(uint64_t height, uint64_t nblocks) const;
+ /**
+ * @brief flush the invalid blocks set
+ */
+ void flush_invalid_blocks();
+
#ifndef IN_UNIT_TESTS
private:
#endif
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 5c8f59291..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())
@@ -1175,10 +1164,10 @@ namespace cryptonote
return m_mempool.check_for_key_images(key_im, spent);
}
//-----------------------------------------------------------------------------------------------
- std::pair<uint64_t, uint64_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
+ std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
{
- uint64_t emission_amount = 0;
- uint64_t total_fee_amount = 0;
+ boost::multiprecision::uint128_t emission_amount = 0;
+ boost::multiprecision::uint128_t total_fee_amount = 0;
if (count)
{
const uint64_t end = start_offset + count - 1;
@@ -1200,7 +1189,7 @@ namespace cryptonote
});
}
- return std::pair<uint64_t, uint64_t>(emission_amount, total_fee_amount);
+ return std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t>(emission_amount, total_fee_amount);
}
//-----------------------------------------------------------------------------------------------
bool core::check_tx_inputs_keyimages_diff(const transaction& tx) const
@@ -1942,6 +1931,16 @@ namespace cryptonote
bad_semantics_txes_lock.unlock();
}
//-----------------------------------------------------------------------------------------------
+ void core::flush_invalid_blocks()
+ {
+ m_blockchain_storage.flush_invalid_blocks();
+ }
+ //-----------------------------------------------------------------------------------------------
+ bool core::get_txpool_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes)
+ {
+ return m_mempool.get_complement(hashes, txes);
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::update_blockchain_pruning()
{
return m_blockchain_storage.update_blockchain_pruning();
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 55efb566c..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
@@ -765,7 +755,7 @@ namespace cryptonote
*
* @return the number of blocks to sync in one go
*/
- std::pair<uint64_t, uint64_t> get_coinbase_tx_sum(const uint64_t start_offset, const size_t count);
+ std::pair<boost::multiprecision::uint128_t, boost::multiprecision::uint128_t> get_coinbase_tx_sum(const uint64_t start_offset, const size_t count);
/**
* @brief get the network type we're on
@@ -859,6 +849,20 @@ namespace cryptonote
*/
void flush_bad_txs_cache();
+ /**
+ * @brief flushes the invalid block cache
+ */
+ void flush_invalid_blocks();
+
+ /**
+ * @brief returns the set of transactions in the txpool which are not in the argument
+ *
+ * @param hashes hashes of transactions to exclude from the result
+ *
+ * @return true iff success, false otherwise
+ */
+ bool get_txpool_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes);
+
private:
/**
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 13320e69f..53a6ce579 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))
{
@@ -594,6 +576,39 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------------------------
+ bool tx_memory_pool::get_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes) const
+ {
+ CRITICAL_REGION_LOCAL(m_transactions_lock);
+ CRITICAL_REGION_LOCAL1(m_blockchain);
+
+ m_blockchain.for_all_txpool_txes([this, &hashes, &txes](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata*) {
+ const auto relay_method = meta.get_relay_method();
+ if (relay_method != relay_method::block && relay_method != relay_method::fluff)
+ return true;
+ const auto i = std::find(hashes.begin(), hashes.end(), txid);
+ if (i == hashes.end())
+ {
+ cryptonote::blobdata bd;
+ try
+ {
+ if (!m_blockchain.get_txpool_tx_blob(txid, bd, cryptonote::relay_category::broadcasted))
+ {
+ MERROR("Failed to get blob for txpool transaction " << txid);
+ return true;
+ }
+ txes.emplace_back(std::move(bd));
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to get blob for txpool transaction " << txid << ": " << e.what());
+ return true;
+ }
+ }
+ return true;
+ }, false);
+ return true;
+ }
+ //---------------------------------------------------------------------------------
void tx_memory_pool::on_idle()
{
m_remove_stuck_tx_interval.do_call([this](){return remove_stuck_transactions();});
@@ -638,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;
@@ -709,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
@@ -1186,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());
@@ -1282,7 +1297,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)
@@ -1419,7 +1434,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
@@ -1499,7 +1514,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_pool.h b/src/cryptonote_core/tx_pool.h
index f716440ad..ca0e50415 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -441,6 +441,11 @@ namespace cryptonote
*/
bool get_transaction_info(const crypto::hash &txid, tx_details &td) const;
+ /**
+ * @brief get transactions not in the passed set
+ */
+ bool get_complement(const std::vector<crypto::hash> &hashes, std::vector<cryptonote::blobdata> &txes) const;
+
private:
/**
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);
}