1
0
Fork 0
forked from lthn/blockchain

changed parameters of get_block_template

This commit is contained in:
cryptozoidberg 2019-11-14 19:53:38 +01:00
parent 57d1245ab6
commit 5b14456c61
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
4 changed files with 54 additions and 4 deletions

View file

@ -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()

View file

@ -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;

View file

@ -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;

View file

@ -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<transaction> 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;
};
}