From ad0241f25829c4c6c67bfeb751fdd2ad0ddcd9d1 Mon Sep 17 00:00:00 2001 From: Leny Kholodov Date: Sun, 10 Mar 2019 01:40:54 +0100 Subject: [PATCH] Use supernode aggregated stakes instead of stake transactions --- src/cryptonote_core/blockchain_based_list.cpp | 21 +- src/cryptonote_core/cryptonote_core.cpp | 9 +- src/cryptonote_core/cryptonote_core.h | 10 +- .../stake_transaction_processor.cpp | 106 +++------ .../stake_transaction_processor.h | 21 +- .../stake_transaction_storage.cpp | 205 +++++++++++++++++- .../stake_transaction_storage.h | 34 ++- src/p2p/net_node.h | 4 +- src/p2p/net_node.inl | 39 ++-- src/rpc/core_rpc_server.cpp | 11 +- src/rpc/core_rpc_server.h | 4 +- src/rpc/core_rpc_server_commands_defs.h | 12 +- 12 files changed, 335 insertions(+), 141 deletions(-) diff --git a/src/cryptonote_core/blockchain_based_list.cpp b/src/cryptonote_core/blockchain_based_list.cpp index d9b301d33..855e065a3 100644 --- a/src/cryptonote_core/blockchain_based_list.cpp +++ b/src/cryptonote_core/blockchain_based_list.cpp @@ -86,7 +86,7 @@ void BlockchainBasedList::apply_block(uint64_t block_height, const crypto::hash& if (block_height != m_block_height + 1) throw std::runtime_error("block_height should be next after the block already processed"); - const StakeTransactionStorage::stake_transaction_array& stake_txs = stake_txs_storage.get_txs(); + const StakeTransactionStorage::supernode_stake_array& stakes = stake_txs_storage.get_supernode_stakes(); //build blockchain based list for each tier @@ -107,22 +107,25 @@ void BlockchainBasedList::apply_block(uint64_t block_height, const crypto::hash& return !is_valid_stake(block_height, desc.block_height, desc.unlock_time); }), prev_supernodes.end()); - current_supernodes.reserve(stake_txs.size()); + current_supernodes.reserve(stakes.size()); - for (const stake_transaction& stake_tx : stake_txs) + for (const supernode_stake& stake : stakes) { - if (!is_valid_stake(block_height, stake_tx.block_height, stake_tx.unlock_time)) + if (!stake.amount) continue; - if (stake_tx.tier != i) + if (!is_valid_stake(block_height, stake.block_height, stake.unlock_time)) + continue; + + if (stake.tier != i) continue; supernode sn; - sn.supernode_public_id = stake_tx.supernode_public_id; - sn.supernode_public_address = stake_tx.supernode_public_address; - sn.block_height = stake_tx.block_height; - sn.unlock_time = stake_tx.unlock_time; + sn.supernode_public_id = stake.supernode_public_id; + sn.supernode_public_address = stake.supernode_public_address; + sn.block_height = stake.block_height; + sn.unlock_time = stake.unlock_time; current_supernodes.emplace_back(std::move(sn)); } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index ef7c4a140..2c6d01985 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -1096,14 +1096,14 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- - void core::set_update_stake_transactions_handler(const stake_transactions_update_handler& handler) + void core::set_update_stakes_handler(const supernode_stakes_update_handler& handler) { - m_graft_stake_transaction_processor.set_on_update_stake_transactions_handler(handler); + m_graft_stake_transaction_processor.set_on_update_stakes_handler(handler); } //----------------------------------------------------------------------------------------------- - void core::invoke_update_stake_transactions_handler() + void core::invoke_update_stakes_handler() { - m_graft_stake_transaction_processor.invoke_update_stake_transactions_handler(true); + m_graft_stake_transaction_processor.invoke_update_stakes_handler(true); } //----------------------------------------------------------------------------------------------- void core::set_update_blockchain_based_list_handler(const blockchain_based_list_update_handler& handler) @@ -1294,6 +1294,7 @@ namespace cryptonote m_check_updates_interval.do_call(boost::bind(&core::check_updates, this)); m_miner.on_idle(); m_mempool.on_idle(); + m_graft_stake_transaction_processor.synchronize(); return true; } //----------------------------------------------------------------------------------------------- diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 00c12ca29..ac3f7bb5e 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -737,16 +737,16 @@ namespace cryptonote bool fluffy_blocks_enabled() const { return m_fluffy_blocks_enabled; } /** - * @brief set update handler for new stake transactions + * @brief set update handler for supernode stakes */ - typedef StakeTransactionProcessor::stake_transactions_update_handler stake_transactions_update_handler; + typedef StakeTransactionProcessor::supernode_stakes_update_handler supernode_stakes_update_handler; - void set_update_stake_transactions_handler(const stake_transactions_update_handler&); + void set_update_stakes_handler(const supernode_stakes_update_handler&); /** - * @brief invoke stake transactions update handler + * @brief invoke stakes update handler */ - void invoke_update_stake_transactions_handler(); + void invoke_update_stakes_handler(); /** * @brief set update handler for new blockchain based list diff --git a/src/cryptonote_core/stake_transaction_processor.cpp b/src/cryptonote_core/stake_transaction_processor.cpp index a7f06545a..558892e67 100644 --- a/src/cryptonote_core/stake_transaction_processor.cpp +++ b/src/cryptonote_core/stake_transaction_processor.cpp @@ -8,17 +8,8 @@ using namespace cryptonote; namespace { -const char* STAKE_TRANSACTION_STORAGE_FILE_NAME = "stake_transactions.bin"; -const char* BLOCKCHAIN_BASED_LIST_FILE_NAME = "blockchain_based_list.v1.bin"; - -unsigned int get_tier(uint64_t stake) -{ - return 0 + - (stake >= config::graft::TIER1_STAKE_AMOUNT) + - (stake >= config::graft::TIER2_STAKE_AMOUNT) + - (stake >= config::graft::TIER3_STAKE_AMOUNT) + - (stake >= config::graft::TIER4_STAKE_AMOUNT); -} +const char* STAKE_TRANSACTION_STORAGE_FILE_NAME = "stake_transactions.v1.bin"; +const char* BLOCKCHAIN_BASED_LIST_FILE_NAME = "blockchain_based_list.v2.bin"; } @@ -30,7 +21,7 @@ bool stake_transaction::is_valid(uint64_t block_index) const if (block_index < stake_first_valid_block) return false; - if (block_index > stake_last_valid_block) + if (block_index >= stake_last_valid_block) return false; return true; @@ -38,11 +29,19 @@ bool stake_transaction::is_valid(uint64_t block_index) const StakeTransactionProcessor::StakeTransactionProcessor(Blockchain& blockchain) : m_blockchain(blockchain) - , m_stake_transactions_need_update(true) + , m_stakes_need_update(true) , m_blockchain_based_list_need_update(true) { } +const supernode_stake* StakeTransactionProcessor::find_supernode_stake(const std::string& supernode_public_id) const +{ + if (!m_storage) + return nullptr; + + return m_storage->find_supernode_stake(supernode_public_id); +} + namespace { @@ -129,6 +128,8 @@ void StakeTransactionProcessor::process_block_stake_transaction(uint64_t block_i BlockchainDB& db = m_blockchain.get_db(); + //analyze block transactions and add new stake transactions if exist + stake_transaction stake_tx; for (const crypto::hash& tx_hash : block.tx_hashes) @@ -187,38 +188,23 @@ void StakeTransactionProcessor::process_block_stake_transaction(uint64_t block_i stake_tx.block_height = block_index; stake_tx.hash = tx_hash; stake_tx.unlock_time = unlock_time; - stake_tx.tier = get_tier(stake_tx.amount); - - if (!stake_tx.tier) - { - MCLOG(el::Level::Warning, "global", "Ignore stake transaction at block #" << block_index << ", tx_hash=" << tx_hash << ", supernode_public_id '" << stake_tx.supernode_public_id << "'" - << " because amount " << amount / double(COIN) << " is less than minimum required " << config::graft::TIER1_STAKE_AMOUNT / double(COIN)); - continue; - } m_storage->add_tx(stake_tx); - m_stake_transactions_need_update = true; - MCLOG(el::Level::Info, "global", "New stake transaction found at block #" << block_index << ", tx_hash=" << tx_hash << ", supernode_public_id '" << stake_tx.supernode_public_id << "', amount=" << amount / double(COIN)); } - uint64_t prev_block = m_storage->get_last_processed_block_index(); + //remove obsolete stake transactions from a storage - const stake_transaction_array& stake_txs = m_storage->get_txs(); + m_storage->remove_obsolete_txs(block_index); - for (const stake_transaction& tx : stake_txs) - { - bool is_valid_for_this_block = tx.is_valid(block_index), - is_valid_for_prev_block = prev_block && tx.is_valid(prev_block); + //update supernode stakes - if (is_valid_for_prev_block != is_valid_for_this_block) - { - m_stake_transactions_need_update = true; - break; - } - } + if (m_storage->update_supernode_stakes(block_index)) + m_stakes_need_update = true; + + //update cache entries and save storage m_storage->add_last_processed_block(block_index, block_hash); @@ -277,7 +263,7 @@ void StakeTransactionProcessor::synchronize() m_storage->remove_last_processed_block(); if (stake_tx_count != m_storage->get_tx_count()) - m_stake_transactions_need_update = true; + m_storage->clear_supernode_stakes(); if (m_blockchain_based_list->block_height() == last_processed_block_index) m_blockchain_based_list->remove_latest_block(); @@ -320,8 +306,8 @@ void StakeTransactionProcessor::synchronize() if (m_storage->need_store()) m_storage->store(); - if (m_stake_transactions_need_update && m_on_stake_transactions_update) - invoke_update_stake_transactions_handler_impl(); + if (m_stakes_need_update && m_on_stakes_update) + invoke_update_stakes_handler_impl(); if (m_blockchain_based_list_need_update && m_on_blockchain_based_list_update) invoke_update_blockchain_based_list_handler_impl(height - first_block_index); @@ -330,45 +316,19 @@ void StakeTransactionProcessor::synchronize() MCLOG(el::Level::Info, "global", "Stake transactions sync OK"); } -void StakeTransactionProcessor::set_on_update_stake_transactions_handler(const stake_transactions_update_handler& handler) +void StakeTransactionProcessor::set_on_update_stakes_handler(const supernode_stakes_update_handler& handler) { CRITICAL_REGION_LOCAL1(m_storage_lock); - m_on_stake_transactions_update = handler; + m_on_stakes_update = handler; } -void StakeTransactionProcessor::invoke_update_stake_transactions_handler_impl() +void StakeTransactionProcessor::invoke_update_stakes_handler_impl() { try { - stake_transaction_array valid_stake_txs; - const stake_transaction_array& stake_txs = m_storage->get_txs(); - - valid_stake_txs.reserve(stake_txs.size()); - - uint64_t top_block_index = m_blockchain.get_db().height() - 1; - - for (const stake_transaction& tx : stake_txs) - { - stake_transaction tx_copy = tx; - - if (!tx_copy.is_valid(top_block_index)) - { - uint64_t first_history_block = top_block_index - config::graft::SUPERNODE_HISTORY_SIZE; - - if (tx_copy.block_height + tx_copy.unlock_time < first_history_block) - continue; - - //add stake transaction with zero amount to indicate correspondent node presense for search in supernode - - tx_copy.amount = 0; - } - - valid_stake_txs.emplace_back(std::move(tx_copy)); - } - - m_on_stake_transactions_update(valid_stake_txs); + m_on_stakes_update(m_storage->get_supernode_stakes()); - m_stake_transactions_need_update = false; + m_stakes_need_update = false; } catch (std::exception& e) { @@ -376,17 +336,17 @@ void StakeTransactionProcessor::invoke_update_stake_transactions_handler_impl() } } -void StakeTransactionProcessor::invoke_update_stake_transactions_handler(bool force) +void StakeTransactionProcessor::invoke_update_stakes_handler(bool force) { CRITICAL_REGION_LOCAL1(m_storage_lock); - if (!m_on_stake_transactions_update) + if (!m_on_stakes_update) return; - if (!m_stake_transactions_need_update && !force) + if (!m_stakes_need_update && !force) return; - invoke_update_stake_transactions_handler_impl(); + invoke_update_stakes_handler_impl(); } void StakeTransactionProcessor::set_on_update_blockchain_based_list_handler(const blockchain_based_list_update_handler& handler) diff --git a/src/cryptonote_core/stake_transaction_processor.h b/src/cryptonote_core/stake_transaction_processor.h index d0174abbe..2d26dad35 100644 --- a/src/cryptonote_core/stake_transaction_processor.h +++ b/src/cryptonote_core/stake_transaction_processor.h @@ -13,23 +13,26 @@ namespace cryptonote class StakeTransactionProcessor { public: - typedef StakeTransactionStorage::stake_transaction_array stake_transaction_array; + typedef StakeTransactionStorage::supernode_stake_array supernode_stake_array; StakeTransactionProcessor(Blockchain& blockchain); /// Initialize storages void init_storages(const std::string& config_dir); + /// Search supernode stake by supernode public id (returns nullptr if no stake is found) + const supernode_stake* find_supernode_stake(const std::string& supernode_public_id) const; + /// Synchronize with blockchain void synchronize(); - typedef std::function stake_transactions_update_handler; + typedef std::function supernode_stakes_update_handler; - /// Update handler for new stake transactions - void set_on_update_stake_transactions_handler(const stake_transactions_update_handler&); + /// Update handler for new stakes + void set_on_update_stakes_handler(const supernode_stakes_update_handler&); - /// Force invoke update handler for stake transactions - void invoke_update_stake_transactions_handler(bool force = true); + /// Force invoke update handler for stakes + void invoke_update_stakes_handler(bool force = true); typedef BlockchainBasedList::supernode_tier_array supernode_tier_array; typedef std::function blockchain_based_list_update_handler; @@ -42,7 +45,7 @@ class StakeTransactionProcessor private: void process_block(uint64_t block_index, const block& block, const crypto::hash& block_hash, bool update_storage = true); - void invoke_update_stake_transactions_handler_impl(); + void invoke_update_stakes_handler_impl(); void invoke_update_blockchain_based_list_handler_impl(size_t depth); void process_block_stake_transaction(uint64_t block_index, const block& block, const crypto::hash& block_hash, bool update_storage = true); void process_block_blockchain_based_list(uint64_t block_index, const block& block, const crypto::hash& block_hash, bool update_storage = true); @@ -52,9 +55,9 @@ class StakeTransactionProcessor std::unique_ptr m_storage; std::unique_ptr m_blockchain_based_list; epee::critical_section m_storage_lock; - stake_transactions_update_handler m_on_stake_transactions_update; + supernode_stakes_update_handler m_on_stakes_update; blockchain_based_list_update_handler m_on_blockchain_based_list_update; - bool m_stake_transactions_need_update; + bool m_stakes_need_update; bool m_blockchain_based_list_need_update; }; diff --git a/src/cryptonote_core/stake_transaction_storage.cpp b/src/cryptonote_core/stake_transaction_storage.cpp index f8d228d18..e1b649789 100644 --- a/src/cryptonote_core/stake_transaction_storage.cpp +++ b/src/cryptonote_core/stake_transaction_storage.cpp @@ -2,13 +2,15 @@ #include "file_io_utils.h" #include "serialization/binary_utils.h" #include "cryptonote_basic/account_boost_serialization.h" +#include "../graft_rta_config.h" using namespace cryptonote; namespace { -const uint64_t BLOCK_HASHES_HISTORY_DEPTH = 1000; +const uint64_t BLOCK_HASHES_HISTORY_DEPTH = 1000; +const uint64_t STAKE_TRANSACTIONS_HISTORY_DEPTH = BLOCK_HASHES_HISTORY_DEPTH + config::graft::STAKE_VALIDATION_PERIOD + config::graft::TRUSTED_RESTAKING_PERIOD; struct stake_transaction_file_data { @@ -41,6 +43,7 @@ StakeTransactionStorage::StakeTransactionStorage(const std::string& storage_file , m_last_processed_block_index() , m_last_processed_block_hashes_count() , m_need_store() + , m_supernode_stakes_update_block_number() { load(); } @@ -104,7 +107,205 @@ void StakeTransactionStorage::remove_last_processed_block() m_stake_txs.clear(); m_last_processed_block_index = 0; - } + } +} + +void StakeTransactionStorage::remove_obsolete_txs(uint64_t block_number) +{ + if (block_number < STAKE_TRANSACTIONS_HISTORY_DEPTH) + return; + + stake_transaction_array::iterator it = std::remove_if(m_stake_txs.begin(), m_stake_txs.end(), [&](const stake_transaction& tx) { + return tx.block_height + tx.unlock_time < block_number - STAKE_TRANSACTIONS_HISTORY_DEPTH; + }); + + if (it == m_stake_txs.end()) + return; + + m_need_store = true; + + m_stake_txs.erase(it, m_stake_txs.end()); +} + +void StakeTransactionStorage::clear_supernode_stakes() +{ + m_supernode_stakes.clear(); + m_supernode_stake_indexes.clear(); + + m_supernode_stakes_update_block_number = 0; +} + +namespace +{ + +unsigned int get_tier(uint64_t stake) +{ + return 0 + + (stake >= config::graft::TIER1_STAKE_AMOUNT) + + (stake >= config::graft::TIER2_STAKE_AMOUNT) + + (stake >= config::graft::TIER3_STAKE_AMOUNT) + + (stake >= config::graft::TIER4_STAKE_AMOUNT); +} + +} + +bool StakeTransactionStorage::update_supernode_stakes(uint64_t block_number) +{ + if (block_number == m_supernode_stakes_update_block_number) + return false; + + if (m_supernode_stakes_update_block_number) + { + bool updated = false; + + if (m_stake_txs.empty() && !m_supernode_stakes.empty()) + updated = true; + + for (const stake_transaction& tx : m_stake_txs) + { + //compare validity of transaction between this and previous updates + + bool is_valid_for_this_block = tx.is_valid(block_number), + is_valid_for_prev_block = tx.is_valid(m_supernode_stakes_update_block_number); + + if (is_valid_for_prev_block != is_valid_for_this_block) + { + updated = true; + break; + } + } + + if (!updated) + return false; + } + + //because transactions validity has changed, update all stakes + + m_supernode_stakes.clear(); + m_supernode_stake_indexes.clear(); + + try + { + m_supernode_stakes.reserve(m_stake_txs.size()); + + for (const stake_transaction& tx : m_stake_txs) + { + bool obsolete_stake = false; + + if (!tx.is_valid(block_number)) + { + uint64_t first_history_block = block_number - config::graft::SUPERNODE_HISTORY_SIZE; + + if (tx.block_height + tx.unlock_time < first_history_block) + continue; + + //add stake transaction with zero amount to indicate correspondent node presense for search in supernode + + obsolete_stake = true; + } + + //search for a stake of the corresponding supernode + + supernode_stake_index_map::iterator it = m_supernode_stake_indexes.find(tx.supernode_public_id); + + if (it == m_supernode_stake_indexes.end()) + { + //add new supernode stake + + supernode_stake new_stake; + + if (obsolete_stake) + { + new_stake.amount = 0; + new_stake.tier = 0; + new_stake.block_height = 0; + new_stake.unlock_time = 0; + } + else + { + new_stake.amount = tx.amount; + new_stake.tier = get_tier(new_stake.amount); + new_stake.block_height = tx.block_height; + new_stake.unlock_time = tx.unlock_time; + } + + new_stake.supernode_public_id = tx.supernode_public_id; + new_stake.supernode_public_address = tx.supernode_public_address; + + m_supernode_stakes.emplace_back(std::move(new_stake)); + + m_supernode_stake_indexes[tx.supernode_public_id] = m_supernode_stakes.size() - 1; + + continue; + } + + //update existing supernode's stake + + if (obsolete_stake) + continue; //no need to aggregate fields from obsolete stake + + supernode_stake& stake = m_supernode_stakes[it->second]; + + if (!stake.amount) + { + //set fields for supernode which has been constructed for obsolete stake + + stake.amount = tx.amount; + stake.tier = get_tier(stake.amount); + stake.block_height = tx.block_height; + stake.unlock_time = tx.unlock_time; + + continue; + } + + //aggregate fields for existing stake + + stake.amount += tx.amount; + stake.tier = get_tier(stake.amount); + + //find intersection of stake transaction intervals + + uint64_t min_block_height = stake.block_height, + max_block_height = min_block_height + stake.unlock_time, + min_tx_block_height = tx.block_height, + max_tx_block_height = min_tx_block_height + tx.unlock_time; + + if (min_tx_block_height > min_block_height) + min_block_height = min_tx_block_height; + + if (max_tx_block_height < max_block_height) + max_block_height = max_tx_block_height; + + if (max_block_height <= min_block_height) + max_block_height = min_block_height; + + stake.block_height = min_block_height; + stake.unlock_time = max_block_height - min_block_height; + } + } + catch (...) + { + m_supernode_stakes.clear(); + m_supernode_stake_indexes.clear(); + + m_supernode_stakes_update_block_number = 0; + + throw; + } + + m_supernode_stakes_update_block_number = block_number; + + return true; +} + +const supernode_stake* StakeTransactionStorage::find_supernode_stake(const std::string& supernode_public_id) const +{ + supernode_stake_index_map::const_iterator it = m_supernode_stake_indexes.find(supernode_public_id); + + if (it == m_supernode_stake_indexes.end()) + return nullptr; + + return &m_supernode_stakes[it->second]; } void StakeTransactionStorage::load() diff --git a/src/cryptonote_core/stake_transaction_storage.h b/src/cryptonote_core/stake_transaction_storage.h index 2f48133b3..ddecc6480 100644 --- a/src/cryptonote_core/stake_transaction_storage.h +++ b/src/cryptonote_core/stake_transaction_storage.h @@ -2,6 +2,7 @@ #include #include +#include #include "crypto/hash.h" #include "cryptonote_basic/cryptonote_basic.h" @@ -14,7 +15,6 @@ struct stake_transaction { crypto::hash hash; uint64_t amount; - unsigned int tier; //based from index 0 uint64_t block_height; uint64_t unlock_time; std::string supernode_public_id; @@ -27,7 +27,6 @@ struct stake_transaction BEGIN_SERIALIZE_OBJECT() FIELD(amount) FIELD(hash) - FIELD(tier) FIELD(block_height) FIELD(unlock_time) FIELD(supernode_public_id) @@ -37,11 +36,22 @@ struct stake_transaction END_SERIALIZE() }; +struct supernode_stake +{ + uint64_t amount; + unsigned int tier; //based from index 0 + uint64_t block_height; + uint64_t unlock_time; + std::string supernode_public_id; + cryptonote::account_public_address supernode_public_address; +}; + class StakeTransactionStorage { public: typedef std::vector stake_transaction_array; typedef std::list block_hash_list; + typedef std::vector supernode_stake_array; StakeTransactionStorage(const std::string& storage_file_name); @@ -66,6 +76,21 @@ class StakeTransactionStorage /// Add transaction void add_tx(const stake_transaction&); + /// Remove obsolete stake transactions + void remove_obsolete_txs(uint64_t block_number); + + /// List of supernode stakes + const supernode_stake_array& get_supernode_stakes() const { return m_supernode_stakes; } + + /// Search supernode stake by supernode public id (returns nullptr if no stake is found) + const supernode_stake* find_supernode_stake(const std::string& supernode_public_id) const; + + /// Update supernode stakes (returns true if stakes have been updated, false if the result is same) + bool update_supernode_stakes(uint64_t block_number); + + /// Clear supernode stakes + void clear_supernode_stakes(); + /// Save storage to file void store() const; @@ -76,12 +101,17 @@ class StakeTransactionStorage /// Load storage from file void load(); + typedef std::unordered_map supernode_stake_index_map; + private: std::string m_storage_file_name; uint64_t m_last_processed_block_index; block_hash_list m_last_processed_block_hashes; size_t m_last_processed_block_hashes_count; stake_transaction_array m_stake_txs; + uint64_t m_supernode_stakes_update_block_number; + supernode_stake_array m_supernode_stakes; + supernode_stake_index_map m_supernode_stake_indexes; mutable bool m_need_store; }; diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index d47ed3c32..fcee41cd8 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -405,7 +405,7 @@ namespace nodetool bool notify_peer_list(int command, const std::string& buf, const std::vector& peers_to_send, bool try_connect = false); - void send_stake_transactions_to_supernode(); + void send_stakes_to_supernode(); void send_blockchain_based_list_to_supernode(uint64_t last_received_block_height); uint64_t get_announce_bytes_in() const { return m_announce_bytes_in; } @@ -416,7 +416,7 @@ namespace nodetool uint64_t get_multicast_bytes_out() const { return m_multicast_bytes_out; } private: - void handle_stake_transactions_update(const cryptonote::StakeTransactionProcessor::stake_transaction_array& stake_txs); + void handle_stakes_update(const cryptonote::StakeTransactionProcessor::supernode_stake_array& stakes); void handle_blockchain_based_list_update(uint64_t block_number, const cryptonote::StakeTransactionProcessor::supernode_tier_array& tiers); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 0cf5faec8..839e0df53 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -528,8 +528,8 @@ namespace nodetool template bool node_server::init(const boost::program_options::variables_map& vm) { - m_payload_handler.get_core().set_update_stake_transactions_handler( - [&](const cryptonote::StakeTransactionProcessor::stake_transaction_array& stake_txs) { handle_stake_transactions_update(stake_txs); } + m_payload_handler.get_core().set_update_stakes_handler( + [&](const cryptonote::StakeTransactionProcessor::supernode_stake_array& stakes) { handle_stakes_update(stakes); } ); m_payload_handler.get_core().set_update_blockchain_based_list_handler( @@ -2933,43 +2933,42 @@ namespace nodetool } template - void node_server::handle_stake_transactions_update(const cryptonote::StakeTransactionProcessor::stake_transaction_array& stake_txs) + void node_server::handle_stakes_update(const cryptonote::StakeTransactionProcessor::supernode_stake_array& stakes) { - static std::string supernode_endpoint("send_supernode_stake_txs"); + static std::string supernode_endpoint("send_supernode_stakes"); boost::lock_guard guard(m_supernode_lock); if (!m_have_supernode) return; - LOG_PRINT_L0("handle_stake_transactions_update to supernode"); + LOG_PRINT_L0("handle_stakes_update to supernode"); - cryptonote::COMMAND_RPC_SUPERNODE_STAKE_TRANSACTIONS::request request; + cryptonote::COMMAND_RPC_SUPERNODE_STAKES::request request; - request.stake_txs.reserve(stake_txs.size()); + request.stakes.reserve(stakes.size()); - for (const cryptonote::stake_transaction& src_tx : stake_txs) + for (const cryptonote::supernode_stake& src_stake : stakes) { - cryptonote::COMMAND_RPC_SUPERNODE_STAKE_TRANSACTIONS::stake_transaction dst_tx; + cryptonote::COMMAND_RPC_SUPERNODE_STAKES::supernode_stake dst_stake; - dst_tx.hash = epee::string_tools::pod_to_hex(src_tx.hash); - dst_tx.amount = src_tx.amount; - dst_tx.tier = src_tx.tier; - dst_tx.block_height = src_tx.block_height; - dst_tx.unlock_time = src_tx.unlock_time; - dst_tx.supernode_public_id = src_tx.supernode_public_id; - dst_tx.supernode_public_address = cryptonote::get_account_address_as_str(m_testnet, src_tx.supernode_public_address); + dst_stake.amount = src_stake.amount; + dst_stake.tier = src_stake.tier; + dst_stake.block_height = src_stake.block_height; + dst_stake.unlock_time = src_stake.unlock_time; + dst_stake.supernode_public_id = src_stake.supernode_public_id; + dst_stake.supernode_public_address = cryptonote::get_account_address_as_str(m_testnet, src_stake.supernode_public_address); - request.stake_txs.emplace_back(std::move(dst_tx)); + request.stakes.emplace_back(std::move(dst_stake)); } - post_request_to_supernode(supernode_endpoint, request); + post_request_to_supernode(supernode_endpoint, request); } template - void node_server::send_stake_transactions_to_supernode() + void node_server::send_stakes_to_supernode() { - m_payload_handler.get_core().invoke_update_stake_transactions_handler(); + m_payload_handler.get_core().invoke_update_stakes_handler(); } template diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 83355bf73..00ac7e27d 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1778,9 +1778,9 @@ namespace cryptonote } //------------------------------------------------------------------------------------------------------------------------------ - bool core_rpc_server::on_supernode_stake_txs(const COMMAND_RPC_SUPERNODE_GET_STAKE_TRANSACTIONS::request &req, COMMAND_RPC_SUPERNODE_GET_STAKE_TRANSACTIONS::response &res, json_rpc::error &error_resp) + bool core_rpc_server::on_supernode_stakes(const COMMAND_RPC_SUPERNODE_GET_STAKES::request &req, COMMAND_RPC_SUPERNODE_GET_STAKES::response &res, json_rpc::error &error_resp) { - LOG_PRINT_L0("RPC Request: on_supernode_stake_txs: start"); + LOG_PRINT_L0("RPC Request: on_supernode_stakes: start"); if (!check_core_busy()) { error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; @@ -1788,12 +1788,11 @@ namespace cryptonote return false; } - - // send p2p stake txs + // send p2p stakes m_p2p.set_supernode(req.supernode_public_id, req.network_address); - m_p2p.send_stake_transactions_to_supernode(); + m_p2p.send_stakes_to_supernode(); res.status = 0; - LOG_PRINT_L0("RPC Request: on_supernode_stake_txs: end"); + LOG_PRINT_L0("RPC Request: on_supernode_stakes: end"); return true; } diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index c2155bc2f..bab5bcf9e 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -135,7 +135,7 @@ namespace cryptonote MAP_JON_RPC_WE("unicast", on_unicast, COMMAND_RPC_UNICAST) MAP_JON_RPC_WE("get_tunnels", on_get_tunnels, COMMAND_RPC_TUNNEL_DATA) - MAP_JON_RPC_WE("send_supernode_stake_txs", on_supernode_stake_txs, COMMAND_RPC_SUPERNODE_GET_STAKE_TRANSACTIONS) + MAP_JON_RPC_WE("send_supernode_stakes", on_supernode_stakes, COMMAND_RPC_SUPERNODE_GET_STAKES) MAP_JON_RPC_WE("send_supernode_blockchain_based_list", on_supernode_blockchain_based_list, COMMAND_RPC_SUPERNODE_GET_BLOCKCHAIN_BASED_LIST) MAP_JON_RPC_WE("get_stats", on_get_rta_stats, COMMAND_RPC_RTA_STATS) END_JSON_RPC_MAP() @@ -199,7 +199,7 @@ namespace cryptonote //----------------------- // RTA bool on_supernode_announce(const COMMAND_RPC_SUPERNODE_ANNOUNCE::request& req, COMMAND_RPC_SUPERNODE_ANNOUNCE::response& res, epee::json_rpc::error& error_resp); - bool on_supernode_stake_txs(const COMMAND_RPC_SUPERNODE_GET_STAKE_TRANSACTIONS::request& req, COMMAND_RPC_SUPERNODE_GET_STAKE_TRANSACTIONS::response& res, epee::json_rpc::error& error_resp); + bool on_supernode_stakes(const COMMAND_RPC_SUPERNODE_GET_STAKES::request& req, COMMAND_RPC_SUPERNODE_GET_STAKES::response& res, epee::json_rpc::error& error_resp); bool on_supernode_blockchain_based_list(const COMMAND_RPC_SUPERNODE_GET_BLOCKCHAIN_BASED_LIST::request& req, COMMAND_RPC_SUPERNODE_GET_BLOCKCHAIN_BASED_LIST::response& res, epee::json_rpc::error& error_resp); bool on_broadcast(const COMMAND_RPC_BROADCAST::request &req, COMMAND_RPC_BROADCAST::response &res, epee::json_rpc::error &error_resp); bool on_multicast(const COMMAND_RPC_MULTICAST::request &req, COMMAND_RPC_MULTICAST::response &res, epee::json_rpc::error &error_resp); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 5d8b40044..9f1e574ae 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -1705,7 +1705,7 @@ namespace cryptonote }; //---------- Graft RTA commands --------------------- - struct COMMAND_RPC_SUPERNODE_GET_STAKE_TRANSACTIONS + struct COMMAND_RPC_SUPERNODE_GET_STAKES { struct request { @@ -1726,11 +1726,10 @@ namespace cryptonote }; }; - struct COMMAND_RPC_SUPERNODE_STAKE_TRANSACTIONS + struct COMMAND_RPC_SUPERNODE_STAKES { - struct stake_transaction + struct supernode_stake { - std::string hash; uint64_t amount; unsigned int tier; uint64_t block_height; @@ -1738,7 +1737,6 @@ namespace cryptonote std::string supernode_public_id; std::string supernode_public_address; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(hash) KV_SERIALIZE(amount) KV_SERIALIZE(tier) KV_SERIALIZE(block_height) @@ -1750,9 +1748,9 @@ namespace cryptonote struct request { - std::vector stake_txs; + std::vector stakes; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(stake_txs) + KV_SERIALIZE(stakes) END_KV_SERIALIZE_MAP() };