Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate line count only once in linea_estimateGas #13

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,14 @@ private Long estimateGasUsed(
final Transaction transaction,
final Wei minGasPrice) {

final var estimateGasOperationTracer = new EstimateGasOperationTracer();
final var estimateGasTracer = new EstimateGasOperationTracer();
final var chainHeadHeader = blockchainService.getChainHeadHeader();
final var zkTracer = createZkTracer(chainHeadHeader);
TracerAggregator tracerAggregator =
TracerAggregator.create(estimateGasOperationTracer, zkTracer);
final TracerAggregator zkAndGasTracer = TracerAggregator.create(estimateGasTracer, zkTracer);

final var chainHeadHash = chainHeadHeader.getBlockHash();
final var maybeSimulationResults =
transactionSimulationService.simulate(transaction, chainHeadHash, tracerAggregator, true);
transactionSimulationService.simulate(transaction, chainHeadHash, zkAndGasTracer, true);

ModuleLimitsValidationResult moduleLimit =
moduleLineCountValidator.validate(zkTracer.getModulesLineCount());
Expand Down Expand Up @@ -265,7 +264,7 @@ private Long estimateGasUsed(
transactionSimulationService.simulate(
createTransactionForSimulation(callParameters, lowGasEstimation, minGasPrice),
chainHeadHash,
tracerAggregator,
estimateGasTracer,
true);

return lowResult
Expand All @@ -289,8 +288,7 @@ private Long estimateGasUsed(

// else do a binary search to find the right estimation
int iterations = 0;
var high =
highGasEstimation(lr.getGasEstimate(), estimateGasOperationTracer);
var high = highGasEstimation(lr.getGasEstimate(), estimateGasTracer);
var mid = high;
var low = lowGasEstimation;
while (low + 1 < high) {
Expand All @@ -302,7 +300,7 @@ private Long estimateGasUsed(
createTransactionForSimulation(
callParameters, mid, minGasPrice),
chainHeadHash,
tracerAggregator,
estimateGasTracer,
true);

if (binarySearchResult.isEmpty()
Expand Down Expand Up @@ -383,17 +381,17 @@ private void validateParameters(final JsonCallParameter callParameters) {
* calls
*
* @param gasEstimation transaction gas estimation
* @param operationTracer estimate gas operation tracer
* @param estimateGasTracer estimate gas operation tracer
* @return estimate gas
*/
private long highGasEstimation(
final long gasEstimation, final EstimateGasOperationTracer operationTracer) {
final long gasEstimation, final EstimateGasOperationTracer estimateGasTracer) {

// no more than 63/64s of the remaining gas can be passed to the sub calls
final double subCallMultiplier =
Math.pow(SUB_CALL_REMAINING_GAS_RATIO, operationTracer.getMaxDepth());
Math.pow(SUB_CALL_REMAINING_GAS_RATIO, estimateGasTracer.getMaxDepth());
// and minimum gas remaining is necessary for some operation (additionalStipend)
final long gasStipend = operationTracer.getStipendNeeded();
final long gasStipend = estimateGasTracer.getStipendNeeded();
return ((long) ((gasEstimation + gasStipend) * subCallMultiplier));
}

Expand Down
Loading