From 0a4d0549d664e5cf059f09baed7c90f562aa011b Mon Sep 17 00:00:00 2001 From: jeremy-then Date: Thu, 16 Nov 2023 23:36:28 -0400 Subject: [PATCH] Adds extra logs for HSM related classes --- .../java/co/rsk/federate/signing/ECDSAHSMSigner.java | 2 +- .../hsm/advanceblockchain/HSMBookkeepingService.java | 12 ++++++++---- .../signing/hsm/client/HSMClientProtocol.java | 4 ++-- .../signing/hsm/client/HSMResponseHandlerBase.java | 6 ++++++ .../signing/hsm/client/HSMSigningClientProvider.java | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/co/rsk/federate/signing/ECDSAHSMSigner.java b/src/main/java/co/rsk/federate/signing/ECDSAHSMSigner.java index aba9efdb..c7f89097 100644 --- a/src/main/java/co/rsk/federate/signing/ECDSAHSMSigner.java +++ b/src/main/java/co/rsk/federate/signing/ECDSAHSMSigner.java @@ -90,7 +90,7 @@ public ECDSASignerCheckResult check() { client.getPublicKey(mapping.getValue()); } catch (HSMClientException e) { messages.add(e.getMessage()); - LOGGER.error("Unable to retrieve public key", e); + LOGGER.error("[check] Unable to retrieve public key", e); } } diff --git a/src/main/java/co/rsk/federate/signing/hsm/advanceblockchain/HSMBookkeepingService.java b/src/main/java/co/rsk/federate/signing/hsm/advanceblockchain/HSMBookkeepingService.java index b0203b22..314de7af 100644 --- a/src/main/java/co/rsk/federate/signing/hsm/advanceblockchain/HSMBookkeepingService.java +++ b/src/main/java/co/rsk/federate/signing/hsm/advanceblockchain/HSMBookkeepingService.java @@ -155,12 +155,16 @@ protected void informConfirmedBlockHeaders() { informing = false; return; } + logger.debug( - "[informConfirmedBlockHeaders] Going to inform {} block headers. From {} to {}", - blocks.size(), - blocks.get(0).getHash(), - blocks.get(blocks.size() - 1).getHash() + "[informConfirmedBlockHeaders] Going to inform {} block headers. From block number {} with hash {} to block number {} with hash {}", + blocks.size(), + blocks.get(0).getNumber(), + blocks.get(0).getHash(), + blocks.get(blocks.size() - 1).getNumber(), + blocks.get(blocks.size() - 1).getHash() ); + hsmBookkeepingClient.advanceBlockchain(blocks); hsmCurrentBestBlock = getHsmBestBlock(); logger.debug( diff --git a/src/main/java/co/rsk/federate/signing/hsm/client/HSMClientProtocol.java b/src/main/java/co/rsk/federate/signing/hsm/client/HSMClientProtocol.java index ad46dcb9..e021b793 100644 --- a/src/main/java/co/rsk/federate/signing/hsm/client/HSMClientProtocol.java +++ b/src/main/java/co/rsk/federate/signing/hsm/client/HSMClientProtocol.java @@ -104,11 +104,11 @@ public JsonNode send(ObjectNode command) throws HSMClientException { client = clientProvider.acquire(); String commandName = command.get(COMMAND.getFieldName()).toString(); logger.trace("[send] Sending command to hsm: {}", commandName); - Future future = getExecutor().submit(new HSMRequest(client, command)); + Future future = getExecutor().submit(new HSMRequest(client, command)); JsonNode result = null; try { logger.trace("[send] Fetching response for command: {}", commandName); - result = (JsonNode) future.get(); + result = future.get(); logger.trace("[send] Got response for command: {}", commandName); } catch (ExecutionException e) { Throwable cause = e.getCause(); diff --git a/src/main/java/co/rsk/federate/signing/hsm/client/HSMResponseHandlerBase.java b/src/main/java/co/rsk/federate/signing/hsm/client/HSMResponseHandlerBase.java index 3b49e673..84c3ae24 100644 --- a/src/main/java/co/rsk/federate/signing/hsm/client/HSMResponseHandlerBase.java +++ b/src/main/java/co/rsk/federate/signing/hsm/client/HSMResponseHandlerBase.java @@ -24,6 +24,8 @@ import com.fasterxml.jackson.databind.JsonNode; import java.util.ArrayList; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static co.rsk.federate.signing.HSMField.ERROR; import static co.rsk.federate.signing.HSMField.ERROR_CODE; @@ -31,6 +33,8 @@ public class HSMResponseHandlerBase { + private static final Logger logger = LoggerFactory.getLogger(HSMResponseHandlerBase.class); + //When a `getVersion` request is sent to HSM a `device error` can occur //Since the HSM version is yet undefined we need to handle error codes for both versions at this stage protected void handleErrorResponse(String methodName, int errorCode, JsonNode response) throws HSMClientException { @@ -41,9 +45,11 @@ protected void handleErrorResponse(String methodName, int errorCode, JsonNode re } protected final int validateResponse(String methodName, JsonNode response) throws HSMClientException { + logger.trace("[validateResponse] validating response for HSM method {}. Response: {}", methodName, response.asText()); validatePresenceOf(response, ERROR_CODE.getFieldName()); int errorCode = response.get(ERROR_CODE.getFieldName()).asInt(); + logger.trace("[validateResponse] response error code: {}", errorCode); if (getOkErrorCodes().contains(errorCode)) { return errorCode; } diff --git a/src/main/java/co/rsk/federate/signing/hsm/client/HSMSigningClientProvider.java b/src/main/java/co/rsk/federate/signing/hsm/client/HSMSigningClientProvider.java index 18530d59..1df144cb 100644 --- a/src/main/java/co/rsk/federate/signing/hsm/client/HSMSigningClientProvider.java +++ b/src/main/java/co/rsk/federate/signing/hsm/client/HSMSigningClientProvider.java @@ -46,7 +46,7 @@ public HSMSigningClientProvider(HSMClientProtocol protocol, String keyId) { public HSMSigningClient getSigningClient() throws HSMClientException { int version = this.hsmClientProtocol.getVersion(); HSMSigningClient client; - logger.debug("[getClient] version: {}, keyId: {}", version, keyId); + logger.debug("[getSigningClient] version: {}, keyId: {}", version, keyId); if (version == 1) { client = new HSMSigningClientV1(this.hsmClientProtocol); } else if (version >= 2) {