From 83cda110aa0dfd955be4daef5520741ce376b5dd Mon Sep 17 00:00:00 2001
From: SChernykh <sergey.v.chernykh@gmail.com>
Date: Thu, 3 Nov 2022 21:19:48 +0100
Subject: [PATCH] P2PServer: tweaked invalid timestamp messages

---
 src/p2p_server.cpp | 10 ++++++++--
 src/wallet.cpp     |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp
index afe8240..142b031 100644
--- a/src/p2p_server.cpp
+++ b/src/p2p_server.cpp
@@ -2083,9 +2083,15 @@ bool P2PServer::P2PClient::handle_incoming_block_async(const PoolBlock* block, u
 
 		if (failed) {
 			if (is_new) {
+				int64_t dt = static_cast<int64_t>(block->m_timestamp - t);
+				char sign = '+';
+				if (dt < 0) {
+					sign = '-';
+					dt = -dt;
+				}
 				LOGWARN(4, "peer " << static_cast<char*>(m_addrString)
 					<< " sent a block " << block->m_sidechainId << " (mined by " << block->m_minerWallet << ") with an invalid timestamp " << block->m_timestamp
-					<< " (your local timestamp is " << t << ")");
+					<< " (" << sign << dt << " seconds)");
 
 				uint32_t failed_checks = 0;
 
@@ -2096,7 +2102,7 @@ bool P2PServer::P2PClient::handle_incoming_block_async(const PoolBlock* block, u
 				}
 
 				if (failed_checks > 16) {
-					LOGWARN(1, "Your system clock might be invalid: " << failed_checks << " of 32 last blocks were rejected due to timestamp difference");
+					LOGWARN(1, "Your system clock might be invalid: " << failed_checks << " of 32 last blocks were rejected due to high timestamp diff");
 				}
 			}
 			return true;
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 7d32c42..a421846 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -222,7 +222,7 @@ void Wallet::encode(char (&buf)[ADDRESS_LENGTH]) const
 		for (int j = 0; (j < 8) && (i * sizeof(uint64_t) + j < sizeof(data)); ++j) {
 			n = (n << 8) | data[i * sizeof(uint64_t) + j];
 		}
-		for (int j = (((i < num_full_blocks) ? block_sizes.back() : last_block_size)) - 1; j >= 0; --j) {
+		for (int j = ((i < num_full_blocks) ? block_sizes.back() : last_block_size) - 1; j >= 0; --j) {
 			const int digit = n % alphabet_size;
 			n /= alphabet_size;
 			buf[i * block_sizes.back() + j] = alphabet[digit];