1
0
Fork 0
forked from lthn/blockchain

fixed wallet for new PoS rules

This commit is contained in:
cryptozoidberg 2019-07-20 14:36:12 +02:00
parent c9f93364ad
commit d4233ff013
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
4 changed files with 24 additions and 7 deletions

View file

@ -971,7 +971,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional(bool pos) con
wide_difficulty_type& dif = pos ? m_cached_next_pos_difficulty : m_cached_next_pow_difficulty;
TIME_MEASURE_FINISH_PD(target_calculating_enum_blocks);
TIME_MEASURE_START_PD(target_calculating_calc);
if (m_db_blocks.size() > ZANO_HARDFORK_1_AFTER_HEIGHT)
if (m_db_blocks.size() > m_core_runtime_config.hard_fork1_starts_after_height)
{
dif = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET);
}
@ -1010,7 +1010,7 @@ wide_difficulty_type blockchain_storage::get_next_diff_conditional2(bool pos, co
enum_blockchain(cb, alt_chain, split_height);
wide_difficulty_type diff = 0;
if(abei.height > ZANO_HARDFORK_1_AFTER_HEIGHT)
if(abei.height > m_core_runtime_config.hard_fork1_starts_after_height)
diff = next_difficulty_2(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET);
else
diff = next_difficulty_1(timestamps, commulative_difficulties, pos ? DIFFICULTY_POS_TARGET : DIFFICULTY_POW_TARGET);
@ -1698,7 +1698,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 <= ZANO_HARDFORK_1_AFTER_HEIGHT)
if (alt_chain_bei.bl.major_version == BLOCK_MAJOR_VERSION_INITAL || 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)
@ -4348,6 +4348,12 @@ bool blockchain_storage::validate_pos_block(const block& b,
// Txs in alternative PoS blocks (including miner_tx) are validated by validate_alt_block_txs()
r = check_tx_input(b.miner_tx, 1, coinstake_in, id, b.miner_tx.signatures[0], &max_related_block_height);
CHECK_AND_ASSERT_MES(r, false, "Failed to validate coinstake input in miner tx, block_id = " << get_block_hash(b));
if (get_block_height(b) > m_core_runtime_config.hard_fork1_starts_after_height)
{
uint64_t last_pow_h = get_last_x_block_height(false);
CHECK_AND_ASSERT_MES(max_related_block_height < last_pow_h, false, "Failed to failed to validate coinbase in pos block, condition failed: max_related_block_height(" << max_related_block_height << ") < last_pow_h(" << last_pow_h << ")");
}
}
uint64_t block_height = for_altchain ? split_height + alt_chain.size() : m_db_blocks.size();

View file

@ -203,7 +203,7 @@
#define BC_OFFERS_CURRENCY_MARKET_FILENAME "market.bin"
#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+64)
#define WALLET_FILE_SERIALIZATION_VERSION (CURRENCY_FORMATION_VERSION+65)
#define CURRENT_MEMPOOL_ARCHIVE_VER (CURRENCY_FORMATION_VERSION+31)

View file

@ -1027,6 +1027,8 @@ void wallet2::process_new_blockchain_entry(const currency::block& b, const curre
m_blockchain.push_back(bl_id);
++m_local_bc_height;
m_last_bc_timestamp = b.timestamp;
if (!is_pos_block(b))
m_last_pow_block_h = height;
m_wcallback->on_new_block(height, b);
}
@ -1761,6 +1763,7 @@ bool wallet2::reset_all()
m_last_bc_timestamp = 0;
m_height_of_start_sync = 0;
m_last_sync_percent = 0;
m_last_pow_block_h = 0;
return true;
}
//----------------------------------------------------------------------------------------------------
@ -2406,6 +2409,10 @@ bool wallet2::is_transfer_okay_for_pos(const transfer_details& tr)
if (m_blockchain.size() - tr.m_ptx_wallet_info->m_block_height <= m_core_runtime_config.min_coinstake_age)
return false;
if (tr.m_ptx_wallet_info->m_block_height >= m_last_pow_block_h)
return false;
return true;
}
//----------------------------------------------------------------------------------------------------

View file

@ -310,7 +310,8 @@ namespace tools
m_height_of_start_sync(0),
m_last_sync_percent(0),
m_do_rise_transfer(false),
m_watch_only(false)
m_watch_only(false),
m_last_pow_block_h(0)
{};
public:
wallet2() : m_stop(false),
@ -322,7 +323,8 @@ namespace tools
m_fake_outputs_count(0),
m_do_rise_transfer(false),
m_log_prefix("???"),
m_watch_only(false)
m_watch_only(false),
m_last_pow_block_h(0)
{
m_core_runtime_config = currency::get_default_core_runtime_config();
};
@ -615,7 +617,7 @@ namespace tools
return;
}
if (ver < 147)
if (ver < 149)
{
LOG_PRINT_MAGENTA("Wallet file truncated due to old version", LOG_LEVEL_0);
return;
@ -650,6 +652,7 @@ namespace tools
a & m_money_expirations;
a & m_pending_key_images;
a & m_tx_keys;
a & m_last_pow_block_h;
}
@ -862,6 +865,7 @@ private:
std::shared_ptr<i_wallet2_callback> m_wcallback;
uint64_t m_height_of_start_sync;
uint64_t m_last_sync_percent;
uint64_t m_last_pow_block_h;
currency::core_runtime_config m_core_runtime_config;
escrow_contracts_container m_contracts;
std::list<expiration_entry_info> m_money_expirations;