From 5a798746efefa7d15d23d844a75aa323327d9efd Mon Sep 17 00:00:00 2001 From: Jakub Fornadel Date: Thu, 11 Jul 2024 13:21:36 -0700 Subject: [PATCH] refactor pillar votes syncing test --- .../src/pillar_chain/pillar_chain_manager.cpp | 2 +- ...get_pillar_votes_bundle_packet_handler.cpp | 4 +-- tests/pillar_chain_test.cpp | 25 +++++++++++-------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp index 309ec49665..0e224971f2 100644 --- a/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp +++ b/libraries/core_libs/consensus/src/pillar_chain/pillar_chain_manager.cpp @@ -284,7 +284,7 @@ uint64_t PillarChainManager::addVerifiedPillarVote(const std::shared_ptrgetPeriod())) { const auto threshold = getPillarConsensusThreshold(vote->getPeriod() - 1); if (!threshold) { - LOG(log_er_) << "Unable to get pillar consensus threshold for period " << vote->getPeriod(); + LOG(log_er_) << "Unable to get pillar consensus threshold for period " << vote->getPeriod() - 1; return 0; } pillar_votes_.initializePeriodData(vote->getPeriod(), *threshold); diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp index 8c3872e758..2c01eff1ae 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/get_pillar_votes_bundle_packet_handler.cpp @@ -31,7 +31,7 @@ void GetPillarVotesBundlePacketHandler::process(const threadpool::PacketData &pa throw MaliciousPeerException(err_msg.str()); } - if (!kConf.genesis.state.hardforks.ficus_hf.isPillarBlockPeriod(period)) { + if (!kConf.genesis.state.hardforks.ficus_hf.isPbftWithPillarBlockPeriod(period)) { std::ostringstream err_msg; err_msg << "Pillar votes bundle request for period " << period << ". Wrong requested period"; throw MaliciousPeerException(err_msg.str()); @@ -53,7 +53,7 @@ void GetPillarVotesBundlePacketHandler::process(const threadpool::PacketData &pa peer->markPillarVoteAsKnown(vote->getHash()); } - LOG(log_nf_) << "Pillar votes bundle for period " << period << " ans hash " << pillar_block_hash << " sent to " + LOG(log_nf_) << "Pillar votes bundle for period " << period << ", hash " << pillar_block_hash << " sent to " << peer->getId(); } } diff --git a/tests/pillar_chain_test.cpp b/tests/pillar_chain_test.cpp index ffd3842419..b7d20fe3aa 100644 --- a/tests/pillar_chain_test.cpp +++ b/tests/pillar_chain_test.cpp @@ -215,31 +215,34 @@ TEST_F(PillarChainTest, pillar_chain_syncing) { // Wait until node1 creates at least 3 pillar blocks const auto pillar_blocks_count = 3; ASSERT_HAPPENS({20s, 250ms}, [&](auto& ctx) { - WAIT_EXPECT_GE(ctx, node1->getFinalChain()->last_block_number(), - pillar_blocks_count * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval + 1) + WAIT_EXPECT_EQ(ctx, node1->getFinalChain()->last_block_number(), + pillar_blocks_count * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval) }); node1->getPbftManager()->stop(); // Start second node auto node2 = launch_nodes({node_cfgs[1]})[0]; // Wait until node2 syncs pbft chain with node1 - ASSERT_HAPPENS({20s, 250ms}, [&](auto& ctx) { + ASSERT_HAPPENS({20s, 200ms}, [&](auto& ctx) { WAIT_EXPECT_EQ(ctx, node2->getFinalChain()->last_block_number(), node1->getFinalChain()->last_block_number()) }); + node2->getPbftManager()->stop(); - // Pbft/pillar chain syncing works in a way that pbft block with period N contains pillar votes for pillar block with - // period N-ficus_hf.pillar_blocks_interval. + // Node 2 should not have yet finalized pillar block with period pillar_blocks_count * pillar_blocks_interval const auto node2_latest_finalized_pillar_block_data = node2->getDB()->getLatestPillarBlockData(); ASSERT_TRUE(node2_latest_finalized_pillar_block_data.has_value()); - // ASSERT_EQ(node2_latest_finalized_pillar_block_data->block_->getPeriod(), - // (pillar_blocks_count - 1) * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval); ASSERT_EQ(node2_latest_finalized_pillar_block_data->block_->getPeriod(), + (pillar_blocks_count - 1) * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval); + + // Node 2 should have already created pillar block with period pillar_blocks_count * pillar_blocks_interval + const auto node2_current_pillar_block_data = node2->getPillarChainManager()->getCurrentPillarBlock(); + ASSERT_TRUE(node2_current_pillar_block_data != nullptr); + ASSERT_EQ(node2_current_pillar_block_data->getPeriod(), pillar_blocks_count * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval); - // Trigger pillar votes syncing - // node2->getPillarChainManager()->checkPillarChainSynced( - // pillar_blocks_count * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval); - // Wait until node2 gets pillar votes and finalized pillar block #3 + // Trigger pillar votes syncing for the latest unfinalized pillar block + node2->getNetwork()->requestPillarBlockVotesBundle(node2_current_pillar_block_data->getPeriod() + 1, node2_current_pillar_block_data->getHash()); + // After pillar votes syncing, node 2 should not have already finalized pillar block with period pillar_blocks_count * pillar_blocks_interval ASSERT_HAPPENS({20s, 250ms}, [&](auto& ctx) { WAIT_EXPECT_EQ(ctx, node2->getDB()->getLatestPillarBlockData()->block_->getPeriod(), pillar_blocks_count * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval)