From 2d1bd42a65c1a72b62e172c6ffff110cd18e11a8 Mon Sep 17 00:00:00 2001 From: Jakub Fornadel Date: Sat, 2 Nov 2024 19:13:17 +0100 Subject: [PATCH 1/2] refactor dag blocks processing to work with shared pointers to avoid objects copying --- .../include/dag/dag_block_proposer.hpp | 4 +- .../consensus/include/dag/dag_manager.hpp | 13 +- .../consensus/include/pbft/pbft_manager.hpp | 6 +- .../consensus/src/dag/dag_block_proposer.cpp | 20 +- .../consensus/src/dag/dag_manager.cpp | 128 ++--- .../src/dag/sortition_params_manager.cpp | 2 +- .../consensus/src/pbft/pbft_manager.cpp | 16 +- .../consensus/src/rewards/block_stats.cpp | 14 +- .../network/include/network/network.hpp | 2 +- .../packets/latest/dag_block_packet.hpp | 2 +- .../latest/dag_block_packet_handler.hpp | 7 +- .../v4/dag_block_packet_handler.hpp | 7 +- .../network/include/network/ws_server.hpp | 4 +- libraries/core_libs/network/src/network.cpp | 2 +- .../latest/dag_block_packet_handler.cpp | 34 +- .../latest/dag_sync_packet_handler.cpp | 5 +- .../latest/pbft_sync_packet_handler.cpp | 8 +- .../v4/dag_block_packet_handler.cpp | 36 +- .../v4/dag_sync_packet_handler.cpp | 20 +- .../v4/pbft_sync_packet_handler.cpp | 8 +- libraries/core_libs/network/src/ws_server.cpp | 6 +- libraries/core_libs/node/src/node.cpp | 2 +- .../storage/include/storage/storage.hpp | 6 +- libraries/core_libs/storage/src/storage.cpp | 72 ++- .../include/dag/dag_block_bundle_rlp.hpp | 4 +- .../dag_block/src/dag_block_bundle_rlp.cpp | 14 +- .../pbft_block/include/pbft/period_data.hpp | 2 +- .../types/pbft_block/src/period_data.cpp | 4 +- tests/dag_block_test.cpp | 53 +- tests/dag_test.cpp | 180 ++++--- tests/final_chain_test.cpp | 5 +- tests/full_node_test.cpp | 25 +- tests/network_test.cpp | 244 +++++----- tests/pbft_chain_test.cpp | 4 +- tests/rewards_stats_test.cpp | 28 +- tests/sortition_test.cpp | 4 +- .../test_util/node_dag_creation_fixture.hpp | 2 +- tests/test_util/include/test_util/samples.hpp | 7 +- .../src/node_dag_creation_fixture.cpp | 13 +- tests/test_util/src/samples.cpp | 457 ++++++++---------- tests/transaction_test.cpp | 5 +- 41 files changed, 764 insertions(+), 711 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 5ceb738401..9e1fea8fc6 100644 --- a/libraries/core_libs/consensus/include/dag/dag_block_proposer.hpp +++ b/libraries/core_libs/consensus/include/dag/dag_block_proposer.hpp @@ -90,8 +90,8 @@ class DagBlockProposer { * @param estimations transactions gas estimation * @param vdf vdf with correct difficulty calculation */ - DagBlock createDagBlock(DagFrontier&& frontier, level_t level, const SharedTransactions& trxs, - std::vector&& estimations, VdfSortition&& vdf) const; + std::shared_ptr createDagBlock(DagFrontier&& frontier, level_t level, const SharedTransactions& trxs, + std::vector&& estimations, VdfSortition&& vdf) const; /** * @brief Gets transactions to include in the block - sharding not supported yet diff --git a/libraries/core_libs/consensus/include/dag/dag_manager.hpp b/libraries/core_libs/consensus/include/dag/dag_manager.hpp index 62232a57e9..4eb8eb0e4a 100644 --- a/libraries/core_libs/consensus/include/dag/dag_manager.hpp +++ b/libraries/core_libs/consensus/include/dag/dag_manager.hpp @@ -79,14 +79,15 @@ class DagManager : public std::enable_shared_from_this { * @return verification result and all the transactions which are part of the block */ std::pair verifyBlock( - const DagBlock &blk, const std::unordered_map> &trxs = {}); + const std::shared_ptr &blk, + const std::unordered_map> &trxs = {}); /** * @brief Checks if block pivot and tips are in DAG * @param blk Block to check * @return true if all pivot and tips are in the DAG, false if some is missing with the hash of missing tips/pivot */ - std::pair> pivotAndTipsAvailable(DagBlock const &blk); + std::pair> pivotAndTipsAvailable(const std::shared_ptr &blk); /** * @brief adds verified DAG block in the DAG @@ -95,8 +96,8 @@ class DagManager : public std::enable_shared_from_this { * @param save if true save block and transactions to database * @return true if block added successfully, false with the hash of missing tips/pivot */ - std::pair> addDagBlock(DagBlock &&blk, SharedTransactions &&trxs = {}, - bool proposed = false, + std::pair> addDagBlock(const std::shared_ptr &blk, + SharedTransactions &&trxs = {}, bool proposed = false, bool save = true); // insert to buffer if fail /** @@ -184,7 +185,7 @@ class DagManager : public std::enable_shared_from_this { */ std::pair getNonFinalizedBlocksSize() const; - util::Event const block_verified_{}; + util::Event> const block_verified_{}; /** * @brief Retrieves Dag Manager mutex, only to be used when finalizing pbft block @@ -273,7 +274,7 @@ class DagManager : public std::enable_shared_from_this { const uint32_t cache_max_size_ = 10000; const uint32_t cache_delete_step_ = 100; - ExpirationCacheMap seen_blocks_; + ExpirationCacheMap> seen_blocks_; std::shared_ptr final_chain_; const uint64_t kPbftGasLimit; const HardforksConfig kHardforks; diff --git a/libraries/core_libs/consensus/include/pbft/pbft_manager.hpp b/libraries/core_libs/consensus/include/pbft/pbft_manager.hpp index 9bdbaed94e..6e8d46fb6e 100644 --- a/libraries/core_libs/consensus/include/pbft/pbft_manager.hpp +++ b/libraries/core_libs/consensus/include/pbft/pbft_manager.hpp @@ -212,7 +212,7 @@ class PbftManager { * @param dag_blocks DAG blocks * @return DAG blocks ordering hash */ - static blk_hash_t calculateOrderHash(const std::vector &dag_blocks); + static blk_hash_t calculateOrderHash(const std::vector> &dag_blocks); /** * @brief Reorder transactions data if DAG reordering caused transactions with same sender to have nonce in incorrect @@ -226,7 +226,7 @@ class PbftManager { * @param dag_blocks dag blocks * @return true if total weight of gas estimation is less or equal to gas limit. Otherwise return false */ - bool checkBlockWeight(const std::vector &dag_blocks) const; + bool checkBlockWeight(const std::vector> &dag_blocks) const; blk_hash_t getLastPbftBlockHash(); @@ -564,7 +564,7 @@ class PbftManager { // Multiple proposed pbft blocks could have same dag block anchor at same period so this cache improves retrieval of // dag block order for specific anchor - mutable std::unordered_map> anchor_dag_block_order_cache_; + mutable std::unordered_map>> anchor_dag_block_order_cache_; std::unique_ptr daemon_; std::shared_ptr db_; 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 cdc137af23..9f9b486d68 100644 --- a/libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp +++ b/libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp @@ -157,12 +157,12 @@ bool DagBlockProposer::proposeDagBlock() { auto dag_block = createDagBlock(std::move(frontier), propose_level, transactions, std::move(estimations), std::move(vdf)); - if (dag_mgr_->addDagBlock(std::move(dag_block), std::move(transactions), true).first) { - LOG(log_nf_) << "Proposed new DAG block " << dag_block.getHash() << ", pivot " << dag_block.getPivot() - << " , txs num " << dag_block.getTrxs().size(); + if (dag_mgr_->addDagBlock(dag_block, std::move(transactions), true).first) { + LOG(log_nf_) << "Proposed new DAG block " << dag_block->getHash() << ", pivot " << dag_block->getPivot() + << " , txs num " << dag_block->getTrxs().size(); proposed_blocks_count_ += 1; } else { - LOG(log_er_) << "Failed to add newly proposed dag block " << dag_block.getHash() << " into dag"; + LOG(log_er_) << "Failed to add newly proposed dag block " << dag_block->getHash() << " into dag"; } last_propose_level_ = propose_level; @@ -320,8 +320,10 @@ vec_blk_t DagBlockProposer::selectDagBlockTips(const vec_blk_t& frontier_tips, u return tips; } -DagBlock DagBlockProposer::createDagBlock(DagFrontier&& frontier, level_t level, const SharedTransactions& trxs, - std::vector&& estimations, VdfSortition&& vdf) const { +std::shared_ptr DagBlockProposer::createDagBlock(DagFrontier&& frontier, level_t level, + const SharedTransactions& trxs, + std::vector&& estimations, + VdfSortition&& vdf) const { // When we propose block we know it is valid, no need for block verification with queue, // simply add the block to the DAG vec_trx_t trx_hashes; @@ -336,10 +338,8 @@ DagBlock DagBlockProposer::createDagBlock(DagFrontier&& frontier, level_t level, frontier.tips = selectDagBlockTips(frontier.tips, kPbftGasLimit - block_estimation); } - DagBlock block(frontier.pivot, std::move(level), std::move(frontier.tips), std::move(trx_hashes), block_estimation, - std::move(vdf), node_sk_); - - return block; + return std::make_shared(frontier.pivot, std::move(level), std::move(frontier.tips), std::move(trx_hashes), + block_estimation, std::move(vdf), node_sk_); } bool DagBlockProposer::isValidDposProposer(PbftPeriod propose_period) const { diff --git a/libraries/core_libs/consensus/src/dag/dag_manager.cpp b/libraries/core_libs/consensus/src/dag/dag_manager.cpp index b08db434e4..7bfbb8791f 100644 --- a/libraries/core_libs/consensus/src/dag/dag_manager.cpp +++ b/libraries/core_libs/consensus/src/dag/dag_manager.cpp @@ -88,9 +88,9 @@ void DagManager::drawPivotGraph(std::string const &str) const { pivot_tree_->drawGraph(str); } -std::pair> DagManager::pivotAndTipsAvailable(DagBlock const &blk) { - auto dag_blk_hash = blk.getHash(); - const auto pivot_hash = blk.getPivot(); +std::pair> DagManager::pivotAndTipsAvailable(const std::shared_ptr &blk) { + auto dag_blk_hash = blk->getHash(); + const auto pivot_hash = blk->getPivot(); const auto dag_blk_pivot = getDagBlock(pivot_hash); std::vector missing_tips_or_pivot; @@ -102,7 +102,7 @@ std::pair> DagManager::pivotAndTipsAvailable(DagBl missing_tips_or_pivot.push_back(pivot_hash); } - for (auto const &tip : blk.getTips()) { + for (auto const &tip : blk->getTips()) { auto tip_block = getDagBlock(tip); if (tip_block) { expected_level = std::max(expected_level, tip_block->getLevel() + 1); @@ -116,8 +116,8 @@ std::pair> DagManager::pivotAndTipsAvailable(DagBl return {false, missing_tips_or_pivot}; } - if (expected_level != blk.getLevel()) { - LOG(log_er_) << "DAG Block " << dag_blk_hash << " level " << blk.getLevel() + if (expected_level != blk->getLevel()) { + LOG(log_er_) << "DAG Block " << dag_blk_hash << " level " << blk->getLevel() << ", expected level: " << expected_level; return {false, missing_tips_or_pivot}; } @@ -130,9 +130,9 @@ DagFrontier DagManager::getDagFrontier() { return frontier_; } -std::pair> DagManager::addDagBlock(DagBlock &&blk, SharedTransactions &&trxs, - bool proposed, bool save) { - auto blk_hash = blk.getHash(); +std::pair> DagManager::addDagBlock(const std::shared_ptr &blk, + SharedTransactions &&trxs, bool proposed, bool save) { + auto blk_hash = blk->getHash(); { // One mutex protects the DagManager internal state, the other mutex ensures that dag blocks are gossiped in @@ -142,14 +142,14 @@ std::pair> DagManager::addDagBlock(DagBlock &&blk, { std::scoped_lock lock(mutex_); if (save) { - if (db_->dagBlockInDb(blk.getHash())) { + if (db_->dagBlockInDb(blk->getHash())) { // It is a valid scenario that two threads can receive same block from two peers and process at same time return {true, {}}; } - if (blk.getLevel() < dag_expiry_level_) { + if (blk->getLevel() < dag_expiry_level_) { LOG(log_nf_) << "Dropping old block: " << blk_hash << ". Expiry level: " << dag_expiry_level_ - << ". Block level: " << blk.getLevel(); + << ". Block level: " << blk->getLevel(); return {false, {}}; } @@ -162,14 +162,14 @@ std::pair> DagManager::addDagBlock(DagBlock &&blk, // Save the dag block db_->saveDagBlock(blk); } - seen_blocks_.insert(blk.getHash(), blk); - auto pivot_hash = blk.getPivot(); + seen_blocks_.insert(blk->getHash(), blk); + auto pivot_hash = blk->getPivot(); - std::vector tips = blk.getTips(); + std::vector tips = blk->getTips(); level_t current_max_level = max_level_; - max_level_ = std::max(current_max_level, blk.getLevel()); + max_level_ = std::max(current_max_level, blk->getLevel()); - addToDag(blk_hash, pivot_hash, tips, blk.getLevel()); + addToDag(blk_hash, pivot_hash, tips, blk->getLevel()); updateFrontier(); } @@ -332,11 +332,11 @@ uint DagManager::setDagBlockOrder(blk_hash_t const &new_anchor, PbftPeriod perio } // Only update counter for blocks that are in the dag_order and not in memory DAG, this is only possible when pbft // syncing and processing period data - std::vector dag_blocks_to_update_counters; + std::vector> dag_blocks_to_update_counters; for (auto const &blk : dag_order) { if (non_finalized_blocks_set.count(blk) == 0) { auto dag_block = getDagBlock(blk); - dag_blocks_to_update_counters.push_back(*dag_block); + dag_blocks_to_update_counters.push_back(dag_block); } } @@ -483,38 +483,38 @@ void DagManager::recoverDag() { for (auto &blk : lvl.second) { // These are some sanity checks that difficulty is correct and block is truly non-finalized. // This is only done on startup - auto period = db_->getDagBlockPeriod(blk.getHash()); + auto period = db_->getDagBlockPeriod(blk->getHash()); if (period != nullptr) { LOG(log_er_) << "Nonfinalized Dag Block actually finalized in period " << period->first; break; } else { - auto propose_period = db_->getProposalPeriodForDagLevel(blk.getLevel()); + auto propose_period = db_->getProposalPeriodForDagLevel(blk->getLevel()); if (!propose_period.has_value()) { - LOG(log_er_) << "No propose period for dag level " << blk.getLevel() << " found"; + LOG(log_er_) << "No propose period for dag level " << blk->getLevel() << " found"; assert(false); break; } - const auto pk = key_manager_->getVrfKey(*propose_period, blk.getSender()); + const auto pk = key_manager_->getVrfKey(*propose_period, blk->getSender()); if (!pk) { - LOG(log_er_) << "DAG block " << blk.getHash() << " with " << blk.getLevel() - << " level is missing VRF key for sender " << blk.getSender(); + LOG(log_er_) << "DAG block " << blk->getHash() << " with " << blk->getLevel() + << " level is missing VRF key for sender " << blk->getSender(); break; } // Verify VDF solution try { uint64_t max_vote_count = 0; - const auto vote_count = final_chain_->dposEligibleVoteCount(*propose_period, blk.getSender()); + const auto vote_count = final_chain_->dposEligibleVoteCount(*propose_period, blk->getSender()); if (*propose_period < kHardforks.magnolia_hf.block_num) { max_vote_count = final_chain_->dposEligibleTotalVoteCount(*propose_period); } else { max_vote_count = kValidatorMaxVote; } - blk.verifyVdf(sortition_params_manager_.getSortitionParams(*propose_period), - db_->getPeriodBlockHash(*propose_period), *pk, vote_count, max_vote_count); + blk->verifyVdf(sortition_params_manager_.getSortitionParams(*propose_period), + 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 " + LOG(log_er_) << "DAG block " << blk->getHash() << " with " << blk->getLevel() + << " level failed on VDF verification with pivot hash " << blk->getPivot() << " reason " << e.what(); break; } @@ -523,14 +523,14 @@ void DagManager::recoverDag() { // In case an invalid block somehow ended in DAG db, remove it auto res = pivotAndTipsAvailable(blk); if (res.first) { - if (!addDagBlock(std::move(blk), {}, false, false).first) { - LOG(log_er_) << "DAG block " << blk.getHash() << " could not be added to DAG on startup, removing from db"; - db_->removeDagBlock(blk.getHash()); + if (!addDagBlock(blk, {}, false, false).first) { + LOG(log_er_) << "DAG block " << blk->getHash() << " could not be added to DAG on startup, removing from db"; + db_->removeDagBlock(blk->getHash()); } } else { - LOG(log_er_) << "DAG block " << blk.getHash() + LOG(log_er_) << "DAG block " << blk->getHash() << " could not be added to DAG on startup since it has missing tip/pivot"; - db_->removeDagBlock(blk.getHash()); + db_->removeDagBlock(blk->getHash()); } } } @@ -584,34 +584,34 @@ std::pair DagManager::getNonFinalizedBlocksSize() const { } std::pair DagManager::verifyBlock( - const DagBlock &blk, const std::unordered_map> &trxs) { - const auto &block_hash = blk.getHash(); - vec_trx_t const &all_block_trx_hashes = blk.getTrxs(); + const std::shared_ptr &blk, const std::unordered_map> &trxs) { + const auto &block_hash = blk->getHash(); + vec_trx_t const &all_block_trx_hashes = blk->getTrxs(); vec_trx_t trx_hashes_to_query; SharedTransactions all_block_trxs; // Verify tips/pivot count and uniqueness std::unordered_set unique_tips_pivot; - unique_tips_pivot.insert(blk.getPivot()); - if (blk.getTips().size() > kDagBlockMaxTips) { - LOG(log_er_) << "DAG Block " << block_hash << " tips count " << blk.getTips().size() << " over the limit"; + unique_tips_pivot.insert(blk->getPivot()); + if (blk->getTips().size() > kDagBlockMaxTips) { + LOG(log_er_) << "DAG Block " << block_hash << " tips count " << blk->getTips().size() << " over the limit"; return {VerifyBlockReturnType::FailedTipsVerification, {}}; } - for (auto const &tip : blk.getTips()) { + for (auto const &tip : blk->getTips()) { if (!unique_tips_pivot.insert(tip).second) { LOG(log_er_) << "DAG Block " << block_hash << " tip " << tip << " duplicate"; return {VerifyBlockReturnType::FailedTipsVerification, {}}; } } - auto propose_period = db_->getProposalPeriodForDagLevel(blk.getLevel()); + auto propose_period = db_->getProposalPeriodForDagLevel(blk->getLevel()); // Verify DPOS if (!propose_period.has_value()) { // Cannot find the proposal period in DB yet. The slow node gets an ahead block, remove from seen_blocks - LOG(log_nf_) << "Cannot find proposal period in DB for DAG block " << blk.getHash(); + LOG(log_nf_) << "Cannot find proposal period in DB for DAG block " << blk->getHash(); seen_blocks_.erase(block_hash); return {VerifyBlockReturnType::AheadBlock, {}}; } @@ -643,39 +643,39 @@ std::pair DagManager::ver all_block_trxs.emplace_back(std::move(t)); } - if (blk.getLevel() < dag_expiry_level_) { - LOG(log_nf_) << "Dropping old block: " << blk.getHash() << ". Expiry level: " << dag_expiry_level_ - << ". Block level: " << blk.getLevel(); + if (blk->getLevel() < dag_expiry_level_) { + LOG(log_nf_) << "Dropping old block: " << blk->getHash() << ". Expiry level: " << dag_expiry_level_ + << ". Block level: " << blk->getLevel(); return {VerifyBlockReturnType::ExpiredBlock, {}}; } // Verify VDF solution - const auto pk = key_manager_->getVrfKey(*propose_period, blk.getSender()); + const auto pk = key_manager_->getVrfKey(*propose_period, blk->getSender()); if (!pk) { - LOG(log_er_) << "DAG block " << blk.getHash() << " with " << blk.getLevel() - << " level is missing VRF key for sender " << blk.getSender(); + LOG(log_er_) << "DAG block " << blk->getHash() << " with " << blk->getLevel() + << " level is missing VRF key for sender " << blk->getSender(); return {VerifyBlockReturnType::FailedVdfVerification, {}}; } try { const auto proposal_period_hash = db_->getPeriodBlockHash(*propose_period); uint64_t max_vote_count = 0; - const auto vote_count = final_chain_->dposEligibleVoteCount(*propose_period, blk.getSender()); + const auto vote_count = final_chain_->dposEligibleVoteCount(*propose_period, blk->getSender()); if (*propose_period < kHardforks.magnolia_hf.block_num) { max_vote_count = final_chain_->dposEligibleTotalVoteCount(*propose_period); } else { max_vote_count = kValidatorMaxVote; } - blk.verifyVdf(sortition_params_manager_.getSortitionParams(*propose_period), proposal_period_hash, *pk, vote_count, - max_vote_count); + blk->verifyVdf(sortition_params_manager_.getSortitionParams(*propose_period), proposal_period_hash, *pk, 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(); + LOG(log_er_) << "DAG block " << block_hash << " with " << blk->getLevel() + << " level failed on VDF verification with pivot hash " << blk->getPivot() << " reason " << e.what(); LOG(log_er_) << "period from map: " << *propose_period << " current: " << pbft_chain_->getPbftChainSize(); return {VerifyBlockReturnType::FailedVdfVerification, {}}; } - auto dag_block_sender = blk.getSender(); + auto dag_block_sender = blk->getSender(); bool dpos_qualified; try { dpos_qualified = final_chain_->dposIsEligible(*propose_period, dag_block_sender); @@ -691,27 +691,27 @@ std::pair DagManager::ver } { u256 total_block_weight = 0; - auto block_gas_estimation = blk.getGasEstimation(); + auto block_gas_estimation = blk->getGasEstimation(); for (const auto &trx : all_block_trxs) { total_block_weight += trx_mgr_->estimateTransactionGas(trx, propose_period); } if (total_block_weight != block_gas_estimation) { - LOG(log_er_) << "Invalid block_gas_estimation. DAG block " << blk.getHash() + LOG(log_er_) << "Invalid block_gas_estimation. DAG block " << blk->getHash() << " block_gas_estimation: " << block_gas_estimation << " total_block_weight " << total_block_weight << " current period " << final_chain_->lastBlockNumber(); return {VerifyBlockReturnType::IncorrectTransactionsEstimation, {}}; } if (total_block_weight > getDagConfig().gas_limit) { - LOG(log_er_) << "BlockTooBig. DAG block " << blk.getHash() << " gas_limit: " << getDagConfig().gas_limit + LOG(log_er_) << "BlockTooBig. DAG block " << blk->getHash() << " gas_limit: " << getDagConfig().gas_limit << " total_block_weight " << total_block_weight << " current period " << final_chain_->lastBlockNumber(); return {VerifyBlockReturnType::BlockTooBig, {}}; } - if ((blk.getTips().size() + 1) > kPbftGasLimit / getDagConfig().gas_limit) { - for (const auto &t : blk.getTips()) { + if ((blk->getTips().size() + 1) > kPbftGasLimit / getDagConfig().gas_limit) { + for (const auto &t : blk->getTips()) { const auto tip_blk = getDagBlock(t); if (tip_blk == nullptr) { LOG(log_er_) << "DAG Block " << block_hash << " tip " << t << " not present"; @@ -720,7 +720,7 @@ std::pair DagManager::ver block_gas_estimation += tip_blk->getGasEstimation(); } if (block_gas_estimation > kPbftGasLimit) { - LOG(log_er_) << "BlockTooBig. DAG block " << blk.getHash() << " with tips has limit: " << kPbftGasLimit + LOG(log_er_) << "BlockTooBig. DAG block " << blk->getHash() << " with tips has limit: " << kPbftGasLimit << " block_gas_estimation " << block_gas_estimation << " current period " << final_chain_->lastBlockNumber(); return {VerifyBlockReturnType::BlockTooBig, {}}; @@ -728,7 +728,7 @@ std::pair DagManager::ver } } - LOG(log_dg_) << "Verified DAG block " << blk.getHash(); + LOG(log_dg_) << "Verified DAG block " << blk->getHash(); return {VerifyBlockReturnType::Verified, std::move(all_block_trxs)}; } @@ -744,7 +744,7 @@ bool DagManager::isDagBlockKnown(const blk_hash_t &hash) const { std::shared_ptr DagManager::getDagBlock(const blk_hash_t &hash) const { auto blk = seen_blocks_.get(hash); if (blk.second) { - return std::make_shared(blk.first); + return blk.first; } if (hash == genesis_block_->getHash()) { return genesis_block_; diff --git a/libraries/core_libs/consensus/src/dag/sortition_params_manager.cpp b/libraries/core_libs/consensus/src/dag/sortition_params_manager.cpp index 69d1158486..ab8894fda7 100644 --- a/libraries/core_libs/consensus/src/dag/sortition_params_manager.cpp +++ b/libraries/core_libs/consensus/src/dag/sortition_params_manager.cpp @@ -79,7 +79,7 @@ SortitionParams SortitionParamsManager::getSortitionParams(std::optionalgetTrxs(); total_transactions_count += trxs.size(); } diff --git a/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp b/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp index 7ad1a51a68..499afd3cdb 100644 --- a/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp +++ b/libraries/core_libs/consensus/src/pbft/pbft_manager.cpp @@ -1169,14 +1169,14 @@ blk_hash_t PbftManager::calculateOrderHash(const std::vector &dag_bl return dev::sha3(order_stream.out()); } -blk_hash_t PbftManager::calculateOrderHash(const std::vector &dag_blocks) { +blk_hash_t PbftManager::calculateOrderHash(const std::vector> &dag_blocks) { if (dag_blocks.empty()) { return kNullBlockHash; } dev::RLPStream order_stream(1); order_stream.appendList(dag_blocks.size()); for (auto const &blk : dag_blocks) { - order_stream << blk.getHash(); + order_stream << blk->getHash(); } return dev::sha3(order_stream.out()); } @@ -1534,7 +1534,7 @@ bool PbftManager::validatePbftBlock(const std::shared_ptr &pbft_block for (auto const &dag_blk_hash : dag_blocks_order) { auto dag_block = dag_mgr_->getDagBlock(dag_blk_hash); assert(dag_block); - anchor_dag_block_order_cache_[anchor_hash].emplace_back(std::move(*dag_block)); + anchor_dag_block_order_cache_[anchor_hash].emplace_back(std::move(dag_block)); } auto last_pbft_block_hash = pbft_chain_->getLastPbftBlockHash(); @@ -1564,7 +1564,7 @@ bool PbftManager::pushCertVotedPbftBlockIntoChain_(const std::shared_ptr transactions_to_query; period_data.dag_blocks.reserve(dag_order_it->second.size()); for (const auto &dag_blk : dag_order_it->second) { - for (const auto &trx_hash : dag_blk.getTrxs()) { + for (const auto &trx_hash : dag_blk->getTrxs()) { if (trx_set.insert(trx_hash).second) { transactions_to_query.emplace_back(trx_hash); } @@ -1735,7 +1735,7 @@ bool PbftManager::pushPbftBlock_(PeriodData &&period_data, std::vectorgetHash(); }); // We need to reorder transactions before saving them reorderTransactions(period_data.transactions); @@ -1919,7 +1919,7 @@ std::optional>>> Pbf std::unordered_set trx_set; std::vector transactions_to_query; for (auto const &dag_block : period_data.dag_blocks) { - for (auto const &trx_hash : dag_block.getTrxs()) { + for (auto const &trx_hash : dag_block->getTrxs()) { if (trx_set.insert(trx_hash).second) { transactions_to_query.emplace_back(trx_hash); } @@ -2144,10 +2144,10 @@ void PbftManager::periodDataQueuePush(PeriodData &&period_data, dev::p2p::NodeID size_t PbftManager::periodDataQueueSize() const { return sync_queue_.size(); } -bool PbftManager::checkBlockWeight(const std::vector &dag_blocks) const { +bool PbftManager::checkBlockWeight(const std::vector> &dag_blocks) const { const u256 total_weight = std::accumulate(dag_blocks.begin(), dag_blocks.end(), u256(0), - [](u256 value, const auto &dag_block) { return value + dag_block.getGasEstimation(); }); + [](u256 value, const auto &dag_block) { return value + dag_block->getGasEstimation(); }); if (total_weight > kGenesisConfig.pbft.gas_limit) { return false; } diff --git a/libraries/core_libs/consensus/src/rewards/block_stats.cpp b/libraries/core_libs/consensus/src/rewards/block_stats.cpp index 643e098eee..caa02c32cb 100644 --- a/libraries/core_libs/consensus/src/rewards/block_stats.cpp +++ b/libraries/core_libs/consensus/src/rewards/block_stats.cpp @@ -86,9 +86,9 @@ void BlockStats::processStats(const PeriodData& block, const bool aspen_dag_rewa void BlockStats::processDagBlocks(const PeriodData& block) { auto block_transactions_hashes_ = toTrxHashesSet(block.transactions); for (const auto& dag_block : block.dag_blocks) { - const addr_t& dag_block_author = dag_block.getSender(); + const addr_t& dag_block_author = dag_block->getSender(); bool has_unique_transactions = false; - for (const auto& tx_hash : dag_block.getTrxs()) { + for (const auto& tx_hash : dag_block->getTrxs()) { // we should also check that we have transactions in pbft block(period data). Because in dag blocks could be // included transaction that was finalized in previous blocks if (!block_transactions_hashes_.contains(tx_hash)) { @@ -110,17 +110,17 @@ void BlockStats::processDagBlocks(const PeriodData& block) { void BlockStats::processDagBlocksAspen(const PeriodData& block) { uint16_t min_difficulty = UINT16_MAX; for (const auto& dag_block : block.dag_blocks) { - if (dag_block.getDifficulty() < min_difficulty) { - min_difficulty = dag_block.getDifficulty(); + if (dag_block->getDifficulty() < min_difficulty) { + min_difficulty = dag_block->getDifficulty(); } } for (const auto& dag_block : block.dag_blocks) { - const addr_t& dag_block_author = dag_block.getSender(); - if (dag_block.getDifficulty() == min_difficulty) { + const addr_t& dag_block_author = dag_block->getSender(); + if (dag_block->getDifficulty() == min_difficulty) { validators_stats_[dag_block_author].dag_blocks_count_ += 1; total_dag_blocks_count_ += 1; } - for (const auto& tx_hash : dag_block.getTrxs()) { + for (const auto& tx_hash : dag_block->getTrxs()) { addTransaction(tx_hash, dag_block_author); } } diff --git a/libraries/core_libs/network/include/network/network.hpp b/libraries/core_libs/network/include/network/network.hpp index 36d55064b5..9cce7ec551 100644 --- a/libraries/core_libs/network/include/network/network.hpp +++ b/libraries/core_libs/network/include/network/network.hpp @@ -55,7 +55,7 @@ class Network { uint64_t syncTimeSeconds() const; void setSyncStatePeriod(PbftPeriod period); - void gossipDagBlock(const DagBlock &block, bool proposed, const SharedTransactions &trxs); + void gossipDagBlock(const std::shared_ptr &block, bool proposed, const SharedTransactions &trxs); void gossipVote(const std::shared_ptr &vote, const std::shared_ptr &block, bool rebroadcast = false); void gossipVotesBundle(const std::vector> &votes, bool rebroadcast = false); diff --git a/libraries/core_libs/network/include/network/tarcap/packets/latest/dag_block_packet.hpp b/libraries/core_libs/network/include/network/tarcap/packets/latest/dag_block_packet.hpp index f624996840..092bc55054 100644 --- a/libraries/core_libs/network/include/network/tarcap/packets/latest/dag_block_packet.hpp +++ b/libraries/core_libs/network/include/network/tarcap/packets/latest/dag_block_packet.hpp @@ -7,7 +7,7 @@ namespace taraxa::network::tarcap { struct DagBlockPacket { std::vector> transactions; - DagBlock dag_block; + std::shared_ptr dag_block; RLP_FIELDS_DEFINE_INPLACE(transactions, dag_block) }; diff --git a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/dag_block_packet_handler.hpp b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/dag_block_packet_handler.hpp index 4d99d08cba..a639a57301 100644 --- a/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/dag_block_packet_handler.hpp +++ b/libraries/core_libs/network/include/network/tarcap/packets_handlers/latest/dag_block_packet_handler.hpp @@ -18,10 +18,11 @@ class DagBlockPacketHandler : public ExtSyncingPacketHandler { std::shared_ptr trx_mgr, std::shared_ptr db, const addr_t &node_addr, const std::string &logs_prefix = ""); - void sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, DagBlock block, const SharedTransactions &trxs); - void onNewBlockReceived(DagBlock &&block, const std::shared_ptr &peer = nullptr, + void sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, const std::shared_ptr &block, + const SharedTransactions &trxs); + void onNewBlockReceived(std::shared_ptr &&block, const std::shared_ptr &peer = nullptr, const std::unordered_map> &trxs = {}); - void onNewBlockVerified(const DagBlock &block, bool proposed, const SharedTransactions &trxs); + void onNewBlockVerified(const std::shared_ptr &block, bool proposed, const SharedTransactions &trxs); // Packet type that is processed by this handler static constexpr SubprotocolPacketType kPacketType_ = SubprotocolPacketType::kDagBlockPacket; diff --git a/libraries/core_libs/network/include/network/tarcap/packets_handlers/v4/dag_block_packet_handler.hpp b/libraries/core_libs/network/include/network/tarcap/packets_handlers/v4/dag_block_packet_handler.hpp index dc9a172a25..6de3bb9fcf 100644 --- a/libraries/core_libs/network/include/network/tarcap/packets_handlers/v4/dag_block_packet_handler.hpp +++ b/libraries/core_libs/network/include/network/tarcap/packets_handlers/v4/dag_block_packet_handler.hpp @@ -17,10 +17,11 @@ class DagBlockPacketHandler : public ExtSyncingPacketHandler { std::shared_ptr trx_mgr, std::shared_ptr db, const addr_t &node_addr, const std::string &logs_prefix = ""); - void sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, DagBlock block, const SharedTransactions &trxs); - void onNewBlockReceived(DagBlock &&block, const std::shared_ptr &peer = nullptr, + void sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, const std::shared_ptr &block, + const SharedTransactions &trxs); + void onNewBlockReceived(std::shared_ptr &&block, const std::shared_ptr &peer = nullptr, const std::unordered_map> &trxs = {}); - void onNewBlockVerified(const DagBlock &block, bool proposed, const SharedTransactions &trxs); + void onNewBlockVerified(const std::shared_ptr &block, bool proposed, const SharedTransactions &trxs); // Packet type that is processed by this handler static constexpr SubprotocolPacketType kPacketType_ = SubprotocolPacketType::kDagBlockPacket; diff --git a/libraries/core_libs/network/include/network/ws_server.hpp b/libraries/core_libs/network/include/network/ws_server.hpp index 60a3f6ccbd..c7224e79f1 100644 --- a/libraries/core_libs/network/include/network/ws_server.hpp +++ b/libraries/core_libs/network/include/network/ws_server.hpp @@ -51,7 +51,7 @@ class WsSession : public std::enable_shared_from_this { virtual std::string processRequest(const std::string_view& request) = 0; void newEthBlock(const ::taraxa::final_chain::BlockHeader& payload, const TransactionHashes& trx_hashes); - void newDagBlock(const DagBlock& blk); + void newDagBlock(const std::shared_ptr& blk); void newDagBlockFinalized(const blk_hash_t& blk, uint64_t period); void newPbftBlockExecuted(const Json::Value& payload); void newPendingTransaction(const trx_hash_t& trx_hash); @@ -97,7 +97,7 @@ class WsServer : public std::enable_shared_from_this, public jsonrpc:: // Start accepting incoming connections void run(); void newEthBlock(const ::taraxa::final_chain::BlockHeader& payload, const TransactionHashes& trx_hashes); - void newDagBlock(const DagBlock& blk); + void newDagBlock(const std::shared_ptr& blk); void newDagBlockFinalized(const blk_hash_t& blk, uint64_t period); void newPbftBlockExecuted(const PbftBlock& sche_blk, const std::vector& finalized_dag_blk_hashes); void newPendingTransaction(const trx_hash_t& trx_hash); diff --git a/libraries/core_libs/network/src/network.cpp b/libraries/core_libs/network/src/network.cpp index d450320159..1e8ad6f63d 100644 --- a/libraries/core_libs/network/src/network.cpp +++ b/libraries/core_libs/network/src/network.cpp @@ -289,7 +289,7 @@ void Network::addBootNodes(bool initial) { } } -void Network::gossipDagBlock(const DagBlock &block, bool proposed, const SharedTransactions &trxs) { +void Network::gossipDagBlock(const std::shared_ptr &block, bool proposed, const SharedTransactions &trxs) { for (const auto &tarcap : tarcaps_) { tarcap.second->getSpecificHandler()->onNewBlockVerified(block, proposed, trxs); diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_block_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_block_packet_handler.cpp index d6da181ddb..43bfd4e5d2 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_block_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_block_packet_handler.cpp @@ -20,19 +20,19 @@ DagBlockPacketHandler::DagBlockPacketHandler(const FullNodeConfig &conf, std::sh trx_mgr_(std::move(trx_mgr)) {} void DagBlockPacketHandler::process(DagBlockPacket &&packet, const std::shared_ptr &peer) { - blk_hash_t const hash = packet.dag_block.getHash(); + blk_hash_t const hash = packet.dag_block->getHash(); for (const auto &tx : packet.transactions) { peer->markTransactionAsKnown(tx->getHash()); } peer->markDagBlockAsKnown(hash); - if (packet.dag_block.getLevel() > peer->dag_level_) { - peer->dag_level_ = packet.dag_block.getLevel(); + if (packet.dag_block->getLevel() > peer->dag_level_) { + peer->dag_level_ = packet.dag_block->getLevel(); } // Do not process this block in case we already have it - if (dag_mgr_->isDagBlockKnown(packet.dag_block.getHash())) { + if (dag_mgr_->isDagBlockKnown(packet.dag_block->getHash())) { LOG(log_tr_) << "Received known DagBlockPacket " << hash << "from: " << peer->getId(); return; } @@ -46,11 +46,12 @@ void DagBlockPacketHandler::process(DagBlockPacket &&packet, const std::shared_p onNewBlockReceived(std::move(packet.dag_block), peer, txs_map); } -void DagBlockPacketHandler::sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, taraxa::DagBlock block, +void DagBlockPacketHandler::sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, + const std::shared_ptr &block, const SharedTransactions &trxs) { std::shared_ptr peer = peers_state_->getPeer(peer_id); if (!peer) { - LOG(log_wr_) << "Send dag block " << block.getHash() << ". Failed to obtain peer " << peer_id; + LOG(log_wr_) << "Send dag block " << block->getHash() << ". Failed to obtain peer " << peer_id; return; } @@ -61,18 +62,18 @@ void DagBlockPacketHandler::sendBlockWithTransactions(dev::p2p::NodeID const &pe DagBlockPacket dag_block_packet{.transactions = trxs, .dag_block = block}; if (!sealAndSend(peer_id, SubprotocolPacketType::kDagBlockPacket, encodePacketRlp(dag_block_packet))) { - LOG(log_wr_) << "Sending DagBlock " << block.getHash() << " failed to " << peer_id; + LOG(log_wr_) << "Sending DagBlock " << block->getHash() << " failed to " << peer_id; return; } // Mark data as known if sending was successful - peer->markDagBlockAsKnown(block.getHash()); + peer->markDagBlockAsKnown(block->getHash()); } void DagBlockPacketHandler::onNewBlockReceived( - DagBlock &&block, const std::shared_ptr &peer, + std::shared_ptr &&block, const std::shared_ptr &peer, const std::unordered_map> &trxs) { - const auto block_hash = block.getHash(); + const auto block_hash = block->getHash(); auto verified = dag_mgr_->verifyBlock(block, trxs); switch (verified.first) { case DagManager::VerifyBlockReturnType::IncorrectTransactionsEstimation: @@ -135,7 +136,7 @@ void DagBlockPacketHandler::onNewBlockReceived( } break; case DagManager::VerifyBlockReturnType::Verified: { - auto status = dag_mgr_->addDagBlock(std::move(block), std::move(verified.second)); + auto status = dag_mgr_->addDagBlock(block, std::move(verified.second)); if (!status.first) { LOG(log_dg_) << "Received DagBlockPacket " << block_hash << "from: " << peer->getId(); // Ignore new block packets when pbft syncing @@ -147,9 +148,9 @@ void DagBlockPacketHandler::onNewBlockReceived( if (peer->peer_dag_synced_) { std::ostringstream err_msg; if (status.second.size() > 0) - err_msg << "DagBlock" << block.getHash() << " has missing pivot or/and tips " << status.second; + err_msg << "DagBlock" << block->getHash() << " has missing pivot or/and tips " << status.second; else - err_msg << "DagBlock" << block.getHash() << " could not be added to DAG"; + err_msg << "DagBlock" << block->getHash() << " could not be added to DAG"; throw MaliciousPeerException(err_msg.str()); } else { // peer_dag_synced_ flag ensures that this can only be performed once for a peer @@ -163,14 +164,15 @@ void DagBlockPacketHandler::onNewBlockReceived( } } -void DagBlockPacketHandler::onNewBlockVerified(const DagBlock &block, bool proposed, const SharedTransactions &trxs) { +void DagBlockPacketHandler::onNewBlockVerified(const std::shared_ptr &block, bool proposed, + const SharedTransactions &trxs) { // If node is pbft syncing and block is not proposed by us, this is an old block that has been verified - no block // gossip is needed if (!proposed && pbft_syncing_state_->isDeepPbftSyncing()) { return; } - const auto &block_hash = block.getHash(); + const auto &block_hash = block->getHash(); LOG(log_tr_) << "Verified NewBlock " << block_hash.toString(); std::vector peers_to_send; @@ -218,7 +220,7 @@ void DagBlockPacketHandler::onNewBlockVerified(const DagBlock &block, bool propo } } } - LOG(log_dg_) << "Send DagBlock " << block.getHash() << " to peers: " << peer_and_transactions_to_log; + LOG(log_dg_) << "Send DagBlock " << block->getHash() << " to peers: " << peer_and_transactions_to_log; if (!peers_to_send.empty()) LOG(log_tr_) << "Sent block to " << peers_to_send.size() << " peers"; } } // namespace taraxa::network::tarcap diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_sync_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_sync_packet_handler.cpp index 9c8e2319fe..ca002eba3b 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_sync_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/dag_sync_packet_handler.cpp @@ -74,7 +74,7 @@ void DagSyncPacketHandler::process(DagSyncPacket&& packet, const std::shared_ptr continue; } - auto verified = dag_mgr_->verifyBlock(*block, transactions_map); + auto verified = dag_mgr_->verifyBlock(block, transactions_map); if (verified.first != DagManager::VerifyBlockReturnType::Verified) { std::ostringstream err_msg; err_msg << "DagBlock " << block->getHash() << " failed verification with error code " @@ -84,8 +84,7 @@ void DagSyncPacketHandler::process(DagSyncPacket&& packet, const std::shared_ptr if (block->getLevel() > peer->dag_level_) peer->dag_level_ = block->getLevel(); - // TODO[2869]: fix dag blocks usage - shared_ptr vs object type on different places... - auto status = dag_mgr_->addDagBlock(std::move(*block), std::move(verified.second)); + auto status = dag_mgr_->addDagBlock(block, std::move(verified.second)); if (!status.first) { std::ostringstream err_msg; if (status.second.size() > 0) diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pbft_sync_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pbft_sync_packet_handler.cpp index 6a83b26787..93ebe44028 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pbft_sync_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/latest/pbft_sync_packet_handler.cpp @@ -45,9 +45,9 @@ void PbftSyncPacketHandler::process(PbftSyncPacket &&packet, const std::shared_p std::string received_dag_blocks_str; // This is just log related stuff for (auto const &block : packet.period_data.dag_blocks) { - received_dag_blocks_str += block.getHash().toString() + " "; - if (peer->dag_level_ < block.getLevel()) { - peer->dag_level_ = block.getLevel(); + received_dag_blocks_str += block->getHash().toString() + " "; + if (peer->dag_level_ < block->getLevel()) { + peer->dag_level_ = block->getLevel(); } } @@ -119,7 +119,7 @@ void PbftSyncPacketHandler::process(PbftSyncPacket &&packet, const std::shared_p trx_order.push_back(t->getHash()); } for (auto b : packet.period_data.dag_blocks) { - blk_order.push_back(b.getHash()); + blk_order.push_back(b->getHash()); } LOG(log_er_) << "Order hash incorrect in period data " << pbft_blk_hash << " expected: " << order_hash << " received " << packet.period_data.pbft_blk->getOrderHash() << "; Dag order: " << blk_order diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_block_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_block_packet_handler.cpp index d3a82cd7b5..65c1754512 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_block_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_block_packet_handler.cpp @@ -46,17 +46,17 @@ void DagBlockPacketHandler::process(const threadpool::PacketData &packet_data, } dag_rlp = packet_data.rlp_[1]; } - DagBlock block(dag_rlp); - blk_hash_t const hash = block.getHash(); + auto block = std::make_shared(dag_rlp); + blk_hash_t const hash = block->getHash(); peer->markDagBlockAsKnown(hash); - if (block.getLevel() > peer->dag_level_) { - peer->dag_level_ = block.getLevel(); + if (block->getLevel() > peer->dag_level_) { + peer->dag_level_ = block->getLevel(); } // Do not process this block in case we already have it - if (dag_mgr_->isDagBlockKnown(block.getHash())) { + if (dag_mgr_->isDagBlockKnown(block->getHash())) { LOG(log_tr_) << "Received known DagBlockPacket " << hash << "from: " << peer->getId(); return; } @@ -64,11 +64,12 @@ void DagBlockPacketHandler::process(const threadpool::PacketData &packet_data, onNewBlockReceived(std::move(block), peer, transactions); } -void DagBlockPacketHandler::sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, taraxa::DagBlock block, +void DagBlockPacketHandler::sendBlockWithTransactions(dev::p2p::NodeID const &peer_id, + const std::shared_ptr &block, const SharedTransactions &trxs) { std::shared_ptr peer = peers_state_->getPeer(peer_id); if (!peer) { - LOG(log_wr_) << "Send dag block " << block.getHash() << ". Failed to obtain peer " << peer_id; + LOG(log_wr_) << "Send dag block " << block->getHash() << ". Failed to obtain peer " << peer_id; return; } @@ -86,21 +87,21 @@ void DagBlockPacketHandler::sendBlockWithTransactions(dev::p2p::NodeID const &pe s.appendList(trxs.size()); s.appendRaw(trx_bytes, trxs.size()); - s.appendRaw(block.rlp(true)); + s.appendRaw(block->rlp(true)); if (!sealAndSend(peer_id, SubprotocolPacketType::kDagBlockPacket, std::move(s))) { - LOG(log_wr_) << "Sending DagBlock " << block.getHash() << " failed to " << peer_id; + LOG(log_wr_) << "Sending DagBlock " << block->getHash() << " failed to " << peer_id; return; } // Mark data as known if sending was successful - peer->markDagBlockAsKnown(block.getHash()); + peer->markDagBlockAsKnown(block->getHash()); } void DagBlockPacketHandler::onNewBlockReceived( - DagBlock &&block, const std::shared_ptr &peer, + std::shared_ptr &&block, const std::shared_ptr &peer, const std::unordered_map> &trxs) { - const auto block_hash = block.getHash(); + const auto block_hash = block->getHash(); auto verified = dag_mgr_->verifyBlock(block, trxs); switch (verified.first) { case DagManager::VerifyBlockReturnType::IncorrectTransactionsEstimation: @@ -175,9 +176,9 @@ void DagBlockPacketHandler::onNewBlockReceived( if (peer->peer_dag_synced_) { std::ostringstream err_msg; if (status.second.size() > 0) - err_msg << "DagBlock" << block.getHash() << " has missing pivot or/and tips " << status.second; + err_msg << "DagBlock" << block->getHash() << " has missing pivot or/and tips " << status.second; else - err_msg << "DagBlock" << block.getHash() << " could not be added to DAG"; + err_msg << "DagBlock" << block->getHash() << " could not be added to DAG"; throw MaliciousPeerException(err_msg.str()); } else { // peer_dag_synced_ flag ensures that this can only be performed once for a peer @@ -191,14 +192,15 @@ void DagBlockPacketHandler::onNewBlockReceived( } } -void DagBlockPacketHandler::onNewBlockVerified(const DagBlock &block, bool proposed, const SharedTransactions &trxs) { +void DagBlockPacketHandler::onNewBlockVerified(const std::shared_ptr &block, bool proposed, + const SharedTransactions &trxs) { // If node is pbft syncing and block is not proposed by us, this is an old block that has been verified - no block // gossip is needed if (!proposed && pbft_syncing_state_->isDeepPbftSyncing()) { return; } - const auto &block_hash = block.getHash(); + const auto &block_hash = block->getHash(); LOG(log_tr_) << "Verified NewBlock " << block_hash.toString(); std::vector peers_to_send; @@ -246,7 +248,7 @@ void DagBlockPacketHandler::onNewBlockVerified(const DagBlock &block, bool propo } } } - LOG(log_dg_) << "Send DagBlock " << block.getHash() << " to peers: " << peer_and_transactions_to_log; + LOG(log_dg_) << "Send DagBlock " << block->getHash() << " to peers: " << peer_and_transactions_to_log; if (!peers_to_send.empty()) LOG(log_tr_) << "Sent block to " << peers_to_send.size() << " peers"; } } // namespace taraxa::network::tarcap::v4 diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_sync_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_sync_packet_handler.cpp index 64400f909d..f2b6894921 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_sync_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/v4/dag_sync_packet_handler.cpp @@ -67,16 +67,16 @@ void DagSyncPacketHandler::process(const threadpool::PacketData& packet_data, co } } - std::vector dag_blocks; + std::vector> dag_blocks; std::vector dag_blocks_to_log; dag_blocks.reserve((*it).itemCount()); dag_blocks_to_log.reserve((*it).itemCount()); for (const auto block_rlp : *it) { - DagBlock block(block_rlp); - peer->markDagBlockAsKnown(block.getHash()); - if (dag_mgr_->isDagBlockKnown(block.getHash())) { - LOG(log_tr_) << "Received known DagBlock " << block.getHash() << "from: " << peer->getId(); + auto block = std::make_shared(block_rlp); + peer->markDagBlockAsKnown(block->getHash()); + if (dag_mgr_->isDagBlockKnown(block->getHash())) { + LOG(log_tr_) << "Received known DagBlock " << block->getHash() << "from: " << peer->getId(); continue; } dag_blocks.emplace_back(std::move(block)); @@ -97,25 +97,25 @@ void DagSyncPacketHandler::process(const threadpool::PacketData& packet_data, co } for (auto& block : dag_blocks) { - dag_blocks_to_log.push_back(block.getHash()); + dag_blocks_to_log.push_back(block->getHash()); auto verified = dag_mgr_->verifyBlock(block, transactions); if (verified.first != DagManager::VerifyBlockReturnType::Verified) { std::ostringstream err_msg; - err_msg << "DagBlock " << block.getHash() << " failed verification with error code " + err_msg << "DagBlock " << block->getHash() << " failed verification with error code " << static_cast(verified.first); throw MaliciousPeerException(err_msg.str()); } - if (block.getLevel() > peer->dag_level_) peer->dag_level_ = block.getLevel(); + if (block->getLevel() > peer->dag_level_) peer->dag_level_ = block->getLevel(); auto status = dag_mgr_->addDagBlock(std::move(block), std::move(verified.second)); if (!status.first) { std::ostringstream err_msg; if (status.second.size() > 0) - err_msg << "DagBlock" << block.getHash() << " has missing pivot or/and tips " << status.second; + err_msg << "DagBlock" << block->getHash() << " has missing pivot or/and tips " << status.second; else - err_msg << "DagBlock" << block.getHash() << " could not be added to DAG"; + err_msg << "DagBlock" << block->getHash() << " could not be added to DAG"; throw MaliciousPeerException(err_msg.str()); } } diff --git a/libraries/core_libs/network/src/tarcap/packets_handlers/v4/pbft_sync_packet_handler.cpp b/libraries/core_libs/network/src/tarcap/packets_handlers/v4/pbft_sync_packet_handler.cpp index 0710cac3de..a7acc54653 100644 --- a/libraries/core_libs/network/src/tarcap/packets_handlers/v4/pbft_sync_packet_handler.cpp +++ b/libraries/core_libs/network/src/tarcap/packets_handlers/v4/pbft_sync_packet_handler.cpp @@ -73,9 +73,9 @@ void PbftSyncPacketHandler::process(const threadpool::PacketData &packet_data, std::string received_dag_blocks_str; // This is just log related stuff for (auto const &block : period_data.dag_blocks) { - received_dag_blocks_str += block.getHash().toString() + " "; - if (peer->dag_level_ < block.getLevel()) { - peer->dag_level_ = block.getLevel(); + received_dag_blocks_str += block->getHash().toString() + " "; + if (peer->dag_level_ < block->getLevel()) { + peer->dag_level_ = block->getLevel(); } } @@ -148,7 +148,7 @@ void PbftSyncPacketHandler::process(const threadpool::PacketData &packet_data, trx_order.push_back(t->getHash()); } for (auto b : period_data.dag_blocks) { - blk_order.push_back(b.getHash()); + blk_order.push_back(b->getHash()); } LOG(log_er_) << "Order hash incorrect in period data " << pbft_blk_hash << " expected: " << order_hash << " received " << period_data.pbft_blk->getOrderHash() << "; Dag order: " << blk_order diff --git a/libraries/core_libs/network/src/ws_server.cpp b/libraries/core_libs/network/src/ws_server.cpp index bb361550e8..d25a1175d6 100644 --- a/libraries/core_libs/network/src/ws_server.cpp +++ b/libraries/core_libs/network/src/ws_server.cpp @@ -120,12 +120,12 @@ void WsSession::newEthBlock(const ::taraxa::final_chain::BlockHeader &payload, c writeAsync(std::move(response)); } } -void WsSession::newDagBlock(DagBlock const &blk) { +void WsSession::newDagBlock(const std::shared_ptr &blk) { if (new_dag_blocks_subscription_) { Json::Value res, params; res["jsonrpc"] = "2.0"; res["method"] = "eth_subscription"; - params["result"] = blk.getJson(); + params["result"] = blk->getJson(); params["subscription"] = dev::toJS(new_dag_blocks_subscription_); res["params"] = params; auto response = util::to_string(res); @@ -292,7 +292,7 @@ void WsServer::on_accept(beast::error_code ec, tcp::socket socket) { if (!stopped_) do_accept(); } -void WsServer::newDagBlock(DagBlock const &blk) { +void WsServer::newDagBlock(const std::shared_ptr &blk) { boost::shared_lock lock(sessions_mtx_); for (auto const &session : sessions) { if (!session->is_closed()) session->newDagBlock(blk); diff --git a/libraries/core_libs/node/src/node.cpp b/libraries/core_libs/node/src/node.cpp index c05a4d4e5c..bc86ad17d9 100644 --- a/libraries/core_libs/node/src/node.cpp +++ b/libraries/core_libs/node/src/node.cpp @@ -271,7 +271,7 @@ void FullNode::start() { }, *rpc_thread_pool_); dag_mgr_->block_verified_.subscribe( - [eth_json_rpc = as_weak(eth_json_rpc), ws = as_weak(jsonrpc_ws_)](auto const &dag_block) { + [eth_json_rpc = as_weak(eth_json_rpc), ws = as_weak(jsonrpc_ws_)](const std::shared_ptr &dag_block) { if (auto _ws = ws.lock()) { _ws->newDagBlock(dag_block); } diff --git a/libraries/core_libs/storage/include/storage/storage.hpp b/libraries/core_libs/storage/include/storage/storage.hpp index 31e3498c4b..47264c59f2 100644 --- a/libraries/core_libs/storage/include/storage/storage.hpp +++ b/libraries/core_libs/storage/include/storage/storage.hpp @@ -242,14 +242,14 @@ class DbStorage : public std::enable_shared_from_this { std::optional getCurrentPillarBlockData() const; // DAG - void saveDagBlock(DagBlock const& blk, Batch* write_batch_p = nullptr); + void saveDagBlock(const std::shared_ptr& blk, Batch* write_batch_p = nullptr); std::shared_ptr getDagBlock(blk_hash_t const& hash); bool dagBlockInDb(blk_hash_t const& hash); std::set getBlocksByLevel(level_t level); level_t getLastBlocksLevel() const; std::vector> getDagBlocksAtLevel(level_t level, int number_of_levels); - void updateDagBlockCounters(std::vector blks); - std::map> getNonfinalizedDagBlocks(); + void updateDagBlockCounters(std::vector> blks); + std::map>> getNonfinalizedDagBlocks(); void removeDagBlockBatch(Batch& write_batch, blk_hash_t const& hash); void removeDagBlock(blk_hash_t const& hash); // Sortition params diff --git a/libraries/core_libs/storage/src/storage.cpp b/libraries/core_libs/storage/src/storage.cpp index eddc4a177e..b2c0401e7b 100644 --- a/libraries/core_libs/storage/src/storage.cpp +++ b/libraries/core_libs/storage/src/storage.cpp @@ -487,12 +487,12 @@ std::vector> DbStorage::getDagBlocksAtLevel(level_t le return res; } -std::map> DbStorage::getNonfinalizedDagBlocks() { - std::map> res; +std::map>> DbStorage::getNonfinalizedDagBlocks() { + std::map>> res; auto i = std::unique_ptr(db_->NewIterator(read_options_, handle(Columns::dag_blocks))); for (i->SeekToFirst(); i->Valid(); i->Next()) { - DagBlock block(asBytes(i->value().ToString())); - res[block.getLevel()].emplace_back(std::move(block)); + auto block = std::make_shared(asBytes(i->value().ToString())); + res[block->getLevel()].emplace_back(std::move(block)); } return res; } @@ -512,39 +512,39 @@ void DbStorage::removeDagBlockBatch(Batch& write_batch, blk_hash_t const& hash) void DbStorage::removeDagBlock(blk_hash_t const& hash) { remove(Columns::dag_blocks, toSlice(hash)); } -void DbStorage::updateDagBlockCounters(std::vector blks) { +void DbStorage::updateDagBlockCounters(std::vector> blks) { // Lock is needed since we are editing some fields std::lock_guard u_lock(dag_blocks_mutex_); auto write_batch = createWriteBatch(); for (auto const& blk : blks) { - auto level = blk.getLevel(); + auto level = blk->getLevel(); auto block_hashes = getBlocksByLevel(level); - block_hashes.emplace(blk.getHash()); + block_hashes.emplace(blk->getHash()); dev::RLPStream blocks_stream(block_hashes.size()); for (auto const& hash : block_hashes) { blocks_stream << hash; } insert(write_batch, Columns::dag_blocks_level, toSlice(level), toSlice(blocks_stream.out())); dag_blocks_count_.fetch_add(1); - dag_edge_count_.fetch_add(blk.getTips().size() + 1); + dag_edge_count_.fetch_add(blk->getTips().size() + 1); } insert(write_batch, Columns::status, toSlice((uint8_t)StatusDbField::DagBlkCount), toSlice(dag_blocks_count_.load())); insert(write_batch, Columns::status, toSlice((uint8_t)StatusDbField::DagEdgeCount), toSlice(dag_edge_count_.load())); commitWriteBatch(write_batch); } -void DbStorage::saveDagBlock(DagBlock const& blk, Batch* write_batch_p) { +void DbStorage::saveDagBlock(const std::shared_ptr& blk, Batch* write_batch_p) { // Lock is needed since we are editing some fields std::lock_guard u_lock(dag_blocks_mutex_); auto write_batch_up = write_batch_p ? std::unique_ptr() : std::make_unique(); auto commit = !write_batch_p; auto& write_batch = write_batch_p ? *write_batch_p : *write_batch_up; - auto block_bytes = blk.rlp(true); - auto block_hash = blk.getHash(); + auto block_bytes = blk->rlp(true); + auto block_hash = blk->getHash(); insert(write_batch, Columns::dag_blocks, toSlice(block_hash.asBytes()), toSlice(block_bytes)); - auto level = blk.getLevel(); + auto level = blk->getLevel(); auto block_hashes = getBlocksByLevel(level); - block_hashes.emplace(blk.getHash()); + block_hashes.emplace(blk->getHash()); dev::RLPStream blocks_stream(block_hashes.size()); for (auto const& hash : block_hashes) { blocks_stream << hash; @@ -552,7 +552,7 @@ void DbStorage::saveDagBlock(DagBlock const& blk, Batch* write_batch_p) { insert(write_batch, Columns::dag_blocks_level, toSlice(level), toSlice(blocks_stream.out())); dag_blocks_count_.fetch_add(1); - dag_edge_count_.fetch_add(blk.getTips().size() + 1); + dag_edge_count_.fetch_add(blk->getTips().size() + 1); insert(write_batch, Columns::status, toSlice((uint8_t)StatusDbField::DagBlkCount), toSlice(dag_blocks_count_.load())); insert(write_batch, Columns::status, toSlice((uint8_t)StatusDbField::DagEdgeCount), toSlice(dag_edge_count_.load())); if (commit) { @@ -686,8 +686,8 @@ void DbStorage::savePeriodData(const PeriodData& period_data, Batch& write_batch // Remove dag blocks from non finalized column in db and add dag_block_period in DB uint32_t block_pos = 0; for (auto const& block : period_data.dag_blocks) { - removeDagBlockBatch(write_batch, block.getHash()); - addDagBlockPeriodToBatch(block.getHash(), period, block_pos, write_batch); + removeDagBlockBatch(write_batch, block->getHash()); + addDagBlockPeriodToBatch(block->getHash(), period, block_pos, write_batch); block_pos++; } @@ -1262,41 +1262,35 @@ std::vector DbStorage::getFinalizedDagBlockHashesByPeriod(PbftPeriod const auto dag_blocks = decodeDAGBlocksBundleRlp(dag_blocks_data); ret.reserve(dag_blocks.size()); std::transform(dag_blocks.begin(), dag_blocks.end(), std::back_inserter(ret), - [](const auto& dag_block) { return dag_block.getHash(); }); + [](const auto& dag_block) { return dag_block->getHash(); }); } return ret; } std::vector> DbStorage::getFinalizedDagBlockByPeriod(PbftPeriod period) { - std::vector> ret; - if (auto period_data = getPeriodDataRaw(period); period_data.size() > 0) { - auto dag_blocks_data = dev::RLP(period_data)[DAG_BLOCKS_POS_IN_PERIOD_DATA]; - auto dag_blocks = decodeDAGBlocksBundleRlp(dag_blocks_data); - ret.reserve(dag_blocks.size()); - for (const auto& block : dag_blocks) { - ret.emplace_back(std::make_shared(std::move(block))); - } + auto period_data = getPeriodDataRaw(period); + if (period_data.empty()) { + return {}; } - return ret; + + auto dag_blocks_data = dev::RLP(period_data)[DAG_BLOCKS_POS_IN_PERIOD_DATA]; + return decodeDAGBlocksBundleRlp(dag_blocks_data); } std::pair>> DbStorage::getLastPbftBlockHashAndFinalizedDagBlockByPeriod(PbftPeriod period) { - std::vector> ret; - blk_hash_t last_pbft_block_hash; - if (auto period_data = getPeriodDataRaw(period); period_data.size() > 0) { - auto const period_data_rlp = dev::RLP(period_data); - auto dag_blocks_data = period_data_rlp[DAG_BLOCKS_POS_IN_PERIOD_DATA]; - auto dag_blocks = decodeDAGBlocksBundleRlp(dag_blocks_data); - ret.reserve(dag_blocks.size()); - for (const auto& block : dag_blocks) { - ret.emplace_back(std::make_shared(std::move(block))); - } - last_pbft_block_hash = - period_data_rlp[PBFT_BLOCK_POS_IN_PERIOD_DATA][PREV_BLOCK_HASH_POS_IN_PBFT_BLOCK].toHash(); + auto period_data = getPeriodDataRaw(period); + if (period_data.empty()) { + return {}; } - return {last_pbft_block_hash, ret}; + + const auto period_data_rlp = dev::RLP(period_data); + auto dag_blocks_data = period_data_rlp[DAG_BLOCKS_POS_IN_PERIOD_DATA]; + auto blocks = decodeDAGBlocksBundleRlp(dag_blocks_data); + auto last_pbft_block_hash = + period_data_rlp[PBFT_BLOCK_POS_IN_PERIOD_DATA][PREV_BLOCK_HASH_POS_IN_PBFT_BLOCK].toHash(); + return {last_pbft_block_hash, std::move(blocks)}; } std::optional DbStorage::getProposalPeriodForDagLevel(uint64_t level) { diff --git a/libraries/types/dag_block/include/dag/dag_block_bundle_rlp.hpp b/libraries/types/dag_block/include/dag/dag_block_bundle_rlp.hpp index 828399ec7d..21b6be4135 100644 --- a/libraries/types/dag_block/include/dag/dag_block_bundle_rlp.hpp +++ b/libraries/types/dag_block/include/dag/dag_block_bundle_rlp.hpp @@ -21,7 +21,7 @@ constexpr static size_t kDAGBlocksBundleRlpSize{3}; * @param blocks * @return blocks bundle rlp bytes */ -dev::bytes encodeDAGBlocksBundleRlp(const std::vector& blocks); +dev::bytes encodeDAGBlocksBundleRlp(const std::vector>& blocks); /** * @brief Decodes pbft blocks from optimized blocks bundle rlp @@ -29,7 +29,7 @@ dev::bytes encodeDAGBlocksBundleRlp(const std::vector& blocks); * @param blocks_bundle_rlp * @return blocks */ -std::vector decodeDAGBlocksBundleRlp(const dev::RLP& blocks_bundle_rlp); +std::vector> decodeDAGBlocksBundleRlp(const dev::RLP& blocks_bundle_rlp); /** * @brief Decodes single dag block from optimized blocks bundle rlp diff --git a/libraries/types/dag_block/src/dag_block_bundle_rlp.cpp b/libraries/types/dag_block/src/dag_block_bundle_rlp.cpp index b57a196669..57831ccea6 100644 --- a/libraries/types/dag_block/src/dag_block_bundle_rlp.cpp +++ b/libraries/types/dag_block/src/dag_block_bundle_rlp.cpp @@ -7,7 +7,7 @@ namespace taraxa { -dev::bytes encodeDAGBlocksBundleRlp(const std::vector& blocks) { +dev::bytes encodeDAGBlocksBundleRlp(const std::vector>& blocks) { if (blocks.empty()) { return {}; } @@ -18,9 +18,9 @@ dev::bytes encodeDAGBlocksBundleRlp(const std::vector& blocks) { for (const auto& block : blocks) { std::vector idx; - idx.reserve(block.getTrxs().size()); + idx.reserve(block->getTrxs().size()); - for (const auto& trx : block.getTrxs()) { + for (const auto& trx : block->getTrxs()) { if (const auto [_, ok] = trx_hash_map.try_emplace(trx, static_cast(trx_hash_map.size())); ok) { ordered_trx_hashes.push_back(trx); // Track the insertion order } @@ -43,12 +43,12 @@ dev::bytes encodeDAGBlocksBundleRlp(const std::vector& blocks) { } blocks_bundle_rlp.appendList(blocks.size()); for (const auto& block : blocks) { - blocks_bundle_rlp.appendRaw(block.rlp(true, false)); + blocks_bundle_rlp.appendRaw(block->rlp(true, false)); } return blocks_bundle_rlp.invalidate(); } -std::vector decodeDAGBlocksBundleRlp(const dev::RLP& blocks_bundle_rlp) { +std::vector> decodeDAGBlocksBundleRlp(const dev::RLP& blocks_bundle_rlp) { if (blocks_bundle_rlp.itemCount() != kDAGBlocksBundleRlpSize) { return {}; } @@ -70,11 +70,11 @@ std::vector decodeDAGBlocksBundleRlp(const dev::RLP& blocks_bundle_rlp dags_trx_hashes.push_back(std::move(hashes)); } - std::vector blocks; + std::vector> blocks; blocks.reserve(blocks_bundle_rlp[2].itemCount()); for (size_t i = 0; i < blocks_bundle_rlp[2].itemCount(); i++) { - auto block = DagBlock(blocks_bundle_rlp[2][i], std::move(dags_trx_hashes[i])); + auto block = std::make_shared(blocks_bundle_rlp[2][i], std::move(dags_trx_hashes[i])); blocks.push_back(std::move(block)); } diff --git a/libraries/types/pbft_block/include/pbft/period_data.hpp b/libraries/types/pbft_block/include/pbft/period_data.hpp index 060a75268b..f1eb17282b 100644 --- a/libraries/types/pbft_block/include/pbft/period_data.hpp +++ b/libraries/types/pbft_block/include/pbft/period_data.hpp @@ -38,7 +38,7 @@ class PeriodData { std::shared_ptr pbft_blk; std::vector> previous_block_cert_votes; // These votes are the cert votes of previous block // which match reward votes in current pbft block - std::vector dag_blocks; + std::vector> dag_blocks; SharedTransactions transactions; // Pillar votes should be present only if pbft block contains also pillar block hash diff --git a/libraries/types/pbft_block/src/period_data.cpp b/libraries/types/pbft_block/src/period_data.cpp index 8948ca683b..7f9a09572b 100644 --- a/libraries/types/pbft_block/src/period_data.cpp +++ b/libraries/types/pbft_block/src/period_data.cpp @@ -88,7 +88,7 @@ PeriodData PeriodData::FromOldPeriodData(const dev::RLP& rlp) { } for (auto const dag_block_rlp : *it++) { - period_data.dag_blocks.emplace_back(dag_block_rlp); + period_data.dag_blocks.emplace_back(std::make_shared(dag_block_rlp)); } for (auto const trx_rlp : *it++) { @@ -116,7 +116,7 @@ bytes PeriodData::ToOldPeriodData(const bytes& rlp) { s.appendList(period_data.dag_blocks.size()); for (auto const& b : period_data.dag_blocks) { - s.appendRaw(b.rlp(true)); + s.appendRaw(b->rlp(true)); } s.appendList(period_data.transactions.size()); diff --git a/tests/dag_block_test.cpp b/tests/dag_block_test.cpp index 7e0f639028..b4df096fcd 100644 --- a/tests/dag_block_test.cpp +++ b/tests/dag_block_test.cpp @@ -26,8 +26,6 @@ using namespace vdf_sortition; struct DagBlockTest : NodesTest {}; struct DagBlockMgrTest : NodesTest {}; -auto g_blk_samples = samples::createMockDagBlkSamples(0, NUM_BLK, 0, BLK_TRX_LEN, BLK_TRX_OVERLAP); - auto g_secret = dev::Secret("3800b2875669d9b2053c1aff9224ecfdc411423aac5b5a73d7a45ced1c3b9dcd", dev::Secret::ConstructFromStringType::FromHex); auto g_key_pair = dev::KeyPair(g_secret); @@ -230,14 +228,16 @@ TEST_F(DagBlockMgrTest, incorrect_tx_estimation) { // transactions.size and estimations size is not equal { - DagBlock blk(dag_genesis, propose_level, {}, {trx->getHash()}, {}, vdf1, node->getSecretKey()); + auto blk = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, vec_trx_t{trx->getHash()}, 0, vdf1, + node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(std::move(blk)).first, DagManager::VerifyBlockReturnType::IncorrectTransactionsEstimation); } // wrong estimated tx { - DagBlock blk(dag_genesis, propose_level, {}, {trx->getHash()}, 100, vdf1, node->getSecretKey()); + auto blk = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, vec_trx_t{trx->getHash()}, 100, vdf1, + node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(std::move(blk)).first, DagManager::VerifyBlockReturnType::IncorrectTransactionsEstimation); } @@ -265,8 +265,9 @@ TEST_F(DagBlockMgrTest, dag_block_tips_verification) { dev::bytes vdf_msg = DagManager::getVdfMessage(dag_genesis, {trx}); vdf.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk(dag_genesis, propose_level, {}, {trx->getHash()}, 100000, vdf, node->getSecretKey()); - dag_blocks_hashes.push_back(blk.getHash()); + auto blk = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, vec_trx_t{trx->getHash()}, 100000, + vdf, node->getSecretKey()); + dag_blocks_hashes.push_back(blk->getHash()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk).first, DagManager::VerifyBlockReturnType::Verified); EXPECT_TRUE(node->getDagManager()->addDagBlock(std::move(blk), {trx}).first); } @@ -275,21 +276,21 @@ TEST_F(DagBlockMgrTest, dag_block_tips_verification) { vdf.computeVdfSolution(vdf_config, vdf_msg, false); // Verify block over the kDagBlockMaxTips is rejected - DagBlock blk_over_limit(dag_genesis, propose_level, dag_blocks_hashes, {trxs[0]->getHash()}, 100000, vdf, - node->getSecretKey()); + auto blk_over_limit = std::make_shared(dag_genesis, propose_level, dag_blocks_hashes, + vec_trx_t{trxs[0]->getHash()}, 100000, vdf, node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk_over_limit).first, DagManager::VerifyBlockReturnType::FailedTipsVerification); // Verify block at kDagBlockMaxTips is accepted dag_blocks_hashes.resize(kDagBlockMaxTips); - DagBlock blk_at_limit(dag_genesis, propose_level, dag_blocks_hashes, {trxs[0]->getHash()}, 100000, vdf, - node->getSecretKey()); + auto blk_at_limit = std::make_shared(dag_genesis, propose_level, dag_blocks_hashes, + vec_trx_t{trxs[0]->getHash()}, 100000, vdf, node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk_at_limit).first, DagManager::VerifyBlockReturnType::Verified); // Verify block below kDagBlockMaxTips is accepted dag_blocks_hashes.resize(kDagBlockMaxTips - 1); - DagBlock blk_under_limit(dag_genesis, propose_level, dag_blocks_hashes, {trxs[0]->getHash()}, 100000, vdf, - node->getSecretKey()); + auto blk_under_limit = std::make_shared(dag_genesis, propose_level, dag_blocks_hashes, + vec_trx_t{trxs[0]->getHash()}, 100000, vdf, node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk_under_limit).first, DagManager::VerifyBlockReturnType::Verified); auto dag_blocks_hashes_with_duplicate_pivot = dag_blocks_hashes; @@ -299,14 +300,16 @@ TEST_F(DagBlockMgrTest, dag_block_tips_verification) { dag_blocks_hashes_with_duplicate_tip.push_back(dag_blocks_hashes[0]); // Verify block with duplicate pivot is rejected - DagBlock blk_with_duplicate_pivot(dag_genesis, propose_level, dag_blocks_hashes_with_duplicate_pivot, - {trxs[0]->getHash()}, 100000, vdf, node->getSecretKey()); + auto blk_with_duplicate_pivot = + std::make_shared(dag_genesis, propose_level, dag_blocks_hashes_with_duplicate_pivot, + vec_trx_t{trxs[0]->getHash()}, 100000, vdf, node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk_with_duplicate_pivot).first, DagManager::VerifyBlockReturnType::FailedTipsVerification); // Verify block with duplicate tip is rejected - DagBlock blk_with_duplicate_tip(dag_genesis, propose_level, dag_blocks_hashes_with_duplicate_tip, - {trxs[0]->getHash()}, 100000, vdf, node->getSecretKey()); + auto blk_with_duplicate_tip = + std::make_shared(dag_genesis, propose_level, dag_blocks_hashes_with_duplicate_tip, + vec_trx_t{trxs[0]->getHash()}, 100000, vdf, node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk_with_duplicate_tip).first, DagManager::VerifyBlockReturnType::FailedTipsVerification); } @@ -334,8 +337,9 @@ TEST_F(DagBlockMgrTest, dag_block_tips_proposal) { dev::bytes vdf_msg = DagManager::getVdfMessage(dag_genesis, {trx}); vdf.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk(dag_genesis, propose_level, {}, {trx->getHash()}, dag_block_gas, vdf, node->getSecretKey()); - dag_blocks_hashes.push_back(blk.getHash()); + auto blk = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, vec_trx_t{trx->getHash()}, + dag_block_gas, vdf, node->getSecretKey()); + dag_blocks_hashes.push_back(blk->getHash()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk).first, DagManager::VerifyBlockReturnType::Verified); EXPECT_TRUE(node->getDagManager()->addDagBlock(std::move(blk), {trx}).first); } @@ -366,8 +370,9 @@ TEST_F(DagBlockMgrTest, dag_block_tips_proposal) { dev::bytes vdf_msg = DagManager::getVdfMessage(dag_blocks_hashes[0], {trx}); vdf.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk(dag_blocks_hashes[0], propose_level, {}, {trx->getHash()}, 100000, vdf, node->getSecretKey()); - dag_blocks_hashes.push_back(blk.getHash()); + auto blk = std::make_shared(dag_blocks_hashes[0], propose_level, vec_blk_t{}, vec_trx_t{trx->getHash()}, + 100000, vdf, node->getSecretKey()); + dag_blocks_hashes.push_back(blk->getHash()); EXPECT_EQ(node->getDagManager()->verifyBlock(blk).first, DagManager::VerifyBlockReturnType::Verified); EXPECT_TRUE(node->getDagManager()->addDagBlock(std::move(blk), {trx}).first); } @@ -387,8 +392,9 @@ TEST_F(DagBlockMgrTest, dag_block_tips_proposal) { dev::bytes vdf_msg = DagManager::getVdfMessage(dag_genesis, {trxs[0]}); vdf.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk(dag_genesis, propose_level, {}, {trxs[0]->getHash()}, 100000, vdf, node_cfgs[1].node_secret); - dag_blocks_hashes.push_back(blk.getHash()); + auto blk = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, vec_trx_t{trxs[0]->getHash()}, 100000, + vdf, node_cfgs[1].node_secret); + dag_blocks_hashes.push_back(blk->getHash()); EXPECT_TRUE(node->getDagManager()->addDagBlock(std::move(blk), {trxs[0]}).first); selected_tips = node->getDagBlockProposer()->selectDagBlockTips(dag_blocks_hashes, selection_gas_limit); @@ -434,7 +440,8 @@ TEST_F(DagBlockMgrTest, too_big_dag_block) { vdf1.computeVdfSolution(vdf_config, vdf_msg, false); { - DagBlock blk(dag_genesis, propose_level, {}, hashes, estimations, vdf1, node->getSecretKey()); + auto blk = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, hashes, estimations, vdf1, + node->getSecretKey()); EXPECT_EQ(node->getDagManager()->verifyBlock(std::move(blk)).first, DagManager::VerifyBlockReturnType::BlockTooBig); } } diff --git a/tests/dag_test.cpp b/tests/dag_test.cpp index 6885b82624..3d9e5cb1c0 100644 --- a/tests/dag_test.cpp +++ b/tests/dag_test.cpp @@ -138,23 +138,34 @@ TEST_F(DagTest, compute_epoch) { node_cfgs[0].genesis.pbft.gas_limit = 100000; auto mgr = std::make_shared(node_cfgs[0], addr_t(), trx_mgr, pbft_chain, nullptr, db_ptr, nullptr); - 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)); - DagBlock blkC(blk_hash_t(2), 2, {blk_hash_t(3)}, {}, sig_t(1), blk_hash_t(4), addr_t(1)); - DagBlock blkD(blk_hash_t(2), 2, {}, {}, sig_t(1), blk_hash_t(5), addr_t(1)); - DagBlock blkE(blk_hash_t(4), 3, {blk_hash_t(5), blk_hash_t(7)}, {}, sig_t(1), blk_hash_t(6), addr_t(1)); - DagBlock blkF(blk_hash_t(3), 2, {}, {}, sig_t(1), blk_hash_t(7), addr_t(1)); - DagBlock blkG(blk_hash_t(2), 2, {}, {trx_hash_t(4)}, sig_t(1), blk_hash_t(8), addr_t(1)); - DagBlock blkH(blk_hash_t(6), 5, {blk_hash_t(8), blk_hash_t(10)}, {}, sig_t(1), blk_hash_t(9), addr_t(1)); - DagBlock blkI(blk_hash_t(11), 4, {blk_hash_t(4)}, {}, sig_t(1), blk_hash_t(10), addr_t(1)); - DagBlock blkJ(blk_hash_t(7), 3, {}, {}, sig_t(1), blk_hash_t(11), addr_t(1)); - DagBlock blkK(blk_hash_t(9), 6, {}, {}, sig_t(1), blk_hash_t(12), addr_t(1)); - - const auto blkA_hash = blkA.getHash(); - const auto blkC_hash = blkC.getHash(); - const auto blkE_hash = blkE.getHash(); - const auto blkH_hash = blkH.getHash(); - const auto blkK_hash = blkK.getHash(); + auto blkA = + std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{trx_hash_t(2)}, sig_t(1), blk_hash_t(2), addr_t(1)); + auto blkB = std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{trx_hash_t(3), trx_hash_t(4)}, sig_t(1), + blk_hash_t(3), addr_t(1)); + auto blkC = std::make_shared(blk_hash_t(2), 2, vec_blk_t{blk_hash_t(3)}, vec_trx_t{}, sig_t(1), + blk_hash_t(4), addr_t(1)); + auto blkD = + std::make_shared(blk_hash_t(2), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(5), addr_t(1)); + auto blkE = std::make_shared(blk_hash_t(4), 3, vec_blk_t{blk_hash_t(5), blk_hash_t(7)}, vec_trx_t{}, + sig_t(1), blk_hash_t(6), addr_t(1)); + auto blkF = + std::make_shared(blk_hash_t(3), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(7), addr_t(1)); + auto blkG = std::make_shared(blk_hash_t(2), 2, vec_blk_t{}, vec_trx_t{trx_hash_t(4)}, sig_t(1), + blk_hash_t(8), addr_t(1)); + auto blkH = std::make_shared(blk_hash_t(6), 5, vec_blk_t{blk_hash_t(8), blk_hash_t(10)}, vec_trx_t{}, + sig_t(1), blk_hash_t(9), addr_t(1)); + auto blkI = std::make_shared(blk_hash_t(11), 4, vec_blk_t{blk_hash_t(4)}, vec_trx_t{}, sig_t(1), + blk_hash_t(10), addr_t(1)); + auto blkJ = + std::make_shared(blk_hash_t(7), 3, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(11), addr_t(1)); + auto blkK = + std::make_shared(blk_hash_t(9), 6, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(12), addr_t(1)); + + const auto blkA_hash = blkA->getHash(); + const auto blkC_hash = blkC->getHash(); + const auto blkE_hash = blkE->getHash(); + const auto blkH_hash = blkH->getHash(); + const auto blkK_hash = blkK->getHash(); EXPECT_TRUE(mgr->addDagBlock(std::move(blkA)).first); EXPECT_TRUE(mgr->addDagBlock(std::move(blkB)).first); @@ -232,19 +243,30 @@ TEST_F(DagTest, dag_expiry) { node_cfgs[0].genesis.pbft.gas_limit = 100000; auto mgr = std::make_shared(node_cfgs[0], addr_t(), trx_mgr, pbft_chain, nullptr, db_ptr, nullptr); - 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)); - DagBlock blkC(blk_hash_t(2), 2, {blk_hash_t(3)}, {}, sig_t(1), blk_hash_t(4), addr_t(1)); - DagBlock blkD(blk_hash_t(2), 2, {}, {}, sig_t(1), blk_hash_t(5), addr_t(1)); - DagBlock blkE(blk_hash_t(4), 3, {blk_hash_t(5), blk_hash_t(7)}, {}, sig_t(1), blk_hash_t(6), addr_t(1)); - DagBlock blkF(blk_hash_t(3), 2, {}, {}, sig_t(1), blk_hash_t(7), addr_t(1)); - DagBlock blkG(blk_hash_t(2), 2, {}, {trx_hash_t(4)}, sig_t(1), blk_hash_t(8), addr_t(1)); - DagBlock blkH(blk_hash_t(6), 5, {blk_hash_t(8), blk_hash_t(10)}, {}, sig_t(1), blk_hash_t(9), addr_t(1)); - DagBlock blkI(blk_hash_t(11), 4, {blk_hash_t(4)}, {}, sig_t(1), blk_hash_t(10), addr_t(1)); - DagBlock blkJ(blk_hash_t(7), 3, {}, {}, sig_t(1), blk_hash_t(11), addr_t(1)); - DagBlock blkK(blk_hash_t(9), 6, {}, {}, sig_t(1), blk_hash_t(12), addr_t(1)); - - const auto blkK_hash = blkK.getHash(); + auto blkA = + std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{trx_hash_t(2)}, sig_t(1), blk_hash_t(2), addr_t(1)); + auto blkB = std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{trx_hash_t(3), trx_hash_t(4)}, sig_t(1), + blk_hash_t(3), addr_t(1)); + auto blkC = std::make_shared(blk_hash_t(2), 2, vec_blk_t{blk_hash_t(3)}, vec_trx_t{}, sig_t(1), + blk_hash_t(4), addr_t(1)); + auto blkD = + std::make_shared(blk_hash_t(2), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(5), addr_t(1)); + auto blkE = std::make_shared(blk_hash_t(4), 3, vec_blk_t{blk_hash_t(5), blk_hash_t(7)}, vec_trx_t{}, + sig_t(1), blk_hash_t(6), addr_t(1)); + auto blkF = + std::make_shared(blk_hash_t(3), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(7), addr_t(1)); + auto blkG = std::make_shared(blk_hash_t(2), 2, vec_blk_t{}, vec_trx_t{trx_hash_t(4)}, sig_t(1), + blk_hash_t(8), addr_t(1)); + auto blkH = std::make_shared(blk_hash_t(6), 5, vec_blk_t{blk_hash_t(8), blk_hash_t(10)}, vec_trx_t{}, + sig_t(1), blk_hash_t(9), addr_t(1)); + auto blkI = std::make_shared(blk_hash_t(11), 4, vec_blk_t{blk_hash_t(4)}, vec_trx_t{}, sig_t(1), + blk_hash_t(10), addr_t(1)); + auto blkJ = + std::make_shared(blk_hash_t(7), 3, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(11), addr_t(1)); + auto blkK = + std::make_shared(blk_hash_t(9), 6, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(12), addr_t(1)); + + const auto blkK_hash = blkK->getHash(); mgr->addDagBlock(std::move(blkA)); mgr->addDagBlock(std::move(blkB)); @@ -270,33 +292,35 @@ TEST_F(DagTest, dag_expiry) { mgr->setDagBlockOrder(blkK_hash, 1, orders); // Verify expiry level - EXPECT_EQ(mgr->getDagExpiryLevel(), blkK.getLevel() - EXPIRY_LIMIT); + EXPECT_EQ(mgr->getDagExpiryLevel(), blkK->getLevel() - EXPIRY_LIMIT); - DagBlock blk_under_limit(blk_hash_t(2), blkK.getLevel() - EXPIRY_LIMIT - 1, {}, {}, sig_t(1), blk_hash_t(13), - addr_t(1)); - DagBlock blk_at_limit(blk_hash_t(4), blkK.getLevel() - EXPIRY_LIMIT, {}, {}, sig_t(1), blk_hash_t(14), addr_t(1)); - DagBlock blk_over_limit(blk_hash_t(11), blkK.getLevel() - EXPIRY_LIMIT + 1, {}, {}, sig_t(1), blk_hash_t(15), - addr_t(1)); + auto blk_under_limit = std::make_shared(blk_hash_t(2), blkK->getLevel() - EXPIRY_LIMIT - 1, vec_blk_t{}, + vec_trx_t{}, sig_t(1), blk_hash_t(13), addr_t(1)); + auto blk_at_limit = std::make_shared(blk_hash_t(4), blkK->getLevel() - EXPIRY_LIMIT, vec_blk_t{}, + vec_trx_t{}, sig_t(1), blk_hash_t(14), addr_t(1)); + auto blk_over_limit = std::make_shared(blk_hash_t(11), blkK->getLevel() - EXPIRY_LIMIT + 1, vec_blk_t{}, + vec_trx_t{}, sig_t(1), blk_hash_t(15), addr_t(1)); // Block under limit is not accepted to DAG since it is expired EXPECT_FALSE(mgr->addDagBlock(std::move(blk_under_limit)).first); EXPECT_TRUE(mgr->addDagBlock(std::move(blk_at_limit)).first); EXPECT_TRUE(mgr->addDagBlock(std::move(blk_over_limit)).first); - EXPECT_FALSE(db_ptr->dagBlockInDb(blk_under_limit.getHash())); - EXPECT_TRUE(db_ptr->dagBlockInDb(blk_at_limit.getHash())); - EXPECT_TRUE(db_ptr->dagBlockInDb(blk_over_limit.getHash())); + EXPECT_FALSE(db_ptr->dagBlockInDb(blk_under_limit->getHash())); + EXPECT_TRUE(db_ptr->dagBlockInDb(blk_at_limit->getHash())); + EXPECT_TRUE(db_ptr->dagBlockInDb(blk_over_limit->getHash())); - DagBlock blk_new_anchor(blk_hash_t(12), 7, {}, {}, sig_t(1), blk_hash_t(16), addr_t(1)); + auto blk_new_anchor = + std::make_shared(blk_hash_t(12), 7, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(16), addr_t(1)); EXPECT_TRUE(mgr->addDagBlock(std::move(blk_new_anchor)).first); - orders = mgr->getDagBlockOrder(blk_new_anchor.getHash(), 2); - mgr->setDagBlockOrder(blk_new_anchor.getHash(), 2, orders); + orders = mgr->getDagBlockOrder(blk_new_anchor->getHash(), 2); + mgr->setDagBlockOrder(blk_new_anchor->getHash(), 2, orders); // Verify that the block blk_at_limit which was initially part of the DAG became expired once new anchor moved the // limit - EXPECT_FALSE(db_ptr->dagBlockInDb(blk_under_limit.getHash())); - EXPECT_FALSE(db_ptr->dagBlockInDb(blk_at_limit.getHash())); - EXPECT_TRUE(db_ptr->dagBlockInDb(blk_over_limit.getHash())); + EXPECT_FALSE(db_ptr->dagBlockInDb(blk_under_limit->getHash())); + EXPECT_FALSE(db_ptr->dagBlockInDb(blk_at_limit->getHash())); + EXPECT_TRUE(db_ptr->dagBlockInDb(blk_over_limit->getHash())); } TEST_F(DagTest, receive_block_in_order) { @@ -307,9 +331,11 @@ TEST_F(DagTest, receive_block_in_order) { node_cfgs[0].genesis.pbft.gas_limit = 100000; auto mgr = std::make_shared(node_cfgs[0], addr_t(), trx_mgr, pbft_chain, nullptr, db_ptr, nullptr); - 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)); - DagBlock blk3(GENESIS, 3, {blk_hash_t(1), blk_hash_t(2)}, {}, sig_t(777), blk_hash_t(3), addr_t(15)); + auto blk1 = std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{}, sig_t(777), blk_hash_t(1), addr_t(15)); + auto blk2 = + std::make_shared(blk_hash_t(1), 2, vec_blk_t{}, vec_trx_t{}, sig_t(777), blk_hash_t(2), addr_t(15)); + auto blk3 = std::make_shared(GENESIS, 3, vec_blk_t{blk_hash_t(1), blk_hash_t(2)}, vec_trx_t{}, sig_t(777), + blk_hash_t(3), addr_t(15)); mgr->addDagBlock(std::move(blk1)); mgr->addDagBlock(std::move(blk2)); @@ -338,23 +364,34 @@ TEST_F(DagTest, compute_epoch_2) { node_cfgs[0].genesis.pbft.gas_limit = 100000; auto mgr = std::make_shared(node_cfgs[0], addr_t(), trx_mgr, pbft_chain, nullptr, db_ptr, nullptr); - 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)); - DagBlock blkC(blk_hash_t(2), 2, {blk_hash_t(3)}, {}, sig_t(1), blk_hash_t(4), addr_t(1)); - DagBlock blkD(blk_hash_t(2), 2, {}, {}, sig_t(1), blk_hash_t(5), addr_t(1)); - DagBlock blkE(blk_hash_t(4), 3, {blk_hash_t(5), blk_hash_t(7)}, {}, sig_t(1), blk_hash_t(6), addr_t(1)); - DagBlock blkF(blk_hash_t(3), 2, {}, {}, sig_t(1), blk_hash_t(7), addr_t(1)); - DagBlock blkG(blk_hash_t(2), 2, {}, {trx_hash_t(4)}, sig_t(1), blk_hash_t(8), addr_t(1)); - DagBlock blkH(blk_hash_t(6), 5, {blk_hash_t(8), blk_hash_t(10)}, {}, sig_t(1), blk_hash_t(9), addr_t(1)); - DagBlock blkI(blk_hash_t(11), 4, {blk_hash_t(4)}, {}, sig_t(1), blk_hash_t(10), addr_t(1)); - DagBlock blkJ(blk_hash_t(7), 3, {}, {}, sig_t(1), blk_hash_t(11), addr_t(1)); - DagBlock blkK(blk_hash_t(10), 5, {}, {}, sig_t(1), blk_hash_t(12), addr_t(1)); - - const auto blkA_hash = blkA.getHash(); - const auto blkC_hash = blkC.getHash(); - const auto blkE_hash = blkE.getHash(); - const auto blkH_hash = blkH.getHash(); - const auto blkK_hash = blkK.getHash(); + auto blkA = + std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{trx_hash_t(2)}, sig_t(1), blk_hash_t(2), addr_t(1)); + auto blkB = std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{trx_hash_t(3), trx_hash_t(4)}, sig_t(1), + blk_hash_t(3), addr_t(1)); + auto blkC = std::make_shared(blk_hash_t(2), 2, vec_blk_t{blk_hash_t(3)}, vec_trx_t{}, sig_t(1), + blk_hash_t(4), addr_t(1)); + auto blkD = + std::make_shared(blk_hash_t(2), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(5), addr_t(1)); + auto blkE = std::make_shared(blk_hash_t(4), 3, vec_blk_t{blk_hash_t(5), blk_hash_t(7)}, vec_trx_t{}, + sig_t(1), blk_hash_t(6), addr_t(1)); + auto blkF = + std::make_shared(blk_hash_t(3), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(7), addr_t(1)); + auto blkG = std::make_shared(blk_hash_t(2), 2, vec_blk_t{}, vec_trx_t{trx_hash_t(4)}, sig_t(1), + blk_hash_t(8), addr_t(1)); + auto blkH = std::make_shared(blk_hash_t(6), 5, vec_blk_t{blk_hash_t(8), blk_hash_t(10)}, vec_trx_t{}, + sig_t(1), blk_hash_t(9), addr_t(1)); + auto blkI = std::make_shared(blk_hash_t(11), 4, vec_blk_t{blk_hash_t(4)}, vec_trx_t{}, sig_t(1), + blk_hash_t(10), addr_t(1)); + auto blkJ = + std::make_shared(blk_hash_t(7), 3, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(11), addr_t(1)); + auto blkK = + std::make_shared(blk_hash_t(10), 5, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(12), addr_t(1)); + + const auto blkA_hash = blkA->getHash(); + const auto blkC_hash = blkC->getHash(); + const auto blkE_hash = blkE->getHash(); + const auto blkH_hash = blkH->getHash(); + const auto blkK_hash = blkK->getHash(); mgr->addDagBlock(std::move(blkA)); mgr->addDagBlock(std::move(blkB)); @@ -420,11 +457,14 @@ TEST_F(DagTest, get_latest_pivot_tips) { node_cfgs[0].genesis.pbft.gas_limit = 100000; auto mgr = std::make_shared(node_cfgs[0], addr_t(), trx_mgr, pbft_chain, nullptr, db_ptr, nullptr); - 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)); - DagBlock blk4(GENESIS, 1, {}, {}, sig_t(1), blk_hash_t(4), addr_t(15)); - DagBlock blk5(blk_hash_t(4), 2, {}, {}, sig_t(1), blk_hash_t(5), addr_t(15)); - DagBlock blk6(blk_hash_t(2), 3, {blk_hash_t(5)}, {}, sig_t(1), blk_hash_t(6), addr_t(15)); + auto blk2 = std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(2), addr_t(15)); + auto blk3 = + std::make_shared(blk_hash_t(2), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(3), addr_t(15)); + auto blk4 = std::make_shared(GENESIS, 1, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(4), addr_t(15)); + auto blk5 = + std::make_shared(blk_hash_t(4), 2, vec_blk_t{}, vec_trx_t{}, sig_t(1), blk_hash_t(5), addr_t(15)); + auto blk6 = std::make_shared(blk_hash_t(2), 3, vec_blk_t{blk_hash_t(5)}, vec_trx_t{}, sig_t(1), + blk_hash_t(6), addr_t(15)); mgr->addDagBlock(std::move(blk2)); mgr->addDagBlock(std::move(blk3)); mgr->addDagBlock(std::move(blk4)); diff --git a/tests/final_chain_test.cpp b/tests/final_chain_test.cpp index 451bfd970a..376ce2fa92 100644 --- a/tests/final_chain_test.cpp +++ b/tests/final_chain_test.cpp @@ -66,7 +66,8 @@ struct FinalChainTest : WithDataDir { trx_hashes.emplace_back(trx->getHash()); } - DagBlock dag_blk({}, {}, {}, trx_hashes, {}, {}, dag_proposer_keys.secret()); + auto dag_blk = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, trx_hashes, 0, VdfSortition{}, + dag_proposer_keys.secret()); db->saveDagBlock(dag_blk); std::vector reward_votes_hashes; auto pbft_block = @@ -87,7 +88,7 @@ struct FinalChainTest : WithDataDir { db->savePeriodData(period_data, batch); db->commitWriteBatch(batch); - auto result = SUT->finalize(std::move(period_data), {dag_blk.getHash()}).get(); + auto result = SUT->finalize(std::move(period_data), {dag_blk->getHash()}).get(); const auto& blk_h = *result->final_chain_blk; EXPECT_EQ(util::rlp_enc(blk_h), util::rlp_enc(*SUT->blockHeader(blk_h.number))); EXPECT_EQ(util::rlp_enc(blk_h), util::rlp_enc(*SUT->blockHeader())); diff --git a/tests/full_node_test.cpp b/tests/full_node_test.cpp index b8816637df..df78f052e8 100644 --- a/tests/full_node_test.cpp +++ b/tests/full_node_test.cpp @@ -55,20 +55,23 @@ struct FullNodeTest : NodesTest {}; TEST_F(FullNodeTest, db_test) { auto db_ptr = std::make_shared(data_dir); auto &db = *db_ptr; - DagBlock blk1(blk_hash_t(1), 1, {}, {trx_hash_t(1), trx_hash_t(2)}, sig_t(777), blk_hash_t(0xB1), addr_t(999)); - DagBlock blk2(blk_hash_t(1), 1, {}, {trx_hash_t(3), trx_hash_t(4)}, sig_t(777), blk_hash_t(0xB2), addr_t(999)); - DagBlock blk3(blk_hash_t(0xB1), 2, {}, {trx_hash_t(5)}, sig_t(777), blk_hash_t(0xB6), addr_t(999)); + auto blk1 = std::make_shared(blk_hash_t(1), 1, vec_blk_t{}, vec_trx_t{trx_hash_t(1), trx_hash_t(2)}, + sig_t(777), blk_hash_t(0xB1), addr_t(999)); + auto blk2 = std::make_shared(blk_hash_t(1), 1, vec_blk_t{}, vec_trx_t{trx_hash_t(3), trx_hash_t(4)}, + sig_t(777), blk_hash_t(0xB2), addr_t(999)); + auto blk3 = std::make_shared(blk_hash_t(0xB1), 2, vec_blk_t{}, vec_trx_t{trx_hash_t(5)}, sig_t(777), + blk_hash_t(0xB6), addr_t(999)); // DAG db.saveDagBlock(blk1); db.saveDagBlock(blk2); db.saveDagBlock(blk3); - EXPECT_EQ(blk1, *db.getDagBlock(blk1.getHash())); - EXPECT_EQ(blk2, *db.getDagBlock(blk2.getHash())); - EXPECT_EQ(blk3, *db.getDagBlock(blk3.getHash())); + EXPECT_EQ(*blk1, *db.getDagBlock(blk1->getHash())); + EXPECT_EQ(*blk2, *db.getDagBlock(blk2->getHash())); + EXPECT_EQ(*blk3, *db.getDagBlock(blk3->getHash())); std::set s1, s2; - s1.emplace(blk1.getHash()); - s1.emplace(blk2.getHash()); - s2.emplace(blk3.getHash()); + s1.emplace(blk1->getHash()); + s1.emplace(blk2->getHash()); + s2.emplace(blk3->getHash()); EXPECT_EQ(db.getBlocksByLevel(1), s1); EXPECT_EQ(db.getBlocksByLevel(2), s2); @@ -833,7 +836,7 @@ TEST_F(FullNodeTest, reconstruct_dag) { taraxa::thisThreadSleepForMilliSeconds(100); for (size_t i = 0; i < num_blks; i++) { - EXPECT_EQ(true, node->getDagManager()->addDagBlock(DagBlock(mock_dags[i])).first); + EXPECT_EQ(true, node->getDagManager()->addDagBlock(mock_dags[i]).first); } taraxa::thisThreadSleepForMilliSeconds(100); @@ -853,7 +856,7 @@ TEST_F(FullNodeTest, reconstruct_dag) { // TODO: pbft does not support node stop yet, to be fixed ... node->getPbftManager()->stop(); for (size_t i = 0; i < num_blks; i++) { - EXPECT_EQ(true, node->getDagManager()->addDagBlock(DagBlock(mock_dags[i])).first); + EXPECT_EQ(true, node->getDagManager()->addDagBlock(mock_dags[i]).first); } taraxa::thisThreadSleepForMilliSeconds(100); vertices3 = node->getDagManager()->getNumVerticesInDag().first; diff --git a/tests/network_test.cpp b/tests/network_test.cpp index ce5bfb7767..4ea21a43d2 100644 --- a/tests/network_test.cpp +++ b/tests/network_test.cpp @@ -99,8 +99,9 @@ TEST_F(NetworkTest, transfer_lot_of_blocks) { const auto dag_genesis = node1->getConfig().genesis.dag_genesis_block.getHash(); dev::bytes vdf_msg = DagManager::getVdfMessage(dag_genesis, {trxs[0]}); vdf.computeVdfSolution(sortition_params, vdf_msg, false); - DagBlock blk(dag_genesis, proposal_level, {}, {trxs[0]->getHash()}, estimation, vdf, node1->getSecretKey()); - const auto block_hash = blk.getHash(); + auto blk = std::make_shared(dag_genesis, proposal_level, vec_blk_t{}, vec_trx_t{trxs[0]->getHash()}, + estimation, vdf, node1->getSecretKey()); + const auto block_hash = blk->getHash(); dag_mgr1->addDagBlock(std::move(blk), {trxs[0]}); std::vector> dag_blocks; @@ -124,8 +125,8 @@ TEST_F(NetworkTest, transfer_lot_of_blocks) { node1->getTransactionManager()->insertValidatedTransaction(std::move(tx)); } for (size_t i = 0; i < dag_blocks.size(); i++) { - if (dag_mgr1->verifyBlock(*dag_blocks[i]).first == DagManager::VerifyBlockReturnType::Verified) - dag_mgr1->addDagBlock(DagBlock(*dag_blocks[i]), {trxs[i]}); + if (dag_mgr1->verifyBlock(dag_blocks[i]).first == DagManager::VerifyBlockReturnType::Verified) + dag_mgr1->addDagBlock(dag_blocks[i], {trxs[i]}); } wait({1s, 200ms}, [&](auto& ctx) { WAIT_EXPECT_NE(ctx, dag_mgr1->getDagBlock(block_hash), nullptr) }); const auto node1_period = node1->getPbftChain()->getPbftChainSize(); @@ -164,9 +165,10 @@ TEST_F(NetworkTest, propagate_block) { const auto dag_genesis = node1->getConfig().genesis.dag_genesis_block.getHash(); dev::bytes vdf_msg = DagManager::getVdfMessage(dag_genesis, {trxs[0]}); vdf.computeVdfSolution(sortition_params, vdf_msg, false); - DagBlock blk(dag_genesis, proposal_level, {}, {trxs[0]->getHash()}, estimation, vdf, node1->getSecretKey()); + auto blk = std::make_shared(dag_genesis, proposal_level, vec_blk_t{}, vec_trx_t{trxs[0]->getHash()}, + estimation, vdf, node1->getSecretKey()); - const auto block_hash = blk.getHash(); + const auto block_hash = blk->getHash(); // Add block gossip it to connected peers dag_mgr1->addDagBlock(std::move(blk), {trxs[0]}); @@ -413,7 +415,7 @@ TEST_F(NetworkTest, node_sync) { // Allow node to start up taraxa::thisThreadSleepForMilliSeconds(1000); - std::vector>> blks; + std::vector, std::shared_ptr>> blks; // Generate DAG blocks const auto dag_genesis = node1->getConfig().genesis.dag_genesis_block.getHash(); const auto sk = node1->getSecretKey(); @@ -428,43 +430,48 @@ TEST_F(NetworkTest, node_sync) { dev::bytes vdf_msg1 = DagManager::getVdfMessage(dag_genesis, {g_signed_trx_samples[1]}); vdf1.computeVdfSolution(vdf_config, vdf_msg1, false); - DagBlock blk1(dag_genesis, propose_level, {}, {g_signed_trx_samples[1]->getHash()}, estimation, vdf1, sk); + auto blk1 = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[1]->getHash()}, estimation, vdf1, sk); propose_level = 2; vdf_sortition::VdfSortition vdf2(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1.getHash(), {g_signed_trx_samples[2]}); + dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1->getHash(), {g_signed_trx_samples[2]}); vdf2.computeVdfSolution(vdf_config, vdf_msg2, false); - DagBlock blk2(blk1.getHash(), propose_level, {}, {g_signed_trx_samples[2]->getHash()}, estimation, vdf2, sk); + auto blk2 = std::make_shared(blk1->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[2]->getHash()}, estimation, vdf2, sk); propose_level = 3; vdf_sortition::VdfSortition vdf3(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg3 = DagManager::getVdfMessage(blk2.getHash(), {g_signed_trx_samples[3]}); + dev::bytes vdf_msg3 = DagManager::getVdfMessage(blk2->getHash(), {g_signed_trx_samples[3]}); vdf3.computeVdfSolution(vdf_config, vdf_msg3, false); - DagBlock blk3(blk2.getHash(), propose_level, {}, {g_signed_trx_samples[3]->getHash()}, estimation, vdf3, sk); + auto blk3 = std::make_shared(blk2->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[3]->getHash()}, estimation, vdf3, sk); propose_level = 4; vdf_sortition::VdfSortition vdf4(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg4 = DagManager::getVdfMessage(blk3.getHash(), {g_signed_trx_samples[4]}); + dev::bytes vdf_msg4 = DagManager::getVdfMessage(blk3->getHash(), {g_signed_trx_samples[4]}); vdf4.computeVdfSolution(vdf_config, vdf_msg4, false); - DagBlock blk4(blk3.getHash(), propose_level, {}, {g_signed_trx_samples[4]->getHash()}, estimation, vdf4, sk); + auto blk4 = std::make_shared(blk3->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[4]->getHash()}, estimation, vdf4, sk); propose_level = 5; vdf_sortition::VdfSortition vdf5(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg5 = DagManager::getVdfMessage(blk4.getHash(), {g_signed_trx_samples[5]}); + dev::bytes vdf_msg5 = DagManager::getVdfMessage(blk4->getHash(), {g_signed_trx_samples[5]}); vdf5.computeVdfSolution(vdf_config, vdf_msg5, false); - DagBlock blk5(blk4.getHash(), propose_level, {}, {g_signed_trx_samples[5]->getHash()}, estimation, vdf5, sk); + auto blk5 = std::make_shared(blk4->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[5]->getHash()}, estimation, vdf5, sk); propose_level = 6; vdf_sortition::VdfSortition vdf6(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg6 = DagManager::getVdfMessage(blk5.getHash(), {g_signed_trx_samples[6]}); + dev::bytes vdf_msg6 = DagManager::getVdfMessage(blk5->getHash(), {g_signed_trx_samples[6]}); vdf6.computeVdfSolution(vdf_config, vdf_msg6, false); - DagBlock blk6(blk5.getHash(), propose_level, {blk4.getHash(), blk3.getHash()}, {g_signed_trx_samples[6]->getHash()}, - estimation, vdf6, sk); + auto blk6 = std::make_shared(blk5->getHash(), propose_level, vec_blk_t{blk4->getHash(), blk3->getHash()}, + vec_trx_t{g_signed_trx_samples[6]->getHash()}, estimation, vdf6, sk); blks.push_back(std::make_pair(blk1, g_signed_trx_samples[1])); blks.push_back(std::make_pair(blk2, g_signed_trx_samples[2])); @@ -521,18 +528,19 @@ TEST_F(NetworkTest, node_pbft_sync) { vdf_sortition::VdfSortition vdf1(vdf_config, vrf_sk, getRlpBytes(level), 1, 1); dev::bytes vdf_msg1 = DagManager::getVdfMessage(dag_genesis, {g_signed_trx_samples[0], g_signed_trx_samples[1]}); vdf1.computeVdfSolution(vdf_config, vdf_msg1, false); - DagBlock blk1(dag_genesis, 1, {}, {g_signed_trx_samples[0]->getHash(), g_signed_trx_samples[1]->getHash()}, 0, vdf1, - sk); + auto blk1 = std::make_shared( + dag_genesis, 1, vec_blk_t{}, vec_trx_t{g_signed_trx_samples[0]->getHash(), g_signed_trx_samples[1]->getHash()}, 0, + vdf1, sk); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[0])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[1])); - node1->getDagManager()->verifyBlock(DagBlock(blk1)); - node1->getDagManager()->addDagBlock(DagBlock(blk1)); + node1->getDagManager()->verifyBlock(blk1); + node1->getDagManager()->addDagBlock(blk1); dev::RLPStream order_stream(1); order_stream.appendList(1); - order_stream << blk1.getHash(); + order_stream << blk1->getHash(); - PbftBlock pbft_block1(prev_block_hash, blk1.getHash(), dev::sha3(order_stream.out()), kNullBlockHash, period, + PbftBlock pbft_block1(prev_block_hash, blk1->getHash(), dev::sha3(order_stream.out()), kNullBlockHash, period, beneficiary, node1->getSecretKey(), {}, {}); std::vector> votes_for_pbft_blk1; votes_for_pbft_blk1.emplace_back( @@ -557,10 +565,10 @@ TEST_F(NetworkTest, node_pbft_sync) { db1->commitWriteBatch(batch); vec_blk_t order1; - order1.push_back(blk1.getHash()); + order1.push_back(blk1->getHash()); { std::unique_lock dag_lock(node1->getDagManager()->getDagMutex()); - node1->getDagManager()->setDagBlockOrder(blk1.getHash(), level, order1); + node1->getDagManager()->setDagBlockOrder(blk1->getHash(), level, order1); } uint64_t expect_pbft_chain_size = 1; @@ -571,22 +579,23 @@ TEST_F(NetworkTest, node_pbft_sync) { level = 2; vdf_sortition::VdfSortition vdf2(vdf_config, vrf_sk, getRlpBytes(level), 1, 1); - dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1.getHash(), {g_signed_trx_samples[2], g_signed_trx_samples[3]}); + dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1->getHash(), {g_signed_trx_samples[2], g_signed_trx_samples[3]}); vdf2.computeVdfSolution(vdf_config, vdf_msg2, false); - DagBlock blk2(blk1.getHash(), 2, {}, {g_signed_trx_samples[2]->getHash(), g_signed_trx_samples[3]->getHash()}, 0, - vdf2, sk); + auto blk2 = std::make_shared( + blk1->getHash(), 2, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[2]->getHash(), g_signed_trx_samples[3]->getHash()}, 0, vdf2, sk); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[2])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[3])); - node1->getDagManager()->verifyBlock(DagBlock(blk2)); - node1->getDagManager()->addDagBlock(DagBlock(blk2)); + node1->getDagManager()->verifyBlock(blk2); + node1->getDagManager()->addDagBlock(blk2); batch = db1->createWriteBatch(); period = 2; beneficiary = addr_t(654); dev::RLPStream order_stream2(1); order_stream2.appendList(1); - order_stream2 << blk2.getHash(); - PbftBlock pbft_block2(prev_block_hash, blk2.getHash(), dev::sha3(order_stream2.out()), kNullBlockHash, period, + order_stream2 << blk2->getHash(); + PbftBlock pbft_block2(prev_block_hash, blk2->getHash(), dev::sha3(order_stream2.out()), kNullBlockHash, period, beneficiary, node1->getSecretKey(), {}, {}); std::vector> votes_for_pbft_blk2; votes_for_pbft_blk2.emplace_back( @@ -617,10 +626,10 @@ TEST_F(NetworkTest, node_pbft_sync) { db1->commitWriteBatch(batch); vec_blk_t order2; - order2.push_back(blk2.getHash()); + order2.push_back(blk2->getHash()); { std::unique_lock dag_lock(node1->getDagManager()->getDagMutex()); - node1->getDagManager()->setDagBlockOrder(blk2.getHash(), level, order2); + node1->getDagManager()->setDagBlockOrder(blk2->getHash(), level, order2); } expect_pbft_chain_size = 2; @@ -668,18 +677,19 @@ TEST_F(NetworkTest, node_pbft_sync_without_enough_votes) { vdf_sortition::VdfSortition vdf1(vdf_config, vrf_sk, getRlpBytes(level), 1, 1); dev::bytes vdf_msg1 = DagManager::getVdfMessage(dag_genesis, {g_signed_trx_samples[0], g_signed_trx_samples[1]}); vdf1.computeVdfSolution(vdf_config, vdf_msg1, false); - DagBlock blk1(dag_genesis, 1, {}, {g_signed_trx_samples[0]->getHash(), g_signed_trx_samples[1]->getHash()}, 0, vdf1, - sk); + auto blk1 = std::make_shared( + dag_genesis, 1, vec_blk_t{}, vec_trx_t{g_signed_trx_samples[0]->getHash(), g_signed_trx_samples[1]->getHash()}, 0, + vdf1, sk); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[0])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[1])); - node1->getDagManager()->verifyBlock(DagBlock(blk1)); - node1->getDagManager()->addDagBlock(DagBlock(blk1)); + node1->getDagManager()->verifyBlock(blk1); + node1->getDagManager()->addDagBlock(blk1); dev::RLPStream order_stream(1); order_stream.appendList(1); - order_stream << blk1.getHash(); + order_stream << blk1->getHash(); - PbftBlock pbft_block1(prev_block_hash, blk1.getHash(), dev::sha3(order_stream.out()), kNullBlockHash, period, + PbftBlock pbft_block1(prev_block_hash, blk1->getHash(), dev::sha3(order_stream.out()), kNullBlockHash, period, beneficiary, node1->getSecretKey(), {}, {}); const auto pbft_block1_cert_vote = node1->getVoteManager()->generateVote( pbft_block1.getBlockHash(), PbftVoteTypes::cert_vote, pbft_block1.getPeriod(), 1, 3); @@ -707,14 +717,15 @@ TEST_F(NetworkTest, node_pbft_sync_without_enough_votes) { prev_block_hash = pbft_block1.getBlockHash(); level = 2; vdf_sortition::VdfSortition vdf2(vdf_config, vrf_sk, getRlpBytes(level), 1, 1); - dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1.getHash(), {g_signed_trx_samples[2], g_signed_trx_samples[3]}); + dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1->getHash(), {g_signed_trx_samples[2], g_signed_trx_samples[3]}); vdf2.computeVdfSolution(vdf_config, vdf_msg2, false); - DagBlock blk2(blk1.getHash(), 2, {}, {g_signed_trx_samples[2]->getHash(), g_signed_trx_samples[3]->getHash()}, 0, - vdf2, sk); + auto blk2 = std::make_shared( + blk1->getHash(), 2, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[2]->getHash(), g_signed_trx_samples[3]->getHash()}, 0, vdf2, sk); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[2])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[3])); - node1->getDagManager()->verifyBlock(DagBlock(blk2)); - node1->getDagManager()->addDagBlock(DagBlock(blk2)); + node1->getDagManager()->verifyBlock(blk2); + node1->getDagManager()->addDagBlock(blk2); batch = db1->createWriteBatch(); period = 2; @@ -722,9 +733,9 @@ TEST_F(NetworkTest, node_pbft_sync_without_enough_votes) { dev::RLPStream order_stream2(1); order_stream2.appendList(1); - order_stream2 << blk2.getHash(); + order_stream2 << blk2->getHash(); - PbftBlock pbft_block2(prev_block_hash, blk2.getHash(), dev::sha3(order_stream2.out()), kNullBlockHash, period, + PbftBlock pbft_block2(prev_block_hash, blk2->getHash(), dev::sha3(order_stream2.out()), kNullBlockHash, period, beneficiary, node1->getSecretKey(), {}, {}); const auto pbft_block2_cert_vote = node1->getVoteManager()->generateVote( pbft_block2.getBlockHash(), PbftVoteTypes::cert_vote, pbft_block2.getPeriod(), 1, 3); @@ -886,71 +897,76 @@ TEST_F(NetworkTest, node_sync_with_transactions) { dev::RLPStream s; dev::bytes vdf_msg1 = DagManager::getVdfMessage(dag_genesis, {g_signed_trx_samples[0], g_signed_trx_samples[1]}); vdf1.computeVdfSolution(vdf_config, vdf_msg1, false); - DagBlock blk1(dag_genesis, propose_level, {}, - {g_signed_trx_samples[0]->getHash(), g_signed_trx_samples[1]->getHash()}, 2 * estimation, vdf1, sk); + auto blk1 = std::make_shared( + dag_genesis, propose_level, vec_blk_t{}, + vec_trx_t{g_signed_trx_samples[0]->getHash(), g_signed_trx_samples[1]->getHash()}, 2 * estimation, vdf1, sk); propose_level = 2; vdf_sortition::VdfSortition vdf2(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1.getHash(), {g_signed_trx_samples[2]}); + dev::bytes vdf_msg2 = DagManager::getVdfMessage(blk1->getHash(), {g_signed_trx_samples[2]}); vdf2.computeVdfSolution(vdf_config, vdf_msg2, false); - DagBlock blk2(blk1.getHash(), propose_level, {}, {g_signed_trx_samples[2]->getHash()}, estimation, vdf2, sk); + auto blk2 = std::make_shared(blk1->getHash(), propose_level, vec_trx_t{}, + vec_trx_t{g_signed_trx_samples[2]->getHash()}, estimation, vdf2, sk); propose_level = 3; vdf_sortition::VdfSortition vdf3(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg3 = DagManager::getVdfMessage(blk2.getHash(), {g_signed_trx_samples[3]}); + dev::bytes vdf_msg3 = DagManager::getVdfMessage(blk2->getHash(), {g_signed_trx_samples[3]}); vdf3.computeVdfSolution(vdf_config, vdf_msg3, false); - DagBlock blk3(blk2.getHash(), propose_level, {}, {g_signed_trx_samples[3]->getHash()}, estimation, vdf3, sk); + auto blk3 = std::make_shared(blk2->getHash(), propose_level, vec_trx_t{}, + vec_trx_t{g_signed_trx_samples[3]->getHash()}, estimation, vdf3, sk); propose_level = 4; vdf_sortition::VdfSortition vdf4(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg4 = DagManager::getVdfMessage(blk3.getHash(), {g_signed_trx_samples[4]}); + dev::bytes vdf_msg4 = DagManager::getVdfMessage(blk3->getHash(), {g_signed_trx_samples[4]}); vdf4.computeVdfSolution(vdf_config, vdf_msg4, false); - DagBlock blk4(blk3.getHash(), propose_level, {}, {g_signed_trx_samples[4]->getHash()}, estimation, vdf4, sk); + auto blk4 = std::make_shared(blk3->getHash(), propose_level, vec_trx_t{}, + vec_trx_t{g_signed_trx_samples[4]->getHash()}, estimation, vdf4, sk); propose_level = 5; vdf_sortition::VdfSortition vdf5(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg5 = DagManager::getVdfMessage(blk4.getHash(), {g_signed_trx_samples[5], g_signed_trx_samples[6], - g_signed_trx_samples[7], g_signed_trx_samples[8]}); + dev::bytes vdf_msg5 = DagManager::getVdfMessage(blk4->getHash(), {g_signed_trx_samples[5], g_signed_trx_samples[6], + g_signed_trx_samples[7], g_signed_trx_samples[8]}); vdf5.computeVdfSolution(vdf_config, vdf_msg5, false); - DagBlock blk5(blk4.getHash(), propose_level, {}, - {g_signed_trx_samples[5]->getHash(), g_signed_trx_samples[6]->getHash(), - g_signed_trx_samples[7]->getHash(), g_signed_trx_samples[8]->getHash()}, - 4 * estimation, vdf5, sk); + auto blk5 = + std::make_shared(blk4->getHash(), propose_level, vec_trx_t{}, + vec_trx_t{g_signed_trx_samples[5]->getHash(), g_signed_trx_samples[6]->getHash(), + g_signed_trx_samples[7]->getHash(), g_signed_trx_samples[8]->getHash()}, + 4 * estimation, vdf5, sk); propose_level = 6; vdf_sortition::VdfSortition vdf6(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - dev::bytes vdf_msg6 = DagManager::getVdfMessage(blk5.getHash(), {g_signed_trx_samples[9]}); + dev::bytes vdf_msg6 = DagManager::getVdfMessage(blk5->getHash(), {g_signed_trx_samples[9]}); vdf6.computeVdfSolution(vdf_config, vdf_msg6, false); - DagBlock blk6(blk5.getHash(), propose_level, {blk4.getHash(), blk3.getHash()}, {g_signed_trx_samples[9]->getHash()}, - estimation, vdf6, sk); + auto blk6 = std::make_shared(blk5->getHash(), propose_level, vec_trx_t{blk4->getHash(), blk3->getHash()}, + vec_trx_t{g_signed_trx_samples[9]->getHash()}, estimation, vdf6, sk); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[0])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[1])); EXPECT_EQ(node1->getDagManager()->verifyBlock(std::move(blk1)).first, DagManager::VerifyBlockReturnType::Verified); - node1->getDagManager()->addDagBlock(DagBlock(blk1)); + node1->getDagManager()->addDagBlock(blk1); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[2])); EXPECT_EQ(node1->getDagManager()->verifyBlock(std::move(blk2)).first, DagManager::VerifyBlockReturnType::Verified); - node1->getDagManager()->addDagBlock(DagBlock(blk2)); + node1->getDagManager()->addDagBlock(blk2); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[3])); EXPECT_EQ(node1->getDagManager()->verifyBlock(std::move(blk3)).first, DagManager::VerifyBlockReturnType::Verified); - node1->getDagManager()->addDagBlock(DagBlock(blk3)); + node1->getDagManager()->addDagBlock(blk3); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[4])); EXPECT_EQ(node1->getDagManager()->verifyBlock(std::move(blk4)).first, DagManager::VerifyBlockReturnType::Verified); - node1->getDagManager()->addDagBlock(DagBlock(blk4)); + node1->getDagManager()->addDagBlock(blk4); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[5])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[6])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[7])); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[8])); EXPECT_EQ(node1->getDagManager()->verifyBlock(std::move(blk5)).first, DagManager::VerifyBlockReturnType::Verified); - node1->getDagManager()->addDagBlock(DagBlock(blk5)); + node1->getDagManager()->addDagBlock(blk5); node1->getTransactionManager()->insertValidatedTransaction(std::shared_ptr(g_signed_trx_samples[9])); EXPECT_EQ(node1->getDagManager()->verifyBlock(std::move(blk6)).first, DagManager::VerifyBlockReturnType::Verified); - node1->getDagManager()->addDagBlock(DagBlock(blk6)); + node1->getDagManager()->addDagBlock(blk6); // To make sure blocks are stored before starting node 2 taraxa::thisThreadSleepForMilliSeconds(1000); @@ -974,7 +990,7 @@ TEST_F(NetworkTest, node_sync2) { auto node_cfgs = make_node_cfgs(2, 1, 5); auto node1 = create_nodes({node_cfgs[0]}, true /*start*/).front(); - std::vector blks; + std::vector> blks; // Generate DAG blocks const auto dag_genesis = node1->getConfig().genesis.dag_genesis_block.getHash(); const auto sk = node1->getSecretKey(); @@ -989,8 +1005,9 @@ TEST_F(NetworkTest, node_sync2) { 1, 1); dev::bytes vdf_msg = DagManager::getVdfMessage(dag_genesis, {transactions[0], transactions[1]}); vdf1.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk1(dag_genesis, propose_level, {}, {transactions[0]->getHash(), transactions[1]->getHash()}, - 2 * estimation, vdf1, sk); + auto blk1 = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, + vec_trx_t{transactions[0]->getHash(), transactions[1]->getHash()}, + 2 * estimation, vdf1, sk); SharedTransactions tr1({transactions[0], transactions[1]}); // DAG block2 propose_level = 1; @@ -998,98 +1015,109 @@ TEST_F(NetworkTest, node_sync2) { 1, 1); vdf_msg = DagManager::getVdfMessage(dag_genesis, {transactions[2], transactions[3]}); vdf2.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk2(dag_genesis, propose_level, {}, {transactions[2]->getHash(), transactions[3]->getHash()}, - 2 * estimation, vdf2, sk); + auto blk2 = std::make_shared(dag_genesis, propose_level, vec_blk_t{}, + vec_trx_t{transactions[2]->getHash(), transactions[3]->getHash()}, + 2 * estimation, vdf2, sk); SharedTransactions tr2({transactions[2], transactions[3]}); // DAG block3 propose_level = 2; vdf_sortition::VdfSortition vdf3(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk1.getHash(), {transactions[4], transactions[5]}); + vdf_msg = DagManager::getVdfMessage(blk1->getHash(), {transactions[4], transactions[5]}); vdf3.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk3(blk1.getHash(), propose_level, {}, {transactions[4]->getHash(), transactions[5]->getHash()}, - 2 * estimation, vdf3, sk); + auto blk3 = std::make_shared(blk1->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[4]->getHash(), transactions[5]->getHash()}, + 2 * estimation, vdf3, sk); SharedTransactions tr3({transactions[4], transactions[5]}); // DAG block4 propose_level = 3; vdf_sortition::VdfSortition vdf4(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk3.getHash(), {transactions[6], transactions[7]}); + vdf_msg = DagManager::getVdfMessage(blk3->getHash(), {transactions[6], transactions[7]}); vdf4.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk4(blk3.getHash(), propose_level, {}, {transactions[6]->getHash(), transactions[7]->getHash()}, - 2 * estimation, vdf4, sk); + auto blk4 = std::make_shared(blk3->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[6]->getHash(), transactions[7]->getHash()}, + 2 * estimation, vdf4, sk); SharedTransactions tr4({transactions[6], transactions[7]}); // DAG block5 propose_level = 2; vdf_sortition::VdfSortition vdf5(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk2.getHash(), {transactions[8], transactions[9]}); + vdf_msg = DagManager::getVdfMessage(blk2->getHash(), {transactions[8], transactions[9]}); vdf5.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk5(blk2.getHash(), propose_level, {}, {transactions[8]->getHash(), transactions[9]->getHash()}, - 2 * estimation, vdf5, sk); + auto blk5 = std::make_shared(blk2->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[8]->getHash(), transactions[9]->getHash()}, + 2 * estimation, vdf5, sk); SharedTransactions tr5({transactions[8], transactions[9]}); // DAG block6 propose_level = 2; vdf_sortition::VdfSortition vdf6(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk1.getHash(), {transactions[10], transactions[11]}); + vdf_msg = DagManager::getVdfMessage(blk1->getHash(), {transactions[10], transactions[11]}); vdf6.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk6(blk1.getHash(), propose_level, {}, {transactions[10]->getHash(), transactions[11]->getHash()}, - 2 * estimation, vdf6, sk); + auto blk6 = std::make_shared(blk1->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[10]->getHash(), transactions[11]->getHash()}, + 2 * estimation, vdf6, sk); SharedTransactions tr6({transactions[10], transactions[11]}); // DAG block7 propose_level = 3; vdf_sortition::VdfSortition vdf7(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk6.getHash(), {transactions[12], transactions[13]}); + vdf_msg = DagManager::getVdfMessage(blk6->getHash(), {transactions[12], transactions[13]}); vdf7.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk7(blk6.getHash(), propose_level, {}, {transactions[12]->getHash(), transactions[13]->getHash()}, - 2 * estimation, vdf7, sk); + auto blk7 = std::make_shared(blk6->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[12]->getHash(), transactions[13]->getHash()}, + 2 * estimation, vdf7, sk); SharedTransactions tr7({transactions[12], transactions[13]}); // DAG block8 propose_level = 4; vdf_sortition::VdfSortition vdf8(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk1.getHash(), {transactions[14], transactions[15]}); + vdf_msg = DagManager::getVdfMessage(blk1->getHash(), {transactions[14], transactions[15]}); vdf8.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk8(blk1.getHash(), propose_level, {blk7.getHash()}, - {transactions[14]->getHash(), transactions[15]->getHash()}, 2 * estimation, vdf8, sk); + auto blk8 = std::make_shared(blk1->getHash(), propose_level, vec_blk_t{blk7->getHash()}, + vec_trx_t{transactions[14]->getHash(), transactions[15]->getHash()}, + 2 * estimation, vdf8, sk); SharedTransactions tr8({transactions[14], transactions[15]}); // DAG block9 propose_level = 2; vdf_sortition::VdfSortition vdf9(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk1.getHash(), {transactions[16], transactions[17]}); + vdf_msg = DagManager::getVdfMessage(blk1->getHash(), {transactions[16], transactions[17]}); vdf9.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk9(blk1.getHash(), propose_level, {}, {transactions[16]->getHash(), transactions[17]->getHash()}, - 2 * estimation, vdf9, sk); + auto blk9 = std::make_shared(blk1->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[16]->getHash(), transactions[17]->getHash()}, + 2 * estimation, vdf9, sk); SharedTransactions tr9({transactions[16], transactions[17]}); // DAG block10 propose_level = 5; vdf_sortition::VdfSortition vdf10(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk8.getHash(), {transactions[18], transactions[19]}); + vdf_msg = DagManager::getVdfMessage(blk8->getHash(), {transactions[18], transactions[19]}); vdf10.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk10(blk8.getHash(), propose_level, {}, {transactions[18]->getHash(), transactions[19]->getHash()}, - 2 * estimation, vdf10, sk); + auto blk10 = std::make_shared(blk8->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[18]->getHash(), transactions[19]->getHash()}, + 2 * estimation, vdf10, sk); SharedTransactions tr10({transactions[18], transactions[19]}); // DAG block11 propose_level = 3; vdf_sortition::VdfSortition vdf11(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk3.getHash(), {transactions[20], transactions[21]}); + vdf_msg = DagManager::getVdfMessage(blk3->getHash(), {transactions[20], transactions[21]}); vdf11.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk11(blk3.getHash(), propose_level, {}, {transactions[20]->getHash(), transactions[21]->getHash()}, - 2 * estimation, vdf11, sk); + auto blk11 = std::make_shared(blk3->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[20]->getHash(), transactions[21]->getHash()}, + 2 * estimation, vdf11, sk); SharedTransactions tr11({transactions[20], transactions[21]}); // DAG block12 propose_level = 3; vdf_sortition::VdfSortition vdf12(vdf_config, vrf_sk, VrfSortitionBase::makeVrfInput(propose_level, period_block_hash), 1, 1); - vdf_msg = DagManager::getVdfMessage(blk5.getHash(), {transactions[22], transactions[23]}); + vdf_msg = DagManager::getVdfMessage(blk5->getHash(), {transactions[22], transactions[23]}); vdf12.computeVdfSolution(vdf_config, vdf_msg, false); - DagBlock blk12(blk5.getHash(), propose_level, {}, {transactions[22]->getHash(), transactions[23]->getHash()}, - 2 * estimation, vdf12, sk); + auto blk12 = std::make_shared(blk5->getHash(), propose_level, vec_blk_t{}, + vec_trx_t{transactions[22]->getHash(), transactions[23]->getHash()}, + 2 * estimation, vdf12, sk); SharedTransactions tr12({transactions[22], transactions[23]}); blks.push_back(blk1); @@ -1122,7 +1150,7 @@ TEST_F(NetworkTest, node_sync2) { for (size_t i = 0; i < blks.size(); ++i) { for (auto t : trxs[i]) node1->getTransactionManager()->insertValidatedTransaction(std::move(t)); node1->getDagManager()->verifyBlock(std::move(blks[i])); - node1->getDagManager()->addDagBlock(DagBlock(blks[i])); + node1->getDagManager()->addDagBlock(blks[i]); } auto node2 = create_nodes({node_cfgs[1]}, true /*start*/).front(); diff --git a/tests/pbft_chain_test.cpp b/tests/pbft_chain_test.cpp index 5769fee427..978db2674e 100644 --- a/tests/pbft_chain_test.cpp +++ b/tests/pbft_chain_test.cpp @@ -51,11 +51,11 @@ TEST_F(PbftChainTest, pbft_db_test) { level_t level = 1; vdf_sortition::VdfSortition vdf1(vdf_config, vrf_sk, getRlpBytes(level), 1, 100); vdf1.computeVdfSolution(vdf_config, dag_genesis.asBytes(), false); - DagBlock blk1(dag_genesis, 1, {}, {}, {}, vdf1, sk); + auto blk1 = std::make_shared(dag_genesis, 1, vec_blk_t{}, vec_trx_t{}, 0, vdf1, sk); PbftPeriod period = 1; addr_t beneficiary(987); - PbftBlock pbft_block(prev_block_hash, blk1.getHash(), kNullBlockHash, kNullBlockHash, period, beneficiary, + PbftBlock pbft_block(prev_block_hash, blk1->getHash(), kNullBlockHash, kNullBlockHash, period, beneficiary, node->getSecretKey(), {}); // put into pbft chain and store into DB diff --git a/tests/rewards_stats_test.cpp b/tests/rewards_stats_test.cpp index ea813a1c44..9b2e9d4272 100644 --- a/tests/rewards_stats_test.cpp +++ b/tests/rewards_stats_test.cpp @@ -207,7 +207,8 @@ TEST_F(RewardsStatsTest, feeRewards) { auto trx = std::make_shared(nonce++, 0, 1, trx_gas_fee, dev::fromHex(samples::greeter_contract_code), pbft_proposer.secret()); - DagBlock dag_blk({}, {}, {}, {trx->getHash()}, {}, {}, dag_proposer.secret()); + auto dag_blk = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, vec_trx_t{trx->getHash()}, 0, + VdfSortition{}, dag_proposer.secret()); db->saveDagBlock(dag_blk); std::vector reward_votes_hashes; auto pbft_block = @@ -266,35 +267,40 @@ TEST_F(RewardsStatsTest, dagBlockRewards) { vdf_sortition::VdfSortition vdf1(sortition_params, vrfs, vrf_wrapper::VrfSortitionBase::makeVrfInput(1, blk_hash_t(1)), 1, 1); - DagBlock dag_blk1({}, {}, {}, {trxs[0]->getHash()}, 0, vdf1, dag_key1.secret()); + auto dag_blk1 = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, vec_trx_t{trxs[0]->getHash()}, 0, + vdf1, dag_key1.secret()); block.dag_blocks.push_back(dag_blk1); vdf_sortition::VdfSortition vdf2(sortition_params, vrfs, vrf_wrapper::VrfSortitionBase::makeVrfInput(1, blk_hash_t(2)), 1, 1); - DagBlock dag_blk2({}, {}, {}, {trxs[1]->getHash()}, 0, vdf2, dag_key2.secret()); + auto dag_blk2 = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, vec_trx_t{trxs[1]->getHash()}, 0, + vdf2, dag_key2.secret()); block.dag_blocks.push_back(dag_blk2); vdf_sortition::VdfSortition vdf3(sortition_params, vrfs, vrf_wrapper::VrfSortitionBase::makeVrfInput(1, blk_hash_t(3)), 1, 1); - DagBlock dag_blk3({}, {}, {}, {trxs[0]->getHash()}, 0, vdf3, dag_key3.secret()); + auto dag_blk3 = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, vec_trx_t{trxs[0]->getHash()}, 0, + vdf3, dag_key3.secret()); block.dag_blocks.push_back(dag_blk3); vdf_sortition::VdfSortition vdf4(sortition_params, vrfs, vrf_wrapper::VrfSortitionBase::makeVrfInput(1, blk_hash_t(4)), 1, 1); - DagBlock dag_blk4({}, {}, {}, {trxs[1]->getHash()}, 0, vdf4, dag_key4.secret()); + auto dag_blk4 = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, vec_trx_t{trxs[1]->getHash()}, 0, + vdf4, dag_key4.secret()); block.dag_blocks.push_back(dag_blk4); vdf_sortition::VdfSortition vdf5(sortition_params, vrfs, vrf_wrapper::VrfSortitionBase::makeVrfInput(1, blk_hash_t(5)), 1, 1); - DagBlock dag_blk5({}, {}, {}, {trxs[2]->getHash()}, 0, vdf5, dag_key5.secret()); + auto dag_blk5 = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, vec_trx_t{trxs[2]->getHash()}, 0, + vdf5, dag_key5.secret()); block.dag_blocks.push_back(dag_blk5); block.transactions = trxs; - ASSERT_EQ(dag_blk1.getDifficulty(), 17); - ASSERT_EQ(dag_blk2.getDifficulty(), 17); - ASSERT_EQ(dag_blk3.getDifficulty(), 16); - ASSERT_EQ(dag_blk4.getDifficulty(), 17); - ASSERT_EQ(dag_blk5.getDifficulty(), 16); + ASSERT_EQ(dag_blk1->getDifficulty(), 17); + ASSERT_EQ(dag_blk2->getDifficulty(), 17); + ASSERT_EQ(dag_blk3->getDifficulty(), 16); + ASSERT_EQ(dag_blk4->getDifficulty(), 17); + ASSERT_EQ(dag_blk5->getDifficulty(), 16); std::vector gas_used{10, 20, 30}; diff --git a/tests/sortition_test.cpp b/tests/sortition_test.cpp index d4c79419de..3bc8023534 100644 --- a/tests/sortition_test.cpp +++ b/tests/sortition_test.cpp @@ -43,7 +43,7 @@ PeriodData createBlock(PbftPeriod period, uint16_t efficiency, size_t dag_blocks for (size_t i = 0; i < dag_blocks_count; ++i) { vec_trx_t trxs{trx_hashes.begin() + i * trx_per_block, trx_hashes.begin() + (i + 1) * trx_per_block}; - b.dag_blocks.push_back({{}, {}, {}, trxs, {}}); + b.dag_blocks.push_back(std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, trxs, secret_t{})); }; size_t issued_overlap_count = 0; @@ -51,7 +51,7 @@ PeriodData createBlock(PbftPeriod period, uint16_t efficiency, size_t dag_blocks size_t overlap = std::min(kTrxCount - effective_transactions - issued_overlap_count, trx_hashes.size()); issued_overlap_count += overlap; vec_trx_t trxs{trx_hashes.begin(), trx_hashes.begin() + overlap}; - b.dag_blocks.push_back({{}, {}, {}, trxs, {}}); + b.dag_blocks.push_back(std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, trxs, secret_t{})); } return b; } diff --git a/tests/test_util/include/test_util/node_dag_creation_fixture.hpp b/tests/test_util/include/test_util/node_dag_creation_fixture.hpp index d8b4d34b7d..938dc124b5 100644 --- a/tests/test_util/include/test_util/node_dag_creation_fixture.hpp +++ b/tests/test_util/include/test_util/node_dag_creation_fixture.hpp @@ -18,7 +18,7 @@ struct NodeDagCreationFixture : NodesTest { NodeDagCreationFixture() : NodesTest() {} ~NodeDagCreationFixture() = default; struct DagBlockWithTxs { - DagBlock blk; + std::shared_ptr blk; SharedTransactions trxs; }; void modifyConfig(FullNodeConfig &cfg); diff --git a/tests/test_util/include/test_util/samples.hpp b/tests/test_util/include/test_util/samples.hpp index 828bdd93ee..ac0e436b59 100644 --- a/tests/test_util/include/test_util/samples.hpp +++ b/tests/test_util/include/test_util/samples.hpp @@ -104,11 +104,8 @@ bool sendTrx(uint64_t count, unsigned port, dev::Secret secret); SharedTransactions createSignedTrxSamples(unsigned start, unsigned num, secret_t const &sk, bytes data = dev::fromHex("00FEDCBA9876543210000000")); -std::vector createMockDagBlkSamples(unsigned pivot_start, unsigned blk_num, unsigned trx_start, - unsigned trx_len, unsigned trx_overlap); +std::vector> createMockDag0(const blk_hash_t &genesis); -std::vector createMockDag0(const blk_hash_t &genesis); - -std::vector createMockDag1(const blk_hash_t &genesis); +std::vector> createMockDag1(const blk_hash_t &genesis); } // namespace taraxa::core_tests::samples diff --git a/tests/test_util/src/node_dag_creation_fixture.cpp b/tests/test_util/src/node_dag_creation_fixture.cpp index 5adc2624f9..45f6a48ad6 100644 --- a/tests/test_util/src/node_dag_creation_fixture.cpp +++ b/tests/test_util/src/node_dag_creation_fixture.cpp @@ -139,8 +139,9 @@ std::vector NodeDagCreationFixture::gen std::vector trx_hashes; std::transform(trx_itr, trx_itr_next, std::back_inserter(trx_hashes), [](std::shared_ptr trx) { return trx->getHash(); }); - DagBlock blk(pivot, level, tips, trx_hashes, trx_per_block * trx_estimation, vdf, node->getSecretKey()); - this_level_blocks.push_back(blk.getHash()); + auto blk = std::make_shared(pivot, level, tips, trx_hashes, trx_per_block * trx_estimation, vdf, + node->getSecretKey()); + this_level_blocks.push_back(blk->getHash()); result.emplace_back(DagBlockWithTxs{blk, SharedTransactions(trx_itr, trx_itr_next)}); trx_itr = trx_itr_next; } @@ -155,11 +156,11 @@ std::vector NodeDagCreationFixture::gen vdf_sortition::VdfSortition vdf(vdf_config, node->getVrfSecretKey(), vrf_wrapper::VrfSortitionBase::makeVrfInput(level, period_block_hash), 1, 1); vdf.computeVdfSolution(vdf_config, dag_genesis.asBytes(), false); - DagBlock blk(pivot, level, tips, {transactions.rbegin()->get()->getHash()}, trx_per_block * trx_estimation, vdf, - node->getSecretKey()); + auto blk = std::make_shared(pivot, level, tips, vec_trx_t{transactions.rbegin()->get()->getHash()}, + trx_per_block * trx_estimation, vdf, node->getSecretKey()); result.emplace_back(DagBlockWithTxs{blk, SharedTransactions(transactions.rbegin(), transactions.rbegin() + 1)}); - pivot = blk.getHash(); - tips = {blk.getHash()}; + pivot = blk->getHash(); + tips = {blk->getHash()}; trx_itr_next++; EXPECT_EQ(trx_itr_next, transactions.end()); diff --git a/tests/test_util/src/samples.cpp b/tests/test_util/src/samples.cpp index c029a700b3..b25fff901c 100644 --- a/tests/test_util/src/samples.cpp +++ b/tests/test_util/src/samples.cpp @@ -39,113 +39,84 @@ SharedTransactions createSignedTrxSamples(unsigned start, unsigned num, secret_t return trxs; } -std::vector createMockDagBlkSamples(unsigned pivot_start, unsigned blk_num, unsigned trx_start, - unsigned trx_len, unsigned trx_overlap) { - assert(pivot_start + blk_num < std::numeric_limits::max()); - std::vector blks; - unsigned trx = trx_start; - for (auto i = pivot_start; i < blk_num; ++i) { - blk_hash_t pivot(i); - blk_hash_t hash(i + 1); - vec_trx_t trxs; - for (unsigned i = 0; i < trx_len; ++i, trx++) { - trxs.emplace_back(trx_hash_t(trx)); - } - for (unsigned i = 0; i < trx_overlap; ++i) { - trx--; - } - - DagBlock blk(blk_hash_t(pivot), // pivot - level_t(0), // level - {blk_hash_t(2), blk_hash_t(3), blk_hash_t(4)}, // tips - trxs, // trxs - sig_t(7777), // sig - blk_hash_t(hash), // hash - addr_t(12345)); // sender - - blks.emplace_back(blk); - } - return blks; -} - -std::vector createMockDag0(const blk_hash_t& genesis) { - std::vector blks; - DagBlock blk1(genesis, // pivot - 1, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk2(genesis, // pivot - 1, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk3(genesis, // pivot - 1, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk4(blk1.getHash(), // pivot - 2, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk5(blk1.getHash(), // pivot - 2, // level - {blk2.getHash()}, // tips - {}, secret_t::random()); - DagBlock blk6(blk3.getHash(), // pivot - 2, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk7(blk5.getHash(), // pivot - 3, // level - {blk6.getHash()}, // tips - {}, secret_t::random()); - DagBlock blk8(blk5.getHash(), // pivot - 3, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk9(blk6.getHash(), // pivot - 3, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk10(blk7.getHash(), // pivot - 4, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk11(blk7.getHash(), // pivot - 4, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk12(blk9.getHash(), // pivot - 4, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk13(blk10.getHash(), // pivot - 5, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk14(blk11.getHash(), // pivot - 5, // level - {blk12.getHash()}, // tips - {}, secret_t::random()); - DagBlock blk15(blk13.getHash(), // pivot - 6, // level - {blk14.getHash()}, // tips - {}, secret_t::random()); - DagBlock blk16(blk13.getHash(), // pivot - 6, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk17(blk12.getHash(), // pivot - 5, // level - {}, // tips - {}, secret_t::random()); - DagBlock blk18(blk15.getHash(), // pivot - 7, // level - {blk8.getHash(), blk16.getHash(), blk17.getHash()}, // tips - {}, secret_t::random()); - DagBlock blk19(blk18.getHash(), // pivot - 8, // level - {}, // tips - {}, secret_t::random()); +std::vector> createMockDag0(const blk_hash_t& genesis) { + std::vector> blks; + auto blk1 = std::make_shared(genesis, // pivot + 1, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk2 = std::make_shared(genesis, // pivot + 1, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk3 = std::make_shared(genesis, // pivot + 1, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk4 = std::make_shared(blk1->getHash(), // pivot + 2, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk5 = std::make_shared(blk1->getHash(), // pivot + 2, // level + vec_blk_t{blk2->getHash()}, // tips + vec_trx_t{}, secret_t::random()); + auto blk6 = std::make_shared(blk3->getHash(), // pivot + 2, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk7 = std::make_shared(blk5->getHash(), // pivot + 3, // level + vec_blk_t{blk6->getHash()}, // tips + vec_trx_t{}, secret_t::random()); + auto blk8 = std::make_shared(blk5->getHash(), // pivot + 3, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk9 = std::make_shared(blk6->getHash(), // pivot + 3, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk10 = std::make_shared(blk7->getHash(), // pivot + 4, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk11 = std::make_shared(blk7->getHash(), // pivot + 4, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk12 = std::make_shared(blk9->getHash(), // pivot + 4, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk13 = std::make_shared(blk10->getHash(), // pivot + 5, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk14 = std::make_shared(blk11->getHash(), // pivot + 5, // level + vec_blk_t{blk12->getHash()}, // tips + vec_trx_t{}, secret_t::random()); + auto blk15 = std::make_shared(blk13->getHash(), // pivot + 6, // level + vec_blk_t{blk14->getHash()}, // tips + vec_trx_t{}, secret_t::random()); + auto blk16 = std::make_shared(blk13->getHash(), // pivot + 6, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk17 = std::make_shared(blk12->getHash(), // pivot + 5, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); + auto blk18 = std::make_shared(blk15->getHash(), // pivot + 7, // level + vec_blk_t{blk8->getHash(), blk16->getHash(), blk17->getHash()}, // tips + vec_trx_t{}, secret_t::random()); + auto blk19 = std::make_shared(blk18->getHash(), // pivot + 8, // level + vec_blk_t{}, // tips + vec_trx_t{}, secret_t::random()); blks.emplace_back(blk1); blks.emplace_back(blk2); blks.emplace_back(blk3); @@ -169,143 +140,143 @@ std::vector createMockDag0(const blk_hash_t& genesis) { return blks; } -std::vector createMockDag1(const blk_hash_t& genesis) { - std::vector blks; - DagBlock dummy; - DagBlock blk1(genesis, // pivot - 1, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(1), // hash - addr_t(123)); +std::vector> createMockDag1(const blk_hash_t& genesis) { + std::vector> blks; + std::shared_ptr dummy; + auto blk1 = std::make_shared(genesis, // pivot + 1, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(1), // hash + addr_t(123)); - DagBlock blk2(genesis, // pivot - 1, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(2), // hash - addr_t(123)); - DagBlock blk3(genesis, // pivot - 1, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(3), // hash - addr_t(123)); - DagBlock blk4(blk_hash_t(1), // pivot - 2, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(4), // hash - addr_t(123)); - DagBlock blk5(blk_hash_t(1), // pivot - 2, // level - {blk_hash_t(2)}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(5), // hash - addr_t(123)); - DagBlock blk6(blk_hash_t(3), // pivot - 2, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(6), // hash - addr_t(123)); - DagBlock blk7(blk_hash_t(5), // pivot - 3, // level - {blk_hash_t(6)}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(7), // hash - addr_t(123)); - DagBlock blk8(blk_hash_t(5), // pivot - 3, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(8), // hash - addr_t(123)); - DagBlock blk9(blk_hash_t(6), // pivot - 3, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(9), // hash - addr_t(123)); - DagBlock blk10(blk_hash_t(7), // pivot - 4, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(10), // hash - addr_t(123)); - DagBlock blk11(blk_hash_t(7), // pivot - 4, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(11), // hash - addr_t(123)); - DagBlock blk12(blk_hash_t(9), // pivot - 4, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(12), // hash - addr_t(123)); - DagBlock blk13(blk_hash_t(10), // pivot - 5, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(13), // hash - addr_t(123)); - DagBlock blk14(blk_hash_t(11), // pivot - 5, // level - {blk_hash_t(12)}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(14), // hash - addr_t(123)); - DagBlock blk15(blk_hash_t(13), // pivot - 6, // level - {blk_hash_t(14)}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(15), // hash - addr_t(123)); - DagBlock blk16(blk_hash_t(13), // pivot - 6, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(16), // hash - addr_t(123)); - DagBlock blk17(blk_hash_t(12), // pivot - 5, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(17), // hash - addr_t(123)); - DagBlock blk18(blk_hash_t(15), // pivot - 7, // level - {blk_hash_t(8), blk_hash_t(16), blk_hash_t(17)}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(18), // hash - addr_t(123)); - DagBlock blk19(blk_hash_t(18), // pivot - 8, // level - {}, // tips - {}, // trxs - sig_t(0), // sig - blk_hash_t(19), // hash - addr_t(123)); + auto blk2 = std::make_shared(genesis, // pivot + 1, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(2), // hash + addr_t(123)); + auto blk3 = std::make_shared(genesis, // pivot + 1, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(3), // hash + addr_t(123)); + auto blk4 = std::make_shared(blk_hash_t(1), // pivot + 2, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(4), // hash + addr_t(123)); + auto blk5 = std::make_shared(blk_hash_t(1), // pivot + 2, // level + vec_blk_t{blk_hash_t(2)}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(5), // hash + addr_t(123)); + auto blk6 = std::make_shared(blk_hash_t(3), // pivot + 2, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(6), // hash + addr_t(123)); + auto blk7 = std::make_shared(blk_hash_t(5), // pivot + 3, // level + vec_blk_t{blk_hash_t(6)}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(7), // hash + addr_t(123)); + auto blk8 = std::make_shared(blk_hash_t(5), // pivot + 3, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(8), // hash + addr_t(123)); + auto blk9 = std::make_shared(blk_hash_t(6), // pivot + 3, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(9), // hash + addr_t(123)); + auto blk10 = std::make_shared(blk_hash_t(7), // pivot + 4, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(10), // hash + addr_t(123)); + auto blk11 = std::make_shared(blk_hash_t(7), // pivot + 4, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(11), // hash + addr_t(123)); + auto blk12 = std::make_shared(blk_hash_t(9), // pivot + 4, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(12), // hash + addr_t(123)); + auto blk13 = std::make_shared(blk_hash_t(10), // pivot + 5, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(13), // hash + addr_t(123)); + auto blk14 = std::make_shared(blk_hash_t(11), // pivot + 5, // level + vec_blk_t{blk_hash_t(12)}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(14), // hash + addr_t(123)); + auto blk15 = std::make_shared(blk_hash_t(13), // pivot + 6, // level + vec_blk_t{blk_hash_t(14)}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(15), // hash + addr_t(123)); + auto blk16 = std::make_shared(blk_hash_t(13), // pivot + 6, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(16), // hash + addr_t(123)); + auto blk17 = std::make_shared(blk_hash_t(12), // pivot + 5, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(17), // hash + addr_t(123)); + auto blk18 = std::make_shared(blk_hash_t(15), // pivot + 7, // level + vec_blk_t{blk_hash_t(8), blk_hash_t(16), blk_hash_t(17)}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(18), // hash + addr_t(123)); + auto blk19 = std::make_shared(blk_hash_t(18), // pivot + 8, // level + vec_blk_t{}, // tips + vec_trx_t{}, // trxs + sig_t(0), // sig + blk_hash_t(19), // hash + addr_t(123)); blks.emplace_back(dummy); blks.emplace_back(blk1); blks.emplace_back(blk2); diff --git a/tests/transaction_test.cpp b/tests/transaction_test.cpp index 73bbd45a5d..2ec3032ef8 100644 --- a/tests/transaction_test.cpp +++ b/tests/transaction_test.cpp @@ -29,7 +29,6 @@ auto g_secret = Lazy([] { }); auto g_key_pair = Lazy([] { return dev::KeyPair(g_secret); }); auto g_signed_trx_samples = Lazy([] { return samples::createSignedTrxSamples(1, NUM_TRX, g_secret); }); -auto g_blk_samples = Lazy([] { return samples::createMockDagBlkSamples(0, NUM_BLK, 0, BLK_TRX_LEN, BLK_TRX_OVERLAP); }); struct TransactionTest : NodesTest {}; @@ -203,7 +202,7 @@ TEST_F(TransactionTest, transaction_low_nonce) { EXPECT_TRUE(trx_mgr.insertTransaction(trx_1).first); EXPECT_TRUE(trx_mgr.insertTransaction(trx_2).first); std::vector trx_hashes{trx_1->getHash(), trx_2->getHash()}; - DagBlock dag_blk({}, {}, {}, trx_hashes, secret_t::random()); + auto dag_blk = std::make_shared(blk_hash_t{}, level_t{}, vec_blk_t{}, trx_hashes, secret_t::random()); db->saveDagBlock(dag_blk); std::vector reward_votes_hashes; auto pbft_block = @@ -216,7 +215,7 @@ TEST_F(TransactionTest, transaction_low_nonce) { auto batch = db->createWriteBatch(); db->savePeriodData(period_data, batch); db->commitWriteBatch(batch); - final_chain->finalize(std::move(period_data), {dag_blk.getHash()}).get(); + final_chain->finalize(std::move(period_data), {dag_blk->getHash()}).get(); // Verify low nonce transaction is detected in verification auto low_nonce_trx = std::make_shared(1, 101, 0, 100000, dev::bytes(), g_secret, addr_t::random()); From cce155fe1c27884c84f8b8a95ace4d26463919e1 Mon Sep 17 00:00:00 2001 From: Jakub Fornadel Date: Tue, 5 Nov 2024 18:27:20 +0100 Subject: [PATCH 2/2] remove unused constants --- tests/dag_block_test.cpp | 3 --- tests/transaction_test.cpp | 3 --- 2 files changed, 6 deletions(-) diff --git a/tests/dag_block_test.cpp b/tests/dag_block_test.cpp index b4df096fcd..2084aeeded 100644 --- a/tests/dag_block_test.cpp +++ b/tests/dag_block_test.cpp @@ -18,9 +18,6 @@ #include "vdf/sortition.hpp" namespace taraxa::core_tests { -const unsigned NUM_BLK = 4; -const unsigned BLK_TRX_LEN = 4; -const unsigned BLK_TRX_OVERLAP = 1; using namespace vdf_sortition; struct DagBlockTest : NodesTest {}; diff --git a/tests/transaction_test.cpp b/tests/transaction_test.cpp index 2ec3032ef8..22bf12014a 100644 --- a/tests/transaction_test.cpp +++ b/tests/transaction_test.cpp @@ -20,9 +20,6 @@ namespace taraxa::core_tests { const unsigned NUM_TRX = 40; -const unsigned NUM_BLK = 4; -const unsigned BLK_TRX_LEN = 4; -const unsigned BLK_TRX_OVERLAP = 1; auto g_secret = Lazy([] { return dev::Secret("3800b2875669d9b2053c1aff9224ecfdc411423aac5b5a73d7a45ced1c3b9dcd", dev::Secret::ConstructFromStringType::FromHex);