1
0
Fork 0
forked from lthn/blockchain

wallet & PoS: don't try to mine a PoS block if the current sequence factor is too high

This commit is contained in:
sowle 2023-08-09 01:38:00 +02:00
parent 940f481454
commit a6036e2a13
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
7 changed files with 29 additions and 12 deletions

View file

@ -70,15 +70,6 @@ using namespace currency;
#define TARGETDATA_CACHE_SIZE DIFFICULTY_WINDOW + 10
#ifndef TESTNET
#define BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION 57000
#else
#define BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION 18000
#endif
#define BLOCK_POS_STRICT_SEQUENCE_LIMIT 20
DISABLE_VS_WARNINGS(4267)
namespace

View file

@ -154,6 +154,13 @@
#define POS_WALLET_MINING_SCAN_INTERVAL POS_SCAN_STEP //seconds
#define POS_MINIMUM_COINSTAKE_AGE 10 // blocks count
#ifndef TESTNET
# define BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION 57000
#else
# define BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION 18000
#endif
#define BLOCK_POS_STRICT_SEQUENCE_LIMIT 20
#define WALLET_FILE_SIGNATURE_OLD 0x1111012101101011LL // Bender's nightmare
#define WALLET_FILE_SIGNATURE_V2 0x1111011201101011LL // another Bender's nightmare

View file

@ -541,6 +541,12 @@ namespace currency
return true;
}
res.pos_sequence_factor_is_good = true;
uint64_t new_block_expected_height = m_core.get_blockchain_storage().get_top_block_height() + 1;
size_t new_block_expected_sequence_factor = m_core.get_blockchain_storage().get_current_sequence_factor(true) + 1;
if (new_block_expected_height > BLOCKCHAIN_HEIGHT_FOR_POS_STRICT_SEQUENCE_LIMITATION && new_block_expected_sequence_factor > BLOCK_POS_STRICT_SEQUENCE_LIMIT)
res.pos_sequence_factor_is_good = false;
res.pos_basic_difficulty = m_core.get_blockchain_storage().get_next_diff_conditional(true).convert_to<std::string>();
m_core.get_blockchain_storage().build_stake_modifier(res.sm, blockchain_storage::alt_chain_type(), 0, &res.last_block_hash);// , &res.height);

View file

@ -1154,12 +1154,14 @@ namespace currency
std::string status;
crypto::hash last_block_hash;
bool pos_mining_allowed;
bool pos_sequence_factor_is_good;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_VAL_POD_AS_BLOB(sm)
KV_SERIALIZE(pos_basic_difficulty)
KV_SERIALIZE(starter_timestamp)
KV_SERIALIZE(pos_mining_allowed)
KV_SERIALIZE(pos_sequence_factor_is_good)
KV_SERIALIZE(status)
KV_SERIALIZE_VAL_POD_AS_BLOB(last_block_hash)
END_KV_SERIALIZE_MAP()

View file

@ -4253,9 +4253,10 @@ bool wallet2::fill_mining_context(mining_context& ctx)
ctx = mining_context{};
ctx.init(wide_difficulty_type(pos_details_resp.pos_basic_difficulty), pos_details_resp.sm, is_in_hardfork_zone(ZANO_HARDFORK_04_ZARCANUM));
ctx.last_block_hash = pos_details_resp.last_block_hash;
ctx.is_pos_allowed = pos_details_resp.pos_mining_allowed;
ctx.starter_timestamp = pos_details_resp.starter_timestamp;
ctx.last_block_hash = pos_details_resp.last_block_hash;
ctx.is_pos_allowed = pos_details_resp.pos_mining_allowed;
ctx.is_pos_sequence_factor_good = pos_details_resp.pos_sequence_factor_is_good;
ctx.starter_timestamp = pos_details_resp.starter_timestamp;
ctx.status = API_RETURN_CODE_NOT_FOUND;
return true;
}
@ -4271,12 +4272,19 @@ bool wallet2::try_mint_pos(const currency::account_public_address& miner_address
mining_context ctx = AUTO_VAL_INIT(ctx);
WLT_LOG_L1("Starting PoS mining iteration");
fill_mining_context(ctx);
if (!ctx.is_pos_allowed)
{
WLT_LOG_YELLOW("POS MINING NOT ALLOWED YET", LOG_LEVEL_0);
return true;
}
if (!ctx.is_pos_sequence_factor_good)
{
WLT_LOG_YELLOW("PoS sequence factor is too big, waiting for a PoW block...", LOG_LEVEL_0);
return true;
}
std::atomic<bool> stop(false);
scan_pos(ctx, stop, [this](){
size_t blocks_fetched;

View file

@ -469,6 +469,7 @@ namespace tools
std::string status;
bool is_pos_allowed = false;
bool is_pos_sequence_factor_good = false;
uint64_t index = 0; // index in m_transfers
uint64_t stake_unlock_time = 0;

View file

@ -430,6 +430,8 @@ bool test_generator::build_wallets(const blockchain_vector& blockchain,
return true;
}
rsp.pos_sequence_factor_is_good = true;
build_stake_modifier(rsp.sm, m_blockchain);
uint64_t median_timestamp = get_timestamps_median(m_blockchain);