forked from lthn/blockchain
blinding_masks_sum now passed via: construct_miner_tx -> create_block_template -> bild_minted_block -> prepare_and_sign_pos_block
This commit is contained in:
parent
d4205fdf89
commit
24ce9d4b40
15 changed files with 61 additions and 60 deletions
|
|
@ -1406,24 +1406,25 @@ uint64_t blockchain_storage::get_current_comulative_blocksize_limit() const
|
|||
return m_db_current_block_cumul_sz_limit;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::create_block_template(block& b,
|
||||
const account_public_address& miner_address,
|
||||
bool blockchain_storage::create_block_template(const account_public_address& miner_address,
|
||||
const blobdata& ex_nonce,
|
||||
block& b,
|
||||
wide_difficulty_type& diffic,
|
||||
uint64_t& height,
|
||||
const blobdata& ex_nonce) const
|
||||
uint64_t& height) const
|
||||
{
|
||||
return create_block_template(b, miner_address, miner_address, diffic, height, ex_nonce, false, pos_entry());
|
||||
return create_block_template(miner_address, miner_address, ex_nonce, false, pos_entry(), nullptr, b, diffic, height, crypto::scalar_t());
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::create_block_template(block& b,
|
||||
const account_public_address& miner_address,
|
||||
bool blockchain_storage::create_block_template(const account_public_address& miner_address,
|
||||
const account_public_address& stakeholder_address,
|
||||
wide_difficulty_type& diffic,
|
||||
uint64_t& height,
|
||||
const blobdata& ex_nonce,
|
||||
bool pos,
|
||||
const blobdata& ex_nonce,
|
||||
bool pos,
|
||||
const pos_entry& pe,
|
||||
fill_block_template_func_t custom_fill_block_template_func /* = nullptr */) const
|
||||
fill_block_template_func_t custom_fill_block_template_func,
|
||||
block& b,
|
||||
wide_difficulty_type& diffic,
|
||||
uint64_t& height,
|
||||
crypto::scalar_t& blinding_mask_sum /* = crypto::scalar_t */) const
|
||||
{
|
||||
create_block_template_params params = AUTO_VAL_INIT(params);
|
||||
params.miner_address = miner_address;
|
||||
|
|
@ -1434,9 +1435,11 @@ bool blockchain_storage::create_block_template(block& b,
|
|||
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;
|
||||
height = resp.height;
|
||||
blinding_mask_sum = resp.blinding_mask_sum;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -1520,7 +1523,8 @@ bool blockchain_storage::create_block_template(const create_block_template_param
|
|||
ex_nonce,
|
||||
CURRENCY_MINER_TX_MAX_OUTS,
|
||||
pos,
|
||||
pe);
|
||||
pe,
|
||||
resp.blinding_mask_sum);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to construc miner tx, first chance");
|
||||
uint64_t coinbase_size = get_object_blobsize(b.miner_tx);
|
||||
// "- 100" - to reserve room for PoS additions into miner tx
|
||||
|
|
|
|||
|
|
@ -260,8 +260,8 @@ namespace currency
|
|||
wide_difficulty_type get_cached_next_difficulty(bool pos) const;
|
||||
|
||||
|
||||
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 account_public_address& miner_address, const blobdata& ex_nonce, block& b, wide_difficulty_type& di, uint64_t& height) const;
|
||||
bool create_block_template(const account_public_address& miner_address, const account_public_address& stakeholder_address, const blobdata& ex_nonce, bool pos, const pos_entry& pe, fill_block_template_func_t custom_fill_block_template_func, block& b, wide_difficulty_type& di, uint64_t& height, crypto::scalar_t& blinding_mask_sum = crypto::scalar_t()) 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;
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ namespace currency
|
|||
block b;
|
||||
wide_difficulty_type diffic;
|
||||
uint64_t height;
|
||||
crypto::scalar_t blinding_mask_sum; // sum of all the outputs' blinding masks
|
||||
};
|
||||
|
||||
typedef std::unordered_map<crypto::hash, transaction> transactions_map;
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ namespace currency
|
|||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_block_template(block& b, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos, const pos_entry& pe)
|
||||
{
|
||||
return m_blockchain_storage.create_block_template(b, adr, stakeholder_address, diffic, height, ex_nonce, pos, pe);
|
||||
return m_blockchain_storage.create_block_template(adr, stakeholder_address, ex_nonce, pos, pe, nullptr, b, diffic, height);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::get_block_template(const create_block_template_params& params, create_block_template_response& resp)
|
||||
|
|
|
|||
|
|
@ -183,10 +183,12 @@ namespace currency
|
|||
const account_public_address &stakeholder_address,
|
||||
transaction& tx,
|
||||
uint64_t tx_version,
|
||||
const blobdata& extra_nonce,
|
||||
size_t max_outs,
|
||||
bool pos,
|
||||
const pos_entry& pe)
|
||||
const blobdata& extra_nonce /* = blobdata() */,
|
||||
size_t max_outs /* = CURRENCY_MINER_TX_MAX_OUTS */,
|
||||
bool pos /* = false */,
|
||||
const pos_entry& pe /* = pos_entry() */,
|
||||
crypto::scalar_t& blinding_masks_sum /* = crypto::scalar_t() */
|
||||
)
|
||||
{
|
||||
bool r = false;
|
||||
|
||||
|
|
@ -295,7 +297,7 @@ namespace currency
|
|||
// fill outputs
|
||||
crypto::scalar_vec_t blinding_masks(destinations.size()); // vector of secret blinging masks for each output. For range proof generation
|
||||
crypto::scalar_vec_t amounts(destinations.size()); // vector of amounts, converted to scalars. For ranage proof generation
|
||||
crypto::scalar_t blinding_masks_sum = 0;
|
||||
blinding_masks_sum = 0;
|
||||
uint64_t output_index = 0;
|
||||
for (auto& d : destinations)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -243,7 +243,8 @@ namespace currency
|
|||
const blobdata& extra_nonce = blobdata(),
|
||||
size_t max_outs = CURRENCY_MINER_TX_MAX_OUTS,
|
||||
bool pos = false,
|
||||
const pos_entry& pe = pos_entry());
|
||||
const pos_entry& pe = pos_entry(),
|
||||
crypto::scalar_t& blinding_masks_sum = crypto::scalar_t());
|
||||
//---------------------------------------------------------------
|
||||
uint64_t get_string_uint64_hash(const std::string& str);
|
||||
bool construct_tx_out(const tx_destination_entry& de, const crypto::secret_key& tx_sec_key, size_t output_index, transaction& tx, std::set<uint16_t>& deriv_cache, const account_keys& self, crypto::scalar_t& out_blinding_mask, finalized_tx& result, uint8_t tx_outs_attr = CURRENCY_TO_KEY_OUT_RELAXED);
|
||||
|
|
|
|||
|
|
@ -863,6 +863,7 @@ namespace currency
|
|||
blobdata block_blob = t_serializable_object_to_blob(resp.b);
|
||||
res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob);
|
||||
res.prev_hash = string_tools::pod_to_hex(resp.b.prev_id);
|
||||
res.blinding_masks_sum = resp.blinding_mask_sum;
|
||||
res.height = resp.height;
|
||||
//calculate epoch seed
|
||||
res.seed = currency::ethash_epoch_to_seed(currency::ethash_height_to_epoch(res.height));
|
||||
|
|
|
|||
|
|
@ -809,28 +809,17 @@ namespace currency
|
|||
blobdata explicit_transaction;
|
||||
std::string extra_text;
|
||||
std::string wallet_address;
|
||||
std::string stakeholder_address;
|
||||
bool pos_block; //is pos block
|
||||
//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;
|
||||
|
||||
pos_entry pe; // for making PoS blocks
|
||||
std::string stakeholder_address; // address for stake return (PoS blocks)
|
||||
pos_entry pe; // for PoS blocks
|
||||
bool pos_block; // is pos block
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE_BLOB_AS_HEX_STRING(explicit_transaction)
|
||||
KV_SERIALIZE(extra_text)
|
||||
KV_SERIALIZE(wallet_address)
|
||||
KV_SERIALIZE(stakeholder_address);
|
||||
KV_SERIALIZE(pos_block)
|
||||
//KV_SERIALIZE(pos_amount)
|
||||
//KV_SERIALIZE(pos_g_index)
|
||||
//KV_SERIALIZE_POD_AS_HEX_STRING(tx_id)
|
||||
//KV_SERIALIZE(tx_out_index)
|
||||
//KV_SERIALIZE(stake_unlock_time)
|
||||
KV_SERIALIZE(pe)
|
||||
KV_SERIALIZE(pos_block)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
|
@ -841,6 +830,7 @@ namespace currency
|
|||
crypto::hash seed;
|
||||
blobdata blocktemplate_blob;
|
||||
std::string prev_hash;
|
||||
crypto::scalar_t blinding_masks_sum; // sum of outputs' blinding masks (for zc outs)
|
||||
std::string status;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
|
|
@ -849,6 +839,7 @@ namespace currency
|
|||
KV_SERIALIZE_POD_AS_HEX_STRING(seed)
|
||||
KV_SERIALIZE(blocktemplate_blob)
|
||||
KV_SERIALIZE(prev_hash)
|
||||
KV_SERIALIZE(blinding_masks_sum)
|
||||
KV_SERIALIZE(status)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3647,7 +3647,7 @@ bool wallet2::is_in_hardfork_zone(uint64_t hardfork_index) const
|
|||
return m_core_runtime_config.is_hardfork_active_for_height(hardfork_index, get_blockchain_current_size());
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const pos_entry& pe) const
|
||||
bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const pos_entry& pe, const crypto::scalar_t& blinding_masks_sum) const
|
||||
{
|
||||
bool r = false;
|
||||
WLT_CHECK_AND_ASSERT_MES(pe.wallet_index < m_transfers.size(), false, "invalid pe.wallet_index: " << pe.wallet_index);
|
||||
|
|
@ -3794,7 +3794,8 @@ bool wallet2::prepare_and_sign_pos_block(const mining_context& cxt, currency::bl
|
|||
}
|
||||
#endif
|
||||
|
||||
crypto::scalar_t pseudo_out_blinding_mask = crypto::scalar_t::random();
|
||||
crypto::scalar_t pseudo_out_blinding_mask = blinding_masks_sum;
|
||||
//process_type_in_variant_container<tx_out_zarcanum>(b.miner_tx.vout, [&](tx_out_zarcanum& o){ pseudo_out_blinding_mask += o. });
|
||||
crypto::point_t pseudo_out_amount_commitment = td.m_amount * crypto::c_point_H + pseudo_out_blinding_mask * crypto::c_point_G;
|
||||
|
||||
crypto::hash tx_hash_for_sig = get_transaction_hash(b.miner_tx);
|
||||
|
|
@ -4042,7 +4043,7 @@ bool wallet2::build_minted_block(const mining_context& cxt, const currency::acco
|
|||
//else
|
||||
//{
|
||||
// old fashioned non-hidden amount PoS scheme
|
||||
res = prepare_and_sign_pos_block(cxt, b, tmpl_req.pe);
|
||||
res = prepare_and_sign_pos_block(cxt, b, tmpl_req.pe, tmpl_rsp.blinding_masks_sum);
|
||||
WLT_CHECK_AND_ASSERT_MES(res, false, "Failed to prepare_and_sign_pos_block");
|
||||
//}
|
||||
|
||||
|
|
|
|||
|
|
@ -840,7 +840,7 @@ namespace tools
|
|||
//next functions in public area only becausce of test_generator
|
||||
//TODO: Need refactoring - remove it back to private zone
|
||||
void set_genesis(const crypto::hash& genesis_hash);
|
||||
bool prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const currency::pos_entry& pe) const;
|
||||
bool prepare_and_sign_pos_block(const mining_context& cxt, currency::block& b, const currency::pos_entry& pe, const crypto::scalar_t& blinding_masks_sum) const;
|
||||
void process_new_blockchain_entry(const currency::block& b,
|
||||
const currency::block_direct_data_entry& bche,
|
||||
const crypto::hash& bl_id,
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ bool block_template_against_txs_size::c1(currency::core& c, size_t ev_index, con
|
|||
wide_difficulty_type diff = 0;
|
||||
uint64_t height = 0;
|
||||
g_block_txs_total_size = txs_total_size; // passing an argument to custom_fill_block_template_func via global variable (not perfect but works well)
|
||||
r = bcs.create_block_template(b, miner_addr, miner_addr, diff, height, ex_nonce, is_pos != 0, pe, &custom_fill_block_template_func);
|
||||
r = bcs.create_block_template(miner_addr, miner_addr, ex_nonce, is_pos != 0, pe, &custom_fill_block_template_func, b, diff, height);
|
||||
CHECK_AND_ASSERT_MES(r, false, "create_block_template failed, txs_total_size = " << txs_total_size);
|
||||
CHECK_AND_ASSERT_MES(height == top_block_height + 1, false, "Incorrect height: " << height << ", expected: " << top_block_height + 1 << ", txs_total_size = " << txs_total_size);
|
||||
|
||||
|
|
|
|||
|
|
@ -276,6 +276,7 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
|
||||
blk.miner_tx = AUTO_VAL_INIT(blk.miner_tx);
|
||||
size_t target_block_size = txs_size + 0; // zero means no cost for ordinary coinbase
|
||||
crypto::scalar_t blinding_masks_sum = 0;
|
||||
while (true)
|
||||
{
|
||||
r = construct_miner_tx(height, misc_utils::median(block_sizes),
|
||||
|
|
@ -289,7 +290,8 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
blobdata(),
|
||||
test_generator::get_test_gentime_settings().miner_tx_max_outs,
|
||||
static_cast<bool>(coin_stake_sources.size()),
|
||||
pe);
|
||||
pe,
|
||||
blinding_masks_sum);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_miner_tx failed");
|
||||
|
||||
size_t coinbase_size = get_object_blobsize(blk.miner_tx);
|
||||
|
|
@ -330,7 +332,7 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
else
|
||||
{
|
||||
//need to build pos block
|
||||
r = sign_block(blk, pe, *wallets[won_walled_index].wallet, wallets[won_walled_index].mining_context, blocks, oi);
|
||||
r = sign_block(wallets[won_walled_index].mining_context, pe, *wallets[won_walled_index].wallet, blinding_masks_sum, blk);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to find_kernel_and_sign()");
|
||||
}
|
||||
|
||||
|
|
@ -347,14 +349,13 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool test_generator::sign_block(currency::block& b,
|
||||
pos_entry& pe,
|
||||
tools::wallet2& w,
|
||||
const tools::wallet2::mining_context& mining_context,
|
||||
const std::vector<const block_info*>& blocks,
|
||||
const outputs_index& oi)
|
||||
bool test_generator::sign_block(const tools::wallet2::mining_context& mining_context,
|
||||
const pos_entry& pe,
|
||||
const tools::wallet2& w,
|
||||
const crypto::scalar_t& blinding_masks_sum,
|
||||
currency::block& b)
|
||||
{
|
||||
bool r = w.prepare_and_sign_pos_block(mining_context, b, pe);
|
||||
bool r = w.prepare_and_sign_pos_block(mining_context, b, pe, blinding_masks_sum);
|
||||
CHECK_AND_ASSERT_MES(r, false, "prepare_and_sign_pos_block failed");
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -434,12 +434,11 @@ public:
|
|||
bool init_test_wallet(const currency::account_base& account, const crypto::hash& genesis_hash, std::shared_ptr<tools::wallet2> &result);
|
||||
bool refresh_test_wallet(const std::vector<test_event_entry>& events, tools::wallet2* w, const crypto::hash& top_block_hash, size_t expected_blocks_to_be_fetched = std::numeric_limits<size_t>::max());
|
||||
|
||||
bool sign_block(currency::block& b,
|
||||
currency::pos_entry& pe,
|
||||
tools::wallet2& w,
|
||||
const tools::wallet2::mining_context& mining_context,
|
||||
const blockchain_vector& blocks,
|
||||
const outputs_index& oi);
|
||||
bool sign_block(const tools::wallet2::mining_context& mining_context,
|
||||
const currency::pos_entry& pe,
|
||||
const tools::wallet2& w,
|
||||
const crypto::scalar_t& blinding_masks_sum,
|
||||
currency::block& b);
|
||||
|
||||
bool get_output_details_by_global_index(const test_generator::blockchain_vector& blck_chain,
|
||||
const test_generator::outputs_index& indexes,
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ inline bool mine_next_pow_block_in_playtime_with_given_txs(const currency::accou
|
|||
{
|
||||
CRITICAL_REGION_LOCAL(s_locker);
|
||||
loc_helper::txs_accessor() = &txs;
|
||||
r = c.get_blockchain_storage().create_block_template(b, miner_addr, miner_addr, diff, height_from_template, extra, false, pe, loc_helper::fill_block_template_func);
|
||||
r = c.get_blockchain_storage().create_block_template(miner_addr, miner_addr, extra, false, pe, loc_helper::fill_block_template_func, b, diff, height_from_template);
|
||||
}
|
||||
CHECK_AND_ASSERT_MES(r, false, "get_block_template failed");
|
||||
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_
|
|||
wide_difficulty_type diff = 0;
|
||||
if (prev_block.height != 0)
|
||||
test_core_time::adjust(prev_block.bl.timestamp + DIFFICULTY_POW_TARGET);
|
||||
r = bcs.create_block_template(b, miner_addr, diff, height, ex_nonce);
|
||||
r = bcs.create_block_template(miner_addr, ex_nonce, b, diff, height);
|
||||
CHECK_AND_ASSERT_MES(r, false, "create_block_template failed");
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue