Skip to content

Commit

Permalink
Merge pull request #2778 from Taraxa-project/fix_executed_trx_count
Browse files Browse the repository at this point in the history
fix: ExecutedTrxCount in the db status
  • Loading branch information
MatusKysel authored Jun 10, 2024
2 parents 9e2820b + f4d3aa3 commit 1b10f9f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ class FinalChainImpl final : public FinalChain {
num_executed_dag_blk_ -= period_data.dag_blocks.size();
num_executed_trx_ -= period_data.transactions.size();
}
auto period_system_transactions = db_->getPeriodSystemTransactionsHashes(block_n);
num_executed_trx_ -= period_system_transactions.size();
}
db_->insert(batch, DB::Columns::status, StatusDbField::ExecutedBlkCount, num_executed_dag_blk_.load());
db_->insert(batch, DB::Columns::status, StatusDbField::ExecutedTrxCount, num_executed_trx_.load());
Expand Down Expand Up @@ -230,7 +232,7 @@ class FinalChainImpl final : public FinalChain {
receipts, new_blk.pbft_blk->getExtraDataRlp());
// Update number of executed DAG blocks and transactions
auto num_executed_dag_blk = num_executed_dag_blk_ + finalized_dag_blk_hashes.size();
auto num_executed_trx = num_executed_trx_ + new_blk.transactions.size();
auto num_executed_trx = num_executed_trx_ + new_blk.transactions.size() + system_transactions.size();
if (!finalized_dag_blk_hashes.empty()) {
db_->insert(batch, DB::Columns::status, StatusDbField::ExecutedBlkCount, num_executed_dag_blk);
db_->insert(batch, DB::Columns::status, StatusDbField::ExecutedTrxCount, num_executed_trx);
Expand Down
19 changes: 6 additions & 13 deletions tests/pillar_chain_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,23 @@ TEST_F(PillarChainTest, votes_count_changes) {

// Change validators delegation
const auto delegation_value = 2 * node_cfgs[0].genesis.state.dpos.eligibility_balance_threshold;
const auto vote_count_change_validators_count = validators_count - 1;
for (size_t i = 0; i < vote_count_change_validators_count; i++) {
for (size_t i = 0; i < validators_count; i++) {
const auto trx = make_delegate_tx(node_cfgs[i], delegation_value, 1, 1000);
nodes[0]->getTransactionManager()->insertTransaction(trx);
}

PbftPeriod executed_delegations_pbft_period = 1000000;
EXPECT_HAPPENS({20s, 1s}, [&](auto& ctx) {
EXPECT_HAPPENS({20s, 100ms}, [&](auto& ctx) {
for (auto& node : nodes) {
if (ctx.fail_if(node->getDB()->getNumTransactionExecuted() != vote_count_change_validators_count)) {
if (ctx.fail_if(node->getDB()->getNumTransactionExecuted() <= validators_count)) {
return;
}
const auto chain_size = node->getPbftChain()->getPbftChainSize();
if (chain_size < executed_delegations_pbft_period) {
executed_delegations_pbft_period = chain_size;
}
}
});
const auto chain_size = nodes[0]->getPbftChain()->getPbftChainSize();

// Wait until new pillar block with changed validators vote_counts is created
const auto new_pillar_block_period =
executed_delegations_pbft_period -
executed_delegations_pbft_period % node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval +
chain_size - chain_size % node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval +
node_cfgs[0].genesis.state.hardforks.ficus_hf.pillar_blocks_interval;
ASSERT_HAPPENS({20s, 250ms}, [&](auto& ctx) {
for (const auto& node : nodes) {
Expand All @@ -203,8 +197,7 @@ TEST_F(PillarChainTest, votes_count_changes) {
const auto new_pillar_block_data = node->getDB()->getPillarBlockData(new_pillar_block_period);
ASSERT_TRUE(new_pillar_block_data.has_value());
ASSERT_EQ(new_pillar_block_data->block_->getPeriod(), new_pillar_block_period);
ASSERT_EQ(new_pillar_block_data->block_->getValidatorsVoteCountsChanges().size(),
vote_count_change_validators_count);
ASSERT_EQ(new_pillar_block_data->block_->getValidatorsVoteCountsChanges().size(), validators_count);
size_t idx = 0;
for (const auto& vote_count_change : new_pillar_block_data->block_->getValidatorsVoteCountsChanges()) {
ASSERT_EQ(vote_count_change.vote_count_change_,
Expand Down

0 comments on commit 1b10f9f

Please sign in to comment.