1
0
Fork 0
forked from lthn/blockchain

refactoring of tx pool/core block's transactions handling

This commit is contained in:
cryptozoidberg 2019-11-15 01:04:51 +01:00
parent 4fadc8b9cb
commit d1e6ef429b
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
6 changed files with 30 additions and 6 deletions

View file

@ -1351,7 +1351,7 @@ bool blockchain_storage::create_block_template(const create_block_template_param
uint64_t fee;
bool block_filled = false;
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);
block_filled = m_tx_pool.fill_block_template(b, pos, median_size, already_generated_coins, txs_size, fee, height, params.explicit_txs);
else
block_filled = (*pcustom_fill_block_template_func)(b, pos, median_size, already_generated_coins, txs_size, fee, height);

View file

@ -193,6 +193,16 @@ namespace currency
return get_object_blobsize(t, tx_blob_size);
}
//---------------------------------------------------------------
size_t get_objects_blobsize(const std::list<transaction>& ls)
{
size_t total = 0;
for (const auto& tx : ls)
{
total += get_object_blobsize(tx);
}
return total;
}
//---------------------------------------------------------------
size_t get_object_blobsize(const transaction& t, uint64_t prefix_blob_size)
{
size_t tx_blob_size = prefix_blob_size;

View file

@ -104,6 +104,7 @@ namespace currency
bool get_transaction_hash(const transaction& t, crypto::hash& res);
bool get_transaction_hash(const transaction& t, crypto::hash& res, uint64_t& blob_size);
size_t get_object_blobsize(const transaction& t);
size_t get_objects_blobsize(const std::list<transaction>& ls);
size_t get_object_blobsize(const transaction& t, uint64_t prefix_blob_size);
blobdata tx_to_blob(const transaction& b);
bool tx_to_blob(const transaction& b, blobdata& b_blob);

View file

@ -987,7 +987,9 @@ namespace currency
const boost::multiprecision::uint128_t& already_generated_coins,
size_t &total_size,
uint64_t &fee,
uint64_t height)
uint64_t height,
const std::list<transaction>& explicit_txs
)
{
LOCAL_READONLY_TRANSACTION();
//typedef transactions_container::value_type txv;
@ -998,8 +1000,8 @@ namespace currency
txs_v.reserve(m_db_transactions.size());
std::vector<txv*> txs;
//std::transform(m_transactions.begin(), m_transactions.end(), txs.begin(), [](txv &a) -> txv * { return &a; });
//keep getting it as a values cz db items cache will keep it as unserialied object stored by shared ptrs
//keep getting it as a values cz db items cache will keep it as unserialised object stored by shared ptrs
m_db_transactions.enumerate_keys([&](uint64_t i, crypto::hash& k){txs_v.resize(i + 1); txs_v[i].first = k; return true;});
txs.resize(txs_v.size(), nullptr);
@ -1024,7 +1026,9 @@ namespace currency
return a_ > b_;
});
size_t current_size = 0;
size_t explicit_total_size = get_objects_blobsize(explicit_txs);
size_t current_size = explicit_total_size;
uint64_t current_fee = 0;
uint64_t best_money;
if (!get_block_reward(pos, median_size, CURRENCY_COINBASE_BLOB_RESERVED_SIZE, already_generated_coins, best_money, height)) {
@ -1133,6 +1137,11 @@ namespace currency
}
}
}
// add explicit transactions
for (const auto& tx : explicit_txs)
{
bl.tx_hashes.push_back(get_transaction_hash(tx));
}
return true;
}
//---------------------------------------------------------------------------------

View file

@ -117,7 +117,7 @@ namespace currency
// load/store operations
bool init(const std::string& config_folder, const boost::program_options::variables_map& vm);
bool deinit();
bool fill_block_template(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 fill_block_template(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, const std::list<transaction>& explicit_txs);
bool get_transactions(std::list<transaction>& txs) const;
bool get_all_transactions_details(std::list<tx_rpc_extended_info>& txs)const;
bool get_all_transactions_brief_details(std::list<tx_rpc_brief_info>& txs)const;

View file

@ -27,5 +27,9 @@ namespace currency
bool m_already_exists;
bool added_to_altchain;
uint64_t height_difference;
//this is work like a first-level cache for transactions while block is getting handled. It lets transactions
//associated with the block to get handled directly to core without being handled by tx_pool(which makes full
//inputs validation, including signatures check)
std::unordered_map<crypto::hash, transaction> m_onboard_transactions;
};
}