From 797bfe5cd5e7d16435707a2b432147f246f23652 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Sat, 29 Oct 2022 22:12:31 -0500 Subject: [PATCH 1/2] Store the build's commit hash in Jarfile manifest. --- build.gradle | 9 +++++++++ common/src/main/java/bisq/common/app/Version.java | 14 ++++++++++++++ .../p2p/inventory/GetInventoryRequestHandler.java | 3 +-- .../network/p2p/inventory/model/RequestInfo.java | 3 --- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 7697799c90..1b1a7a4f2d 100644 --- a/build.gradle +++ b/build.gradle @@ -237,6 +237,15 @@ configure(project(':common')) { modules = ['javafx.graphics'] } + ext.getHash = { + def p1 = 'git rev-parse HEAD'.execute() + p1.waitFor() + return p1.text.substring(0,7) + } + + jar.manifest.attributes( + "Implementation-Version": getHash()) + dependencies { implementation project(':proto') annotationProcessor "org.projectlombok:lombok:$lombokVersion" diff --git a/common/src/main/java/bisq/common/app/Version.java b/common/src/main/java/bisq/common/app/Version.java index 9f63abd6a8..22f95a03c0 100644 --- a/common/src/main/java/bisq/common/app/Version.java +++ b/common/src/main/java/bisq/common/app/Version.java @@ -17,8 +17,12 @@ package bisq.common.app; +import java.net.URL; + import java.util.Arrays; import java.util.List; +import java.util.jar.Attributes; +import java.util.jar.Manifest; import lombok.extern.slf4j.Slf4j; @@ -135,6 +139,16 @@ public class Version { '}'); } + public String readCommitHash() { + try { + String pth = getClass().getResource(getClass().getSimpleName() + ".class").toString(); + String mnf = pth.substring(0, pth.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; + Attributes attr = new Manifest(new URL(mnf).openStream()).getMainAttributes(); + return attr.getValue("Implementation-Version"); + } catch (Exception ignored) { } + return "unknown"; + } + public static final byte COMPENSATION_REQUEST = (byte) 0x01; public static final byte REIMBURSEMENT_REQUEST = (byte) 0x01; public static final byte PROPOSAL = (byte) 0x01; diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java index 6bd646bc29..a8b6f4b7ec 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java @@ -29,7 +29,6 @@ import bisq.core.filter.FilterManager; import bisq.core.network.p2p.inventory.messages.GetInventoryRequest; import bisq.core.network.p2p.inventory.messages.GetInventoryResponse; import bisq.core.network.p2p.inventory.model.InventoryItem; -import bisq.core.network.p2p.inventory.model.RequestInfo; import bisq.network.p2p.network.Connection; import bisq.network.p2p.network.MessageListener; @@ -151,7 +150,7 @@ public class GetInventoryRequestHandler implements MessageListener { // node inventory.put(InventoryItem.version, Version.VERSION); - inventory.put(InventoryItem.commitHash, RequestInfo.COMMIT_HASH); + inventory.put(InventoryItem.commitHash, new Version().readCommitHash()); inventory.put(InventoryItem.usedMemory, String.valueOf(Profiler.getUsedMemoryInBytes())); inventory.put(InventoryItem.jvmStartTime, String.valueOf(ManagementFactory.getRuntimeMXBean().getStartTime())); diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java index c55a9e04ee..c84f69d410 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/model/RequestInfo.java @@ -28,9 +28,6 @@ import org.jetbrains.annotations.Nullable; @Getter public class RequestInfo { - // Carries latest commit hash of feature changes (not latest commit as that is then the commit for editing that field) - public static final String COMMIT_HASH = "c07d47a8"; - private final long requestStartTime; @Setter private long responseTime; From bc8b05ea45b03302dbd537f3153bcae6d1d2f7cf Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Mon, 31 Oct 2022 10:46:12 -0500 Subject: [PATCH 2/2] Log readability will be improved by lowering to trace the repetitive logging of: `The requester had version x.x.x. Our historical data store has version y.y.y As the requester version is not older as our historical store we do not add the data to the result map.` Which takes up many screenfuls of log for every client getDataRequest. --- .../p2p/storage/persistence/HistoricalDataStoreService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/src/main/java/bisq/network/p2p/storage/persistence/HistoricalDataStoreService.java b/p2p/src/main/java/bisq/network/p2p/storage/persistence/HistoricalDataStoreService.java index 1510092654..a1fdcecd26 100644 --- a/p2p/src/main/java/bisq/network/p2p/storage/persistence/HistoricalDataStoreService.java +++ b/p2p/src/main/java/bisq/network/p2p/storage/persistence/HistoricalDataStoreService.java @@ -83,7 +83,7 @@ public abstract class HistoricalDataStoreService