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

03640 Contract create nonce externalization #6934

Merged
merged 40 commits into from
Jul 5, 2023

Conversation

agadzhalov
Copy link
Contributor

@agadzhalov agadzhalov commented Jun 5, 2023

Description:
Externalizes and verifies the nonces on contract create.

Implementation of contracts nonces externalization

  1. Added new method trackContractNonces in HederaWorldState which is called only on enabled isContractsNoncesExternalizationEnabled feature flag.
    1.1 Checks if an account is a new smart contract and externalizes its nonce.
    1.2 Checks if an existing smart contract's nonce is updated and externalizes it.
  2. Persists contracts nonces changes into state in ContractCreateTransitionLogic and ContractCallTransitionLogic on enabled feature flag.
  3. Created new ContractNonceInfo submerkle class with two main entities - contractId and nonce
  4. Added serializableContractNoncesFrom in EvmFnResult that builds List<ContractNonceInfo> (submerkle) from Map<ContractID, Long>
  5. Converts from ContractNonceInfo (submerkle) to grpc (protobuf)
  6. Added new verison 7 (RELEASE_0400_VERSION) and externalized logic for serialize and deserialize of contractNonces in EvmFnResult

E2E testing

  • Added NoncesExternalization.sol that deploys three new contracts in its constructor. Has methods to deploy new contracts (parent) and to deploy child contracts from parents.
  • Added contractWithNonce method in ContractFnResultAsserts in order to assert the expected and actual nonce of the newly created contract.
  • Added contractCreateNoncesExternalizationHappyPath test to verify that the nonces of the created contract are incremented and externalized properly.
  • Added contractCreateFollowedByContractCallNoncesExternalization
    • Deploys one more parent contract and asserts main contract's nonce is 5
    • Deploys child contract from parent and asserts parent contract's nonce is 2
    • Tries to deploy child from parent and reverts. Asserts no contract_nonces entries were created and they are null.
  • Added shouldReturnNullWhenContractsNoncesExternalizationFlagIsDisabled test to verify that there will be no contract_nonces entries when the feature flag is disabled.

Related issue(s):

Fixes #3640

@agadzhalov agadzhalov added Limechain Work planned for the LimeChain team CI:UnitTests labels Jun 5, 2023
@agadzhalov agadzhalov requested review from a team as code owners June 5, 2023 16:10
Signed-off-by: Alexander Gadzhalov <[email protected]>
@Nana-EC Nana-EC added this to the v0.40 milestone Jun 5, 2023
@github-actions
Copy link

github-actions bot commented Jun 6, 2023

Node: Unit Test Results

    1 515 files      1 515 suites   17m 0s ⏱️
102 713 tests 102 707 ✔️ 6 💤 0
109 071 runs  109 065 ✔️ 6 💤 0

Results for commit 7bb8b24.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@tinker-michaelj tinker-michaelj left a comment

Choose a reason for hiding this comment

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

LGTM, tyvm @agadzhalov 🥂

@Nana-EC
Copy link
Contributor

Nana-EC commented Jun 30, 2023

@agadzhalov appreciate the PR description. Nice job 👍🏾

@david-bakin-sl
Copy link
Member

@agadzhalov appreciate the PR description. Nice job 👍🏾

The embedded links to the source is an especially nice touch. Should be a model for any large&nuanced PR.

Copy link
Member

@david-bakin-sl david-bakin-sl left a comment

Choose a reason for hiding this comment

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

This is as far as I've gotten. Will return to it shortly. No problems so far but a bunch of questions.

david-bakin-sl
david-bakin-sl previously approved these changes Jun 30, 2023
Copy link
Member

@david-bakin-sl david-bakin-sl left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Lots of comments and suggestions - if you're going to make changes for these suggestions/comments then they don't have to be in this PR - but if you do defer them to a latter PR don't forget about it ...

@david-bakin-sl
Copy link
Member

Unit test coverage for new code looks pretty good.

@agadzhalov agadzhalov requested a review from a team July 3, 2023 12:39
@agadzhalov agadzhalov requested a review from a team as a code owner July 3, 2023 12:39
@agadzhalov agadzhalov force-pushed the 03640-contracts-nonce-externalization branch 3 times, most recently from 6a9eea9 to c0294f6 Compare July 3, 2023 13:28
# Conflicts:
#	hedera-node/hedera-mono-service/src/test/java/com/hedera/node/app/service/mono/state/submerkle/EvmFnResultSerdeTest.java
#	hedera-node/hedera-mono-service/src/test/java/com/hedera/test/serde/SerializedForms.java
#	hedera-node/hedera-mono-service/src/test/java/com/hedera/test/utils/SeededPropertySource.java
@agadzhalov
Copy link
Contributor Author

Refactor and enhancement will be done here #7376

Signed-off-by: Alexander Gadzhalov <[email protected]>
@agadzhalov agadzhalov force-pushed the 03640-contracts-nonce-externalization branch from bfb6150 to 7bb8b24 Compare July 4, 2023 10:58
@sonarcloud
Copy link

sonarcloud bot commented Jul 4, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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

96.8% 96.8% Coverage
0.0% 0.0% Duplication

Copy link
Collaborator

@tinker-michaelj tinker-michaelj left a comment

Choose a reason for hiding this comment

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

LGTM!

@agadzhalov agadzhalov merged commit 9eb3c5a into develop Jul 5, 2023
@agadzhalov agadzhalov deleted the 03640-contracts-nonce-externalization branch July 5, 2023 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Limechain Work planned for the LimeChain team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update the nonce of the contract account for every CREATE opcode executed from it
7 participants