Skip to content
Open
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
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "thirdparty/fc"]
path = thirdparty/fc
url = https://github.com/VIZ-Blockchain/fc.git
branch = update
url = https://github.com/m0ssa99/fc.git
branch = windows_suport_fc
[submodule "thirdparty/chainbase"]
path = thirdparty/chainbase
url = https://github.com/VIZ-Blockchain/chainbase.git
Expand Down
227 changes: 207 additions & 20 deletions libraries/network/dlt_p2p_node.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ struct dlt_hello_message {
bool has_emergency_key = false;
uint8_t fork_status = DLT_FORK_STATUS_NORMAL;
uint8_t node_status = DLT_NODE_STATUS_SYNC;
// Persistent node identity key — used to deduplicate connections from nodes
// sharing the same NAT IP (different ports). Each node generates a random
// keypair at startup. Zero-value means "unknown" (old protocol peer).
node_id_t node_id;
};

// ── DLT Hello Reply ─────────────────────────────────────────────────
Expand Down Expand Up @@ -269,7 +273,7 @@ FC_REFLECT_ENUM(graphene::network::dlt_peer_lifecycle_state,
FC_REFLECT((graphene::network::dlt_hello_message),
(protocol_version)(head_block_id)(head_block_num)(lib_block_id)(lib_block_num)
(dlt_earliest_block)(dlt_latest_block)(emergency_active)(has_emergency_key)
(fork_status)(node_status))
(fork_status)(node_status)(node_id))

FC_REFLECT((graphene::network::dlt_hello_reply_message),
(exchange_enabled)(fork_alignment)(initiator_head_seen)(initiator_lib_seen)
Expand Down
6 changes: 5 additions & 1 deletion libraries/network/include/graphene/network/dlt_p2p_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class dlt_p2p_node {
bool is_same_subnet(const fc::ip::address& a, const fc::ip::address& b) const;

// ── Per-IP dedup ─────────────────────────────────────────────
peer_id find_active_peer_by_ip(const fc::ip::address& addr) const;
peer_id find_active_peer_by_node_id(const node_id_t& nid) const;

private:
dlt_p2p_delegate* _delegate = nullptr;
Expand Down Expand Up @@ -344,6 +344,7 @@ class dlt_p2p_node {
fc::thread* _thread = nullptr;
bool _running = false;
std::map<peer_id, fc::future<void>> _read_fibers;
std::vector<fc::future<void>> _dead_fibers;
fc::future<void> _accept_fiber;
fc::future<void> _periodic_fiber;

Expand Down Expand Up @@ -443,6 +444,9 @@ class dlt_p2p_node {
std::map<uint32_t, fc::time_point> _blocked_ips;
static constexpr uint32_t BLOCKED_IP_DURATION_SEC = 3600; // 1 hour
void block_incoming_ip(uint32_t ip, const std::string& reason);
// Last time a peer exchange request was sent — used by periodic_peer_exchange()
// to dynamically throttle based on the number of active peers (see impl).
fc::time_point _last_peer_exchange_time;
bool is_ip_blocked(uint32_t ip);

// ── Diagnostics ───────────────────────────────────────────────
Expand Down
7 changes: 6 additions & 1 deletion plugins/validator/validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,12 @@ namespace graphene {
{
int64_t ntp_us = 0;
try { ntp_us = graphene::time::ntp_error().count(); } catch (...) {}
if (ntp_us > 250000) { // local clock >250ms behind NTP
#if defined(_WIN32)
constexpr int64_t NTP_WARN_THRESHOLD_US = 2000000; // 2s pe Windows
#else
constexpr int64_t NTP_WARN_THRESHOLD_US = 250000; // 250ms pe Linux/macOS
#endif
if (ntp_us > NTP_WARN_THRESHOLD_US) { // local clock >250ms behind NTP
static fc::time_point _last_ntp_drift_log;
auto _now_nd = fc::time_point::now();
if ((_now_nd - _last_ntp_drift_log).count() > 10000000) {
Expand Down