Skip to content

Commit

Permalink
fix: newHead notification and chainStats period
Browse files Browse the repository at this point in the history
  • Loading branch information
kstdl committed Jun 11, 2024
1 parent 1b10f9f commit a77075b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 33 deletions.
40 changes: 13 additions & 27 deletions libraries/core_libs/consensus/src/final_chain/final_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@

#include "common/constants.hpp"
#include "common/encoding_solidity.hpp"
#include "common/thread_pool.hpp"
#include "final_chain/cache.hpp"
#include "final_chain/trie_common.hpp"
#include "rewards/rewards_stats.hpp"
#include "transaction/system_transaction.hpp"
#include "vote/pbft_vote.hpp"

namespace taraxa::final_chain {

Expand Down Expand Up @@ -188,16 +186,17 @@ class FinalChainImpl final : public FinalChain {
}
} */

std::vector<state_api::EVMTransaction> evm_trxs;
append_evm_transactions(evm_trxs, new_blk.transactions);

SharedTransactions system_transactions;
std::vector<SharedTransaction> system_transactions;
const auto blk_num = new_blk.pbft_blk->getPeriod();
if (kHardforksConfig.ficus_hf.isPillarBlockPeriod(blk_num)) {
auto finalize_trx = make_bridge_finalization_transaction();
system_transactions.push_back(finalize_trx);
}
append_evm_transactions(evm_trxs, system_transactions);

auto all_transactions = new_blk.transactions;
all_transactions.insert(all_transactions.end(), system_transactions.begin(), system_transactions.end());
std::vector<state_api::EVMTransaction> evm_trxs;
append_evm_transactions(evm_trxs, all_transactions);

const auto& [exec_results] =
state_api_.execute_transactions({new_blk.pbft_blk->getBeneficiary(), kBlockGasLimit,
Expand Down Expand Up @@ -227,17 +226,18 @@ class FinalChainImpl final : public FinalChain {
auto rewards_stats = rewards_.processStats(new_blk, transactions_gas_used, batch);
const auto& [state_root, total_reward] = state_api_.distribute_rewards(rewards_stats);

auto blk_header = append_block(batch, new_blk.pbft_blk->getBeneficiary(), new_blk.pbft_blk->getTimestamp(),
kBlockGasLimit, state_root, total_reward, new_blk.transactions, system_transactions,
receipts, new_blk.pbft_blk->getExtraDataRlp());
auto blk_header =
append_block(batch, new_blk.pbft_blk->getBeneficiary(), new_blk.pbft_blk->getTimestamp(), kBlockGasLimit,
state_root, total_reward, all_transactions, 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() + system_transactions.size();
auto num_executed_trx = num_executed_trx_ + all_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);
LOG(log_nf_) << "Executed dag blocks #" << num_executed_dag_blk_ - finalized_dag_blk_hashes.size() << "-"
<< num_executed_dag_blk_ - 1 << " , Transactions count: " << new_blk.transactions.size();
<< num_executed_dag_blk_ - 1 << " , Transactions count: " << all_transactions.size();
}

//// Update DAG lvl mapping
Expand Down Expand Up @@ -268,7 +268,7 @@ class FinalChainImpl final : public FinalChain {
new_blk.pbft_blk->getBlockHash(),
},
blk_header,
std::move(new_blk.transactions),
std::move(all_transactions),
std::move(receipts),
});

Expand Down Expand Up @@ -321,7 +321,6 @@ class FinalChainImpl final : public FinalChain {
std::shared_ptr<BlockHeader> append_block(DB::Batch& batch, const addr_t& author, uint64_t timestamp,
uint64_t gas_limit, const h256& state_root, u256 total_reward,
const SharedTransactions& transactions = {},
const SharedTransactions& system_transactions = {},
const TransactionReceipts& receipts = {}, const bytes& extra_data = {}) {
auto blk_header_ptr = std::make_shared<BlockHeader>();
auto& blk_header = *blk_header_ptr;
Expand Down Expand Up @@ -349,19 +348,6 @@ class FinalChainImpl final : public FinalChain {

blk_header.log_bloom |= receipt.bloom();
}
if (system_transactions.size()) {
for (const auto& sys_trx : system_transactions) {
auto i_rlp = util::rlp_enc(rlp_strm, trx_idx);
trxs_trie[i_rlp] = sys_trx->rlp();

const auto& receipt = receipts[trx_idx];
receipts_trie[i_rlp] = util::rlp_enc(rlp_strm, receipt);
db_->insert(batch, DB::Columns::final_chain_receipt_by_trx_hash, sys_trx->getHash(), rlp_strm.out());

blk_header.log_bloom |= receipt.bloom();
trx_idx++;
}
}
blk_header.transactions_root = hash256(trxs_trie);
blk_header.receipts_root = hash256(receipts_trie);
rlp_strm.clear(), blk_header.ethereum_rlp(rlp_strm);
Expand Down
6 changes: 1 addition & 5 deletions libraries/core_libs/network/rpc/Taraxa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
#include <libdevcore/CommonJS.h>
#include <libp2p/Common.h>

#include <algorithm>

#include "dag/dag_manager.hpp"
#include "json/reader.h"
#include "network/rpc/eth/data.hpp"
#include "pbft/pbft_manager.hpp"
#include "pillar_chain/pillar_chain_manager.hpp"
#include "transaction/transaction_manager.hpp"

using namespace std;
Expand Down Expand Up @@ -146,7 +142,7 @@ Json::Value Taraxa::taraxa_getConfig() { return enc_json(tryGetNode()->getConfig
Json::Value Taraxa::taraxa_getChainStats() {
Json::Value res;
if (auto node = full_node_.lock()) {
res["pbft_period"] = Json::UInt64(node->getPbftChain()->getPbftChainSize());
res["pbft_period"] = Json::UInt64(node->getFinalChain()->last_block_number());
res["dag_blocks_executed"] = Json::UInt64(node->getDB()->getNumBlockExecuted());
res["transactions_executed"] = Json::UInt64(node->getDB()->getNumTransactionExecuted());
}
Expand Down
2 changes: 1 addition & 1 deletion submodules/taraxa-evm
Submodule taraxa-evm updated 1 files
+1 −1 taraxa/C/state.go

0 comments on commit a77075b

Please sign in to comment.