aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/cryptonote_core.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-05-30 21:12:44 +0200
committerRiccardo Spagni <ric@spagni.net>2017-05-30 21:12:44 +0200
commit545e2b003c6a4930e9f18e6d5696c2cd85a5cb22 (patch)
tree3c156bab193a4d1c01ef20a2764b4439f01e3699 /src/cryptonote_core/cryptonote_core.cpp
parent694470fae705edb06bbfaae9ce327a052adba84d (diff)
parentb52abd1370cc21484d64f45504adbab47240debf (diff)
downloadmonzero-core-545e2b003c6a4930e9f18e6d5696c2cd85a5cb22.tar.gz
monzero-core-545e2b003c6a4930e9f18e6d5696c2cd85a5cb22.tar.xz
monzero-core-545e2b003c6a4930e9f18e6d5696c2cd85a5cb22.zip
Merge pull request #1982
b52abd13 Move txpool to the database (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core/cryptonote_core.cpp')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 9c122f511..1cd285522 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -272,9 +272,6 @@ namespace cryptonote
m_config_folder_mempool = m_config_folder_mempool + "/" + m_port;
}
- r = m_mempool.init(m_fakechain ? std::string() : m_config_folder_mempool);
- CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
-
std::string db_type = command_line::get_arg(vm, command_line::arg_db_type);
std::string db_sync_mode = command_line::get_arg(vm, command_line::arg_db_sync_mode);
bool fast_sync = command_line::get_arg(vm, command_line::arg_fast_block_sync) != 0;
@@ -401,6 +398,9 @@ namespace cryptonote
r = m_blockchain_storage.init(db, m_testnet, test_options);
+ r = m_mempool.init();
+ CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
+
// now that we have a valid m_blockchain_storage, we can clean out any
// transactions in the pool that do not conform to the current fork
m_mempool.validate(m_blockchain_storage.get_current_hard_fork_version());
@@ -760,7 +760,7 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
- bool core::add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::add_new_tx(transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
crypto::hash tx_hash = get_transaction_hash(tx);
crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx);
@@ -774,7 +774,7 @@ namespace cryptonote
return m_blockchain_storage.get_total_transactions();
}
//-----------------------------------------------------------------------------------------------
- bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
if(m_mempool.have_tx(tx_hash))
{
@@ -795,17 +795,15 @@ namespace cryptonote
bool core::relay_txpool_transactions()
{
// we attempt to relay txes that should be relayed, but were not
- std::list<std::pair<crypto::hash, cryptonote::transaction>> txs;
+ std::list<std::pair<crypto::hash, cryptonote::blobdata>> txs;
if (m_mempool.get_relayable_transactions(txs) && !txs.empty())
{
cryptonote_connection_context fake_context = AUTO_VAL_INIT(fake_context);
tx_verification_context tvc = AUTO_VAL_INIT(tvc);
NOTIFY_NEW_TRANSACTIONS::request r;
- blobdata bl;
for (auto it = txs.begin(); it != txs.end(); ++it)
{
- t_serializable_object_to_blob(it->second, bl);
- r.txs.push_back(bl);
+ r.txs.push_back(it->second);
}
get_protocol()->relay_transactions(r, fake_context);
m_mempool.set_relayed(txs);
@@ -815,7 +813,7 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
void core::on_transaction_relayed(const cryptonote::blobdata& tx_blob)
{
- std::list<std::pair<crypto::hash, cryptonote::transaction>> txs;
+ std::list<std::pair<crypto::hash, cryptonote::blobdata>> txs;
cryptonote::transaction tx;
crypto::hash tx_hash, tx_prefix_hash;
if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash))
@@ -823,7 +821,7 @@ namespace cryptonote
LOG_ERROR("Failed to parse relayed transaction");
return;
}
- txs.push_back(std::make_pair(tx_hash, std::move(tx)));
+ txs.push_back(std::make_pair(tx_hash, std::move(tx_blob)));
m_mempool.set_relayed(txs);
}
//-----------------------------------------------------------------------------------------------
@@ -893,9 +891,9 @@ namespace cryptonote
bce.block = cryptonote::block_to_blob(b);
for (const auto &tx_hash: b.tx_hashes)
{
- cryptonote::transaction tx;
- CHECK_AND_ASSERT_THROW_MES(pool.get_transaction(tx_hash, tx), "Transaction not found in pool");
- bce.txs.push_back(cryptonote::tx_to_blob(tx));
+ cryptonote::blobdata txblob;
+ CHECK_AND_ASSERT_THROW_MES(pool.get_transaction(tx_hash, txblob), "Transaction not found in pool");
+ bce.txs.push_back(txblob);
}
return bce;
}
@@ -955,6 +953,7 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool core::prepare_handle_incoming_blocks(const std::list<block_complete_entry> &blocks)
{
+ m_incoming_tx_lock.lock();
m_blockchain_storage.prepare_handle_incoming_blocks(blocks);
return true;
}
@@ -962,7 +961,11 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------
bool core::cleanup_handle_incoming_blocks(bool force_sync)
{
- m_blockchain_storage.cleanup_handle_incoming_blocks(force_sync);
+ try {
+ m_blockchain_storage.cleanup_handle_incoming_blocks(force_sync);
+ }
+ catch (...) {}
+ m_incoming_tx_lock.unlock();
return true;
}
@@ -1043,11 +1046,16 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
- bool core::get_pool_transaction(const crypto::hash &id, transaction& tx) const
+ bool core::get_pool_transaction(const crypto::hash &id, cryptonote::blobdata& tx) const
{
return m_mempool.get_transaction(id, tx);
}
//-----------------------------------------------------------------------------------------------
+ bool core::pool_has_tx(const crypto::hash &id) const
+ {
+ return m_mempool.have_tx(id);
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::get_pool_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos) const
{
return m_mempool.get_transactions_and_spent_keys_info(tx_infos, key_image_infos);