Skip to content

Commit 5cff335

Browse files
committed
feat: throw if fork id differs between fromBlock and toBlock
1 parent ca658d3 commit 5cff335

File tree

5 files changed

+36
-13
lines changed

5 files changed

+36
-13
lines changed

arithmetization/src/main/java/net/consensys/linea/plugins/rpc/batchlinecount/ConflatedCountTracesV2.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private ConflatedLineCounts countConflation(PluginRpcRequest request) {
9191

9292
final long fromBlock = params.startBlockNumber();
9393
final long toBlock = params.endBlockNumber();
94-
final LineCountingTracer counter = createLineCountingTracer(fromBlock);
94+
final LineCountingTracer counter = createLineCountingTracer(fromBlock, toBlock);
9595

9696
traceService.trace(
9797
fromBlock,
@@ -112,9 +112,9 @@ private ConflatedLineCounts countConflation(PluginRpcRequest request) {
112112
params.expectedTracesEngineVersion(), fromBlock, toBlock, new TreeMap<>(counts));
113113
}
114114

115-
private LineCountingTracer createLineCountingTracer(long blockNumber) {
115+
private LineCountingTracer createLineCountingTracer(long fromBlock, long toBlock) {
116116
// Retrieve fork from Besu plugin API with block number
117-
final Fork fork = getForkFromBesuBlockchainService(besuContext, fromBlock);
117+
final Fork fork = getForkFromBesuBlockchainService(besuContext, fromBlock, toBlock);
118118

119119
return tracerSharedConfiguration.isLimitless()
120120
? new ZkCounter(l1L2BridgeSharedConfiguration)

arithmetization/src/main/java/net/consensys/linea/plugins/rpc/capture/CaptureToFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Capture execute(final PluginRpcRequest request) {
6363
final long toBlock = params.toBlock();
6464

6565
// Retrieve fork from Besu plugin API with block number
66-
final Fork fork = getForkFromBesuBlockchainService(besuContext, fromBlock);
66+
final Fork fork = getForkFromBesuBlockchainService(besuContext, fromBlock, toBlock);
6767

6868
final BlockCapturer tracer = new BlockCapturer(fork);
6969

arithmetization/src/main/java/net/consensys/linea/plugins/rpc/linecounts/GenerateLineCountsV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private LineCounts getLineCounts(PluginRpcRequest request) {
123123

124124
private LineCountingTracer createLineCountingTracer(long blockNumber) {
125125
// Retrieve fork from Besu plugin API with block number
126-
final Fork fork = getForkFromBesuBlockchainService(besuContext, fromBlock);
126+
final Fork fork = getForkFromBesuBlockchainService(besuContext, blockNumber);
127127

128128
return tracerSharedConfiguration.isLimitless()
129129
? new ZkCounter(l1L2BridgeSharedConfiguration)

arithmetization/src/main/java/net/consensys/linea/plugins/rpc/tracegeneration/GenerateConflatedTracesV2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private TraceFile generateTraceFile(PluginRpcRequest request) {
101101
final long toBlock = params.endBlockNumber();
102102

103103
// Retrieve fork from Besu plugin API with block number
104-
final Fork fork = getForkFromBesuBlockchainService(besuContext, fromBlock);
104+
final Fork fork = getForkFromBesuBlockchainService(besuContext, fromBlock, toBlock);
105105

106106
final ZkTracer tracer =
107107
new ZkTracer(

arithmetization/src/main/java/net/consensys/linea/zktracer/Fork.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,42 @@ private static Fork fromMainnetHardforkId(MainnetHardforkId hardForkId) {
8181
}
8282

8383
/**
84-
* Start a Besu Blockchain service and retrieve the hardfork id at a given block number
84+
* Start a Besu Blockchain service and retrieve the hardfork id for a given block range
8585
*
8686
* @param context the context on which to start the service
87-
* @param blockNumber the block number at which to retrieve the hardfork id
88-
* @return Fork corresponding Fork instance
87+
* @param fromBlock the block number at which to retrieve the hardfork id
88+
* @param toBlock the block number at which to retrieve the hardfork id
89+
* @return Fork corresponding Fork instance if the hardfork id is the same between fromBlock and
90+
* toBlock, else throw
8991
*/
9092
// Waiting for https://github.com/hyperledger/besu/pull/9115 to uncomment
91-
public static Fork getForkFromBesuBlockchainService(ServiceManager context, long blockNumber) {
92-
// MainnetHardforkId hardforkId = BesuServiceProvider.getBesuService(context,
93+
public static Fork getForkFromBesuBlockchainService(
94+
ServiceManager context, long fromBlock, long toBlock) {
95+
// MainnetHardforkId hardforkIdFromBlock = BesuServiceProvider.getBesuService(context,
9396
// BlockchainService.class)
94-
// .getHardforkId(blockNumber)
97+
// .getHardforkId(fromBlock)
9598
// .orElseThrow();
96-
// return fromMainnetHardforkId(hardforkId);
99+
// if (fromBlock != toBlock) {
100+
// MainnetHardforkId hardforkIdToBlock = BesuServiceProvider.getBesuService(context,
101+
// BlockchainService.class)
102+
// .getHardforkId(toBlock)
103+
// .orElseThrow();
104+
// if(hardforkIdFromBlock != hardforkIdToBlock) {
105+
// throw new IllegalArgumentException("Fork change between blocks " + fromBlock + " and " +
106+
// toBlock) ;
107+
// } }
108+
// return fromMainnetHardforkId(hardforkIdFromBlock);
97109
return LONDON;
98110
}
111+
112+
/**
113+
* Start a Besu Blockchain service and retrieve the hardfork id for a given block number
114+
*
115+
* @param context the context on which to start the service
116+
* @param blockNumber the block number at which to retrieve the hardfork id
117+
* @return Fork corresponding Fork instance
118+
*/
119+
public static Fork getForkFromBesuBlockchainService(ServiceManager context, long blockNumber) {
120+
return getForkFromBesuBlockchainService(context, blockNumber, blockNumber);
121+
}
99122
}

0 commit comments

Comments
 (0)