Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubFornadel committed Jul 11, 2024
1 parent 03ab471 commit 025238b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion for_devs/local-net
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3.11

import click
import subprocess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"generated_rewards": "0x0"
},
"ficus_hf": {
"block_num": 50,
"block_num": 48,
"pillar_blocks_interval": 16,
"bridge_contract_address": "0xcAF2b453FE8382a4B8110356DF0508f6d71F22BF"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@
"ficus_hf": {
"block_num": 1000,
"pillar_blocks_interval": 100,
"pillar_chain_sync_interval": 25,
"pbft_inclusion_delay": 6,
"bridge_contract_address": "0xcAF2b453FE8382a4B8110356DF0508f6d71F22BF"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ class PbftManager {
bool already_next_voted_null_block_hash_ = false;
bool go_finish_state_ = false;
bool loop_back_finish_state_ = false;
bool last_placed_pillar_vote_period_ = 0;
PbftPeriod last_placed_pillar_vote_period_ = 0;

// Used to avoid cyclic logging in voting steps that are called repeatedly
bool printSecondFinishStepInfo_ = true;
Expand Down
17 changes: 8 additions & 9 deletions libraries/core_libs/consensus/src/pbft/pbft_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,10 +1204,14 @@ PbftManager::proposePbftBlock() {
}

// Creates pbft block's extra data
const auto extra_data = createPbftBlockExtraData(current_pbft_period);
if (!extra_data.has_value()) {
LOG(log_er_) << "Unable to propose pbft block due to wrong pillar block, pbft period: " << current_pbft_period;
return {};
std::optional<PbftBlockExtraData> extra_data;
if (kGenesisConfig.state.hardforks.ficus_hf.isFicusHardfork(current_pbft_period)) {
extra_data = createPbftBlockExtraData(current_pbft_period);
if (!extra_data.has_value()) {
LOG(log_er_) << "Unable to propose block for period " << current_pbft_period << ", round " << current_pbft_round
<< ". Empty extra data";
return {};
}
}

auto ghost = dag_mgr_->getGhostPath(last_period_dag_anchor_block_hash);
Expand Down Expand Up @@ -1301,17 +1305,12 @@ PbftManager::proposePbftBlock() {
}

std::optional<PbftBlockExtraData> PbftManager::createPbftBlockExtraData(PbftPeriod pbft_period) const {
if (!kGenesisConfig.state.hardforks.ficus_hf.isFicusHardfork(pbft_period)) {
return {};
}

std::optional<blk_hash_t> pillar_block_hash;
if (kGenesisConfig.state.hardforks.ficus_hf.isPbftWithPillarBlockPeriod(pbft_period)) {
// Anchor pillar block hash into the pbft block
const auto pillar_block = pillar_chain_mgr_->getCurrentPillarBlock();
if (!pillar_block) {
LOG(log_er_) << "Missing pillar block, pbft period " << pbft_period;
assert(false);
return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ std::shared_ptr<PillarVote> PillarChainManager::genAndPlacePillarVote(PbftPeriod

if (auto net = network_.lock(); net && broadcast_vote) {
net->gossipPillarBlockVote(vote);
LOG(log_nf_) << "Created & broadcast pillar vote " << vote->getHash() << " for block " << vote->getBlockHash()
<< ", period " << vote->getPeriod() << ", weight " << vote_weight;
LOG(log_nf_) << "Placed pillar vote " << vote->getHash() << " for block " << vote->getBlockHash() << ", period "
<< vote->getPeriod() << ", weight " << vote_weight;
} else {
LOG(log_nf_) << "Created pillar vote " << vote->getHash() << " for block " << vote->getBlockHash() << ", period "
<< vote->getPeriod() << ", weight " << vote_weight;
Expand Down Expand Up @@ -291,11 +291,13 @@ uint64_t PillarChainManager::addVerifiedPillarVote(const std::shared_ptr<PillarV
}

if (!pillar_votes_.addVerifiedVote(vote, validator_vote_count)) {
LOG(log_er_) << "Non-unique pillar vote " << vote->getHash() << ", validator " << vote->getVoterAddr();
LOG(log_er_) << "Non-unique pillar vote " << vote->getHash() << ", period " << vote->getPeriod() << ", validator "
<< vote->getVoterAddr();
return 0;
}

LOG(log_nf_) << "Added pillar vote " << vote->getHash();
LOG(log_nf_) << "Added pillar vote " << vote->getHash() << ", period " << vote->getPeriod() << ", pillar block hash "
<< vote->getBlockHash();

if (const auto current_pillar_block = getCurrentPillarBlock();
current_pillar_block && vote->getBlockHash() == current_pillar_block->getHash()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ExtPillarVotePacketHandler::ExtPillarVotePacketHandler(
bool ExtPillarVotePacketHandler::processPillarVote(const std::shared_ptr<PillarVote> &vote,
const std::shared_ptr<TaraxaPeer> &peer) {
if (!pillar_chain_manager_->isRelevantPillarVote(vote)) {
LOG(log_dg_) << "Drop irrelevant pillar vote " << vote->getHash() << " from peer " << peer->getId();
LOG(log_dg_) << "Drop irrelevant pillar vote " << vote->getHash() << ", period " << vote->getPeriod()
<< " from peer " << peer->getId();
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void PillarVotePacketHandler::process(const threadpool::PacketData &packet_data,
void PillarVotePacketHandler::onNewPillarVote(const std::shared_ptr<PillarVote> &vote, bool rebroadcast) {
for (const auto &peer : peers_state_->getAllPeers()) {
if (peer.second->syncing_) {
LOG(log_dg_) << "Pillar vote " << vote->getHash() << " not sent to " << peer.first << " peer syncing";
LOG(log_dg_) << "Pillar vote " << vote->getHash() << ", period " << vote->getPeriod() << " not sent to "
<< peer.first << ". Peer syncing";
continue;
}

Expand All @@ -55,7 +56,8 @@ void PillarVotePacketHandler::sendPillarVote(const std::shared_ptr<TaraxaPeer> &

if (sealAndSend(peer->getId(), SubprotocolPacketType::PillarVotePacket, std::move(s))) {
peer->markPillarVoteAsKnown(vote->getHash());
LOG(log_nf_) << "Pillar vote " << vote->getHash() << " sent to " << peer->getId();
LOG(log_dg_) << "Pillar vote " << vote->getHash() << ", period " << vote->getPeriod() << " sent to "
<< peer->getId();
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/pillar_chain_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ TEST_F(PillarChainTest, pillar_chain_syncing) {
pillar_blocks_count * node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval);

// 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
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)
Expand Down

0 comments on commit 025238b

Please sign in to comment.