Skip to content

Commit

Permalink
Merge pull request #2827 from Taraxa-project/dag_prod
Browse files Browse the repository at this point in the history
chore: dag block proposal limit
  • Loading branch information
MatusKysel authored Aug 13, 2024
2 parents 81aa459 + 153ae46 commit 4e82fcb
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"packets_stats_time_period_ms": 60000,
"peer_max_packets_processing_time_us": 10000000,
"peer_max_packets_queue_size_limit": 100000,
"max_packets_queue_size": 200000
"max_packets_queue_size": 100
},
"listen_ip": "0.0.0.0",
"listen_port": 10002,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"packets_stats_time_period_ms": 60000,
"peer_max_packets_processing_time_us": 10000000,
"peer_max_packets_queue_size_limit": 100000,
"max_packets_queue_size": 200000
"max_packets_queue_size": 100
},
"listen_ip": "0.0.0.0",
"listen_port": 10002,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"packets_stats_time_period_ms": 60000,
"peer_max_packets_processing_time_us": 0,
"peer_max_packets_queue_size_limit": 0,
"max_packets_queue_size": 200000
"max_packets_queue_size": 100
},
"listen_ip": "0.0.0.0",
"listen_port": 10002,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"packets_stats_time_period_ms": 60000,
"peer_max_packets_processing_time_us": 0,
"peer_max_packets_queue_size_limit": 0,
"max_packets_queue_size": 200000
"max_packets_queue_size": 100
},
"listen_ip": "0.0.0.0",
"listen_port": 10002,
Expand Down
1 change: 1 addition & 0 deletions libraries/common/include/common/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const uint64_t kMinTxGas{21000};

constexpr uint32_t kMinTransactionPoolSize{30000};
constexpr uint32_t kDefaultTransactionPoolSize{200000};
constexpr uint32_t kMaxNonFinalizedTransactions{1000000};

const size_t kV2NetworkVersion = 2;

Expand Down
13 changes: 10 additions & 3 deletions libraries/core_libs/consensus/src/dag/dag_block_proposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ bool DagBlockProposer::proposeDagBlock() {
return false;
}

// Do not propose dag blocks if number of non finalized transactions is over the limit
if (trx_mgr_->getNonfinalizedTrxSize() > kMaxNonFinalizedTransactions) {
return false;
}

auto frontier = dag_mgr_->getDagFrontier();
LOG(log_dg_) << "Get frontier with pivot: " << frontier.pivot << " tips: " << frontier.tips;
assert(!frontier.pivot.isZero());
Expand Down Expand Up @@ -183,12 +188,14 @@ void DagBlockProposer::start() {
while (!stopped_) {
// Blocks are not proposed if we are behind the network and still syncing
auto syncing = false;
auto packets_over_the_limit = false;
if (auto net = network_.lock()) {
syncing = net->pbft_syncing();
packets_over_the_limit = net->packetQueueOverLimit();
}
// Only sleep if block was not proposed or if we are syncing, if block is proposed try to propose another block
// immediately
if (syncing || !proposeDagBlock()) {
// Only sleep if block was not proposed or if we are syncing or if packets queue is over the limit, if block is
// proposed try to propose another block immediately
if (syncing || packets_over_the_limit || !proposeDagBlock()) {
thisThreadSleepForMilliSeconds(min_proposal_delay);
}
}
Expand Down
7 changes: 7 additions & 0 deletions libraries/core_libs/network/include/network/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class Network {
*/
void requestPillarBlockVotesBundle(PbftPeriod period, const blk_hash_t &pillar_block_hash);

/**
* @brief Get packets queue status
*
* @return true if packets queue is over the limit
*/
bool packetQueueOverLimit() const;

// METHODS USED IN TESTS ONLY
template <typename PacketHandlerType>
std::shared_ptr<PacketHandlerType> getSpecificHandler() const;
Expand Down
6 changes: 6 additions & 0 deletions libraries/core_libs/network/src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ void Network::start() {

bool Network::isStarted() { return tp_.is_running(); }

bool Network::packetQueueOverLimit() const {
auto [hp_queue_size, mp_queue_size, lp_queue_size] = packets_tp_->getQueueSize();
auto total_size = hp_queue_size + mp_queue_size + lp_queue_size;
return total_size > kConf.network.ddos_protection.max_packets_queue_size;
}

std::list<dev::p2p::NodeEntry> Network::getAllNodes() const { return host_->getNodes(); }

size_t Network::getPeerCount() { return host_->peer_count(); }
Expand Down

0 comments on commit 4e82fcb

Please sign in to comment.