1515package org .hyperledger .besu .ethereum .api .jsonrpc .internal .methods ;
1616
1717import org .hyperledger .besu .config .GenesisConfigOptions ;
18+ import org .hyperledger .besu .datatypes .HardforkId ;
1819import org .hyperledger .besu .ethereum .api .jsonrpc .RpcMethod ;
1920import org .hyperledger .besu .ethereum .api .jsonrpc .internal .JsonRpcRequestContext ;
2021import org .hyperledger .besu .ethereum .api .jsonrpc .internal .exception .InvalidJsonRpcParameters ;
@@ -51,6 +52,8 @@ public class EthConfig implements JsonRpcMethod {
5152 private final BlockchainQueries blockchain ;
5253 private final ProtocolSchedule protocolSchedule ;
5354 private final ForkIdManager forkIdManager ;
55+ private final Long firstTimestampMilestone ;
56+ private final Long firstBlobsMilestone ;
5457
5558 public EthConfig (
5659 final BlockchainQueries blockchain ,
@@ -64,6 +67,10 @@ public EthConfig(
6467 blockchain .getBlockchain (),
6568 genesisConfigOptions .getForkBlockNumbers (),
6669 genesisConfigOptions .getForkBlockTimestamps ());
70+ firstTimestampMilestone =
71+ protocolSchedule .milestoneFor (HardforkId .MainnetHardforkId .SHANGHAI ).orElse (0L );
72+ firstBlobsMilestone =
73+ protocolSchedule .milestoneFor (HardforkId .MainnetHardforkId .CANCUN ).orElse (0L );
6774 }
6875
6976 @ Override
@@ -120,8 +127,12 @@ private boolean showAllForks(final JsonRpcRequestContext requestContext) {
120127 }
121128 }
122129
123- private String getForkIdAsHexString (final long currentTime ) {
124- return forkIdManager .getForkIdByTimestamp (currentTime ).getHash ().toHexString ();
130+ private String getForkIdAsHexString (final long milestone ) {
131+ if (milestone >= firstTimestampMilestone ) {
132+ return forkIdManager .getForkIdByTimestamp (milestone ).getHash ().toHexString ();
133+ } else {
134+ return forkIdManager .getForkIdByBlockNumber (milestone ).getHash ().toHexString ();
135+ }
125136 }
126137
127138 void generateConfig (final ObjectNode result , final ScheduledProtocolSpec scheduledSpec ) {
@@ -133,13 +144,19 @@ void generateConfig(final ObjectNode result, final ProtocolSpec spec) {
133144 }
134145
135146 void generateConfig (final ObjectNode result , final Hardfork forkId , final ProtocolSpec spec ) {
136- result .put ("activationTime" , forkId .milestone ());
147+ if (forkId .milestone () < firstTimestampMilestone ) {
148+ result .put ("activationBlock" , forkId .milestone ());
149+ } else {
150+ result .put ("activationTime" , forkId .milestone ());
151+ }
137152
138- ObjectNode blobs = result .putObject ("blobSchedule" );
139- blobs .put (
140- "baseFeeUpdateFraction" , spec .getFeeMarket ().getBaseFeeUpdateFraction ().longValueExact ());
141- blobs .put ("max" , spec .getGasLimitCalculator ().currentBlobGasLimit () / (128 * 1024 ));
142- blobs .put ("target" , spec .getGasLimitCalculator ().getTargetBlobGasPerBlock () / (128 * 1024 ));
153+ if (forkId .milestone () >= firstBlobsMilestone ) {
154+ ObjectNode blobs = result .putObject ("blobSchedule" );
155+ blobs .put (
156+ "baseFeeUpdateFraction" , spec .getFeeMarket ().getBaseFeeUpdateFraction ().longValueExact ());
157+ blobs .put ("max" , spec .getGasLimitCalculator ().currentBlobGasLimit () / (128 * 1024 ));
158+ blobs .put ("target" , spec .getGasLimitCalculator ().getTargetBlobGasPerBlock () / (128 * 1024 ));
159+ }
143160
144161 result .put (
145162 "chainId" , protocolSchedule .getChainId ().map (c -> "0x" + c .toString (16 )).orElse (null ));
0 commit comments