From 05e491f65b068474c4e8f766f3717aff2bf4f140 Mon Sep 17 00:00:00 2001 From: catbref Date: Mon, 29 Jul 2019 10:50:09 +0100 Subject: [PATCH] Relax max clock offsets for block gen and peer connections. It seems unachievable for nodes to keep their clocks accurate to within 500ms. It is unclear whether this is due to Windows' implementation of client NTP or because of terrible network conditions in China. So increasing max NTP offset to allow block generation from 500ms to 30s. Correspondingly increasing max peer timestamp delta from 5s to 30s. The block consensus algorithm will need to change in the near future to address clock issues. --- src/main/java/org/qora/api/model/ConnectedPeer.java | 4 +++- src/main/java/org/qora/controller/Controller.java | 2 +- src/main/java/org/qora/network/Handshake.java | 5 ++++- src/main/java/org/qora/network/Peer.java | 11 +++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/qora/api/model/ConnectedPeer.java b/src/main/java/org/qora/api/model/ConnectedPeer.java index ced54ff7..09cb0c01 100644 --- a/src/main/java/org/qora/api/model/ConnectedPeer.java +++ b/src/main/java/org/qora/api/model/ConnectedPeer.java @@ -20,6 +20,7 @@ public class ConnectedPeer { public Handshake handshakeStatus; public Long lastPing; public Long connectedWhen; + public Long peersConnectedWhen; public String address; public String version; @@ -39,7 +40,8 @@ public class ConnectedPeer { this.lastPing = peer.getLastPing(); PeerData peerData = peer.getPeerData(); - this.connectedWhen = peerData.getLastConnected(); + this.connectedWhen = peer.getConnectionTimestamp(); + this.peersConnectedWhen = peer.getPeersConnectionTimestamp(); this.address = peerData.getAddress().toString(); if (peer.getVersionMessage() != null) { diff --git a/src/main/java/org/qora/controller/Controller.java b/src/main/java/org/qora/controller/Controller.java index ad36c6ee..ada7db35 100644 --- a/src/main/java/org/qora/controller/Controller.java +++ b/src/main/java/org/qora/controller/Controller.java @@ -92,7 +92,7 @@ public class Controller extends Thread { private static final long ARBITRARY_REQUEST_TIMEOUT = 5 * 1000; // ms private static final long REPOSITORY_BACKUP_PERIOD = 123 * 60 * 1000; // ms private static final long NTP_CHECK_PERIOD = 10 * 60 * 1000; // ms - private static final long MAX_NTP_OFFSET = 500; // ms + private static final long MAX_NTP_OFFSET = 30 * 1000; // ms private static volatile boolean isStopping = false; private static BlockGenerator blockGenerator = null; diff --git a/src/main/java/org/qora/network/Handshake.java b/src/main/java/org/qora/network/Handshake.java index cafa6d4f..10aa4ed7 100644 --- a/src/main/java/org/qora/network/Handshake.java +++ b/src/main/java/org/qora/network/Handshake.java @@ -106,6 +106,9 @@ public enum Handshake { return null; } + // Save peer's value for connectionTimestamp + peer.setPeersConnectionTimestamp(proofMessage.getTimestamp()); + // If we connected outbound to peer, then this is a faked confirmation response, so we're good if (peer.isOutbound()) return COMPLETED; @@ -176,7 +179,7 @@ public enum Handshake { private static final Logger LOGGER = LogManager.getLogger(Handshake.class); /** Maximum allowed difference between peer's reported timestamp and when they connected, in milliseconds. */ - private static final long MAX_TIMESTAMP_DELTA = 5000; // ms + private static final long MAX_TIMESTAMP_DELTA = 30 * 1000; // ms public final MessageType expectedMessageType; diff --git a/src/main/java/org/qora/network/Peer.java b/src/main/java/org/qora/network/Peer.java index 068cdcb6..fcd2baaa 100644 --- a/src/main/java/org/qora/network/Peer.java +++ b/src/main/java/org/qora/network/Peer.java @@ -80,6 +80,9 @@ public class Peer { /** Timestamp of when socket was accepted, or connected. */ private Long connectionTimestamp = null; + /** Peer's value of connectionTimestamp. */ + private Long peersConnectionTimestamp = null; + /** Version info as reported by peer. */ private VersionMessage versionMessage = null; @@ -169,6 +172,14 @@ public class Peer { return this.connectionTimestamp; } + public Long getPeersConnectionTimestamp() { + return this.peersConnectionTimestamp; + } + + /* package */ void setPeersConnectionTimestamp(Long peersConnectionTimestamp) { + this.peersConnectionTimestamp = peersConnectionTimestamp; + } + public Long getLastPing() { return this.lastPing; }