diff options
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/account.cpp | 16 | ||||
-rw-r--r-- | src/cryptonote_core/account.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/checkpoints_create.h | 1 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 13 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 1 | ||||
-rw-r--r-- | src/cryptonote_core/tx_pool.cpp | 26 | ||||
-rw-r--r-- | src/cryptonote_core/tx_pool.h | 8 |
7 files changed, 62 insertions, 5 deletions
diff --git a/src/cryptonote_core/account.cpp b/src/cryptonote_core/account.cpp index ba39b9b77..3bedd7404 100644 --- a/src/cryptonote_core/account.cpp +++ b/src/cryptonote_core/account.cpp @@ -10,6 +10,10 @@ #include "account.h" #include "warnings.h" #include "crypto/crypto.h" +extern "C" +{ +#include "crypto/keccak.h" +} #include "cryptonote_core/cryptonote_basic_impl.h" #include "cryptonote_core/cryptonote_format_utils.h" using namespace std; @@ -29,11 +33,17 @@ DISABLE_VS_WARNINGS(4244 4345) m_keys = account_keys(); } //----------------------------------------------------------------- - void account_base::generate() + crypto::secret_key account_base::generate(const crypto::secret_key& recovery_key, bool recover, bool two_random) { - generate_keys(m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key); - generate_keys(m_keys.m_account_address.m_view_public_key, m_keys.m_view_secret_key); + crypto::secret_key first = generate_keys(m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key, recovery_key, recover); + + // rng for generating second set of keys is hash of first rng. means only one set of electrum-style words needed for recovery + crypto::secret_key second; + keccak((uint8_t *)&first, sizeof(crypto::secret_key), (uint8_t *)&second, sizeof(crypto::secret_key)); + + generate_keys(m_keys.m_account_address.m_view_public_key, m_keys.m_view_secret_key, second, two_random ? false : true); m_creation_timestamp = time(NULL); + return first; } //----------------------------------------------------------------- const account_keys& account_base::get_keys() const diff --git a/src/cryptonote_core/account.h b/src/cryptonote_core/account.h index 8b525da97..cb77d7c4e 100644 --- a/src/cryptonote_core/account.h +++ b/src/cryptonote_core/account.h @@ -31,7 +31,7 @@ namespace cryptonote { public: account_base(); - void generate(); + crypto::secret_key generate(const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false, bool two_random = false); const account_keys& get_keys() const; std::string get_public_address_str(); diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 3ecbbf0b6..a92fefd3f 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -15,6 +15,7 @@ namespace cryptonote { ADD_CHECKPOINT(22231, "7cb10e29d67e1c069e6e11b17d30b809724255fee2f6868dc14cfc6ed44dfb25"); ADD_CHECKPOINT(29556, "53c484a8ed91e4da621bb2fa88106dbde426fe90d7ef07b9c1e5127fb6f3a7f6"); ADD_CHECKPOINT(50000, "0fe8758ab06a8b9cb35b7328fd4f757af530a5d37759f9d3e421023231f7b31c"); + ADD_CHECKPOINT(80000, "a62dcd7b536f22e003ebae8726e9e7276f63d594e264b6f0cd7aab27b66e75e3"); return true; } } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index b2389fce2..2609fc13e 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -432,6 +432,18 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- + // Used by the RPC server to check the size of an incoming + // block_blob + bool core::check_incoming_block_size(const blobdata& block_blob) + { + if(block_blob.size() > get_max_block_size()) + { + LOG_PRINT_L0("WRONG BLOCK BLOB, too big size " << block_blob.size() << ", rejected"); + return false; + } + return true; + } + //----------------------------------------------------------------------------------------------- crypto::hash core::get_tail_id() { return m_blockchain_storage.get_tail_id(); @@ -514,6 +526,7 @@ namespace cryptonote m_store_blockchain_interval.do_call(boost::bind(&blockchain_storage::store_blockchain, &m_blockchain_storage)); m_miner.on_idle(); + m_mempool.on_idle(); return true; } //----------------------------------------------------------------------------------------------- diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 7ef0f8b1d..1f1b6eec6 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -34,6 +34,7 @@ namespace cryptonote bool on_idle(); bool handle_incoming_tx(const blobdata& tx_blob, tx_verification_context& tvc, bool keeped_by_block); bool handle_incoming_block(const blobdata& block_blob, block_verification_context& bvc, bool update_miner_blocktemplate = true); + bool check_incoming_block_size(const blobdata& block_blob); i_cryptonote_protocol* get_protocol(){return m_pprotocol;} //-------------------- i_miner_handler ----------------------- diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 4c4c6aea1..ce1bc1ad2 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -83,6 +83,7 @@ namespace cryptonote txd_p.first->second.max_used_block_id = null_hash; txd_p.first->second.max_used_block_height = 0; txd_p.first->second.kept_by_block = kept_by_block; + txd_p.first->second.receive_time = time(nullptr); tvc.m_verifivation_impossible = true; tvc.m_added_to_pool = true; }else @@ -104,6 +105,7 @@ namespace cryptonote txd_p.first->second.max_used_block_height = max_used_block_height; txd_p.first->second.last_failed_height = 0; txd_p.first->second.last_failed_id = null_hash; + txd_p.first->second.receive_time = time(nullptr); tvc.m_added_to_pool = true; if(txd_p.first->second.fee > 0) @@ -178,6 +180,30 @@ namespace cryptonote return true; } //--------------------------------------------------------------------------------- + void tx_memory_pool::on_idle() + { + m_remove_stuck_tx_interval.do_call([this](){return remove_stuck_transactions();}); + } + //--------------------------------------------------------------------------------- + //proper tx_pool handling courtesy of CryptoZoidberg and Boolberry + bool tx_memory_pool::remove_stuck_transactions() + { + CRITICAL_REGION_LOCAL(m_transactions_lock); + for(auto it = m_transactions.begin(); it!= m_transactions.end();) + { + uint64_t tx_age = time(nullptr) - it->second.receive_time; + + if((tx_age > CRYPTONOTE_MEMPOOL_TX_LIVETIME && !it->second.kept_by_block) || + (tx_age > CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME && it->second.kept_by_block) ) + { + LOG_PRINT_L0("Tx " << it->first << " removed from tx pool due to outdated, age: " << tx_age ); + m_transactions.erase(it++); + }else + ++it; + } + return true; + } + //--------------------------------------------------------------------------------- size_t tx_memory_pool::get_transactions_count() { CRITICAL_REGION_LOCAL(m_transactions_lock); diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index 26d273aa7..649af41a3 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -13,6 +13,7 @@ #include "string_tools.h" #include "syncobj.h" +#include "math_helper.h" #include "cryptonote_basic_impl.h" #include "verification_context.h" #include "crypto/hash.h" @@ -40,6 +41,7 @@ namespace cryptonote bool on_blockchain_inc(uint64_t new_block_height, const crypto::hash& top_block_id); bool on_blockchain_dec(uint64_t new_block_height, const crypto::hash& top_block_id); + void on_idle(); void lock(); void unlock(); @@ -59,7 +61,7 @@ namespace cryptonote /*bool flush_pool(const std::strig& folder); bool inflate_pool(const std::strig& folder);*/ -#define CURRENT_MEMPOOL_ARCHIVE_VER 7 +#define CURRENT_MEMPOOL_ARCHIVE_VER 8 template<class archive_t> void serialize(archive_t & a, const unsigned int version) @@ -82,9 +84,11 @@ namespace cryptonote // uint64_t last_failed_height; crypto::hash last_failed_id; + time_t receive_time; }; private: + bool remove_stuck_transactions(); bool is_transaction_ready_to_go(tx_details& txd); typedef std::unordered_map<crypto::hash, tx_details > transactions_container; typedef std::unordered_map<crypto::key_image, std::unordered_set<crypto::hash> > key_images_container; @@ -92,6 +96,7 @@ namespace cryptonote epee::critical_section m_transactions_lock; transactions_container m_transactions; key_images_container m_spent_key_images; + epee::math_helper::once_a_time_seconds<30> m_remove_stuck_tx_interval; //transactions_container m_alternative_transactions; @@ -159,6 +164,7 @@ namespace boost ar & td.max_used_block_id; ar & td.last_failed_height; ar & td.last_failed_id; + ar & td.receive_time; } } |