Skip to content

Commit

Permalink
moved some logs to trace level (#6207)
Browse files Browse the repository at this point in the history
* moved some logs to trace level

* shortNodeId

* Apply suggestions from code review

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Co-authored-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
macfarla and fab-10 authored Nov 30, 2023
1 parent 3765aaf commit fd187bc
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ void cacheLogsBloomForBlockHeader(
return;
}
final long blockNumber = blockHeader.getNumber();
LOG.debug("Caching logs bloom for block {}.", "0x" + Long.toHexString(blockNumber));
LOG.atDebug()
.setMessage("Caching logs bloom for block {}")
.addArgument(() -> "0x" + Long.toHexString(blockNumber))
.log();
final File cacheFile = reusedCacheFile.orElse(calculateCacheFileName(blockNumber, cacheDir));
if (cacheFile.exists()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,20 @@ public void removeChainEstimatedHeightListener(final long listenerId) {
}

public void recordRequestTimeout(final int requestCode) {
LOG.debug("Timed out while waiting for response from peer {}", this.getShortNodeId());
LOG.atDebug()
.setMessage("Timed out while waiting for response from peer {}...")
.addArgument(this::getShortNodeId)
.log();
LOG.trace("Timed out while waiting for response from peer {}", this);
reputation.recordRequestTimeout(requestCode).ifPresent(this::disconnect);
}

public void recordUselessResponse(final String requestType) {
LOG.debug(
"Received useless response for request type {} from peer {}",
requestType,
this.getShortNodeId());
LOG.atTrace()
.setMessage("Received useless response for request type {} from peer {}...")
.addArgument(requestType)
.addArgument(this::getShortNodeId)
.log();
reputation.recordUselessResponse(System.currentTimeMillis()).ifPresent(this::disconnect);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ protected Optional<List<BlockHeader>> processResponse(
updatePeerChainState(peer, header);
}

LOG.atDebug()
LOG.atTrace()
.setMessage("Received {} of {} headers requested from peer {}...")
.addArgument(headersList.size())
.addArgument(headersList::size)
.addArgument(count)
.addArgument(peer.getShortNodeId())
.addArgument(peer::getShortNodeId)
.log();
return Optional.of(headersList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private void refreshPeers() {
peer -> {
LOG.atDebug()
.setMessage(
"Refresh peers disconnecting peer {}. Waiting for better peers. Current {} of max {}")
"Refresh peers disconnecting peer {}... Waiting for better peers. Current {} of max {}")
.addArgument(peer::getShortNodeId)
.addArgument(peers::peerCount)
.addArgument(peers::getMaxPeers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public void requestTransactions() {
transactionTracker.markTransactionsAsSeen(peer, retrievedTransactions);

LOG.atTrace()
.setMessage("Got {} transactions of {} hashes requested from peer {}")
.setMessage("Got {} transactions of {} hashes requested from peer {}...")
.addArgument(retrievedTransactions::size)
.addArgument(task.getTransactionHashes()::size)
.addArgument(peer)
.addArgument(peer::getShortNodeId)
.log();

transactionPool.addRemoteTransactions(retrievedTransactions);
Expand Down Expand Up @@ -120,8 +120,8 @@ private List<Hash> getTxHashesAnnounced() {
metrics.incrementAlreadySeenTransactions(metricLabel, alreadySeenCount);
LOG.atTrace()
.setMessage(
"Transaction hashes to request from peer {}, fresh count {}, already seen count {}")
.addArgument(peer)
"Transaction hashes to request from peer {}... fresh count {}, already seen count {}")
.addArgument(peer::getShortNodeId)
.addArgument(toRetrieve::size)
.addArgument(alreadySeenCount)
.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ protected PendingPeerRequest sendRequest() {

return sendRequestToPeer(
peer -> {
LOG.debug("Requesting {} bodies from peer {}.", blockHashes.size(), peer);
LOG.atTrace()
.setMessage("Requesting {} bodies from peer {}.")
.addArgument(blockHashes.size())
.addArgument(peer)
.log();
return peer.getBodies(blockHashes);
},
minimumRequiredBlockNumber);
Expand All @@ -103,7 +107,7 @@ protected PendingPeerRequest sendRequest() {
protected Optional<List<Block>> processResponse(
final boolean streamClosed, final MessageData message, final EthPeer peer) {
if (streamClosed) {
// All outstanding requests have been responded to and we still haven't found the response
// All outstanding requests have been responded to, and we still haven't found the response
// we wanted. It must have been empty or contain data that didn't match.
peer.recordUselessResponse("bodies");
return Optional.of(Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public static AbstractGetHeadersFromPeerTask forSingleHash(
protected PendingPeerRequest sendRequest() {
return sendRequestToPeer(
peer -> {
LOG.atDebug()
LOG.atTrace()
.setMessage("Requesting {} headers (hash {}...) from peer {}...")
.addArgument(count)
.addArgument(referenceHash.slice(0, 6))
.addArgument(peer.getShortNodeId())
.addArgument(peer::getShortNodeId)
.log();
return peer.getHeadersByHash(referenceHash, count, skip, reverse);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ public static AbstractGetHeadersFromPeerTask forSingleNumber(
protected PendingPeerRequest sendRequest() {
return sendRequestToPeer(
peer -> {
LOG.debug(
"Requesting {} headers (blockNumber {}) from peer {}.",
count,
blockNumber,
peer.getShortNodeId());
LOG.atTrace()
.setMessage("Requesting {} headers (blockNumber {}) from peer {}.")
.addArgument(count)
.addArgument(blockNumber)
.addArgument(peer::getShortNodeId)
.log();
return peer.getHeadersByNumber(blockNumber, count, skip, reverse);
},
blockNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ public static GetNodeDataFromPeerTask forHashes(
protected PendingPeerRequest sendRequest() {
return sendRequestToPeer(
peer -> {
LOG.debug("Requesting {} node data entries from peer {}.", hashes.size(), peer);
LOG.atTrace()
.setMessage("Requesting {} node data entries from peer {}...")
.addArgument(hashes::size)
.addArgument(peer::getShortNodeId)
.log();
return peer.getNodeData(hashes);
},
pivotBlockNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public Set<Hash> getTransactionHashes() {
protected PendingPeerRequest sendRequest() {
return sendRequestToPeer(
peer -> {
LOG.debug("Requesting {} transaction pool entries from peer {}.", hashes.size(), peer);
LOG.atTrace()
.setMessage("Requesting {} transaction pool entries from peer {}...")
.addArgument(hashes::size)
.addArgument(peer::getShortNodeId)
.log();
return peer.getPooledTransactions(new ArrayList<>(hashes));
},
0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ protected PendingPeerRequest sendRequest() {
.collect(toList());
return sendRequestToPeer(
peer -> {
LOG.debug("Requesting {} receipts from peer {}.", blockHeaders.size(), peer);
LOG.atTrace()
.setMessage("Requesting {} receipts from peer {}...")
.addArgument(blockHeaders::size)
.addArgument(peer::getShortNodeId)
.log();
return peer.getReceipts(blockHashes);
},
maximumRequiredBlockNumber);
Expand All @@ -93,7 +97,7 @@ protected PendingPeerRequest sendRequest() {
protected Optional<Map<BlockHeader, List<TransactionReceipt>>> processResponse(
final boolean streamClosed, final MessageData message, final EthPeer peer) {
if (streamClosed) {
// All outstanding requests have been responded to and we still haven't found the response
// All outstanding requests have been responded to, and we still haven't found the response
// we wanted. It must have been empty or contain data that didn't match.
peer.recordUselessResponse("receipts");
return Optional.of(emptyMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public static void trackChainHeadForPeers(

@Override
public void onPeerConnected(final EthPeer peer) {
LOG.debug("Requesting chain head info from {}", peer);
LOG.atDebug()
.setMessage("Requesting chain head info from {}...")
.addArgument(peer::getShortNodeId)
.log();
GetHeadersFromPeerByHashTask.forSingleHash(
protocolSchedule,
ethContext,
Expand All @@ -82,14 +85,14 @@ public void onPeerConnected(final EthPeer peer) {
peer.chainState().update(chainHeadHeader);
trailingPeerLimiter.enforceTrailingPeerLimit();
LOG.atDebug()
.setMessage("Retrieved chain head info {} from {}")
.setMessage("Retrieved chain head info {} from {}...")
.addArgument(
() ->
chainHeadHeader.getNumber()
+ " ("
+ chainHeadHeader.getBlockHash()
+ ")")
.addArgument(peer)
.addArgument(peer::getShortNodeId)
.log();
} else {
LOG.debug("Failed to retrieve chain head info. Disconnecting {}", peer, error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected CompletableFuture<List<BlockHeader>> requestHeaders(final Hash hash) {
}

final int batchSize = context.getBatchSize();
LOG.debug("Requesting headers for hash {}, with batch size {}", hash, batchSize);
LOG.trace("Requesting headers for hash {}, with batch size {}", hash, batchSize);

final RetryingGetHeadersEndingAtFromPeerByHashTask
retryingGetHeadersEndingAtFromPeerByHashTask =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private CompletableFuture<List<BlockHeader>> requestHeaders(
final BlockHeader referenceHeader,
final int headerCount,
final int skip) {
LOG.debug(
LOG.trace(
"Requesting {} range headers, starting from {}, {} blocks apart",
headerCount,
referenceHeader.getNumber(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ private void processNewPooledTransactionHashesMessage(

LOG.atTrace()
.setMessage(
"Received pooled transaction hashes message from {}, incoming hashes {}, incoming list {}")
.addArgument(peer)
"Received pooled transaction hashes message from {}... incoming hashes {}, incoming list {}")
.addArgument(() -> peer == null ? null : peer.getShortNodeId())
.addArgument(incomingTransactionHashes::size)
.addArgument(incomingTransactionHashes)
.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Map<Hash, ValidationResult<TransactionInvalidReason>> addRemoteTransactio
final long started = System.currentTimeMillis();
final int initialCount = transactions.size();
final List<Transaction> addedTransactions = new ArrayList<>(initialCount);
LOG.debug("Adding {} remote transactions", initialCount);
LOG.trace("Adding {} remote transactions", initialCount);

final var validationResults =
sortedBySenderAndNonce(transactions)
Expand All @@ -204,7 +204,7 @@ public Map<Hash, ValidationResult<TransactionInvalidReason>> addRemoteTransactio
.addArgument(() -> pendingTransactions.logStats())
.log();

LOG.atDebug()
LOG.atTrace()
.setMessage(
"Added {} transactions to the pool in {}ms, {} not added, current pool stats {}")
.addArgument(addedTransactions::size)
Expand Down Expand Up @@ -350,7 +350,7 @@ public void onBlockAdded(final BlockAddedEvent event) {
.getByBlockHeader(e.getBlock().getHeader())
.getFeeMarket());
reAddTransactions(e.getRemovedTransactions());
LOG.atDebug()
LOG.atTrace()
.setMessage("Block added event {} processed in {}ms")
.addArgument(e)
.addArgument(() -> System.currentTimeMillis() - started)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void disconnect(

@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable throwable) {
LOG.debug("Handshake error:", throwable);
LOG.trace("Handshake error:", throwable);
connectionFuture.completeExceptionally(throwable);
ctx.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void channelActive(final ChannelHandlerContext ctx) throws Exception {
.addListener(
f -> {
if (f.isSuccess()) {
LOG.debug(
LOG.trace(
"Wrote initial crypto handshake message to {}.", ctx.channel().remoteAddress());
}
});
Expand Down

0 comments on commit fd187bc

Please sign in to comment.