Skip to content

Commit

Permalink
Update SLF4J version (hyperledger#4587)
Browse files Browse the repository at this point in the history
* Bump SLF4J version and replace helper for lambdas

Signed-off-by: Diego López León <dieguitoll@gmail.com>

* Remove unnecessary toString calls

Signed-off-by: Diego López León <dieguitoll@gmail.com>

* Replace unnecessaryy lambdas for constant references

Signed-off-by: Diego López León <dieguitoll@gmail.com>

---------

Signed-off-by: Diego López León <dieguitoll@gmail.com>
  • Loading branch information
diega authored Feb 28, 2023
1 parent b850aa7 commit 66c757d
Show file tree
Hide file tree
Showing 59 changed files with 853 additions and 900 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.hyperledger.besu.consensus.merge;

import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;

import org.hyperledger.besu.consensus.merge.blockcreation.PayloadIdentifier;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.ConsensusContext;
Expand Down Expand Up @@ -239,27 +237,28 @@ public void putPayloadById(
maybeCurrBestBlock.ifPresentOrElse(
currBestBlock -> {
if (compareByGasUsedDesc.compare(newBlockWithReceipts, currBestBlock) < 0) {
debugLambda(
LOG,
"New proposal for payloadId {} {} is better than the previous one {}",
payloadId::toString,
() -> logBlockProposal(newBlockWithReceipts.getBlock()),
() -> logBlockProposal(currBestBlock.getBlock()));
LOG.atDebug()
.setMessage("New proposal for payloadId {} {} is better than the previous one {}")
.addArgument(payloadId)
.addArgument(() -> logBlockProposal(newBlockWithReceipts.getBlock()))
.addArgument(() -> logBlockProposal(currBestBlock.getBlock()))
.log();
blocksInProgress.removeAll(
retrieveTuplesById(payloadId).collect(Collectors.toUnmodifiableList()));
blocksInProgress.add(new PayloadTuple(payloadId, newBlockWithReceipts));
}
},
() -> blocksInProgress.add(new PayloadTuple(payloadId, newBlockWithReceipts)));

debugLambda(
LOG,
"Current best proposal for payloadId {} {}",
payloadId::toString,
() ->
retrieveBlockById(payloadId)
.map(bb -> logBlockProposal(bb.getBlock()))
.orElse("N/A"));
LOG.atDebug()
.setMessage("Current best proposal for payloadId {} {}")
.addArgument(payloadId)
.addArgument(
() ->
retrieveBlockById(payloadId)
.map(bb -> logBlockProposal(bb.getBlock()))
.orElse("N/A"))
.log();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.hyperledger.besu.consensus.merge;

import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;

import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Difficulty;
Expand Down Expand Up @@ -124,10 +122,10 @@ private ProtocolSpec getByBlockHeaderFromTransitionUtils(

// if head is not post-merge, return pre-merge schedule:
if (!mergeContext.isPostMerge()) {
debugLambda(
LOG,
"for {} returning a pre-merge schedule because we are not post-merge",
blockHeader::toLogString);
LOG.atDebug()
.setMessage("for {} returning a pre-merge schedule because we are not post-merge")
.addArgument(blockHeader::toLogString)
.log();
return getPreMergeSchedule().getByBlockNumber(blockHeader.getNumber());
}

Expand All @@ -139,26 +137,29 @@ private ProtocolSpec getByBlockHeaderFromTransitionUtils(
.orElse(Difficulty.ZERO);
Difficulty thisDifficulty = parentDifficulty.add(blockHeader.getDifficulty());
Difficulty terminalDifficulty = mergeContext.getTerminalTotalDifficulty();
debugLambda(
LOG,
" block {} ttd is: {}, parent total diff is: {}, this total diff is: {}",
blockHeader::toLogString,
() -> terminalDifficulty,
() -> parentDifficulty,
() -> thisDifficulty);
LOG.atDebug()
.setMessage(" block {} ttd is: {}, parent total diff is: {}, this total diff is: {}")
.addArgument(blockHeader::toLogString)
.addArgument(terminalDifficulty)
.addArgument(parentDifficulty)
.addArgument(thisDifficulty)
.log();

// if this block is pre-merge or a TTD block
if (thisDifficulty.lessThan(terminalDifficulty)
|| TransitionUtils.isTerminalProofOfWorkBlock(blockHeader, protocolContext)) {
debugLambda(
LOG,
"returning a pre-merge schedule because block {} is pre-merge or TTD",
blockHeader::toLogString);
LOG.atDebug()
.setMessage("returning a pre-merge schedule because block {} is pre-merge or TTD")
.addArgument(blockHeader::toLogString)
.log();
return getPreMergeSchedule().getByBlockNumber(blockHeader.getNumber());
}
}
// else return post-merge schedule
debugLambda(LOG, " for {} returning a post-merge schedule", blockHeader::toLogString);
LOG.atDebug()
.setMessage(" for {} returning a post-merge schedule")
.addArgument(blockHeader::toLogString)
.log();
return getPostMergeSchedule().getByBlockNumber(blockHeader.getNumber());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
*/
package org.hyperledger.besu.consensus.merge;

import static org.hyperledger.besu.util.Slf4jLambdaHelper.warnLambda;

import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
Expand Down Expand Up @@ -124,11 +122,11 @@ public static boolean isTerminalProofOfWorkBlock(
}

if (currentChainTotalDifficulty.isZero()) {
warnLambda(
LOG,
"unable to get total difficulty for {}, parent hash {} difficulty not found",
header::toLogString,
header::getParentHash);
LOG.atWarn()
.setMessage("unable to get total difficulty for {}, parent hash {} difficulty not found")
.addArgument(header::toLogString)
.addArgument(header::getParentHash)
.log();
}
Difficulty configuredTotalTerminalDifficulty = consensusContext.getTerminalTotalDifficulty();

Expand Down
Loading

0 comments on commit 66c757d

Please sign in to comment.