forked from lthn/blockchain
Merge branch 'zarcanum_mint' into zarcanum
This commit is contained in:
commit
2c5c0ddc75
12 changed files with 78 additions and 42 deletions
|
|
@ -1424,7 +1424,8 @@ bool blockchain_storage::create_block_template(const create_block_template_param
|
|||
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;
|
||||
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;
|
||||
|
|
@ -1435,6 +1436,17 @@ bool blockchain_storage::create_block_template(const create_block_template_param
|
|||
size_t median_size;
|
||||
boost::multiprecision::uint128_t already_generated_coins;
|
||||
CRITICAL_REGION_BEGIN(m_read_lock);
|
||||
if (pe.g_index == WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED)
|
||||
{
|
||||
std::vector<uint64_t> indexs;
|
||||
if (!get_tx_outputs_gindexs(pe.tx_id, indexs) || pe.tx_out_index >= indexs.size())
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(false, false, "Failed to get_tx_outputs_gindexs() for tx_id " << pe.tx_id);
|
||||
}
|
||||
pe.g_index = indexs[pe.tx_out_index];
|
||||
}
|
||||
|
||||
|
||||
height = m_db_blocks.size();
|
||||
b.major_version = m_core_runtime_config.hard_forks.get_block_major_version_by_height(height);
|
||||
|
||||
|
|
|
|||
|
|
@ -964,7 +964,7 @@ namespace currency
|
|||
struct pos_entry
|
||||
{
|
||||
uint64_t amount;
|
||||
uint64_t index; // global output index. TODO: remove, use tx_id + tx_out_index to get gindex in construct_miner_tx
|
||||
uint64_t g_index; // global output index. (could be WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED)
|
||||
crypto::key_image keyimage;
|
||||
uint64_t block_timestamp;
|
||||
uint64_t stake_unlock_time;
|
||||
|
|
@ -977,7 +977,7 @@ namespace currency
|
|||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(amount)
|
||||
KV_SERIALIZE(index)
|
||||
KV_SERIALIZE(g_index)
|
||||
KV_SERIALIZE(stake_unlock_time)
|
||||
KV_SERIALIZE(block_timestamp)
|
||||
KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(keyimage)
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ namespace currency
|
|||
posin.amount = pe.amount;
|
||||
|
||||
// TODO: using pe.index is deprecated, get input's global index by pe.tx_id and pe.tx_out_index
|
||||
posin.key_offsets.push_back(pe.index);
|
||||
posin.key_offsets.push_back(pe.g_index);
|
||||
|
||||
posin.k_image = pe.keyimage;
|
||||
tx.vin.push_back(posin);
|
||||
|
|
|
|||
|
|
@ -831,7 +831,9 @@ namespace currency
|
|||
params.ex_nonce = req.extra_text;
|
||||
params.pos = req.pos_block;
|
||||
params.pe.amount = req.pos_amount;
|
||||
params.pe.index = req.pos_index;
|
||||
params.pe.g_index = req.pos_g_index;
|
||||
params.pe.tx_id = req.tx_id;
|
||||
params.pe.tx_out_index = req.tx_out_index;
|
||||
params.pe.stake_unlock_time = req.stake_unlock_time;
|
||||
//params.pe.keyimage key image will be set in the wallet
|
||||
//params.pe.wallet_index is not included in serialization map, TODO: refactoring here
|
||||
|
|
|
|||
|
|
@ -804,8 +804,10 @@ namespace currency
|
|||
std::string wallet_address;
|
||||
std::string stakeholder_address;
|
||||
bool pos_block; //is pos block
|
||||
uint64_t pos_amount; //
|
||||
uint64_t pos_index; //
|
||||
uint64_t pos_amount; //do we still need it?
|
||||
uint64_t pos_g_index; //
|
||||
crypto::hash tx_id;
|
||||
uint64_t tx_out_index;
|
||||
uint64_t stake_unlock_time;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
|
@ -815,7 +817,9 @@ namespace currency
|
|||
KV_SERIALIZE(stakeholder_address);
|
||||
KV_SERIALIZE(pos_block)
|
||||
KV_SERIALIZE(pos_amount)
|
||||
KV_SERIALIZE(pos_index)
|
||||
KV_SERIALIZE(pos_g_index)
|
||||
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id)
|
||||
KV_SERIALIZE(tx_out_index)
|
||||
KV_SERIALIZE(stake_unlock_time)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3545,7 +3545,7 @@ bool wallet2::get_pos_entries(std::vector<currency::pos_entry>& entries)
|
|||
|
||||
pos_entry pe = AUTO_VAL_INIT(pe);
|
||||
pe.amount = tr.amount();
|
||||
pe.index = tr.m_global_output_index;
|
||||
//pe.index = tr.m_global_output_index;
|
||||
pe.keyimage = tr.m_key_image;
|
||||
pe.wallet_index = i;
|
||||
pe.stake_unlock_time = stake_unlock_time;
|
||||
|
|
@ -3633,8 +3633,8 @@ bool wallet2::build_kernel(const pos_entry& pe, const stake_modifier_type& stake
|
|||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::fill_mining_context(mining_context& ctx)
|
||||
{
|
||||
bool r = get_pos_entries(ctx.sp.pos_entries); // TODO: Remove this call. Transfers are filtered in scan_pos
|
||||
WLT_CHECK_AND_ASSERT_MES(r, false, "Failed to get_pos_entries()");
|
||||
//bool r = get_pos_entries(ctx.sp.pos_entries); // TODO: Remove this call. Transfers are filtered in scan_pos
|
||||
//WLT_CHECK_AND_ASSERT_MES(r, false, "Failed to get_pos_entries()");
|
||||
|
||||
currency::COMMAND_RPC_GET_POS_MINING_DETAILS::request pos_details_req = AUTO_VAL_INIT(pos_details_req);
|
||||
currency::COMMAND_RPC_GET_POS_MINING_DETAILS::response pos_details_resp = AUTO_VAL_INIT(pos_details_resp);
|
||||
|
|
@ -3675,9 +3675,9 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address
|
|||
return true;
|
||||
}
|
||||
|
||||
uint64_t pos_entries_amount = 0;
|
||||
for (auto& ent : ctx.sp.pos_entries)
|
||||
pos_entries_amount += ent.amount;
|
||||
//uint64_t pos_entries_amount = 0;
|
||||
//for (auto& ent : ctx.sp.pos_entries)
|
||||
// pos_entries_amount += ent.amount;
|
||||
|
||||
std::atomic<bool> stop(false);
|
||||
scan_pos(ctx, stop, [this](){
|
||||
|
|
@ -3696,7 +3696,7 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address
|
|||
build_minted_block(ctx, miner_address);
|
||||
}
|
||||
|
||||
WLT_LOG_L0("PoS mining: " << ctx.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << print_money_brief(pos_entries_amount));
|
||||
WLT_LOG_L0("PoS mining: " << ctx.iterations_processed << " iterations finished, status: " << ctx.rsp.status << ", " << ctx.total_items_checked << " entries with total amount: " << print_money_brief(ctx.total_amount_checked));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -3788,22 +3788,28 @@ bool wallet2::build_minted_block(const mining_context& cxt,
|
|||
//found a block, construct it, sign and push to daemon
|
||||
WLT_LOG_GREEN("Found kernel, constructing block", LOG_LEVEL_0);
|
||||
|
||||
CHECK_AND_NO_ASSERT_MES(cxt.rsp.index < cxt.sp.pos_entries.size(), false, "call_COMMAND_RPC_SCAN_POS returned wrong index: " << cxt.rsp.index << ", expected less then " << cxt.sp.pos_entries.size());
|
||||
//CHECK_AND_NO_ASSERT_MES(cxt.rsp.index < cxt.sp.pos_entries.size(), false, "call_COMMAND_RPC_SCAN_POS returned wrong index: " << cxt.rsp.index << ", expected less then " << cxt.sp.pos_entries.size());
|
||||
|
||||
pos_entry pe = AUTO_VAL_INIT(pe);
|
||||
|
||||
const pos_entry& pe = cxt.sp.pos_entries[cxt.rsp.index];
|
||||
|
||||
currency::COMMAND_RPC_GETBLOCKTEMPLATE::request tmpl_req = AUTO_VAL_INIT(tmpl_req);
|
||||
currency::COMMAND_RPC_GETBLOCKTEMPLATE::response tmpl_rsp = AUTO_VAL_INIT(tmpl_rsp);
|
||||
tmpl_req.wallet_address = get_account_address_as_str(miner_address);
|
||||
tmpl_req.stakeholder_address = get_account_address_as_str(m_account.get_public_address());
|
||||
tmpl_req.pos_block = true;
|
||||
tmpl_req.pos_amount = pe.amount;
|
||||
|
||||
tmpl_req.pos_index = pe.index; // gindex <--- this should be removed as soon as pos_entry::index is replaced with tx_id and tx_out_index
|
||||
// TODO: also fill out tx_id and tx_out_index for mining tx creation
|
||||
pe.g_index = tmpl_req.pos_g_index = m_transfers[cxt.rsp.index].m_global_output_index;
|
||||
pe.amount = tmpl_req.pos_amount = m_transfers[cxt.rsp.index].amount();// pe.amount;
|
||||
pe.keyimage = m_transfers[cxt.rsp.index].m_key_image;
|
||||
pe.block_timestamp = m_transfers[cxt.rsp.index].m_ptx_wallet_info->m_block_timestamp;
|
||||
pe.stake_unlock_time = tmpl_req.stake_unlock_time = cxt.rsp.stake_unlock_time;
|
||||
pe.tx_id = tmpl_req.tx_id = m_transfers[cxt.rsp.index].tx_hash();
|
||||
pe.tx_out_index = tmpl_req.tx_out_index = m_transfers[cxt.rsp.index].m_internal_output_index;
|
||||
pe.wallet_index = cxt.rsp.index;
|
||||
|
||||
//tmpl_req.pos_index = pe.index; // gindex <--- this should be removed as soon as pos_entry::index is replaced with tx_id and tx_out_index
|
||||
// TODO: also fill out tx_id and tx_out_index for mining tx creation
|
||||
tmpl_req.extra_text = m_miner_text_info;
|
||||
tmpl_req.stake_unlock_time = pe.stake_unlock_time;
|
||||
//generate packing tx
|
||||
transaction pack_tx = AUTO_VAL_INIT(pack_tx);
|
||||
if (generate_packing_transaction_if_needed(pack_tx, 0))
|
||||
|
|
@ -3828,15 +3834,15 @@ bool wallet2::build_minted_block(const mining_context& cxt,
|
|||
}
|
||||
|
||||
std::vector<const crypto::public_key*> keys_ptrs;
|
||||
WLT_CHECK_AND_ASSERT_MES(pe.wallet_index < m_transfers.size(),
|
||||
WLT_CHECK_AND_ASSERT_MES(cxt.rsp.index < m_transfers.size(),
|
||||
false, "Wrong wallet_index at generating coinbase transacton");
|
||||
|
||||
if (m_transfers[pe.wallet_index].m_ptx_wallet_info->m_tx.vout[m_transfers[pe.wallet_index].m_internal_output_index].type() != typeid(tx_out_bare))
|
||||
if (m_transfers[cxt.rsp.index].m_ptx_wallet_info->m_tx.vout[m_transfers[cxt.rsp.index].m_internal_output_index].type() != typeid(tx_out_bare))
|
||||
{
|
||||
//@#@ review zarcanum here
|
||||
return false;
|
||||
}
|
||||
const auto& target = boost::get<tx_out_bare>(m_transfers[pe.wallet_index].m_ptx_wallet_info->m_tx.vout[m_transfers[pe.wallet_index].m_internal_output_index]).target;
|
||||
const auto& target = boost::get<tx_out_bare>(m_transfers[cxt.rsp.index].m_ptx_wallet_info->m_tx.vout[m_transfers[cxt.rsp.index].m_internal_output_index]).target;
|
||||
WLT_CHECK_AND_ASSERT_MES(target.type() == typeid(currency::txout_to_key), false, "wrong type_id in source transaction in coinbase tx");
|
||||
|
||||
const currency::txout_to_key& txtokey = boost::get<currency::txout_to_key>(target);
|
||||
|
|
@ -3852,7 +3858,7 @@ bool wallet2::build_minted_block(const mining_context& cxt,
|
|||
res = prepare_and_sign_pos_block(b,
|
||||
pe,
|
||||
get_tx_pub_key_from_extra(m_transfers[pe.wallet_index].m_ptx_wallet_info->m_tx),
|
||||
m_transfers[pe.wallet_index].m_internal_output_index,
|
||||
m_transfers[cxt.rsp.index].m_internal_output_index,
|
||||
keys_ptrs);
|
||||
WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to prepare_and_sign_pos_block");
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
|
||||
const uint64_t WALLET_MINIMUM_HEIGHT_UNSET_CONST = std::numeric_limits<uint64_t>::max();
|
||||
const uint64_t WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED = std::numeric_limits<uint64_t>::max();
|
||||
|
||||
|
||||
#undef LOG_DEFAULT_CHANNEL
|
||||
#define LOG_DEFAULT_CHANNEL "wallet"
|
||||
|
|
@ -447,7 +447,7 @@ namespace tools
|
|||
struct mining_context
|
||||
{
|
||||
// from struct COMMAND_RPC_SCAN_POS
|
||||
struct request_t
|
||||
/*struct request_t
|
||||
{
|
||||
std::vector<currency::pos_entry> pos_entries;
|
||||
|
||||
|
|
@ -455,11 +455,13 @@ namespace tools
|
|||
KV_SERIALIZE(pos_entries)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
*/
|
||||
|
||||
struct response_t
|
||||
{
|
||||
std::string status;
|
||||
uint64_t index; // index in pos_entries container
|
||||
uint64_t index; // index in m_transfers
|
||||
uint64_t stake_unlock_time;
|
||||
uint64_t block_timestamp;
|
||||
uint64_t height;
|
||||
uint64_t starter_timestamp;
|
||||
|
|
@ -469,6 +471,7 @@ namespace tools
|
|||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
KV_SERIALIZE(index)
|
||||
KV_SERIALIZE(stake_unlock_time)
|
||||
KV_SERIALIZE(block_timestamp)
|
||||
KV_SERIALIZE(height)
|
||||
KV_SERIALIZE(is_pos_allowed)
|
||||
|
|
@ -477,7 +480,7 @@ namespace tools
|
|||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
request_t sp;
|
||||
//request_t sp;
|
||||
response_t rsp;
|
||||
|
||||
currency::wide_difficulty_type basic_diff;
|
||||
|
|
@ -486,7 +489,9 @@ namespace tools
|
|||
bool zarcanum;
|
||||
crypto::scalar_t last_pow_block_id_hashed; // Zarcanum notation: f'
|
||||
|
||||
uint64_t iterations_processed;
|
||||
uint64_t iterations_processed = 0;
|
||||
uint64_t total_items_checked = 0;
|
||||
uint64_t total_amount_checked = 0;
|
||||
};
|
||||
|
||||
struct expiration_entry_info
|
||||
|
|
@ -1364,6 +1369,7 @@ namespace tools
|
|||
if (!is_transfer_okay_for_pos(tr, stake_unlock_time))
|
||||
continue;
|
||||
|
||||
|
||||
bool go_past = true;
|
||||
uint64_t step = 0;
|
||||
|
||||
|
|
@ -1384,7 +1390,8 @@ namespace tools
|
|||
};
|
||||
|
||||
do_pos_mining_prepare_entry(cxt, transfer_index);
|
||||
|
||||
cxt.total_items_checked++;
|
||||
cxt.total_amount_checked += tr.amount();
|
||||
while(step <= ts_window)
|
||||
{
|
||||
//check every WALLET_POS_MINT_CHECK_HEIGHT_INTERVAL seconds wheither top block changed, if so - break the loop
|
||||
|
|
@ -1410,8 +1417,11 @@ namespace tools
|
|||
if (stop)
|
||||
return false;
|
||||
|
||||
cxt.iterations_processed++;
|
||||
if (do_pos_mining_iteration(cxt, transfer_index, ts))
|
||||
{
|
||||
cxt.rsp.index = transfer_index;
|
||||
cxt.rsp.stake_unlock_time = stake_unlock_time;
|
||||
cxt.rsp.status = API_RETURN_CODE_OK;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@
|
|||
#include "currency_core/bc_escrow_service.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
|
||||
const uint64_t WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED = std::numeric_limits<uint64_t>::max();
|
||||
|
||||
namespace tools
|
||||
{
|
||||
namespace wallet_public
|
||||
|
|
|
|||
|
|
@ -1993,9 +1993,9 @@ void wallets_manager::wallet_vs_options::worker_func()
|
|||
return true;
|
||||
}
|
||||
|
||||
uint64_t pos_entries_amount = 0;
|
||||
for (auto& ent : ctx.sp.pos_entries)
|
||||
pos_entries_amount += ent.amount;
|
||||
//uint64_t pos_entries_amount = 0;
|
||||
//for (auto& ent : ctx.sp.pos_entries)
|
||||
// pos_entries_amount += ent.amount;
|
||||
|
||||
w->get()->scan_pos(ctx, break_mining_loop, [this](){
|
||||
return *plast_daemon_network_state == currency::COMMAND_RPC_GET_INFO::daemon_network_state_online && *plast_daemon_height == last_wallet_synch_height;
|
||||
|
|
@ -2005,7 +2005,7 @@ void wallets_manager::wallet_vs_options::worker_func()
|
|||
{
|
||||
w->get()->build_minted_block(ctx);
|
||||
}
|
||||
LOG_PRINT_L1(get_log_prefix() << " PoS mining iteration finished, status: " << ctx.rsp.status << ", used " << ctx.sp.pos_entries.size() << " entries with total amount: " << currency::print_money_brief(pos_entries_amount) << ", processed: " << ctx.iterations_processed << " iter.");
|
||||
LOG_PRINT_L1(get_log_prefix() << " PoS mining iteration finished, status: " << ctx.rsp.status << ", used " << ctx.total_items_checked << " entries with total amount: " << currency::print_money_brief(ctx.total_amount_checked) << ", processed: " << ctx.iterations_processed << " iter.");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ bool block_template_against_txs_size::c1(currency::core& c, size_t ev_index, con
|
|||
pos_entry pe = AUTO_VAL_INIT(pe);
|
||||
pe.amount = boost::get<currency::tx_out_bare>(blk_0.miner_tx.vout[0]).amount;
|
||||
pe.block_timestamp = UINT64_MAX; // doesn't matter
|
||||
pe.index = 0; // global index
|
||||
pe.g_index = 0; // global index
|
||||
pe.keyimage = ki;
|
||||
pe.wallet_index = UINT64_MAX; // doesn't matter
|
||||
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ bool test_generator::sign_block(currency::block& b,
|
|||
bool r = get_output_details_by_global_index(blocks,
|
||||
oi,
|
||||
pe.amount,
|
||||
pe.index,
|
||||
pe.g_index,
|
||||
h,
|
||||
pts,
|
||||
out_i,
|
||||
|
|
@ -556,7 +556,7 @@ bool test_generator::find_kernel(const std::list<currency::account_base>& accs,
|
|||
|
||||
stake_kernel sk = AUTO_VAL_INIT(sk);
|
||||
build_kernel(pos_entries[i].amount,
|
||||
pos_entries[i].index,
|
||||
pos_entries[i].g_index,
|
||||
pos_entries[i].keyimage,
|
||||
sk,
|
||||
blck_chain,
|
||||
|
|
@ -582,7 +582,7 @@ bool test_generator::find_kernel(const std::list<currency::account_base>& accs,
|
|||
|
||||
//found kernel
|
||||
LOG_PRINT_GREEN("Found kernel: amount=" << print_money(pos_entries[i].amount)
|
||||
<< ", index=" << pos_entries[i].index
|
||||
<< ", index=" << pos_entries[i].g_index
|
||||
<< ", key_image" << pos_entries[i].keyimage
|
||||
<< ", diff: " << this_coin_diff, LOG_LEVEL_0);
|
||||
pe = pos_entries[i];
|
||||
|
|
|
|||
|
|
@ -175,12 +175,12 @@ inline bool mine_next_pos_block_in_playtime_with_wallet(tools::wallet2& w, const
|
|||
w.fill_mining_context(ctx);
|
||||
if (!ctx.rsp.is_pos_allowed)
|
||||
return false;
|
||||
|
||||
pos_entries_count = ctx.sp.pos_entries.size();
|
||||
|
||||
|
||||
std::atomic<bool> stop(false);
|
||||
w.scan_pos(ctx, stop, [&w](){size_t blocks_fetched; w.refresh(blocks_fetched); return blocks_fetched == 0; }, w.get_core_runtime_config());
|
||||
|
||||
pos_entries_count = ctx.total_items_checked;
|
||||
if (ctx.rsp.status != API_RETURN_CODE_OK)
|
||||
return false;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue