Skip to content

Commit

Permalink
Merge pull request #222 from rsksmart/add-hsm-related-logs
Browse files Browse the repository at this point in the history
Adds extra logs for HSM related classes
  • Loading branch information
marcos-iov authored Nov 20, 2023
2 parents c0677a9 + 0a4d054 commit 297bf7b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/co/rsk/federate/signing/ECDSAHSMSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonNode> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
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;
import static co.rsk.federate.signing.hsm.client.HSMResponseCode.*;

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 {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 297bf7b

Please sign in to comment.