forked from lthn/blockchain
fixed most of the coretests
This commit is contained in:
parent
8101bc4932
commit
676ad16fca
10 changed files with 29 additions and 27 deletions
|
|
@ -1718,7 +1718,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_
|
|||
const block_extended_info& alt_chain_bei = alt_chain.back()->second;
|
||||
const block_extended_info& connection_point = alt_chain.front()->second;
|
||||
|
||||
if (alt_chain_bei.bl.major_version == BLOCK_MAJOR_VERSION_INITAL || connection_point.height <= m_core_runtime_config.hard_fork1_starts_after_height)
|
||||
if (connection_point.height <= m_core_runtime_config.hard_fork1_starts_after_height)
|
||||
{
|
||||
//use pre-hard fork, old-style comparing
|
||||
if (main_chain_bei.cumulative_diff_adjusted < alt_chain_bei.cumulative_diff_adjusted)
|
||||
|
|
@ -1739,7 +1739,7 @@ bool blockchain_storage::is_reorganize_required(const block_extended_info& main_
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if (alt_chain_bei.bl.major_version == CURRENT_BLOCK_MAJOR_VERSION)
|
||||
else if (alt_chain_bei.height > m_core_runtime_config.hard_fork1_starts_after_height)
|
||||
{
|
||||
//new rules, applied after HARD_FORK_1
|
||||
//to learn this algo please read https://github.com/hyle-team/docs/blob/master/zano/PoS_Analysis_and_improvements_proposal.pdf
|
||||
|
|
@ -4819,7 +4819,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
// rebuild cumulative_diff_precise_adjusted for whole period
|
||||
wide_difficulty_type diff_precise_adj = correct_difficulty_with_sequence_factor(sequence_factor, current_diffic);
|
||||
bei.cumulative_diff_precise_adjusted = m_db_blocks[last_x_h]->cumulative_diff_precise_adjusted + diff_precise_adj;
|
||||
bei.cumulative_diff_precise_adjusted = last_x_h ? m_db_blocks[last_x_h]->cumulative_diff_precise_adjusted + diff_precise_adj : diff_precise_adj;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
@ -5028,7 +5028,7 @@ bool blockchain_storage::add_new_block(const block& bl, block_verification_conte
|
|||
return false;
|
||||
}
|
||||
|
||||
if (prevalidate_block(bl))
|
||||
if (!prevalidate_block(bl))
|
||||
{
|
||||
LOG_PRINT_RED_L0("block with id = " << id << " failed to prevalidate");
|
||||
bvc.m_added_to_main_chain = false;
|
||||
|
|
|
|||
|
|
@ -222,6 +222,9 @@ namespace currency
|
|||
bool have_tx_keyimg_as_spent(const crypto::key_image &key_im, uint64_t before_height = UINT64_MAX) const;
|
||||
std::shared_ptr<transaction> get_tx(const crypto::hash &id) const;
|
||||
|
||||
|
||||
template<class visitor_t>
|
||||
bool scan_outputkeys_for_indexes(const transaction &validated_tx, const txin_to_key& tx_in_to_key, visitor_t& vis) { uint64_t stub = 0; return scan_outputkeys_for_indexes(validated_tx, tx_in_to_key, vis, stub); }
|
||||
template<class visitor_t>
|
||||
bool scan_outputkeys_for_indexes(const transaction &validated_tx, const txin_to_key& tx_in_to_key, visitor_t& vis, uint64_t& max_related_block_height) const ;
|
||||
|
||||
|
|
@ -708,7 +711,7 @@ namespace currency
|
|||
CHECK_AND_ASSERT_MES(mixattr_ok, false, "tx output #" << output_index << " violates mixin restrictions: mix_attr = " << static_cast<uint32_t>(outtk.mix_attr) << ", key_offsets.size = " << tx_in_to_key.key_offsets.size());
|
||||
|
||||
TIME_MEASURE_START_PD(tx_check_inputs_loop_scan_outputkeys_loop_handle_output);
|
||||
if (!vis.handle_output(tx_ptr->tx, validated_tx, tx_ptr->tx.vout[n], output_index))
|
||||
if (!vis.handle_output(tx_ptr->tx, validated_tx, tx_ptr->tx.vout[n], n))
|
||||
{
|
||||
LOG_PRINT_L0("Failed to handle_output for output id = " << tx_id << ", no " << n);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -390,7 +390,7 @@ namespace currency
|
|||
END_SERIALIZE()
|
||||
};
|
||||
|
||||
typedef boost::mpl::vector<tx_service_attachment, tx_comment, tx_payer, tx_receiver, tx_message, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_unlock_time2, etc_tx_details_expiration_time, etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry, extra_user_data, extra_padding, etc_tx_derivation_hint> all_payload_types;
|
||||
typedef boost::mpl::vector<tx_service_attachment, tx_comment, tx_payer, tx_receiver, tx_message, std::string, tx_crypto_checksum, etc_tx_time, etc_tx_details_unlock_time, etc_tx_details_expiration_time, etc_tx_details_flags, crypto::public_key, extra_attachment_info, extra_alias_entry, extra_user_data, extra_padding, etc_tx_derivation_hint, etc_tx_details_unlock_time2> all_payload_types;
|
||||
typedef boost::make_variant_over<all_payload_types>::type attachment_v;
|
||||
typedef boost::make_variant_over<all_payload_types>::type extra_v;
|
||||
typedef boost::make_variant_over<all_payload_types>::type payload_items_v;
|
||||
|
|
|
|||
|
|
@ -165,6 +165,10 @@ namespace currency
|
|||
if (!add_tx_extra_userdata(tx, extra_nonce))
|
||||
return false;
|
||||
|
||||
//at this moment we do apply_unlock_time only for coin_base transactions
|
||||
apply_unlock_time(destinations, tx);
|
||||
//we always add extra_padding with 2 bytes length to make possible for get_block_template to adjust cumulative size
|
||||
tx.extra.push_back(extra_padding());
|
||||
|
||||
|
||||
txin_gen in;
|
||||
|
|
@ -191,12 +195,7 @@ namespace currency
|
|||
CHECK_AND_ASSERT_MES(r, false, "Failed to contruct miner tx out");
|
||||
no++;
|
||||
}
|
||||
|
||||
//at this moment we do apply_unlock_time only for coin_base transactions
|
||||
apply_unlock_time(destinations, tx);
|
||||
|
||||
//we always add extra_padding with 2 bytes length to make possible for get_block_template to adjust cumulative size
|
||||
tx.extra.push_back(extra_padding());
|
||||
|
||||
|
||||
tx.version = CURRENT_TRANSACTION_VERSION;
|
||||
set_tx_unlock_time(tx, height + CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ bool gen_block_unlock_time_is_low::generate(std::vector<test_event_entry>& event
|
|||
BLOCK_VALIDATION_INIT_GENERATE();
|
||||
|
||||
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
|
||||
currency::set_tx_unlock_time(miner_tx, currency::get_tx_unlock_time(miner_tx) - 1);
|
||||
currency::set_tx_unlock_time(miner_tx, currency::get_tx_max_unlock_time(miner_tx) - 1);
|
||||
|
||||
block blk_1;
|
||||
generator.construct_block_manually(blk_1, blk_0, miner_account, test_generator::bf_miner_tx, 0, 0, 0, crypto::hash(), 0, miner_tx);
|
||||
|
|
@ -209,7 +209,7 @@ bool gen_block_unlock_time_is_high::generate(std::vector<test_event_entry>& even
|
|||
BLOCK_VALIDATION_INIT_GENERATE();
|
||||
|
||||
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
|
||||
set_tx_unlock_time(miner_tx, get_tx_unlock_time(miner_tx) + 1);
|
||||
set_tx_unlock_time(miner_tx, get_tx_max_unlock_time(miner_tx) + 1);
|
||||
|
||||
block blk_1;
|
||||
generator.construct_block_manually(blk_1, blk_0, miner_account, test_generator::bf_miner_tx, 0, 0, 0, crypto::hash(), 0, miner_tx);
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
const std::list<currency::transaction>& tx_list,
|
||||
const std::list<currency::account_base>& coin_stake_sources)//in case of PoS block
|
||||
{
|
||||
blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
blk.major_version = BLOCK_MAJOR_VERSION_INITAL;
|
||||
blk.minor_version = CURRENT_BLOCK_MINOR_VERSION;
|
||||
blk.timestamp = timestamp;
|
||||
blk.prev_id = prev_id;
|
||||
|
|
@ -786,7 +786,7 @@ bool test_generator::construct_block(const std::vector<test_event_entry>& events
|
|||
size_t txs_sizes/* = 0*/)
|
||||
{
|
||||
size_t height = get_block_height(prev_block) + 1;
|
||||
blk.major_version = actual_params & bf_major_ver ? major_ver : CURRENT_BLOCK_MAJOR_VERSION;
|
||||
blk.major_version = actual_params & bf_major_ver ? major_ver : BLOCK_MAJOR_VERSION_INITAL;
|
||||
blk.minor_version = actual_params & bf_minor_ver ? minor_ver : CURRENT_BLOCK_MINOR_VERSION;
|
||||
blk.timestamp = actual_params & bf_timestamp ? timestamp : (height > 10 ? prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN: prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN-POW_DIFF_UP_TIMESTAMP_DELTA); // Keep difficulty unchanged
|
||||
blk.prev_id = actual_params & bf_prev_id ? prev_id : get_block_hash(prev_block);
|
||||
|
|
@ -1197,10 +1197,10 @@ bool fill_tx_sources(std::vector<currency::tx_source_entry>& sources, const std:
|
|||
continue;
|
||||
if (check_for_unlocktime)
|
||||
{
|
||||
if (currency::get_tx_unlock_time(*oi.p_tx) < CURRENCY_MAX_BLOCK_NUMBER)
|
||||
if (currency::get_tx_max_unlock_time(*oi.p_tx) < CURRENCY_MAX_BLOCK_NUMBER)
|
||||
{
|
||||
//interpret as block index
|
||||
if (currency::get_tx_unlock_time(*oi.p_tx) > blockchain.size())
|
||||
if (currency::get_tx_max_unlock_time(*oi.p_tx) > blockchain.size())
|
||||
continue;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1194,7 +1194,7 @@ bool multisig_and_unlock_time::generate(std::vector<test_event_entry>& events) c
|
|||
transaction tx_1 = AUTO_VAL_INIT(tx_1);
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, unlock_time, CURRENCY_TO_KEY_OUT_RELAXED, true);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
CHECK_AND_ASSERT_MES(get_tx_unlock_time(tx_1) == unlock_time, false, "Unlock time was not correctly set");
|
||||
CHECK_AND_ASSERT_MES(get_tx_max_unlock_time(tx_1) == unlock_time, false, "Unlock time was not correctly set");
|
||||
events.push_back(tx_1);
|
||||
|
||||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ void pos_block_builder::step1_init_header(size_t block_height, crypto::hash& pre
|
|||
{
|
||||
CHECK_AND_ASSERT_THROW_MES(m_step == 0, "pos_block_builder: incorrect step sequence");
|
||||
m_block.minor_version = CURRENT_BLOCK_MINOR_VERSION;
|
||||
m_block.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
m_block.major_version = BLOCK_MAJOR_VERSION_INITAL;
|
||||
m_block.timestamp = 0; // to be set at step 3
|
||||
m_block.prev_id = prev_block_hash;
|
||||
m_block.flags = CURRENCY_BLOCK_FLAG_POS_BLOCK;
|
||||
|
|
|
|||
|
|
@ -48,15 +48,15 @@ bool determine_tx_real_inputs(currency::core& c, const currency::transaction& tx
|
|||
, m_found(false)
|
||||
{}
|
||||
|
||||
bool handle_output(const currency::transaction& tx, const currency::tx_out& out)
|
||||
bool handle_output(const transaction& source_tx, const transaction& validated_tx, const tx_out& out, uint64_t out_i)
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(!m_found, false, "Internal error: m_found is true but the visitor is still being applied");
|
||||
auto it = std::find(tx.vout.begin(), tx.vout.end(), out);
|
||||
if (it == tx.vout.end())
|
||||
auto it = std::find(validated_tx.vout.begin(), validated_tx.vout.end(), out);
|
||||
if (it == validated_tx.vout.end())
|
||||
return false;
|
||||
size_t output_tx_index = it - tx.vout.begin();
|
||||
size_t output_tx_index = it - validated_tx.vout.begin();
|
||||
|
||||
crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(tx);
|
||||
crypto::public_key tx_pub_key = get_tx_pub_key_from_extra(validated_tx);
|
||||
crypto::key_derivation derivation;
|
||||
bool r = generate_key_derivation(tx_pub_key, m_keys.m_view_secret_key, derivation);
|
||||
CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed");
|
||||
|
|
@ -96,7 +96,7 @@ bool determine_tx_real_inputs(currency::core& c, const currency::transaction& tx
|
|||
continue;
|
||||
}
|
||||
local_visitor vis(keys, in.k_image);
|
||||
bool r = c.get_blockchain_storage().scan_outputkeys_for_indexes(in, vis);
|
||||
bool r = c.get_blockchain_storage().scan_outputkeys_for_indexes(tx, in, vis);
|
||||
CHECK_AND_ASSERT_MES(r || vis.m_found, false, "scan_outputkeys_for_indexes failed");
|
||||
if (!vis.m_found)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ static const std::vector<currency::attachment_v> empty_attachment;
|
|||
bool create_block_template_manually(const currency::block& prev_block, boost::multiprecision::uint128_t already_generated_coins, const std::vector<const currency::transaction*>& txs, const currency::account_public_address& miner_addr, currency::block& result)
|
||||
{
|
||||
result.flags = 0;
|
||||
result.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
result.major_version = BLOCK_MAJOR_VERSION_INITAL;
|
||||
result.minor_version = CURRENT_BLOCK_MINOR_VERSION;
|
||||
result.nonce = 0;
|
||||
result.prev_id = get_block_hash(prev_block);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue