Skip to content

Commit

Permalink
chore: revert changes from PR for #8173
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
  • Loading branch information
victor-yanev committed May 15, 2024
1 parent 9f94426 commit 8fad134
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
import com.hedera.mirror.common.domain.transaction.RecordFile;
import com.hedera.mirror.web3.evm.store.CachingStateFrame;
import com.hedera.mirror.web3.evm.store.StackedStateFrames;
import lombok.Getter;
import lombok.Setter;

import java.util.EmptyStackException;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import lombok.Getter;
import lombok.Setter;

@Getter
@SuppressWarnings("preview")
Expand All @@ -48,12 +47,9 @@ public class ContractCallContext {
/** Fixed "base" of stack: a R/O cache frame on top of the DB-backed cache frame */
private CachingStateFrame<Object> stackBase;

@Setter
private String tracerType;

@Setter
@Getter
private List<Opcode> opcodes;
private List<Opcode> opcodes = List.of();

private ContractCallContext() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

package com.hedera.mirror.web3.evm.contracts.execution;

import com.hedera.mirror.web3.common.ContractCallContext;
import com.hedera.mirror.web3.service.model.CallServiceParameters;
import com.hedera.node.app.service.evm.contracts.execution.HederaEvmTransactionProcessingResult;
import com.hedera.node.app.service.evm.contracts.execution.HederaEvmTxProcessor;

public interface MirrorEvmTxProcessor {
HederaEvmTransactionProcessingResult execute(CallServiceParameters params, long estimatedGas, HederaEvmTxProcessor.TracerType tracerType, ContractCallContext ctx);
HederaEvmTransactionProcessingResult execute(CallServiceParameters params, long estimatedGas);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@

package com.hedera.mirror.web3.evm.contracts.execution;

import com.hedera.mirror.web3.common.ContractCallContext;
import com.hedera.mirror.web3.evm.account.MirrorEvmContractAliases;
import com.hedera.mirror.web3.evm.contracts.execution.traceability.MirrorOperationTracer;
import com.hedera.mirror.web3.evm.store.Store;
import com.hedera.mirror.web3.evm.store.Store.OnMissing;
import com.hedera.mirror.web3.evm.store.contract.EntityAddressSequencer;
import com.hedera.mirror.web3.exception.MirrorEvmTransactionException;
import com.hedera.mirror.web3.service.model.CallServiceParameters;
import com.hedera.node.app.service.evm.contracts.execution.*;
import com.hedera.node.app.service.evm.contracts.execution.traceability.HederaEvmOperationTracer;
import com.hedera.node.app.service.evm.contracts.execution.BlockMetaSource;
import com.hedera.node.app.service.evm.contracts.execution.EvmProperties;
import com.hedera.node.app.service.evm.contracts.execution.HederaEvmTransactionProcessingResult;
import com.hedera.node.app.service.evm.contracts.execution.HederaEvmTxProcessor;
import com.hedera.node.app.service.evm.contracts.execution.PricesAndFeesProvider;
import com.hedera.node.app.service.evm.store.contracts.AbstractCodeCache;
import com.hedera.node.app.service.evm.store.contracts.HederaEvmMutableWorldState;
import com.hedera.node.app.service.evm.store.tokens.TokenAccessor;
Expand All @@ -33,6 +36,9 @@
import com.hederahashgraph.api.proto.java.ResponseCodeEnum;
import com.swirlds.common.utility.SemanticVersion;
import jakarta.inject.Named;
import java.time.Instant;
import java.util.Map;
import javax.inject.Provider;
import org.apache.commons.lang3.StringUtils;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.Address;
Expand All @@ -43,10 +49,6 @@
import org.hyperledger.besu.evm.processor.ContractCreationProcessor;
import org.hyperledger.besu.evm.processor.MessageCallProcessor;

import javax.inject.Provider;
import java.time.Instant;
import java.util.Map;

@Named
public class MirrorEvmTxProcessorImpl extends HederaEvmTxProcessor implements MirrorEvmTxProcessor {

Expand All @@ -67,7 +69,7 @@ public MirrorEvmTxProcessorImpl(
final BlockMetaSource blockMetaSource,
final MirrorEvmContractAliases aliasManager,
final AbstractCodeCache codeCache,
final Map<TracerType, Provider<HederaEvmOperationTracer>> tracerMap,
final MirrorOperationTracer operationTracer,
final Store store,
final EntityAddressSequencer entityAddressSequencer,
final TokenAccessor tokenAccessor) {
Expand All @@ -79,7 +81,7 @@ public MirrorEvmTxProcessorImpl(
mcps,
ccps,
blockMetaSource,
tracerMap);
operationTracer);

this.aliasManager = aliasManager;
this.codeCache = codeCache;
Expand All @@ -88,7 +90,7 @@ public MirrorEvmTxProcessorImpl(
this.tokenAccessor = tokenAccessor;
}

public HederaEvmTransactionProcessingResult execute(CallServiceParameters params, long estimatedGas, TracerType tracerType, ContractCallContext ctx) {
public HederaEvmTransactionProcessingResult execute(CallServiceParameters params, long estimatedGas) {
final long gasPrice = gasPriceTinyBarsGiven(Instant.now());

store.wrap();
Expand All @@ -110,9 +112,7 @@ public HederaEvmTransactionProcessingResult execute(CallServiceParameters params
params.getCallData(),
params.isStatic(),
aliasManager.resolveForEvm(params.getReceiver()),
params.getReceiver().equals(Address.ZERO),
tracerType,
ctx);
params.getReceiver().equals(Address.ZERO));
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import static com.hedera.mirror.web3.evm.exception.ResponseCodeUtil.getStatusOrDefault;
import static com.hedera.mirror.web3.service.model.CallServiceParameters.CallType.ERROR;
import static com.hedera.mirror.web3.service.model.CallServiceParameters.CallType.ETH_ESTIMATE_GAS;
import static com.hedera.node.app.service.evm.contracts.execution.HederaEvmTxProcessor.TracerType.OPCODE;
import static com.hedera.node.app.service.evm.contracts.execution.HederaEvmTxProcessor.TracerType.OPERATION;
import static org.apache.logging.log4j.util.Strings.EMPTY;

import com.google.common.base.Stopwatch;
Expand All @@ -36,7 +34,6 @@
import com.hedera.mirror.web3.service.utils.BinaryGasEstimator;
import com.hedera.mirror.web3.viewmodel.BlockType;
import com.hedera.node.app.service.evm.contracts.execution.HederaEvmTransactionProcessingResult;
import com.hedera.node.app.service.evm.contracts.execution.HederaEvmTxProcessor;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Meter.MeterProvider;
import io.micrometer.core.instrument.MeterRegistry;
Expand Down Expand Up @@ -84,7 +81,7 @@ public String processCall(final CallServiceParameters params) {
ctx.initializeStackFrames(store.getStackedStateFrames());
result = estimateGas(params);
} else {
final var ethCallTxnResult = getCallTxnResult(params, OPERATION, ctx);
final var ethCallTxnResult = getCallTxnResult(params, ctx);

validateResult(ethCallTxnResult, params.getCallType());

Expand All @@ -102,7 +99,7 @@ public String processCall(final CallServiceParameters params) {

public OpcodesProcessingResult processOpcodeCall(final CallServiceParameters params) {
return ContractCallContext.run(ctx -> {
final var ethCallTxnResult = getCallTxnResult(params, OPCODE, ctx);
final var ethCallTxnResult = getCallTxnResult(params, ctx);
validateResult(ethCallTxnResult, params.getCallType());

return OpcodesProcessingResult.builder()
Expand All @@ -113,7 +110,6 @@ public OpcodesProcessingResult processOpcodeCall(final CallServiceParameters par
}

private HederaEvmTransactionProcessingResult getCallTxnResult(CallServiceParameters params,
HederaEvmTxProcessor.TracerType tracerType,
ContractCallContext ctx) throws MirrorEvmTransactionException {
// if we have historical call then set corresponding file record
if (params.getBlock() != BlockType.LATEST) {
Expand All @@ -124,7 +120,7 @@ private HederaEvmTransactionProcessingResult getCallTxnResult(CallServiceParamet
// eth_call initialization - historical timestamp is Optional.of(recordFile.getConsensusEnd())
// if the call is historical
ctx.initializeStackFrames(store.getStackedStateFrames());
return doProcessCall(params, params.getGas(), tracerType, ctx);
return doProcessCall(params, params.getGas());
}

/**
Expand All @@ -139,7 +135,7 @@ private HederaEvmTransactionProcessingResult getCallTxnResult(CallServiceParamet
* gas used in the first step, while the upper bound is the inputted gas parameter.
*/
private Bytes estimateGas(final CallServiceParameters params) {
final var processingResult = doProcessCall(params, params.getGas(), OPERATION, null);
final var processingResult = doProcessCall(params, params.getGas());
validateResult(processingResult, ETH_ESTIMATE_GAS);

final var gasUsedByInitialCall = processingResult.getGasUsed();
Expand All @@ -151,19 +147,16 @@ private Bytes estimateGas(final CallServiceParameters params) {

final var estimatedGas = binaryGasEstimator.search(
(totalGas, iterations) -> updateGasMetric(ETH_ESTIMATE_GAS, totalGas, iterations),
gas -> doProcessCall(params, gas, OPERATION, null),
gas -> doProcessCall(params, gas),
gasUsedByInitialCall,
params.getGas());

return Bytes.ofUnsignedLong(estimatedGas);
}

private HederaEvmTransactionProcessingResult doProcessCall(CallServiceParameters params,
long estimatedGas,
HederaEvmTxProcessor.TracerType tracerType,
ContractCallContext ctx) throws MirrorEvmTransactionException {
private HederaEvmTransactionProcessingResult doProcessCall(CallServiceParameters params, long estimatedGas) {
try {
return mirrorEvmTxProcessor.execute(params, estimatedGas, tracerType, ctx);
return mirrorEvmTxProcessor.execute(params, estimatedGas);
} catch (IllegalStateException | IllegalArgumentException e) {
throw new MirrorEvmTransactionException(e.getMessage(), EMPTY, EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@

package com.hedera.node.app.service.evm.contracts.execution;

import com.hedera.mirror.web3.common.ContractCallContext;
import static com.hedera.mirror.web3.common.PrecompileContext.PRECOMPILE_CONTEXT;

import com.hedera.mirror.web3.common.PrecompileContext;
import com.hedera.mirror.web3.evm.contracts.execution.traceability.OpcodeTracer;
import com.hedera.mirror.web3.evm.contracts.execution.traceability.MirrorOperationTracer;
import com.hedera.mirror.web3.evm.properties.MirrorNodeEvmProperties;
import com.hedera.node.app.service.evm.contracts.execution.traceability.HederaEvmOperationTracer;
import com.hedera.node.app.service.evm.store.contracts.HederaEvmMutableWorldState;
import com.hedera.node.app.service.evm.store.models.HederaEvmAccount;
import com.hederahashgraph.api.proto.java.HederaFunctionality;
import com.swirlds.common.utility.SemanticVersion;
import java.time.Instant;
import java.util.Map;
import javax.inject.Provider;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
Expand All @@ -36,12 +40,6 @@
import org.hyperledger.besu.evm.processor.MessageCallProcessor;
import org.hyperledger.besu.evm.tracing.OperationTracer;

import javax.inject.Provider;
import java.time.Instant;
import java.util.Map;

import static com.hedera.mirror.web3.common.PrecompileContext.PRECOMPILE_CONTEXT;

/**
* Stateless invariant copy of its hedera-services counterpart. It is used to process EVM transactions in
* an asynchronous manner.
Expand All @@ -60,9 +58,7 @@ public class HederaEvmTxProcessor {
protected final PricesAndFeesProvider livePricesSource;
protected final Map<SemanticVersion, Provider<MessageCallProcessor>> mcps;
protected final Map<SemanticVersion, Provider<ContractCreationProcessor>> ccps;

//TODO: do not import TRACER_TYPE from ProcessorImpl
protected final Map<TracerType, Provider<HederaEvmOperationTracer>> tracerMap;
protected final HederaEvmOperationTracer tracer;
protected final EvmProperties dynamicProperties;

@SuppressWarnings("java:S107")
Expand All @@ -74,15 +70,15 @@ protected HederaEvmTxProcessor(
final Map<SemanticVersion, Provider<MessageCallProcessor>> mcps,
final Map<SemanticVersion, Provider<ContractCreationProcessor>> ccps,
final BlockMetaSource blockMetaSource,
final Map<TracerType, Provider<HederaEvmOperationTracer>> tracerMap) {
final MirrorOperationTracer tracer) {
this.worldState = worldState;
this.livePricesSource = livePricesSource;
this.dynamicProperties = dynamicProperties;
this.gasCalculator = gasCalculator;
this.mcps = mcps;
this.ccps = ccps;
this.blockMetaSource = blockMetaSource;
this.tracerMap = tracerMap;
this.tracer = tracer;
}

/**
Expand Down Expand Up @@ -111,9 +107,7 @@ public HederaEvmTransactionProcessingResult execute(
final Bytes payload,
final boolean isStatic,
final Address mirrorReceiver,
final boolean contractCreation,
final TracerType tracerType,
final ContractCallContext contractCallContext) {
final boolean contractCreation) {
final var blockValues = blockMetaSource.computeBlockValues(gasLimit);
final var intrinsicGas = gasCalculator.transactionIntrinsicGasCost(payload, contractCreation);
final var gasAvailable = gasLimit - intrinsicGas;
Expand Down Expand Up @@ -147,7 +141,7 @@ public HederaEvmTransactionProcessingResult execute(

final var initialFrame = buildInitialFrame(commonInitialFrame, receiver, payload, value);
final var messageFrameStack = initialFrame.getMessageFrameStack();
HederaEvmOperationTracer tracer = this.getTracer(tracerType);

tracer.init(initialFrame);

final var evmVersion = ((MirrorNodeEvmProperties) dynamicProperties).getSemanticEvmVersion();
Expand All @@ -160,9 +154,6 @@ public HederaEvmTransactionProcessingResult execute(

tracer.finalizeOperation(initialFrame);

if (tracer instanceof OpcodeTracer opcodeTracer) {
contractCallContext.setOpcodes(opcodeTracer.getOpcodes());
}
// Externalise result
if (initialFrame.getState() == MessageFrame.State.COMPLETED_SUCCESS) {
return HederaEvmTransactionProcessingResult.successful(
Expand Down Expand Up @@ -220,13 +211,4 @@ private AbstractMessageProcessor getMessageProcessor(
case CONTRACT_CREATION -> ccps.get(evmVersion).get();
};
}

private HederaEvmOperationTracer getTracer(TracerType tracerType) {
return tracerMap.get(tracerType).get();
}

public enum TracerType {
OPCODE,
OPERATION
}
}

0 comments on commit 8fad134

Please sign in to comment.