diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index bebd6775..88cc16fb 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -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 diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index b69e86ab..68194132 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -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 diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c2194866..826f84d3 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -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(); m_core.get_blockchain_storage().build_stake_modifier(res.sm, blockchain_storage::alt_chain_type(), 0, &res.last_block_hash);// , &res.height); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index f36f6c1f..59cd7cf8 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -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() diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index d975b86c..30a7db01 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -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 stop(false); scan_pos(ctx, stop, [this](){ size_t blocks_fetched; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 188136be..66cdffe3 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -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; diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index fdbb1f48..2f0aac77 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -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);