Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
api("com.graphql-java-generator:graphql-java-client-runtime:2.9")
api("com.graphql-java:graphql-java-extended-scalars:24.0")
api("com.graphql-java:graphql-java-extended-validation:24.0")
api("com.hedera.hashgraph:app:0.64.3")
api("com.hedera.hashgraph:app:0.65.0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 0.65.1

api("com.hedera.evm:hedera-evm:0.54.2")
api("com.hedera.hashgraph:hedera-protobuf-java-api:0.63.5")
api("com.hedera.hashgraph:sdk:2.62.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@

import static com.hedera.hapi.streams.ContractActionType.PRECOMPILE;
import static com.hedera.hapi.streams.ContractActionType.SYSTEM;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.INSUFFICIENT_CHILD_RECORDS;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.INVALID_CONTRACT_ID;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.INVALID_SIGNATURE;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.*;

Check notice on line 7 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L7

Unused import 'com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.*'

Check warning on line 7 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L7

Using the '.*' form of import should be avoided - com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.*.
import static com.hedera.node.app.service.contract.impl.exec.systemcontracts.hts.create.CreateCommons.createMethodsSet;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.acquiredSenderAuthorizationViaDelegateCall;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.alreadyHalted;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.incrementOpsDuration;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.isPrecompileEnabled;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.isTopLevelTransaction;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.proxyUpdaterFor;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.recordBuilderFor;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.setPropagatedCallFailure;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.transfersValue;
import static com.hedera.node.app.service.contract.impl.hevm.HederaOpsDuration.MULTIPLIER_FACTOR;
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.*;

Check notice on line 9 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L9

Unused import 'com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.*'

Check warning on line 9 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L9

Using the '.*' form of import should be avoided - com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.*.
import static com.hedera.node.app.service.contract.impl.hevm.HevmPropagatedCallFailure.MISSING_RECEIVER_SIGNATURE;
import static com.hedera.node.app.service.contract.impl.hevm.HevmPropagatedCallFailure.RESULT_CANNOT_BE_EXTERNALIZED;
import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.numberOfLongZero;
Expand All @@ -29,20 +18,18 @@
import com.hedera.node.app.service.contract.impl.exec.ActionSidecarContentTracer;
import com.hedera.node.app.service.contract.impl.exec.AddressChecks;
import com.hedera.node.app.service.contract.impl.exec.FeatureFlags;
import com.hedera.node.app.service.contract.impl.exec.metrics.ContractMetrics;
import com.hedera.node.app.service.contract.impl.exec.systemcontracts.HederaSystemContract;
import com.hedera.node.app.service.contract.impl.exec.tracers.AddOnEvmActionTracer;
import com.hedera.node.app.service.contract.impl.hevm.HederaOpsDuration;
import com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils;
import com.hedera.node.app.service.contract.impl.state.ProxyEvmContract;
import com.hedera.node.app.service.contract.impl.state.ProxyWorldUpdater;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import jakarta.annotation.Nonnull;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.hiero.mirror.web3.common.ContractCallContext;
import org.hiero.mirror.web3.evm.contracts.execution.traceability.OpcodeActionTracer;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.EVM;
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
Expand All @@ -65,22 +52,20 @@
* and the core {@link MessageCallProcessor#process(MessageFrame, OperationTracer)} logic we inherit.
*
* Copy of the class from hedera-app. The differences with it are:
*
* - It sets the gasRequirement for a system contract in the ContractCallContext.
* - It sets the current Map with system contracts coming from hedera.app inside {@link OpcodeActionTracer}
* - It calls {@link AddOnEvmActionTracer#tracePrecompileCall(MessageFrame, long, Bytes)} instead of
* {@link AddOnEvmActionTracer#tracePrecompileResult(MessageFrame, ContractActionType)} for precompiles.
* - It calls {@link ActionSidecarContentTracer#tracePrecompileCall(MessageFrame, long, Bytes)} instead of
* {@link ActionSidecarContentTracer#tracePrecompileResult(MessageFrame, ContractActionType)} for precompiles.
* The reasons are that we need to pass the gasRequirement to the tracer and that
* {@link org.hiero.mirror.web3.evm.contracts.execution.traceability.OpcodeActionTracer} is
* added as an addOnTracer. The {@link AddOnEvmActionTracer#tracePrecompileCall(MessageFrame, long, Bytes)} method
* added as an addOnTracer. The {@link ActionSidecarContentTracer#tracePrecompileCall(MessageFrame, long, Bytes)} method
* delegates the call to the list of addOnTracers, where the {@link org.hiero.mirror.web3.evm.contracts.execution.traceability.OpcodeActionTracer} is stored.
*/
public class CustomMessageCallProcessor extends MessageCallProcessor {
private final FeatureFlags featureFlags;
private final AddressChecks addressChecks;
private final PrecompileContractRegistry precompiles;
private final Map<Address, HederaSystemContract> systemContracts;
private final HederaOpsDuration hederaOpsDuration;
private final ContractMetrics contractMetrics;

private enum ForLazyCreation {
YES,
Expand All @@ -96,18 +81,18 @@
* @param systemContracts the Hedera system contracts
*/
public CustomMessageCallProcessor(
@NonNull final EVM evm,
@NonNull final FeatureFlags featureFlags,
@NonNull final PrecompileContractRegistry precompiles,
@NonNull final AddressChecks addressChecks,
@NonNull final Map<Address, HederaSystemContract> systemContracts,
@NonNull final HederaOpsDuration hederaOpsDuration) {
@Nonnull final EVM evm,
@Nonnull final FeatureFlags featureFlags,
@Nonnull final PrecompileContractRegistry precompiles,
@Nonnull final AddressChecks addressChecks,
@Nonnull final Map<Address, HederaSystemContract> systemContracts,
@Nonnull final ContractMetrics contractMetrics) {

Check notice on line 89 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L89

Expected @param tag for 'contractMetrics'.
super(evm, precompiles);
this.featureFlags = Objects.requireNonNull(featureFlags);
this.precompiles = Objects.requireNonNull(precompiles);
this.addressChecks = Objects.requireNonNull(addressChecks);
this.systemContracts = Objects.requireNonNull(systemContracts);
this.hederaOpsDuration = Objects.requireNonNull(hederaOpsDuration);
this.contractMetrics = Objects.requireNonNull(contractMetrics);
}

/**
Expand All @@ -128,7 +113,7 @@
* @param tracer the operation tracer
*/
@Override
public void start(@NonNull final MessageFrame frame, @NonNull final OperationTracer tracer) {
public void start(@Nonnull final MessageFrame frame, @Nonnull final OperationTracer tracer) {

Check notice on line 116 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L116

Method ForLazyCreation::start has 44 lines of code (limit is 30)

Check failure on line 116 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L116

Method ForLazyCreation::start has a cyclomatic complexity of 14 (limit is 12)

Check warning on line 116 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L116

The method 'start(MessageFrame, OperationTracer)' has a cognitive complexity of 20, current threshold is 15

Check warning on line 116 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L116

The method 'start(MessageFrame, OperationTracer)' has a cyclomatic complexity of 14.

Check warning on line 116 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L116

The method 'start(MessageFrame, OperationTracer)' has an NPath complexity of 1080, current threshold is 200
final var codeAddress = frame.getContractAddress();
// This must be done first as the system contract address range overlaps with system
// accounts. Note that unlike EVM precompiles, we do allow sending value "to" Hedera
Expand All @@ -144,10 +129,6 @@
return;
}
}

if (tracer instanceof final OpcodeActionTracer opcodeActionTracer) {
opcodeActionTracer.setSystemContracts(systemContracts);
}
doExecuteSystemContract(systemContracts.get(codeAddress), codeAddress, frame, tracer);
return;
}
Expand Down Expand Up @@ -223,27 +204,37 @@
}

private void handleNonExtantSystemAccount(
@NonNull final MessageFrame frame, @NonNull final OperationTracer tracer) {
@Nonnull final MessageFrame frame, @Nonnull final OperationTracer tracer) {
final PrecompileContractResult result = PrecompileContractResult.success(Bytes.EMPTY);
frame.clearGasRemaining();
finishPrecompileExecution(frame, result, PRECOMPILE, (ActionSidecarContentTracer) tracer);
}

private void doExecutePrecompile(
@NonNull final PrecompiledContract precompile,
@NonNull final MessageFrame frame,
@NonNull final OperationTracer tracer) {
@Nonnull final PrecompiledContract precompile,
@Nonnull final MessageFrame frame,
@Nonnull final OperationTracer tracer) {
final var gasRequirement = precompile.gasRequirement(frame.getInputData());
final PrecompileContractResult result;
if (frame.getRemainingGas() < gasRequirement) {
result = PrecompileContractResult.halt(Bytes.EMPTY, Optional.of(INSUFFICIENT_GAS));
} else {
frame.decrementRemainingGas(gasRequirement);
incrementOpsDuration(
frame, gasRequirement * hederaOpsDuration.precompileDurationMultiplier() / MULTIPLIER_FACTOR);
result = precompile.computePrecompile(frame.getInputData(), frame);
if (result.isRefundGas()) {
frame.incrementRemainingGas(gasRequirement);

final var opsDurationCounter = FrameUtils.opsDurationCounter(frame);

Check notice on line 224 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L224

Unnecessary use of fully qualified name 'FrameUtils.opsDurationCounter' due to existing static import 'com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.*'
final var opsDurationSchedule = opsDurationCounter.schedule();
final var opsDurationCost = gasRequirement
* opsDurationSchedule.precompileGasBasedDurationMultiplier()
/ opsDurationSchedule.multipliersDenominator();
if (!opsDurationCounter.tryConsumeOpsDurationUnits(opsDurationCost)) {

Check notice on line 229 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L229

Avoid if (x != y) ..; else ..;
result = PrecompileContractResult.halt(Bytes.EMPTY, Optional.of(OPS_DURATION_LIMIT_REACHED));
} else {
contractMetrics.opsDurationMetrics().recordPrecompileOpsDuration(precompile.getName(), opsDurationCost);

result = precompile.computePrecompile(frame.getInputData(), frame);
if (result.isRefundGas()) {

Check warning on line 235 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L235

Nested if-else depth is 2 (max allowed is 1).
frame.incrementRemainingGas(gasRequirement);
}
}
}
// We must always call tracePrecompileResult() to ensure the tracer is in a consistent
Expand All @@ -263,10 +254,10 @@
* @param tracer the operation tracer
*/
private void doExecuteSystemContract(
@NonNull final HederaSystemContract systemContract,
@NonNull final Address systemContractAddress,
@NonNull final MessageFrame frame,
@NonNull final OperationTracer tracer) {
@Nonnull final HederaSystemContract systemContract,
@Nonnull final Address systemContractAddress,

Check notice on line 258 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L258

Expected @param tag for 'systemContractAddress'.
@Nonnull final MessageFrame frame,
@Nonnull final OperationTracer tracer) {
final var fullResult = systemContract.computeFully(
ContractID.newBuilder()
.contractNum(numberOfLongZero(systemContractAddress))
Expand All @@ -283,20 +274,31 @@
} else {
if (!fullResult.isRefundGas()) {
frame.decrementRemainingGas(gasRequirement);
incrementOpsDuration(
frame,
gasRequirement * hederaOpsDuration.systemContractDurationMultiplier() / MULTIPLIER_FACTOR);
}
result = fullResult.result();

final var opsDurationCounter = FrameUtils.opsDurationCounter(frame);
final var opsDurationSchedule = opsDurationCounter.schedule();
final var opsDurationCost = gasRequirement
* opsDurationSchedule.systemContractGasBasedDurationMultiplier()
/ opsDurationSchedule.multipliersDenominator();
if (!opsDurationCounter.tryConsumeOpsDurationUnits(opsDurationCost)) {
result = PrecompileContractResult.halt(Bytes.EMPTY, Optional.of(OPS_DURATION_LIMIT_REACHED));
} else {
contractMetrics
.opsDurationMetrics()
.recordSystemContractOpsDuration(
systemContract.getName(), systemContractAddress.toHexString(), opsDurationCost);
result = fullResult.result();
}
}
finishPrecompileExecution(frame, result, SYSTEM, (ActionSidecarContentTracer) tracer);
}

private void finishPrecompileExecution(
@NonNull final MessageFrame frame,
@NonNull final PrecompileContractResult result,
@NonNull final ContractActionType type,
@NonNull final ActionSidecarContentTracer tracer) {
@Nonnull final MessageFrame frame,
@Nonnull final PrecompileContractResult result,
@Nonnull final ContractActionType type,

Check warning on line 300 in web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/exec/processors/CustomMessageCallProcessor.java#L300

Avoid unused method parameters such as 'type'.
@Nonnull final ActionSidecarContentTracer tracer) {
if (result.getState() == MessageFrame.State.REVERT) {
frame.setRevertReason(result.getOutput());
} else {
Expand All @@ -308,7 +310,7 @@
}

private void doTransferValueOrHalt(
@NonNull final MessageFrame frame, @NonNull final OperationTracer operationTracer) {
@Nonnull final MessageFrame frame, @Nonnull final OperationTracer operationTracer) {
final var proxyWorldUpdater = (ProxyWorldUpdater) frame.getWorldUpdater();
// Try to lazy-create the recipient address if it doesn't exist
if (!addressChecks.isPresent(frame.getRecipientAddress(), frame)) {
Expand All @@ -331,31 +333,31 @@
}

private void doHaltIfInvalidSystemCall(
@NonNull final MessageFrame frame, @NonNull final OperationTracer operationTracer) {
@Nonnull final MessageFrame frame, @Nonnull final OperationTracer operationTracer) {
if (transfersValue(frame)) {
doHalt(frame, INVALID_CONTRACT_ID, operationTracer);
}
}

private void doHaltOnFailedLazyCreation(
@NonNull final MessageFrame frame,
@NonNull final ExceptionalHaltReason reason,
@NonNull final OperationTracer tracer) {
@Nonnull final MessageFrame frame,
@Nonnull final ExceptionalHaltReason reason,
@Nonnull final OperationTracer tracer) {
doHalt(frame, reason, tracer, ForLazyCreation.YES);
}

private void doHalt(
@NonNull final MessageFrame frame,
@NonNull final ExceptionalHaltReason reason,
@NonNull final OperationTracer tracer) {
@Nonnull final MessageFrame frame,
@Nonnull final ExceptionalHaltReason reason,
@Nonnull final OperationTracer tracer) {
doHalt(frame, reason, tracer, ForLazyCreation.NO);
}

private void doHalt(
@NonNull final MessageFrame frame,
@NonNull final ExceptionalHaltReason reason,
@Nullable final OperationTracer operationTracer,
@NonNull final ForLazyCreation forLazyCreation) {
@Nonnull final MessageFrame frame,
@Nonnull final ExceptionalHaltReason reason,
@Nonnull final OperationTracer operationTracer,
@Nonnull final ForLazyCreation forLazyCreation) {
frame.setState(EXCEPTIONAL_HALT);
frame.setExceptionalHaltReason(Optional.of(reason));
if (forLazyCreation == ForLazyCreation.YES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static com.hedera.hapi.node.base.ResponseCodeEnum.MAX_CHILD_RECORDS_EXCEEDED;
import static com.hedera.hapi.node.base.ResponseCodeEnum.OK;
import static com.hedera.hapi.node.base.ResponseCodeEnum.SUCCESS;
import static com.hedera.hapi.util.HapiUtils.CONTRACT_ID_COMPARATOR;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.CONTRACT_IS_TREASURY;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.CONTRACT_STILL_OWNS_NFTS;
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.FAILURE_DURING_LAZY_ACCOUNT_CREATION;
Expand Down Expand Up @@ -33,7 +34,6 @@
import com.hedera.hapi.node.state.contract.Bytecode;
import com.hedera.hapi.node.state.contract.SlotKey;
import com.hedera.hapi.node.state.contract.SlotValue;
import com.hedera.hapi.util.HapiUtils;
import com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason;
import com.hedera.node.app.service.contract.impl.exec.scope.ActiveContractVerificationStrategy;
import com.hedera.node.app.service.contract.impl.exec.scope.ActiveContractVerificationStrategy.UseTopLevelSigs;
Expand All @@ -45,9 +45,11 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeMap;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
Expand Down Expand Up @@ -134,24 +136,6 @@
return valueOrZero(contractStateStore.getOriginalSlotValue(slotKey));
}

/**
* {@inheritDoc}
*/
@Override
public @NonNull List<StorageAccesses> getStorageChanges() {
final Map<ContractID, List<StorageAccess>> modifications = new TreeMap<>(HapiUtils.CONTRACT_ID_COMPARATOR);
contractStateStore.getModifiedSlotKeys().forEach(slotKey -> modifications
.computeIfAbsent(slotKey.contractID(), k -> new ArrayList<>())
.add(StorageAccess.newWrite(
pbjToTuweniUInt256(slotKey.key()),
valueOrZero(contractStateStore.getOriginalSlotValue(slotKey)),
valueOrZero(contractStateStore.getSlotValue(slotKey)))));
final List<StorageAccesses> allChanges = new ArrayList<>();
modifications.forEach(
(number, storageAccesses) -> allChanges.add(new StorageAccesses(number, storageAccesses)));
return allChanges;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -332,6 +316,28 @@
return number;
}

@Override
public @NonNull TxStorageUsage getTxStorageUsage(final boolean includeChangedKeys) {
final Map<ContractID, List<StorageAccess>> modifications = new TreeMap<>(CONTRACT_ID_COMPARATOR);

Check warning on line 321 in web3/src/main/java/com/hedera/node/app/service/contract/impl/state/DispatchingEvmFrameState.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/state/DispatchingEvmFrameState.java#L321

If you run in Java5 or newer and have concurrent access, you should use the ConcurrentHashMap implementation
final Set<SlotKey> changedKeys = includeChangedKeys ? new HashSet<>() : null;
contractStateStore.getModifiedSlotKeys().forEach(slotKey -> {

Check notice on line 323 in web3/src/main/java/com/hedera/node/app/service/contract/impl/state/DispatchingEvmFrameState.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web3/src/main/java/com/hedera/node/app/service/contract/impl/state/DispatchingEvmFrameState.java#L323

Lambda body length is 12 lines (max allowed is 10).
final var access = StorageAccess.newWrite(
pbjToTuweniUInt256(slotKey.key()),
valueOrZero(contractStateStore.getOriginalSlotValue(slotKey)),
valueOrZero(contractStateStore.getSlotValue(slotKey)));
modifications
.computeIfAbsent(slotKey.contractID(), k -> new ArrayList<>())
.add(access);
if (includeChangedKeys && access.isLogicalChange()) {
changedKeys.add(slotKey);
}
});
final List<StorageAccesses> allChanges = new ArrayList<>();
modifications.forEach(
(number, storageAccesses) -> allChanges.add(new StorageAccesses(number, storageAccesses)));
return new TxStorageUsage(allChanges, changedKeys);
}

/**
* {@inheritDoc}
*/
Expand Down
Loading
Loading