forked from lthn/blockchain
added test against detecting 'unpowed' stakes in pos blocks
This commit is contained in:
parent
67212dab51
commit
74ce613bde
7 changed files with 27 additions and 4 deletions
|
|
@ -4449,7 +4449,7 @@ bool blockchain_storage::validate_pos_block(const block& 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 << ")");
|
||||
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 << ")");
|
||||
//let's check that coinbase amount and unlock time
|
||||
r = validate_coinbase_outs_unlocktime(b.miner_tx, coinstake_in.amount, max_unlock_time);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to validate_coinbase_outs_unlocktime() in miner tx, block_id = " << get_block_hash(b)
|
||||
|
|
|
|||
|
|
@ -2453,7 +2453,7 @@ bool wallet2::is_transfer_okay_for_pos(const transfer_details& tr, uint64_t& sta
|
|||
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)
|
||||
if (tr.m_ptx_wallet_info->m_block_height > m_last_pow_block_h)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ ENABLE_CHANNEL_BY_DEFAULT("wallet");
|
|||
#define WLT_CHECK_AND_ASSERT_MES_NO_RET(expr, msg) CHECK_AND_ASSERT_MES_NO_RET(expr, "[W:" << m_log_prefix << "]" << msg)
|
||||
#define WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, msg) THROW_IF_FALSE_WALLET_INT_ERR_EX(cond, "[W:" << m_log_prefix << "]" << msg)
|
||||
|
||||
class test_generator;
|
||||
|
||||
namespace tools
|
||||
{
|
||||
#pragma pack(push, 1)
|
||||
|
|
@ -664,7 +666,7 @@ namespace tools
|
|||
//synchronous version of function
|
||||
bool try_mint_pos();
|
||||
//for unit tests
|
||||
friend class test_generator;
|
||||
friend class ::test_generator;
|
||||
|
||||
//next functions in public area only because of test_generator
|
||||
//TODO: Need refactoring - remove it back to private zone
|
||||
|
|
@ -877,6 +879,8 @@ private:
|
|||
uint64_t m_fake_outputs_count;
|
||||
std::string m_miner_text_info;
|
||||
|
||||
//this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions
|
||||
friend class test_generator;
|
||||
|
||||
}; // class wallet2
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ const crypto::signature invalid_signature = create_invalid_signature();
|
|||
test_generator::test_generator()
|
||||
: m_wallet_test_core_proxy(new wallet_test_core_proxy()),
|
||||
m_do_pos_to_low_timestamp(false),
|
||||
m_ignore_last_pow_in_wallets(false),
|
||||
m_last_found_timestamp(0),
|
||||
m_hardfork_after_heigh(CURRENCY_MAX_BLOCK_NUMBER)
|
||||
{
|
||||
|
|
@ -517,6 +518,10 @@ bool test_generator::find_kernel(const std::list<currency::account_base>& accs,
|
|||
//lets try to find block
|
||||
for (auto& w : wallets)
|
||||
{
|
||||
//set m_last_pow_block_h to big value, to let wallet to use any available outputs, including the those which is not behind last pow block
|
||||
if (m_ignore_last_pow_in_wallets)
|
||||
w->m_last_pow_block_h = CURRENCY_MAX_BLOCK_NUMBER;
|
||||
|
||||
currency::COMMAND_RPC_SCAN_POS::request scan_pos_entries;
|
||||
bool r = w->get_pos_entries(scan_pos_entries);
|
||||
CHECK_AND_ASSERT_THROW_MES(r, "Failed to get_pos_entries");
|
||||
|
|
|
|||
|
|
@ -510,10 +510,12 @@ public:
|
|||
static void set_test_gentime_settings(const test_gentime_settings& s) { m_test_gentime_settings = s; }
|
||||
static void set_test_gentime_settings_default() { m_test_gentime_settings = m_test_gentime_settings_default; }
|
||||
void set_pos_to_low_timestamp(bool do_pos_to_low_timestamp) { m_do_pos_to_low_timestamp = do_pos_to_low_timestamp; }
|
||||
void set_ignore_last_pow_in_wallets(bool ignore_last_pow_in_wallets) { m_ignore_last_pow_in_wallets = ignore_last_pow_in_wallets; }
|
||||
void set_hardfork_height(uint64_t h);
|
||||
|
||||
private:
|
||||
bool m_do_pos_to_low_timestamp;
|
||||
bool m_ignore_last_pow_in_wallets;
|
||||
uint64_t m_last_found_timestamp;
|
||||
|
||||
uint64_t m_hardfork_after_heigh;
|
||||
|
|
@ -986,6 +988,16 @@ void append_vector_by_another_vector(U& dst, const V& src)
|
|||
VEC_EVENTS.push_back(BLK_NAME); \
|
||||
PRINT_EVENT_NO(VEC_EVENTS)
|
||||
|
||||
#define MAKE_NEXT_POS_BLOCK_TX1(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, MINERS_ACC_LIST, TX_1) \
|
||||
currency::block BLK_NAME = AUTO_VAL_INIT(BLK_NAME); \
|
||||
{ \
|
||||
std::list<currency::transaction>tx_list; \
|
||||
tx_list.push_back(TX_1); \
|
||||
generator.construct_block(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list, MINERS_ACC_LIST); \
|
||||
} \
|
||||
VEC_EVENTS.push_back(BLK_NAME); \
|
||||
PRINT_EVENT_NO(VEC_EVENTS)
|
||||
|
||||
#define MAKE_NEXT_BLOCK_NO_ADD(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC) \
|
||||
currency::block BLK_NAME = AUTO_VAL_INIT(BLK_NAME); \
|
||||
generator.construct_block(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC); \
|
||||
|
|
@ -1006,6 +1018,7 @@ void append_vector_by_another_vector(U& dst, const V& src)
|
|||
VEC_EVENTS.push_back(BLK_NAME); \
|
||||
PRINT_EVENT_NO(VEC_EVENTS)
|
||||
|
||||
|
||||
#define MAKE_NEXT_BLOCK_TX_LIST(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST) \
|
||||
currency::block BLK_NAME = AUTO_VAL_INIT(BLK_NAME); \
|
||||
generator.construct_block(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST); \
|
||||
|
|
|
|||
|
|
@ -942,7 +942,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(inthe_middle_hard_fork_1_cumulative_difficulty);
|
||||
GENERATE_AND_PLAY(after_hard_fork_1_cumulative_difficulty);
|
||||
GENERATE_AND_PLAY(hard_fork_1_locked_mining_test);
|
||||
|
||||
GENERATE_AND_PLAY(hard_fork_1_bad_pos_source);
|
||||
//GENERATE_AND_PLAY(gen_block_reward); */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -35,3 +35,4 @@
|
|||
#include "emission_test.h"
|
||||
#include "hard_fork_1_locked_pos_test.h"
|
||||
#include "hard_fork_1_consensus_test.h"
|
||||
#include "hard_fork_1_bad_pos_source.h"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue