Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priority nodes #2891

Draft
wants to merge 7 commits into
base: testnet
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20)
# Set current version of the project
set(TARAXA_MAJOR_VERSION 1)
set(TARAXA_MINOR_VERSION 12)
set(TARAXA_PATCH_VERSION 0)
set(TARAXA_PATCH_VERSION 1)
set(TARAXA_VERSION ${TARAXA_MAJOR_VERSION}.${TARAXA_MINOR_VERSION}.${TARAXA_PATCH_VERSION})

# Any time a change in the network protocol is introduced this version should be increased
Expand Down
8 changes: 6 additions & 2 deletions libraries/aleth/libp2p/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ void Host::startPeerSession(Public const& _id, RLP const& _hello, unique_ptr<RLP
}
}
}
if (!disconnect_reason && !peerSlotsAvailable()) {
auto is_priority_node = m_netConfig.priority_nodes.contains(peer->address());
if (!disconnect_reason && (!peerSlotsAvailable() && !is_priority_node)) {
cnetdetails << "Too many peers, can't connect. peer count: " << peer_count_()
<< " pending peers: " << m_pendingPeerConns.size();
disconnect_reason = TooManyPeers;
Expand Down Expand Up @@ -411,7 +412,10 @@ void Host::runAcceptor() {
return;
}
auto socket = make_shared<RLPXSocket>(std::move(_socket));
if (peer_count_() > peerSlots(Ingress)) {

// Since a connecting peer might be a trusted node which should always connect allow up to max number of trusted
// nodes above the limit
if (peer_count_() > (peerSlots(Ingress) + m_netConfig.priority_nodes.size())) {
cnetdetails << "Dropping incoming connect due to maximum peer count (" << Ingress
<< " * ideal peer count): " << socket->remoteEndpoint();
socket->close();
Expand Down
3 changes: 3 additions & 0 deletions libraries/aleth/libp2p/Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct NetworkConfig {
if (!publicIPAddress.empty() && !isPublicAddress(publicIPAddress)) BOOST_THROW_EXCEPTION(InvalidPublicIPAddress());
}

/// Priority Nodes
std::unordered_set<dev::p2p::NodeID> priority_nodes;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be const


/// Addressing

std::string publicIPAddress;
Expand Down
1 change: 1 addition & 0 deletions libraries/aleth/libp2p/taraxa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct TaraxaNetworkConfig {
bool is_boot_node = false;
unsigned chain_id = 0;
uint expected_parallelism = 1;

std::chrono::seconds peer_healthcheck_interval{30};
std::chrono::seconds peer_healthcheck_timeout{1};
std::chrono::milliseconds main_loop_interval{100};
Expand Down
22 changes: 20 additions & 2 deletions libraries/cli/include/cli/config_jsons/testnet/testnet_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"listen_port": 10002,
"transaction_interval_ms": 100,
"ideal_peer_count": 10,
"max_peer_count": 50,
"max_peer_count": 20,
"sync_level_size": 10,
"packets_processing_threads": 14,
"peer_blacklist_timeout": 600,
Expand All @@ -51,7 +51,25 @@
"ip": "boot-node-2.testnet.taraxa.io",
"port": 10002
}
]
],
"priority_nodes" : [
"b4ab8c09f711866b067debd9ab075df1a965ade72bc7409d53799b9783543d89d2264e2650e364d9c84694c2fdaaeb69fe500d720a2f1ad17d4bb37a31ca31a6",
"3c87eb8991fda4728c41752d4e374aab555ce76daac92657e9656aa33615e90a64d9582861bc00954332052c3ac3c969b3e23683533db5ae24f8126ce6de427e",
"adbb7940b859e8fde19a93ce26910d51ddd8490b813f8bfc77381665439f11e42c58b626ae4d9da06a4a1730bf28a19bce146e4ba618760f8ee89ccee2bd64aa",
"835b8270274bee693362f8a1357bde3bffaeb40e43c9d47a731ed8ef982554213e6b66e559c6d647a8782483b243704402122a8826fb97ec36cf722bbfc8c3a1",
"28da51fa13108af8e852c5310d4e137e347232129e0503809b9f30588d20ada6c38989f518ae564a82a6c742196d4beed1374585298ba9dad1d551af7a3adf90",
"71b4f525338f2398bee7574d4904c6e4893ca7e39f2f3bed3a9ed44f8fc45e5346a5fee7650475ce012f872c8883f4bd386989172d9bb486e3cb320a0f09b944",
"7bcb52c0011734b394f2e485d48a942ec2a9daa5038acb2a008d6953c1180c604a5f2213c6e581bf3d58d8bbbdf5f8879a3d833105c99332c3ba567aaf67a116",
"7926670f70d032170be1956a1aecdb836717417f86794574ef01e70593396cd3fe4d888aedca5bd6c1b7ee55d8624016547c6fd5faad73e986f6aa0ac30ee2c7",
"fcafab2f0e9736fdefef9bea757c27fd75c2da4c81c175118d74a41a9de3ba340d72e649672f891e9416f23d6963ef52af81e054e84a5eece5f411de31f1206b",
"9419d4d29352d22f924fd49965eefb36d03efc35d2bde7cd3d98b3b583a4c1137837f85663ec206db66c88b2ba92269b4b702f4fc7685f3816d4ce5e81c0c7fb",
"1e4a866fd64d1a88d8f3181f59b5c5e0655f04c48bb92abe5e21e235334db799e64af79334eec9bebc0de1262766f48f0f5df644a49a7bddfb8506d1bb0dcfb1",
"f820fec3f4679d8b9125a47be802d985294fd59d76aca9ff489e50deb5b438682effbd486b11258a3d6e12076af9f09adc948861ed38e91ad9f5a84b3d33f1f4",
"dcc7f60f64eee9fc470e24fd821b3d82acca646c6c951169a8f5b3de297e241cd9987e1cca1083c85b6482ba09715bbea8765710b149c55493e0bb16fc1c29cc",
"dedae37d9c96e0f2c8ef2796351f5560234a3e8e0407ef5cd16aaf93dd8ffd437608a585d5dc3eea54e30e1392591cfc61c6fce3cbf12b46dcc479b5fbdcde96",
"edc73153c2aa5991aee267f46d3ca153fa15f61eb7847b3f4c8b8fa308282b93a315a071bd5ff4327dd321faf4d979710b0e681a7088f65552ce0065fa7683fd",
"00dd2e12a91efcf2f458c039942d16607cca05dfe1f5a94ca59e573aadd86b576f4660ab1baa1ce475c9513b4c9fd04d48a4d9a8173479ccd301e012d21d8239",
"4ba3ebf739ee9fca54e4502dccecf0d4c1390cf87fe54af7356d9da0dc7be0db64d5272d277ae9f1a2f020d0edbdd8286a9b999a875ea6df3585d0939152fe05" ]
},
"db_config": {
"db_snapshot_each_n_pbft_block": 10000,
Expand Down
2 changes: 1 addition & 1 deletion libraries/common/include/common/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ constexpr uint32_t kMaxNonFinalizedDagBlocks{100};

const size_t kV3NetworkVersion = 3;

const uint32_t kRecentlyFinalizedTransactionsFactor = 2;
const uint32_t kRecentlyFinalizedTransactionsFactor = 20;

// The various denominations; here for ease of use where needed within code.
static const u256 kOneTara = dev::exp10<18>();
Expand Down
2 changes: 2 additions & 0 deletions libraries/config/include/config/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>

#include "common/types.hpp"
#include "libp2p/Common.h"

namespace taraxa {

Expand Down Expand Up @@ -82,6 +83,7 @@ struct NetworkConfig {
bool disable_peer_blacklist = false;
uint16_t deep_syncing_threshold = 10;
DdosProtectionConfig ddos_protection;
std::unordered_set<dev::p2p::NodeID> priority_nodes;

std::optional<ConnectionConfig> rpc;
std::optional<ConnectionConfig> graphql;
Expand Down
7 changes: 7 additions & 0 deletions libraries/config/src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ void dec_json(const Json::Value &json, NetworkConfig &network) {
network.listen_port = getConfigDataAsUInt(json, {"listen_port"});
network.transaction_interval_ms = getConfigDataAsUInt(json, {"transaction_interval_ms"});
network.ideal_peer_count = getConfigDataAsUInt(json, {"ideal_peer_count"});
Json::Value priority_nodes = json["priority_nodes"];
if (!priority_nodes.isNull()) {
for (const auto &item : priority_nodes) {
network.priority_nodes.insert(dev::p2p::NodeID(item.asString()));
}
}

network.max_peer_count = getConfigDataAsUInt(json, {"max_peer_count"});
network.sync_level_size = getConfigDataAsUInt(json, {"sync_level_size"});
network.packets_processing_threads = getConfigDataAsUInt(json, {"packets_processing_threads"});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class TransactionManager : public std::enable_shared_from_this<TransactionManage
*/
SharedTransactions getTransactions(const vec_trx_t &trxs_hashes, PbftPeriod proposal_period);

std::pair<SharedTransactions, SharedTransactions> getTransactionsWithNonFinalized(const vec_trx_t &trxs_hashes,
PbftPeriod proposal_period);

/**
* @brief Updates the status of transactions to finalized
* IMPORTANT: This method is invoked on finalizing a pbft block, it needs to be protected with transactions_mutex_ but
Expand Down
11 changes: 9 additions & 2 deletions libraries/core_libs/consensus/src/dag/dag_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver
vec_trx_t const &all_block_trx_hashes = blk.getTrxs();
vec_trx_t trx_hashes_to_query;
SharedTransactions all_block_trxs;
SharedTransactions all_block_trxs_non_finalized;

// Verify tips/pivot count and uniqueness
std::unordered_set<blk_hash_t> unique_tips_pivot;
Expand Down Expand Up @@ -633,6 +634,7 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver
auto trx_it = trxs.find(tx_hash);
if (trx_it != trxs.end()) {
all_block_trxs.emplace_back(trx_it->second);
all_block_trxs_non_finalized.emplace_back(trx_it->second);
} else {
trx_hashes_to_query.emplace_back(tx_hash);
}
Expand All @@ -642,7 +644,8 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver
}

// Verify transactions
auto transactions = trx_mgr_->getTransactions(trx_hashes_to_query, *propose_period);
auto [transactions, non_finalized_transactions] =
trx_mgr_->getTransactionsWithNonFinalized(trx_hashes_to_query, *propose_period);

if (transactions.size() < trx_hashes_to_query.size()) {
LOG(log_nf_) << "Ignore block " << block_hash << " since it has missing transactions";
Expand All @@ -655,6 +658,10 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver
all_block_trxs.emplace_back(std::move(t));
}

for (auto t : non_finalized_transactions) {
all_block_trxs_non_finalized.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();
Expand Down Expand Up @@ -742,7 +749,7 @@ std::pair<DagManager::VerifyBlockReturnType, SharedTransactions> DagManager::ver

LOG(log_dg_) << "Verified DAG block " << blk.getHash();

return {VerifyBlockReturnType::Verified, std::move(all_block_trxs)};
return {VerifyBlockReturnType::Verified, std::move(all_block_trxs_non_finalized)};
}

bool DagManager::isDagBlockKnown(const blk_hash_t &hash) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,49 @@ SharedTransactions TransactionManager::getTransactions(const vec_trx_t &trxs_has
return transactions;
}

std::pair<SharedTransactions, SharedTransactions> TransactionManager::getTransactionsWithNonFinalized(
const vec_trx_t &trxs_hashes, PbftPeriod proposal_period) {
vec_trx_t finalized_trx_hashes;
SharedTransactions transactions;
SharedTransactions non_finalized_transactions;
transactions.reserve(trxs_hashes.size());
for (auto const &tx_hash : trxs_hashes) {
std::shared_lock transactions_lock(transactions_mutex_);
auto trx = transactions_pool_.get(tx_hash);
if (trx != nullptr) {
transactions.emplace_back(trx);
non_finalized_transactions.emplace_back(trx);
} else {
auto trx_it = nonfinalized_transactions_in_dag_.find(tx_hash);
if (trx_it != nonfinalized_transactions_in_dag_.end()) {
transactions.emplace_back(trx_it->second);
non_finalized_transactions.emplace_back(trx_it->second);
} else {
trx_it = recently_finalized_transactions_.find(tx_hash);
if (trx_it != recently_finalized_transactions_.end()) {
transactions.emplace_back(trx_it->second);
} else {
finalized_trx_hashes.emplace_back(tx_hash);
}
}
}
}

// This should be an extremely rare case since transactions should be found in the caches
auto finalizedTransactions = db_->getFinalizedTransactions(finalized_trx_hashes);

for (auto trx : finalizedTransactions) {
// Only include transactions with valid nonce at proposal period
auto acc = final_chain_->getAccount(trx->getSender(), proposal_period);
if (acc.has_value() && acc->nonce > trx->getNonce()) {
LOG(log_er_) << "Old transaction: " << trx->getHash();
} else {
transactions.emplace_back(std::move(trx));
}
}
return {transactions, non_finalized_transactions};
}

void TransactionManager::blockFinalized(EthBlockNumber block_number) {
std::unique_lock transactions_lock(transactions_mutex_);
transactions_pool_.blockFinalized(block_number);
Expand Down
1 change: 1 addition & 0 deletions libraries/core_libs/network/src/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Network::Network(const FullNodeConfig &config, const h256 &genesis_hash, std::fi
net_conf.traverseNAT = false;
net_conf.publicIPAddress = config.network.public_ip;
net_conf.pin = false;
net_conf.priority_nodes = config.network.priority_nodes;

dev::p2p::TaraxaNetworkConfig taraxa_net_conf;
taraxa_net_conf.ideal_peer_count = config.network.ideal_peer_count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ void DagBlockPacketHandler::sendBlockWithTransactions(dev::p2p::NodeID const &pe

// Mark data as known if sending was successful
peer->markDagBlockAsKnown(block.getHash());
for (auto t : trxs) {
peer->markTransactionAsKnown(t->getHash());
}
}

void DagBlockPacketHandler::onNewBlockReceived(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ void StatusPacketHandler::process(const threadpool::PacketData& packet_data, con
return;
}

if (node_major_version < 1 || (node_major_version == 1 && node_minor_version < 12) ||
(node_major_version == 1 && node_minor_version == 12 && node_patch_version < 1)) {
LOG(log_er_) << "Disconnect node which is not at least 1.12.1";
disconnect(packet_data.from_node_id_, dev::p2p::UserReason);
return;
}

Comment on lines +78 to +84
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should put TODO here to remove before merging to master

// If this is a light node and it cannot serve our sync request disconnect from it
if (is_light_node) {
selected_peer->peer_light_node = true;
Expand Down
8 changes: 4 additions & 4 deletions libraries/core_libs/network/src/tarcap/taraxa_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
namespace taraxa::network::tarcap {

TaraxaPeer::TaraxaPeer()
: known_dag_blocks_(10000, 1000, 10),
known_transactions_(100000, 10000, 10),
: known_dag_blocks_(10000, 1000, 100),
known_transactions_(100000, 10000, 100),
known_pbft_blocks_(10000, 1000, 10),
known_votes_(10000, 1000, 10) {}

TaraxaPeer::TaraxaPeer(const dev::p2p::NodeID& id, size_t transaction_pool_size, std::string address)
: address_(address),
id_(id),
known_dag_blocks_(10000, 1000, 10),
known_transactions_(transaction_pool_size * 1.2, transaction_pool_size / 10, 10),
known_dag_blocks_(10000, 1000, 100),
known_transactions_(transaction_pool_size * 1.2, transaction_pool_size / 10, 100),
known_pbft_blocks_(10000, 1000, 10),
known_votes_(10000, 1000, 10) {}

Expand Down