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

Modularized storage capturing in OpcodeTracer #10307

Closed
wants to merge 14 commits into from

Conversation

kselveliev
Copy link
Contributor

@kselveliev kselveliev commented Feb 5, 2025

Description:
This PR fixes storage capturing in modularized execution.
Storage values are now read from mirror node writable states during execution.
Added a test who actually modifies storage of a contract and can verify execution.
This pr also fixes 4 failing test in OpcodeServiceTests. Now OpcodeServiceTest fixes are completed.

This PR is checkout from -> https://github.com/hashgraph/hedera-mirror-node/pull/10306
It only works with the fixes for the state pollution must be merged after the above PR.

Only relevant changes from the PR - https://github.com/hashgraph/hedera-mirror-node/pull/10307/commits/33eea994a5bfce0a46895b50070307d87d911cd0

Related issue(s):

Fixes #10259

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

bilyana-gospodinova and others added 6 commits February 4, 2025 10:12
Signed-off-by: Bilyana Gospodinova <[email protected]>
Signed-off-by: Bilyana Gospodinova <[email protected]>
Signed-off-by: Bilyana Gospodinova <[email protected]>
Signed-off-by: Bilyana Gospodinova <[email protected]>
@kselveliev kselveliev added this to the 0.124.0 milestone Feb 5, 2025
@kselveliev kselveliev self-assigned this Feb 5, 2025
@kselveliev kselveliev added modularizedEVM web3 Area: Web3 API enhancement Type: New feature labels Feb 5, 2025
@@ -57,11 +66,20 @@
@Getter
public class OpcodeTracer implements HederaOperationTracer {

private static final String CONTRACT_SERVICE = "ContractService";
Copy link
Contributor

Choose a reason for hiding this comment

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

How about ContractService.NAME?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 97.82609% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.24%. Comparing base (756b4cf) to head (8533a23).
Report is 58 commits behind head on main.

Files with missing lines Patch % Lines
...ava/com/swirlds/state/spi/WritableKVStateBase.java 96.29% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10307      +/-   ##
============================================
+ Coverage     92.17%   92.24%   +0.07%     
- Complexity     7966     8072     +106     
============================================
  Files           975      984       +9     
  Lines         33278    33643     +365     
  Branches       4201     4250      +49     
============================================
+ Hits          30673    31033     +360     
- Misses         1606     1608       +2     
- Partials        999     1002       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

bilyana-gospodinova and others added 5 commits February 5, 2025 16:45
Signed-off-by: Bilyana Gospodinova <[email protected]>
Signed-off-by: Kristiyan Selveliev <[email protected]>
Signed-off-by: Kristiyan Selveliev <[email protected]>
Signed-off-by: Kristiyan Selveliev <[email protected]>
@@ -101,6 +114,8 @@
@ExtendWith(MockitoExtension.class)
class OpcodeTracerTest {

private static final String CONTRACT_SERVICE = "ContractService";
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicated constants as in OpcodeTracer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

Set<SlotKey> modifiedKeys = states.get(STORAGE_KEY).modifiedKeys().stream()
.filter(SlotKey.class::isInstance)
.map(SlotKey.class::cast)
.filter(slotKey -> slotKey.hasContractID() && slotKey.contractID() != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that the same check? slotKey.hasContractID() internally checks if the contract ID is not null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's the same. I used it to remove ide warnings below but seems not applicable with latest changes. I removed it now.

@@ -246,4 +269,58 @@ private Bytes formatRevertReason(final Bytes revertReason) {

return BytesDecoder.getAbiEncodedRevertReason(revertReason);
}

private Map<Bytes, Bytes> getStorageUpdates(Address accountAddress) {
Copy link
Contributor

@bilyana-gospodinova bilyana-gospodinova Feb 6, 2025

Choose a reason for hiding this comment

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

Maybe the return type could be wrapped in an Optional and in the caller it can be chained to avoid some empty checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Bytes.of(slotValue.value().toByteArray()));
}
}
} catch (IllegalArgumentException e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this exception actually occur? This is a private method and will be called only within the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can happen when we try to retrieve the storage state ->

states.get(STORAGE_KEY).modifiedKeys() ->

 if (state == null) {
            throw new IllegalArgumentException("Unknown k/v state key: " + stateKey);
 }
 if (!(state instanceof WritableKVState)) {
            throw new IllegalArgumentException("State is not an instance of WritableKVState: " + stateKey);
 }

Signed-off-by: Kristiyan Selveliev <[email protected]>
Signed-off-by: Kristiyan Selveliev <[email protected]>
Signed-off-by: Kristiyan Selveliev <[email protected]>
@kselveliev
Copy link
Contributor Author

@kselveliev kselveliev closed this Feb 11, 2025
@steven-sheehy steven-sheehy deleted the 10259-storage-capturing-modularized branch February 11, 2025 17:42
@steven-sheehy steven-sheehy removed this from the 0.124.0 milestone Feb 11, 2025
steven-sheehy pushed a commit that referenced this pull request Feb 12, 2025
…0357)

This PR is a copy of #10307. (It was checkout from the pr fixing the states caching but it will be delayed due to needed upstream changes). So opening with main as base branch.

This PR fixes storage capturing in modularized execution.
Storage values are now read from mirror node writable states during execution.
Added a test who actually modifies storage of a contract and can verify execution.
This pr also fixes 4 failing test in OpcodeServiceTests. Now OpcodeServiceTest fixes are completed.

Changes:
OpcodeTracer - reads storage changes from writablestates - STORAGE_KEY for modularized
OpcodeTracerTest - adds codecov for new methods
OpcodeServiceTest - adds new test contract which modifies contract storage and verifies storage changes

---------

Signed-off-by: Kristiyan Selveliev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type: New feature modularizedEVM web3 Area: Web3 API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Storage capturing option in OpcodeTracer for modularized
3 participants