diff options
| author | tobtoht <tob@featherwallet.org> | 2025-03-10 16:20:00 +0000 |
|---|---|---|
| committer | tobtoht <tob@featherwallet.org> | 2025-03-10 16:20:00 +0000 |
| commit | 3da68db9789697d30dc309df2f1da5d348bc4ce2 (patch) | |
| tree | 68c98fab9146797007ab778cdb4a609e1e41f43c /src/cryptonote_core/blockchain.h | |
| parent | 0232839913b13cf0ab0bb7ad25fff0c05f37d2fe (diff) | |
| parent | 008ba966da88f073f226b299533faca905ceabf8 (diff) | |
| download | monzero-core-3da68db9789697d30dc309df2f1da5d348bc4ce2.tar.gz monzero-core-3da68db9789697d30dc309df2f1da5d348bc4ce2.tar.xz monzero-core-3da68db9789697d30dc309df2f1da5d348bc4ce2.zip | |
Merge pull request #9740
008ba966d blockchain sync: reduce disk writes from 2 to 1 per tx (jeffro256)
Diffstat (limited to 'src/cryptonote_core/blockchain.h')
| -rw-r--r-- | src/cryptonote_core/blockchain.h | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index fa0f6ce51..f16bc7415 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -92,6 +92,7 @@ namespace cryptonote */ typedef std::function<const epee::span<const unsigned char>(cryptonote::network_type network)> GetCheckpointsCallback; + typedef boost::function<void(std::vector<txpool_event>)> TxpoolNotifyCallback; typedef boost::function<void(uint64_t /* height */, epee::span<const block> /* blocks */)> BlockNotifyCallback; typedef boost::function<void(uint8_t /* major_version */, uint64_t /* height */, const crypto::hash& /* prev_id */, const crypto::hash& /* seed_hash */, difficulty_type /* diff */, uint64_t /* median_weight */, uint64_t /* already_generated_coins */, const std::vector<tx_block_template_backlog_entry>& /* tx_backlog */)> MinerNotifyCallback; @@ -256,6 +257,16 @@ namespace cryptonote bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks); /** + * @brief prepare the blockchain for handling an incoming block, without performing preprocessing + * + * @param block_byte_estimate an estimate of the byte size of the block & its transactions + * + * This function should *always* be followed up by a call to cleanup_handle_incoming_blocks() + * later in the same thread. + */ + void prepare_handle_incoming_block_no_preprocess(const size_t block_byte_estimate); + + /** * @brief incoming blocks post-processing, cleanup, and disk sync * * @param force_sync if true, and Blockchain is handling syncing to disk, always sync @@ -352,11 +363,15 @@ namespace cryptonote * * @param bl_ the block to be added * @param bvc metadata about the block addition's success/failure + * @param extra_block_txs txs belonging to this block that may not be in the mempool * * @return true on successful addition to the blockchain, else false */ bool add_new_block(const block& bl_, block_verification_context& bvc); + bool add_new_block(const block& bl_, block_verification_context& bvc, + pool_supplement& extra_block_txs); + /** * @brief clears the blockchain and starts a new one * @@ -706,10 +721,13 @@ namespace cryptonote * * @param tx the transaction to check the outputs of * @param tvc returned info about tx verification + * @param hf_version hard fork version * * @return false if any outputs do not conform, otherwise true */ - bool check_tx_outputs(const transaction& tx, tx_verification_context &tvc) const; + static bool check_tx_outputs(const transaction& tx, + tx_verification_context &tvc, + std::uint8_t hf_version); /** * @brief gets the block weight limit based on recent blocks @@ -824,6 +842,13 @@ namespace cryptonote blockchain_db_sync_mode sync_mode, bool fast_sync); /** + * @brief sets a txpool notify object to call for every new tx used to add a new block + * + * @param notify the notify object to call at every new tx used to add a new block + */ + void set_txpool_notify(TxpoolNotifyCallback&& notify); + + /** * @brief sets a block notify object to call for every new block * * @param notify the notify object to call at every new block @@ -845,6 +870,11 @@ namespace cryptonote void set_reorg_notify(const std::shared_ptr<tools::Notify> ¬ify) { m_reorg_notify = notify; } /** + * @brief Notify this Blockchain's txpool notifier about a txpool event + */ + void notify_txpool_event(std::vector<txpool_event>&& event) const; + + /** * @brief Put DB in safe sync mode */ void safesyncmode(const bool onoff); @@ -1078,13 +1108,6 @@ namespace cryptonote void cancel(); /** - * @brief called when we see a tx originating from a block - * - * Used for handling txes from historical blocks in a fast way - */ - void on_new_tx_from_block(const cryptonote::transaction &tx); - - /** * @brief returns the timestamps of the last N blocks */ std::vector<time_t> get_last_block_timestamps(unsigned int blocks) const; @@ -1160,7 +1183,6 @@ namespace cryptonote // Keccak hashes for each block and for fast pow checking std::vector<std::pair<crypto::hash, crypto::hash>> m_blocks_hash_of_hashes; std::vector<std::pair<crypto::hash, uint64_t>> m_blocks_hash_check; - std::vector<crypto::hash> m_blocks_txs_check; blockchain_db_sync_mode m_db_sync_mode; bool m_fast_sync; @@ -1220,6 +1242,9 @@ namespace cryptonote bool m_batch_success; + TxpoolNotifyCallback m_txpool_notifier; + mutable std::mutex m_txpool_notifier_mutex; + /* `boost::function` is used because the implementation never allocates if the callable object has a single `std::shared_ptr` or `std::weap_ptr` internally. Whereas, the libstdc++ `std::function` will allocate. */ @@ -1333,11 +1358,10 @@ namespace cryptonote * * @param bl the block to be added * @param bvc metadata concerning the block's validity - * @param notify if set to true, sends new block notification on success * * @return true if the block was added successfully, otherwise false */ - bool handle_block_to_main_chain(const block& bl, block_verification_context& bvc, bool notify = true); + bool handle_block_to_main_chain(const block& bl, block_verification_context& bvc); /** * @brief validate and add a new block to the end of the blockchain @@ -1349,11 +1373,12 @@ namespace cryptonote * @param bl the block to be added * @param id the hash of the block * @param bvc metadata concerning the block's validity - * @param notify if set to true, sends new block notification on success + * @param extra_block_txs txs belonging to this block that may not be in the mempool * * @return true if the block was added successfully, otherwise false */ - bool handle_block_to_main_chain(const block& bl, const crypto::hash& id, block_verification_context& bvc, bool notify = true); + bool handle_block_to_main_chain(const block& bl, const crypto::hash& id, + block_verification_context& bvc, pool_supplement& extra_block_txs); /** * @brief validate and add a new block to an alternate blockchain @@ -1365,10 +1390,12 @@ namespace cryptonote * @param b the block to be added * @param id the hash of the block * @param bvc metadata concerning the block's validity + * @param extra_block_txs txs belonging to this block that may not be in the mempool * * @return true if the block was added successfully, otherwise false */ - bool handle_alternative_block(const block& b, const crypto::hash& id, block_verification_context& bvc); + bool handle_alternative_block(const block& b, const crypto::hash& id, + block_verification_context& bvc, pool_supplement& extra_block_txs); /** * @brief builds a list of blocks connecting a block to the main chain @@ -1553,7 +1580,6 @@ namespace cryptonote * @return true */ bool update_next_cumulative_weight_limit(uint64_t *long_term_effective_median_block_weight = NULL); - void return_tx_to_pool(std::vector<std::pair<transaction, blobdata>> &txs); /** * @brief make sure a transaction isn't attempting a double-spend |
