Skip to content

Commit

Permalink
Log ZkTracer counters for every produced block
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 authored and delehef committed Dec 13, 2023
1 parent bd083f2 commit 2828475
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.zktracer.ZkTracer;
import org.hyperledger.besu.datatypes.PendingTransaction;
import org.hyperledger.besu.plugin.data.BlockBody;
import org.hyperledger.besu.plugin.data.BlockHeader;
import org.hyperledger.besu.plugin.data.TransactionProcessingResult;
import org.hyperledger.besu.plugin.data.TransactionSelectionResult;
import org.hyperledger.besu.plugin.services.tracer.BlockAwareOperationTracer;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelector;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

/**
* This class implements TransactionSelector and provides a specific implementation for evaluating
Expand All @@ -37,7 +41,7 @@
*/
@Slf4j
public class TraceLineLimitTransactionSelector implements PluginTransactionSelector {

private static final Marker BLOCK_LINE_COUNT_MARKER = MarkerFactory.getMarker("BLOCK_LINE_COUNT");
private final ZkTracer zkTracer;
private final String limitFilePath;
private final Map<String, Integer> moduleLimits;
Expand All @@ -47,7 +51,7 @@ public class TraceLineLimitTransactionSelector implements PluginTransactionSelec
public TraceLineLimitTransactionSelector(
final Supplier<Map<String, Integer>> moduleLimitsProvider, final String limitFilePath) {
moduleLimits = moduleLimitsProvider.get();
zkTracer = new ZkTracer();
zkTracer = new ZkTracerWithLog();
zkTracer.traceStartConflation(1L);
this.limitFilePath = limitFilePath;
}
Expand Down Expand Up @@ -157,4 +161,25 @@ private String logTxLineCount() {
+ moduleLimits.get(e.getKey()))
.collect(Collectors.joining(",", "[", "]"));
}

private class ZkTracerWithLog extends ZkTracer {
@Override
public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) {
super.traceEndBlock(blockHeader, blockBody);
log.atDebug()
.addMarker(BLOCK_LINE_COUNT_MARKER)
.addKeyValue("blockNumber", blockHeader::getNumber)
.addKeyValue("blockHash", blockHeader::getBlockHash)
.addKeyValue(
"traceCounts",
() ->
currCumulatedLineCount == null
? "null"
: currCumulatedLineCount.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.map(e -> '"' + e.getKey() + "\":" + e.getValue())
.collect(Collectors.joining(",")))
.log();
}
}
}
30 changes: 30 additions & 0 deletions arithmetization/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Properties>
<Property name="root.log.level">INFO</Property>
</Properties>

<Appenders>
<Console name="Console">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSSZZZ} | %t | %-5level | %c{1} | %msg%n" />
</Console>
<Routing name="Router">
<Routes pattern="$${event:Marker}">
<Route key="BLOCK_LINE_COUNT">
<Console name="ConsoleBLC" target="SYSTEM_OUT">
<PatternLayout pattern='{"blockNumber":%X{blockNumber},"blockHash":"%X{blockHash}","traceCounts":{%X{traceCounts}}}%n'/>
</Console>
</Route>
<Route ref="Console" />
</Routes>
</Routing>
</Appenders>
<Loggers>
<Logger name="net.consensys.linea.sequencer.txselection.selectors.TraceLineLimitTransactionSelector" level="TRACE">
<AppenderRef ref="Router" />
</Logger>
<Root level="${sys:root.log.level}">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>

0 comments on commit 2828475

Please sign in to comment.