From 5b14456c615d8f628d45c6d4bfd8acb7eab72cd8 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 14 Nov 2019 19:53:38 +0100 Subject: [PATCH] changed parameters of get_block_template --- src/common/db_abstract_accessor.h | 2 +- src/currency_core/blockchain_storage.cpp | 33 ++++++++++++++++++-- src/currency_core/blockchain_storage.h | 3 +- src/currency_core/blockchain_storage_basic.h | 20 ++++++++++++ 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/common/db_abstract_accessor.h b/src/common/db_abstract_accessor.h index ca6a3ee2..774284bd 100644 --- a/src/common/db_abstract_accessor.h +++ b/src/common/db_abstract_accessor.h @@ -521,7 +521,7 @@ namespace tools { TRY_ENTRY(); bdb.unbind_parent_container(this); - CATCH_ENTRY2(v); + CATCH_ALL_DO_NOTHING(); } virtual bool on_write_transaction_begin() diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index 28ab6d1a..eaa25474 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -1286,6 +1286,35 @@ bool blockchain_storage::create_block_template(block& b, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func /* = nullptr */) const { + create_block_template_params params = AUTO_VAL_INIT(params); + params.miner_address = miner_address; + params.stakeholder_address = stakeholder_address; + params.ex_nonce = ex_nonce; + params.pos = pos; + params.pe = pe; + params.pcustom_fill_block_template_func = custom_fill_block_template_func; + create_block_template_response resp = AUTO_VAL_INIT(resp); + bool r = create_block_template(params, resp); + b = resp.b; + diffic = resp.diffic; + height = resp.height; + return r; +} + +bool blockchain_storage::create_block_template(const create_block_template_params& params, create_block_template_response& resp) const +{ + const account_public_address& miner_address = params.miner_address; + const account_public_address& stakeholder_address = params.stakeholder_address; + const blobdata& ex_nonce = params.ex_nonce; + bool pos = params.pos; + const pos_entry& pe = params.pe; + fill_block_template_func_t* pcustom_fill_block_template_func = params.pcustom_fill_block_template_func; + + uint64_t& height = resp.height; + block& b = resp.b; + wide_difficulty_type& diffic = resp.diffic; + + size_t median_size; boost::multiprecision::uint128_t already_generated_coins; CRITICAL_REGION_BEGIN(m_read_lock); @@ -1321,10 +1350,10 @@ bool blockchain_storage::create_block_template(block& b, size_t txs_size; uint64_t fee; bool block_filled = false; - if (custom_fill_block_template_func == nullptr) + if (pcustom_fill_block_template_func == nullptr) block_filled = m_tx_pool.fill_block_template(b, pos, median_size, already_generated_coins, txs_size, fee, height); else - block_filled = (*custom_fill_block_template_func)(b, pos, median_size, already_generated_coins, txs_size, fee, height); + block_filled = (*pcustom_fill_block_template_func)(b, pos, median_size, already_generated_coins, txs_size, fee, height); if (!block_filled) return false; diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 6297cb23..46af15bd 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -240,9 +240,10 @@ namespace currency wide_difficulty_type get_next_diff_conditional2(bool pos, const alt_chain_type& alt_chain, uint64_t split_height, const alt_block_extended_info& abei) const; wide_difficulty_type get_cached_next_difficulty(bool pos) const; - typedef bool fill_block_template_func_t(block &bl, bool pos, size_t median_size, const boost::multiprecision::uint128_t& already_generated_coins, size_t &total_size, uint64_t &fee, uint64_t height); + bool create_block_template(block& b, const account_public_address& miner_address, const account_public_address& stakeholder_address, wide_difficulty_type& di, uint64_t& height, const blobdata& ex_nonce, bool pos, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func = nullptr) const; bool create_block_template(block& b, const account_public_address& miner_address, wide_difficulty_type& di, uint64_t& height, const blobdata& ex_nonce) const; + bool create_block_template(const create_block_template_params& params, create_block_template_response& resp) const; bool have_block(const crypto::hash& id) const; size_t get_total_transactions()const; diff --git a/src/currency_core/blockchain_storage_basic.h b/src/currency_core/blockchain_storage_basic.h index 7344f200..5a81d3f7 100644 --- a/src/currency_core/blockchain_storage_basic.h +++ b/src/currency_core/blockchain_storage_basic.h @@ -125,6 +125,26 @@ namespace currency } }; + typedef bool fill_block_template_func_t(block &bl, bool pos, size_t median_size, const boost::multiprecision::uint128_t& already_generated_coins, size_t &total_size, uint64_t &fee, uint64_t height); + struct create_block_template_params + { + account_public_address miner_address; + account_public_address stakeholder_address; + blobdata ex_nonce; + bool pos = false; + pos_entry pe; + std::list explicit_txs; + fill_block_template_func_t *pcustom_fill_block_template_func; + }; + + struct create_block_template_response + { + block b; + wide_difficulty_type diffic; + uint64_t height; + }; + + } \ No newline at end of file