mirror of
https://github.com/oxen-io/oxen-core.git
synced 2023-12-14 02:22:56 +01:00
Expose accessor for service_node_list in core/blockchain
This adds direct access to the service node list via core/blockchain so that it doesn't have to be passes around as reference in quite so many places.
This commit is contained in:
parent
cd06b3c5f1
commit
2dffb730b4
|
@ -654,7 +654,7 @@ block Blockchain::pop_block_from_blockchain()
|
|||
// that might not be always true. Unlikely though, and always relaying
|
||||
// these again might cause a spike of traffic as many nodes re-relay
|
||||
// all the transactions in a popped block when a reorg happens.
|
||||
bool r = m_tx_pool.add_tx(tx, tvc, true, true, false, version, m_service_node_list);
|
||||
bool r = m_tx_pool.add_tx(tx, tvc, true, true, false, version);
|
||||
if (!r)
|
||||
{
|
||||
LOG_ERROR("Error returning transaction to tx_pool");
|
||||
|
@ -3594,7 +3594,7 @@ void Blockchain::return_tx_to_pool(std::vector<std::pair<transaction, blobdata>>
|
|||
// all the transactions in a popped block when a reorg happens.
|
||||
const size_t weight = get_transaction_weight(tx.first, tx.second.size());
|
||||
const crypto::hash tx_hash = get_transaction_hash(tx.first);
|
||||
if (!m_tx_pool.add_tx(tx.first, tx_hash, tx.second, weight, tvc, true, true, false, version, m_service_node_list))
|
||||
if (!m_tx_pool.add_tx(tx.first, tx_hash, tx.second, weight, tvc, true, true, false, version))
|
||||
{
|
||||
MERROR("Failed to return taken transaction with hash: " << get_transaction_hash(tx.first) << " to tx_pool");
|
||||
}
|
||||
|
@ -4022,7 +4022,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
|
|||
bvc.m_added_to_main_chain = true;
|
||||
++m_sync_counter;
|
||||
|
||||
m_tx_pool.on_blockchain_inc(m_service_node_list, bl);
|
||||
m_tx_pool.on_blockchain_inc(bl);
|
||||
get_difficulty_for_next_block(); // just to cache it
|
||||
invalidate_block_template_cache();
|
||||
|
||||
|
|
|
@ -933,6 +933,11 @@ namespace cryptonote
|
|||
return *m_db;
|
||||
}
|
||||
|
||||
/// @brief return a reference to the service node list
|
||||
const service_nodes::service_node_list &get_service_node_list() const { return m_service_node_list; }
|
||||
/// @brief return a reference to the service node list
|
||||
service_nodes::service_node_list &get_service_node_list() { return m_service_node_list; }
|
||||
|
||||
/**
|
||||
* @brief get a number of outputs of a specific amount
|
||||
*
|
||||
|
|
|
@ -1464,7 +1464,7 @@ namespace cryptonote
|
|||
}
|
||||
|
||||
uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
|
||||
return m_mempool.add_tx(tx, tx_hash, blob, tx_weight, tvc, keeped_by_block, relayed, do_not_relay, version, m_service_node_list);
|
||||
return m_mempool.add_tx(tx, tx_hash, blob, tx_weight, tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::relay_txpool_transactions()
|
||||
|
|
|
@ -605,6 +605,11 @@ namespace cryptonote
|
|||
*/
|
||||
const Blockchain& get_blockchain_storage()const{return m_blockchain_storage;}
|
||||
|
||||
/// @brief return a reference to the service node list
|
||||
const service_nodes::service_node_list &get_service_node_list() const { return m_service_node_list; }
|
||||
/// @brief return a reference to the service node list
|
||||
service_nodes::service_node_list &get_service_node_list() { return m_service_node_list; }
|
||||
|
||||
/**
|
||||
* @copydoc tx_memory_pool::print_pool
|
||||
*
|
||||
|
|
|
@ -310,6 +310,10 @@ namespace service_nodes
|
|||
{
|
||||
public:
|
||||
explicit service_node_list(cryptonote::Blockchain& blockchain);
|
||||
// non-copyable:
|
||||
service_node_list(const service_node_list &) = delete;
|
||||
service_node_list &operator=(const service_node_list &) = delete;
|
||||
|
||||
bool block_added(const cryptonote::block& block, const std::vector<cryptonote::transaction>& txs, cryptonote::checkpoint_t const *checkpoint) override;
|
||||
void blockchain_detached(uint64_t height, bool by_pop_blocks) override;
|
||||
void init() override;
|
||||
|
|
|
@ -120,11 +120,12 @@ namespace cryptonote
|
|||
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::have_duplicated_non_standard_tx(transaction const &tx, uint8_t hard_fork_version, service_nodes::service_node_list const &service_node_list) const
|
||||
bool tx_memory_pool::have_duplicated_non_standard_tx(transaction const &tx, uint8_t hard_fork_version) const
|
||||
{
|
||||
if (tx.type == txtype::standard)
|
||||
return false;
|
||||
|
||||
auto &service_node_list = m_blockchain.get_service_node_list();
|
||||
if (tx.type == txtype::state_change)
|
||||
{
|
||||
tx_extra_service_node_state_change state_change;
|
||||
|
@ -223,7 +224,7 @@ namespace cryptonote
|
|||
return false;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::add_tx(transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version, const service_nodes::service_node_list &service_node_list)
|
||||
bool tx_memory_pool::add_tx(transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version)
|
||||
{
|
||||
// this should already be called with that lock, but let's make it explicit for clarity
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
|
@ -291,7 +292,7 @@ namespace cryptonote
|
|||
tvc.m_double_spend = true;
|
||||
return false;
|
||||
}
|
||||
if (have_duplicated_non_standard_tx(tx, version, service_node_list))
|
||||
if (have_duplicated_non_standard_tx(tx, version))
|
||||
{
|
||||
mark_double_spend(tx);
|
||||
LOG_PRINT_L1("Transaction with id= "<< id << " already has a duplicate tx for height");
|
||||
|
@ -336,7 +337,7 @@ namespace cryptonote
|
|||
meta.last_relayed_time = time(NULL);
|
||||
meta.relayed = relayed;
|
||||
meta.do_not_relay = do_not_relay;
|
||||
meta.double_spend_seen = (have_tx_keyimges_as_spent(tx) || have_duplicated_non_standard_tx(tx, version, service_node_list));
|
||||
meta.double_spend_seen = (have_tx_keyimges_as_spent(tx) || have_duplicated_non_standard_tx(tx, version));
|
||||
meta.bf_padding = 0;
|
||||
memset(meta.padding, 0, sizeof(meta.padding));
|
||||
try
|
||||
|
@ -418,7 +419,7 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::add_tx(transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay, uint8_t version, service_nodes::service_node_list const &service_node_list)
|
||||
bool tx_memory_pool::add_tx(transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay, uint8_t version)
|
||||
{
|
||||
crypto::hash h = null_hash;
|
||||
size_t blob_size = 0;
|
||||
|
@ -426,7 +427,7 @@ namespace cryptonote
|
|||
t_serializable_object_to_blob(tx, bl);
|
||||
if (bl.size() == 0 || !get_transaction_hash(tx, h))
|
||||
return false;
|
||||
return add_tx(tx, h, bl, get_transaction_weight(tx, bl.size()), tvc, keeped_by_block, relayed, do_not_relay, version, service_node_list);
|
||||
return add_tx(tx, h, bl, get_transaction_weight(tx, bl.size()), tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
size_t tx_memory_pool::get_txpool_weight() const
|
||||
|
@ -1092,7 +1093,7 @@ namespace cryptonote
|
|||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::on_blockchain_inc(service_nodes::service_node_list const &service_node_list, block const &blk)
|
||||
bool tx_memory_pool::on_blockchain_inc(block const &blk)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
m_input_cache.clear();
|
||||
|
@ -1110,6 +1111,7 @@ namespace cryptonote
|
|||
// Otherwise multiple state changes can queue up until they are applicable
|
||||
// and be applied on the node.
|
||||
uint64_t const block_height = cryptonote::get_block_height(blk);
|
||||
auto &service_node_list = m_blockchain.get_service_node_list();
|
||||
for (transaction const &pool_tx : pool_txs)
|
||||
{
|
||||
tx_extra_service_node_state_change state_change;
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace cryptonote
|
|||
* @param id the transaction's hash
|
||||
* @param tx_weight the transaction's weight
|
||||
*/
|
||||
bool add_tx(transaction &tx, const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version, const service_nodes::service_node_list &service_node_list);
|
||||
bool add_tx(transaction &tx, const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
|
||||
|
||||
/**
|
||||
* @brief add a transaction to the transaction pool
|
||||
|
@ -128,7 +128,7 @@ namespace cryptonote
|
|||
*
|
||||
* @return true if the transaction passes validations, otherwise false
|
||||
*/
|
||||
bool add_tx(transaction &tx, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version, service_nodes::service_node_list const &service_node_list);
|
||||
bool add_tx(transaction &tx, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
|
||||
|
||||
/**
|
||||
* @brief takes a transaction with the given hash from the pool
|
||||
|
@ -163,7 +163,7 @@ namespace cryptonote
|
|||
*
|
||||
* @return true
|
||||
*/
|
||||
bool on_blockchain_inc(service_nodes::service_node_list const &service_node_list, block const &blk);
|
||||
bool on_blockchain_inc(block const &blk);
|
||||
|
||||
/**
|
||||
* @brief action to take when notified of a block removed from the blockchain
|
||||
|
@ -461,7 +461,7 @@ namespace cryptonote
|
|||
* @return true if it already exists
|
||||
*
|
||||
*/
|
||||
bool have_duplicated_non_standard_tx(transaction const &tx, uint8_t hard_fork_version, service_nodes::service_node_list const &node_list) const;
|
||||
bool have_duplicated_non_standard_tx(transaction const &tx, uint8_t hard_fork_version) const;
|
||||
|
||||
/**
|
||||
* @brief check if any spent key image in a transaction is in the pool
|
||||
|
|
Loading…
Reference in a new issue