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

Refactor operations to eliminate duplicate code between EVM versions #7000

Merged
merged 41 commits into from
Jun 23, 2023

Conversation

tinker-michaelj
Copy link
Collaborator

@tinker-michaelj tinker-michaelj commented Jun 8, 2023

Description:

Notes to reviewer:
The main constraints relative to mono-service are:

  1. The ContractService can no longer directly mutate any account, token, or token association property (nonce, deleted, balance, supply, etc.) and must use a "dispatch" facility provided by something called the HandleContext.
  2. The ContractService can no longer directly create or manage records.

The main goals relative to mono-service are:

  1. Mirror the Besu TransactionProcessor pattern much more closely, where given a ProtocolSpec, a transaction can be handled in a single call with a bit of context (e.g. current gasPrice, BlockValues) and a choice of EVM version.
  2. Encapsulate the EVM version-specific behavior in a few well-defined interfaces (FeatureFlags, AccountChecks) instead of having different Operation implementations for each versions.
  3. Have a cleaner boundary between Besu types and Hedera types.
  4. Make the final module much more reusable for mirror nodes.

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
…oxyWorldUpdater

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
@tinker-michaelj tinker-michaelj requested review from a team and jasperpotts June 12, 2023 20:38
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
* Need to clean up and refactor {@link com.hedera.node.app.service.mono.contracts.gascalculator.GasCalculatorHederaV22}
* to get its price and exchange rate from the transaction's {@link com.hedera.node.app.spi.meta.bni.Scope}.
*/
public class CustomGasCalculator extends LondonGasCalculator {}
Copy link
Member

@lukelee-sl lukelee-sl Jun 12, 2023

Choose a reason for hiding this comment

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

Should we be extending London or Shandong.? I believe that the ShandongGasCalculator had the update for EIP-3860 limit the size of the initcode. hyperledger/besu#4726


@Override
public OperationResult execute(@NonNull final MessageFrame frame, @NonNull final EVM evm) {
if (!isEnabled(frame)) {
Copy link
Member

Choose a reason for hiding this comment

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

Did this get copied and modified from AbstractEvmRecordingCreateOperation or from AbstractCreateOperation in besu? The implementations seems very similar but slightly different. I'm not sure if the differences are meaningful.

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
* A {@link VerificationStrategy} that verifies signatures from a single active contract. This is the
* verification strategy used within the EVM to check receiver signature requirements.
*/
public class ActiveContractVerificationStrategy implements VerificationStrategy {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think hedera-app-spi is not the right place for these classes as it is only relevant for the smart contract service.

@@ -28,6 +28,10 @@ dependencies {
}
}

val generatedSources = file("build/generated/sources/annotationProcessor/java/main")
Copy link
Member

Choose a reason for hiding this comment

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

what is the change in this file used for?

Copy link
Member

@Neeharika-Sompalli Neeharika-Sompalli left a comment

Choose a reason for hiding this comment

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

LGTM !

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Comment on lines 25 to 42
public interface FeatureFlags {
/**
* Whether the {@code CREATE2} operation should be enabled for the given {@code frame}.
*
* @param frame the {@link MessageFrame} to check
* @return whether {@code CREATE2} should be enabled
*/
boolean isCreate2Enabled(@NonNull MessageFrame frame);

/**
* Whether "implicit creation" of accounts via sending value or targeting a {@code CREATE2} to an EIP-1014 address
* should be enabled for the given {@code frame}.
*
* @param frame the {@link MessageFrame} to check
* @return whether implicit creation should be enabled
*/
boolean isImplicitCreationEnabled(@NonNull MessageFrame frame);
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we need an interface for this or can we get from config ?

import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;

/**
* Some {@link ExceptionalHaltReason}s that are not part of the Besu core.
Copy link
Member

Choose a reason for hiding this comment

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

Don't we use HandleException here with appropriate response codes ?

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
@github-actions
Copy link

github-actions bot commented Jun 21, 2023

Node: Unit Test Results

    1 506 files      1 506 suites   19m 39s ⏱️
101 913 tests 101 905 ✔️ 8 💤 0
108 267 runs  108 259 ✔️ 8 💤 0

Results for commit 6cae8f3.

♻️ This comment has been updated with latest results.

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 91.79% and project coverage change: +21.78 🎉

Comparison is base (c79469c) 68.46% compared to head (6cae8f3) 90.24%.

Additional details and impacted files
@@              Coverage Diff               @@
##             develop    #7000       +/-   ##
==============================================
+ Coverage      68.46%   90.24%   +21.78%     
+ Complexity     24022    19079     -4943     
==============================================
  Files           2211     1513      -698     
  Lines         142881    55611    -87270     
  Branches        8413     5791     -2622     
==============================================
- Hits           97817    50185    -47632     
+ Misses         43323     4230    -39093     
+ Partials        1741     1196      -545     
Impacted Files Coverage Δ
...edera/node/app/state/merkle/MerkleHederaState.java 65.21% <0.00%> (ø)
...ontracts/operations/HederaEvmCreate2Operation.java 100.00% <ø> (ø)
...ontracts/gascalculator/GasCalculatorHederaV18.java 100.00% <ø> (ø)
.../app/service/contract/impl/exec/AddressChecks.java 0.00% <0.00%> (ø)
...vice/contract/impl/exec/gas/GasChargingResult.java 0.00% <0.00%> (ø)
.../impl/exec/operations/CustomCallCodeOperation.java 0.00% <0.00%> (ø)
...ice/contract/impl/state/BaseProxyWorldUpdater.java 100.00% <ø> (ø)
...rvice/contract/impl/exec/TransactionProcessor.java 38.46% <38.46%> (+38.46%) ⬆️
...p/service/contract/impl/exec/utils/FrameUtils.java 66.66% <66.66%> (ø)
...rvice/contract/impl/hevm/HederaEvmTransaction.java 71.42% <71.42%> (ø)
... and 41 more

... and 979 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link

github-actions bot commented Jun 21, 2023

Node: E2E Test Results

    1 files      1 suites   18m 27s ⏱️
310 tests 310 ✔️ 0 💤 0
328 runs  328 ✔️ 0 💤 0

Results for commit 6cae8f3.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jun 21, 2023

Node: Integration Test Results

275 tests   275 ✔️  27m 51s ⏱️
    5 suites      0 💤
    5 files        0

Results for commit 6cae8f3.

♻️ This comment has been updated with latest results.

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
@sonarcloud
Copy link

sonarcloud bot commented Jun 21, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 19 Code Smells

93.5% 93.5% Coverage
0.8% 0.8% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Copy link
Member

@lukelee-sl lukelee-sl left a comment

Choose a reason for hiding this comment

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

LGTM

@tinker-michaelj tinker-michaelj merged commit d0d9b28 into develop Jun 23, 2023
@tinker-michaelj tinker-michaelj deleted the 06905-hedera-evm-spec branch June 23, 2023 14:51
povolev15 pushed a commit that referenced this pull request Jun 27, 2023
…7000)

Signed-off-by: Michael Tinker <michael.tinker@swirldslabs.com>
povolev15 added a commit that referenced this pull request Jun 27, 2023
povolev15 added a commit that referenced this pull request Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants