From b9c995ee0b0f7e4ced03e139472c20ac91c18f29 Mon Sep 17 00:00:00 2001 From: mfrankovi Date: Tue, 19 Sep 2023 12:06:55 +0200 Subject: [PATCH] chore: improve dag propose probability --- .../include/dag/dag_block_proposer.hpp | 6 +- .../consensus/include/dag/dag_manager.hpp | 6 +- .../consensus/src/dag/dag_block_proposer.cpp | 16 +++-- .../consensus/src/dag/dag_manager.cpp | 26 +++++--- .../consensus/src/pbft/pbft_manager.cpp | 2 +- libraries/core_libs/node/src/node.cpp | 10 +-- tests/crypto_test.cpp | 63 +++++++++++++++++++ tests/dag_test.cpp | 36 +++++------ tests/full_node_test.cpp | 12 +++- tests/state_api_test.cpp | 2 +- 10 files changed, 137 insertions(+), 42 deletions(-) diff --git a/libraries/core_libs/consensus/include/dag/dag_block_proposer.hpp b/libraries/core_libs/consensus/include/dag/dag_block_proposer.hpp index fe78837f05..0b79a617ed 100644 --- a/libraries/core_libs/consensus/include/dag/dag_block_proposer.hpp +++ b/libraries/core_libs/consensus/include/dag/dag_block_proposer.hpp @@ -38,7 +38,8 @@ class DagBlockProposer { DagBlockProposer(const DagBlockProposerConfig& bp_config, std::shared_ptr dag_mgr, std::shared_ptr trx_mgr, std::shared_ptr final_chain, std::shared_ptr db, std::shared_ptr key_manager, addr_t node_addr, - secret_t node_sk, vrf_wrapper::vrf_sk_t vrf_sk, uint64_t pbft_gas_limit, uint64_t dag_gas_limit); + secret_t node_sk, vrf_wrapper::vrf_sk_t vrf_sk, uint64_t pbft_gas_limit, uint64_t dag_gas_limit, + const state_api::Config& state_config); ~DagBlockProposer() { stop(); } DagBlockProposer(const DagBlockProposer&) = delete; DagBlockProposer(DagBlockProposer&&) = delete; @@ -149,6 +150,9 @@ class DagBlockProposer { const uint64_t kPbftGasLimit; const uint64_t kDagGasLimit; + const HardforksConfig kHardforks; + const uint64_t kValidatorMaxVote; + LOG_OBJECTS_DEFINE }; diff --git a/libraries/core_libs/consensus/include/dag/dag_manager.hpp b/libraries/core_libs/consensus/include/dag/dag_manager.hpp index b9cde3e56b..6e77862f1b 100644 --- a/libraries/core_libs/consensus/include/dag/dag_manager.hpp +++ b/libraries/core_libs/consensus/include/dag/dag_manager.hpp @@ -48,8 +48,8 @@ class DagManager : public std::enable_shared_from_this { const DagConfig &dag_config, std::shared_ptr trx_mgr, std::shared_ptr pbft_chain, std::shared_ptr final_chain, std::shared_ptr db, std::shared_ptr key_manager, uint64_t pbft_gas_limit, - bool is_light_node = false, uint64_t light_node_history = 0, - uint32_t max_levels_per_period = kMaxLevelsPerPeriod, + const state_api::Config &state_config, bool is_light_node = false, + uint64_t light_node_history = 0, uint32_t max_levels_per_period = kMaxLevelsPerPeriod, uint32_t dag_expiry_limit = kDagExpiryLevelLimit); DagManager(const DagManager &) = delete; @@ -282,6 +282,8 @@ class DagManager : public std::enable_shared_from_this { ExpirationCacheMap seen_blocks_; std::shared_ptr final_chain_; const uint64_t kPbftGasLimit; + const HardforksConfig kHardforks; + const uint64_t kValidatorMaxVote; LOG_OBJECTS_DEFINE }; diff --git a/libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp b/libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp index 416a8f6906..44d6d4f0a1 100644 --- a/libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp +++ b/libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp @@ -17,7 +17,8 @@ DagBlockProposer::DagBlockProposer(const DagBlockProposerConfig& bp_config, std: std::shared_ptr trx_mgr, std::shared_ptr final_chain, std::shared_ptr db, std::shared_ptr key_manager, addr_t node_addr, secret_t node_sk, - vrf_wrapper::vrf_sk_t vrf_sk, uint64_t pbft_gas_limit, uint64_t dag_gas_limit) + vrf_wrapper::vrf_sk_t vrf_sk, uint64_t pbft_gas_limit, uint64_t dag_gas_limit, + const state_api::Config& state_config) : bp_config_(bp_config), total_trx_shards_(std::max(bp_config_.shard, uint16_t(1))), dag_mgr_(std::move(dag_mgr)), @@ -30,7 +31,9 @@ DagBlockProposer::DagBlockProposer(const DagBlockProposerConfig& bp_config, std: vrf_sk_(std::move(vrf_sk)), vrf_pk_(vrf_wrapper::getVrfPublicKey(vrf_sk_)), kPbftGasLimit(pbft_gas_limit), - kDagGasLimit(dag_gas_limit) { + kDagGasLimit(dag_gas_limit), + kHardforks(state_config.hardforks), + kValidatorMaxVote(state_config.dpos.validator_maximum_stake / state_config.dpos.vote_eligibility_balance_step) { LOG_OBJECTS_CREATE("DAG_PROPOSER"); // Add a random component in proposing stale blocks so that not all nodes propose stale blocks at the same time @@ -69,15 +72,20 @@ bool DagBlockProposer::proposeDagBlock() { return false; } - const auto total_vote_count = final_chain_->dpos_eligible_total_vote_count(*proposal_period); + uint64_t max_vote_count = 0; const auto vote_count = final_chain_->dpos_eligible_vote_count(*proposal_period, node_addr_); + if (*proposal_period < kHardforks.magnolia_hf.block_num) { + max_vote_count = final_chain_->dpos_eligible_total_vote_count(*proposal_period); + } else { + max_vote_count = kValidatorMaxVote; + } const auto period_block_hash = db_->getPeriodBlockHash(*proposal_period); // get sortition const auto sortition_params = dag_mgr_->sortitionParamsManager().getSortitionParams(*proposal_period); vdf_sortition::VdfSortition vdf(sortition_params, vrf_sk_, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), vote_count, - total_vote_count); + max_vote_count); if (vdf.isStale(sortition_params)) { if (last_propose_level_ == propose_level) { if (num_tries_ < max_num_tries_) { diff --git a/libraries/core_libs/consensus/src/dag/dag_manager.cpp b/libraries/core_libs/consensus/src/dag/dag_manager.cpp index a27985784c..d9e4229ff1 100644 --- a/libraries/core_libs/consensus/src/dag/dag_manager.cpp +++ b/libraries/core_libs/consensus/src/dag/dag_manager.cpp @@ -19,8 +19,8 @@ DagManager::DagManager(const DagBlock &dag_genesis_block, addr_t node_addr, cons const DagConfig &dag_config, std::shared_ptr trx_mgr, std::shared_ptr pbft_chain, std::shared_ptr final_chain, std::shared_ptr db, std::shared_ptr key_manager, uint64_t pbft_gas_limit, - bool is_light_node, uint64_t light_node_history, uint32_t max_levels_per_period, - uint32_t dag_expiry_limit) try + const state_api::Config &state_config, bool is_light_node, uint64_t light_node_history, + uint32_t max_levels_per_period, uint32_t dag_expiry_limit) try : max_level_(db->getLastBlocksLevel()), pivot_tree_(std::make_shared(dag_genesis_block.getHash(), node_addr)), total_dag_(std::make_shared(dag_genesis_block.getHash(), node_addr)), @@ -39,7 +39,9 @@ DagManager::DagManager(const DagBlock &dag_genesis_block, addr_t node_addr, cons dag_expiry_limit_(dag_expiry_limit), seen_blocks_(cache_max_size_, cache_delete_step_), final_chain_(std::move(final_chain)), - kPbftGasLimit(pbft_gas_limit) { + kPbftGasLimit(pbft_gas_limit), + kHardforks(state_config.hardforks), + kValidatorMaxVote(state_config.dpos.validator_maximum_stake / state_config.dpos.vote_eligibility_balance_step) { LOG_OBJECTS_CREATE("DAGMGR"); if (auto ret = getLatestPivotAndTips(); ret) { frontier_.pivot = ret->first; @@ -502,10 +504,15 @@ void DagManager::recoverDag() { } // Verify VDF solution try { - const auto total_vote_count = final_chain_->dpos_eligible_total_vote_count(*propose_period); + uint64_t max_vote_count = 0; const auto vote_count = final_chain_->dpos_eligible_vote_count(*propose_period, blk.getSender()); + if (*propose_period < kHardforks.magnolia_hf.block_num) { + max_vote_count = final_chain_->dpos_eligible_total_vote_count(*propose_period); + } else { + max_vote_count = kValidatorMaxVote; + } blk.verifyVdf(sortition_params_manager_.getSortitionParams(*propose_period), - db_->getPeriodBlockHash(*propose_period), *pk, vote_count, total_vote_count); + db_->getPeriodBlockHash(*propose_period), *pk, vote_count, max_vote_count); } catch (vdf_sortition::VdfSortition::InvalidVdfSortition const &e) { LOG(log_er_) << "DAG block " << blk.getHash() << " with " << blk.getLevel() << " level failed on VDF verification with pivot hash " << blk.getPivot() << " reason " @@ -630,10 +637,15 @@ DagManager::VerifyBlockReturnType DagManager::verifyBlock(const DagBlock &blk) { try { const auto proposal_period_hash = db_->getPeriodBlockHash(*propose_period); - const auto total_vote_count = final_chain_->dpos_eligible_total_vote_count(*propose_period); + uint64_t max_vote_count = 0; const auto vote_count = final_chain_->dpos_eligible_vote_count(*propose_period, blk.getSender()); + if (*propose_period < kHardforks.magnolia_hf.block_num) { + max_vote_count = final_chain_->dpos_eligible_total_vote_count(*propose_period); + } else { + max_vote_count = kValidatorMaxVote; + } blk.verifyVdf(sortition_params_manager_.getSortitionParams(*propose_period), proposal_period_hash, *pk, vote_count, - total_vote_count); + max_vote_count); } catch (vdf_sortition::VdfSortition::InvalidVdfSortition const &e) { LOG(log_er_) << "DAG block " << block_hash << " with " << blk.getLevel() << " level failed on VDF verification with pivot hash " << blk.getPivot() << " reason " << e.what(); diff --git a/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp b/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp index 88f2c65d11..59c04938ea 100644 --- a/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp +++ b/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp @@ -307,7 +307,7 @@ bool PbftManager::advancePeriod() { // Cleanup proposed blocks proposed_blocks_.cleanupProposedPbftBlocksByPeriod(new_period); - LOG(log_er_) << "Period advanced to: " << new_period << ", round and step reset to 1"; + LOG(log_nf_) << "Period advanced to: " << new_period << ", round and step reset to 1"; // Restart while loop... return true; diff --git a/libraries/core_libs/node/src/node.cpp b/libraries/core_libs/node/src/node.cpp index cf3eeb43a1..a0d834ac64 100644 --- a/libraries/core_libs/node/src/node.cpp +++ b/libraries/core_libs/node/src/node.cpp @@ -123,10 +123,10 @@ void FullNode::init() { } pbft_chain_ = std::make_shared(node_addr, db_); - dag_mgr_ = std::make_shared(conf_.genesis.dag_genesis_block, node_addr, conf_.genesis.sortition, - conf_.genesis.dag, trx_mgr_, pbft_chain_, final_chain_, db_, key_manager_, - conf_.genesis.pbft.gas_limit, conf_.is_light_node, conf_.light_node_history, - conf_.max_levels_per_period, conf_.dag_expiry_limit); + dag_mgr_ = std::make_shared( + conf_.genesis.dag_genesis_block, node_addr, conf_.genesis.sortition, conf_.genesis.dag, trx_mgr_, pbft_chain_, + final_chain_, db_, key_manager_, conf_.genesis.pbft.gas_limit, conf_.genesis.state, conf_.is_light_node, + conf_.light_node_history, conf_.max_levels_per_period, conf_.dag_expiry_limit); auto slashing_manager = std::make_shared(final_chain_, trx_mgr_, gas_pricer_, conf_, kp_.secret()); vote_mgr_ = std::make_shared(node_addr, conf_.genesis.pbft, kp_.secret(), conf_.vrf_secret, db_, pbft_chain_, final_chain_, key_manager_, slashing_manager); @@ -135,7 +135,7 @@ void FullNode::init() { pbft_chain_, vote_mgr_, dag_mgr_, trx_mgr_, final_chain_, kp_.secret()); dag_block_proposer_ = std::make_shared( conf_.genesis.dag.block_proposer, dag_mgr_, trx_mgr_, final_chain_, db_, key_manager_, node_addr, getSecretKey(), - getVrfSecretKey(), conf_.genesis.pbft.gas_limit, conf_.genesis.dag.gas_limit); + getVrfSecretKey(), conf_.genesis.pbft.gas_limit, conf_.genesis.dag.gas_limit, conf_.genesis.state); network_ = std::make_shared(conf_, genesis_hash, conf_.net_file_path().string(), kp_, db_, pbft_mgr_, pbft_chain_, vote_mgr_, dag_mgr_, trx_mgr_, std::move(slashing_manager)); diff --git a/tests/crypto_test.cpp b/tests/crypto_test.cpp index 5218146128..fb82494eb1 100644 --- a/tests/crypto_test.cpp +++ b/tests/crypto_test.cpp @@ -173,6 +173,69 @@ TEST_F(CryptoTest, vdf_stake_test) { << (count_dag_blocks_production[i] * 1000 / total_dags % 100) << "%" << std::endl; } } + + // Post magnolia hardfork stakes + for (uint32_t upper_threshold = 0x5ff; upper_threshold < 0xffff; upper_threshold *= 3) { + std::cout << "Upper threshold: " << upper_threshold << std::endl; + SortitionParams sortition_params(upper_threshold, 16, 21, 23, 0x64); + uint64_t total_vote_count = 800; + const uint64_t voters_count = 8; + uint64_t voters_vote_count[voters_count]; + uint64_t count_dag_blocks_production[voters_count]; + for (uint64_t i = 0; i < voters_count; i++) { + count_dag_blocks_production[i] = 0; + } + voters_vote_count[0] = 50; + voters_vote_count[1] = 100; + voters_vote_count[2] = 200; + voters_vote_count[3] = 300; + voters_vote_count[4] = 400; + voters_vote_count[5] = 500; + voters_vote_count[6] = 650; + voters_vote_count[7] = 800; + vrf_sk_t sk( + "0b6627a6680e01cea3d9f36fa797f7f34e8869c3a526d9ed63ed8170e35542aad05dc12c" + "1df1edc9f3367fba550b7971fc2de6c5998d8784051c5be69abc9644"); + for (uint32_t counter = 1; counter < 3000; counter++) { + level_t level = counter * voters_count; + uint64_t difficulties[voters_count]; + for (uint64_t i = 0; i < voters_count; i++) { + VdfSortition vdf(sortition_params, sk, getRlpBytes(level + i), voters_vote_count[i], total_vote_count); + difficulties[i] = vdf.getDifficulty(); + } + uint64_t min_diff = 24; + for (uint64_t i = 0; i < voters_count; i++) { + if (difficulties[i] < min_diff) { + min_diff = difficulties[i]; + } + } + // Stale block is produced by random node + if (min_diff == 23) { + count_dag_blocks_production[rand() % voters_count]++; + } else { + for (uint64_t i = 0; i < voters_count; i++) { + if (difficulties[i] == min_diff) { + count_dag_blocks_production[i]++; + // std::cout << "min AT " << i << std::endl; + } + } + } + } + uint64_t total_dags = 0; + for (auto count : count_dag_blocks_production) { + total_dags += count; + } + std::cout << "total_dags: " << total_dags << std::endl; + for (uint64_t i = 0; i < voters_count; i++) { + if (i > 0) { + // Verify that greater stake produce more dag blocks + EXPECT_GE(count_dag_blocks_production[i], count_dag_blocks_production[i - 1]); + } + std::cout << "Vote stake " << voters_vote_count[i] / 8 << "." << voters_vote_count[i] % 8 + << "% - Dag ratio: " << count_dag_blocks_production[i] * 100 / total_dags << "." + << (count_dag_blocks_production[i] * 1000 / total_dags % 100) << "%" << std::endl; + } + } } TEST_F(CryptoTest, vdf_sortition) { diff --git a/tests/dag_test.cpp b/tests/dag_test.cpp index 8d7cdc07ff..9a74fad8dc 100644 --- a/tests/dag_test.cpp +++ b/tests/dag_test.cpp @@ -135,9 +135,9 @@ TEST_F(DagTest, compute_epoch) { auto trx_mgr = std::make_shared(FullNodeConfig(), db_ptr, nullptr, addr_t()); auto pbft_chain = std::make_shared(addr_t(), db_ptr); const blk_hash_t GENESIS = node_cfgs[0].genesis.dag_genesis_block.getHash(); - auto mgr = - std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), node_cfgs[0].genesis.sortition, - node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, nullptr, db_ptr, nullptr, 100000); + auto mgr = std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), + node_cfgs[0].genesis.sortition, node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, + nullptr, db_ptr, nullptr, 100000, node_cfgs[0].genesis.state); DagBlock blkA(GENESIS, 1, {}, {trx_hash_t(2)}, sig_t(1), blk_hash_t(2), addr_t(1)); DagBlock blkB(GENESIS, 1, {}, {trx_hash_t(3), trx_hash_t(4)}, sig_t(1), blk_hash_t(3), addr_t(1)); @@ -228,9 +228,9 @@ TEST_F(DagTest, dag_expiry) { auto trx_mgr = std::make_shared(FullNodeConfig(), db_ptr, nullptr, addr_t()); auto pbft_chain = std::make_shared(addr_t(), db_ptr); const blk_hash_t GENESIS = node_cfgs[0].genesis.dag_genesis_block.getHash(); - auto mgr = std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), - node_cfgs[0].genesis.sortition, node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, - nullptr, db_ptr, nullptr, 100000, false, 0, 3, EXPIRY_LIMIT); + auto mgr = std::make_shared( + node_cfgs[0].genesis.dag_genesis_block, addr_t(), node_cfgs[0].genesis.sortition, node_cfgs[0].genesis.dag, + trx_mgr, pbft_chain, nullptr, db_ptr, nullptr, 100000, node_cfgs[0].genesis.state, false, 0, 3, EXPIRY_LIMIT); DagBlock blkA(GENESIS, 1, {}, {trx_hash_t(2)}, sig_t(1), blk_hash_t(2), addr_t(1)); DagBlock blkB(GENESIS, 1, {}, {trx_hash_t(3), trx_hash_t(4)}, sig_t(1), blk_hash_t(3), addr_t(1)); @@ -304,9 +304,9 @@ TEST_F(DagTest, receive_block_in_order) { auto pbft_chain = std::make_shared(addr_t(), db_ptr); auto trx_mgr = std::make_shared(FullNodeConfig(), db_ptr, nullptr, addr_t()); const blk_hash_t GENESIS = node_cfgs[0].genesis.dag_genesis_block.getHash(); - auto mgr = - std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), node_cfgs[0].genesis.sortition, - node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, nullptr, db_ptr, nullptr, 100000); + auto mgr = std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), + node_cfgs[0].genesis.sortition, node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, + nullptr, db_ptr, nullptr, 100000, node_cfgs[0].genesis.state); DagBlock blk1(GENESIS, 1, {}, {}, sig_t(777), blk_hash_t(1), addr_t(15)); DagBlock blk2(blk_hash_t(1), 2, {}, {}, sig_t(777), blk_hash_t(2), addr_t(15)); @@ -336,9 +336,9 @@ TEST_F(DagTest, compute_epoch_2) { auto pbft_chain = std::make_shared(addr_t(), db_ptr); auto trx_mgr = std::make_shared(FullNodeConfig(), db_ptr, nullptr, addr_t()); const blk_hash_t GENESIS = node_cfgs[0].genesis.dag_genesis_block.getHash(); - auto mgr = - std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), node_cfgs[0].genesis.sortition, - node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, nullptr, db_ptr, nullptr, 100000); + auto mgr = std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), + node_cfgs[0].genesis.sortition, node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, + nullptr, db_ptr, nullptr, 100000, node_cfgs[0].genesis.state); DagBlock blkA(GENESIS, 1, {}, {trx_hash_t(2)}, sig_t(1), blk_hash_t(2), addr_t(1)); DagBlock blkB(GENESIS, 1, {}, {trx_hash_t(3), trx_hash_t(4)}, sig_t(1), blk_hash_t(3), addr_t(1)); @@ -419,9 +419,9 @@ TEST_F(DagTest, get_latest_pivot_tips) { auto trx_mgr = std::make_shared(FullNodeConfig(), db_ptr, nullptr, addr_t()); auto pbft_chain = std::make_shared(addr_t(), db_ptr); const blk_hash_t GENESIS = node_cfgs[0].genesis.dag_genesis_block.getHash(); - auto mgr = - std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), node_cfgs[0].genesis.sortition, - node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, nullptr, db_ptr, nullptr, 100000); + auto mgr = std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), + node_cfgs[0].genesis.sortition, node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, + nullptr, db_ptr, nullptr, 100000, node_cfgs[0].genesis.state); DagBlock blk2(GENESIS, 1, {}, {}, sig_t(1), blk_hash_t(2), addr_t(15)); DagBlock blk3(blk_hash_t(2), 2, {}, {}, sig_t(1), blk_hash_t(3), addr_t(15)); @@ -446,9 +446,9 @@ TEST_F(DagTest, initial_pivot) { auto db_ptr = std::make_shared(data_dir / "db"); auto trx_mgr = std::make_shared(FullNodeConfig(), db_ptr, nullptr, addr_t()); auto pbft_chain = std::make_shared(addr_t(), db_ptr); - auto mgr = - std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), node_cfgs[0].genesis.sortition, - node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, nullptr, db_ptr, nullptr, 100000); + auto mgr = std::make_shared(node_cfgs[0].genesis.dag_genesis_block, addr_t(), + node_cfgs[0].genesis.sortition, node_cfgs[0].genesis.dag, trx_mgr, pbft_chain, + nullptr, db_ptr, nullptr, 100000, node_cfgs[0].genesis.state); auto pt = mgr->getLatestPivotAndTips(); diff --git a/tests/full_node_test.cpp b/tests/full_node_test.cpp index f9df1ee239..770939230d 100644 --- a/tests/full_node_test.cpp +++ b/tests/full_node_test.cpp @@ -1433,11 +1433,17 @@ TEST_F(FullNodeTest, light_node) { non_empty_counter++; } } + + uint32_t non_empty_counter_full_node = 0; + for (uint64_t i = 0; i < nodes[0]->getPbftChain()->getPbftChainSize(); i++) { + const auto pbft_block = nodes[0]->getDB()->getPbftBlock(i); + if (pbft_block) { + non_empty_counter_full_node++; + } + } // Verify light node keeps at least light_node_history and it deletes old blocks EXPECT_GE(non_empty_counter, node_cfgs[1].light_node_history); - // Actual history size will be between 100% and 110% of light_node_history_ to - // avoid deleting on every period - EXPECT_LE(non_empty_counter, node_cfgs[1].light_node_history * 1.1 + node_cfgs[1].dag_expiry_limit); + EXPECT_LT(non_empty_counter, non_empty_counter_full_node); } TEST_F(FullNodeTest, clear_period_data) { diff --git a/tests/state_api_test.cpp b/tests/state_api_test.cpp index 3fd5dae072..723ac88150 100644 --- a/tests/state_api_test.cpp +++ b/tests/state_api_test.cpp @@ -235,7 +235,7 @@ TEST_F(StateAPITest, slashing) { ASSERT_EQ(true, slashing_manager->submitDoubleVotingProof(vote_a, vote_b)); // After few blocks malicious validator should be jailed - ASSERT_HAPPENS({5s, 100ms}, [&](auto& ctx) { + ASSERT_HAPPENS({10s, 100ms}, [&](auto& ctx) { WAIT_EXPECT_EQ( ctx, false, node->getFinalChain()->dpos_is_eligible(node->getFinalChain()->last_block_number(), node->getAddress()))