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

feat: emit events from staking precompile #2861

Merged
merged 7 commits into from
Sep 11, 2024

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Sep 10, 2024

Description

Emit events in stake, unstake and moveStake functions of staking precompile contract. Extend e2e tests to check if events are emitted.

closes: #2811

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Introduced new events for staking operations: MoveStake, Stake, and Unstake to enhance tracking and transparency.
    • Added logging functionalities for staking actions to improve event tracking within the blockchain.
  • Bug Fixes

    • Updated tests to validate emitted staking events, ensuring correct handling of stake and unstake operations.
  • Documentation

    • Enhanced documentation for new event declarations and logging functionalities related to staking.

Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The pull request introduces significant modifications across various files, primarily focusing on enhancing staking functionalities within the blockchain context. Key changes include the removal of the setCosmosConfig function, the addition of new staking-related events in the TestStaking contract, and the implementation of logging mechanisms for staking operations. Additionally, the test files have been updated to validate the emitted events, ensuring that the contract's behavior aligns with expectations.

Changes

Files Change Summary
cmd/zetae2e/local/config.go, cmd/zetae2e/local/local.go Removed the setCosmosConfig function and associated SDK import in config.go. Replaced calls to setCosmosConfig() with app.SetConfig() in local.go, indicating a refactor in configuration handling for the Cosmos environment.
e2e/contracts/teststaking/TestStaking.abi, e2e/contracts/teststaking/TestStaking.go, e2e/contracts/teststaking/TestStaking.json, e2e/contracts/teststaking/TestStaking.sol Added three new events (MoveStake, Stake, Unstake) to the ABI and contract definitions. Introduced iterators and functions for filtering and watching these events in TestStaking.go. Updated the JSON and Solidity files to reflect the new events, enhancing tracking of staking activities.
e2e/e2etests/test_precompiles_staking_through_contract.go Enhanced the TestPrecompilesStakingThroughContract function to validate emitted events for staking operations, ensuring that the expected values are correctly logged. Imported the common package for address conversions.
precompiles/staking/IStaking.abi, precompiles/staking/IStaking.go, precompiles/staking/IStaking.json, precompiles/staking/IStaking.sol Added new event declarations for MoveStake, Stake, and Unstake in the ABI and interface files. Introduced event handling capabilities, including iterators and filtering functions, to enhance interactivity with the contract.
precompiles/staking/logs.go Introduced logging functionalities for staking operations, including methods for logging stake, unstake, and move stake events. Implemented a helper function to pack amounts into log data.
precompiles/staking/staking.go, precompiles/staking/staking_test.go Modified staking methods to include logging calls for stake, unstake, and move stake operations. Updated method signatures to include the Ethereum Virtual Machine context for state management. Adjusted test cases to utilize a mock EVM for improved testing accuracy.

Assessment against linked issues

Objective Addressed Explanation
Extend precompile contracts with emitted events ( #2811 )

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 64.70588% with 30 lines in your changes missing coverage. Please review.

Project coverage is 66.80%. Comparing base (23ecfde) to head (ead6173).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
precompiles/staking/logs.go 57.44% 10 Missing and 10 partials ⚠️
precompiles/staking/staking.go 53.84% 3 Missing and 3 partials ⚠️
precompiles/logs/logs.go 84.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2861      +/-   ##
===========================================
- Coverage    66.81%   66.80%   -0.02%     
===========================================
  Files          371      373       +2     
  Lines        20910    20993      +83     
===========================================
+ Hits         13972    14025      +53     
- Misses        6300     6315      +15     
- Partials       638      653      +15     
Files with missing lines Coverage Δ
precompiles/logs/logs.go 84.00% <84.00%> (ø)
precompiles/staking/staking.go 93.92% <53.84%> (-2.26%) ⬇️
precompiles/staking/logs.go 57.44% <57.44%> (ø)

precompiles/staking/logs.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kingpinXD kingpinXD left a comment

Choose a reason for hiding this comment

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

Had a quick look , maybe my understanding is wrong , so wanted to clarify before adding more comments.

Should the staking precompiles functionality follow the naming / terminology of regular staking as much as possible , or is there a reason behind using different terms , because I see all three functions implemented have different names.

e2e/contracts/teststaking/TestStaking.sol Show resolved Hide resolved
precompiles/staking/logs.go Outdated Show resolved Hide resolved
precompiles/staking/logs.go Outdated Show resolved Hide resolved
Copy link
Contributor

@fbac fbac left a comment

Choose a reason for hiding this comment

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

LGTM, I really like the shape this is taking.

Copy link
Contributor

@kingpinXD kingpinXD left a comment

Choose a reason for hiding this comment

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

Thanks for the clarification ,regarding the naming ,

I see the logs are added to the state DB. Would you be able to confirm what is the underlying database file which this gets added into ? application.db or tx_index.db

Cosmos logs are stored as part of block result so they end up in tx_index.db which is fine because we can define the config for tx_index.db separately .
However if these logs end up in application.db , we should consider the implications on the state growth .

@kingpinXD
Copy link
Contributor

Thanks for the clarification ,regarding the naming ,

I see the logs are added to the state DB. Would you be able to confirm what is the underlying database file which this gets added into ? application.db or tx_index.db

Cosmos logs are stored as part of block result so they end up in tx_index.db which is fine because we can define the config for tx_index.db separately . However if these logs end up in application.db , we should consider the implications on the state growth .

Actually it seems to be fine , the logs go the transient store , which is discarded , would be great if you could double check as well
https://github.com/zeta-chain/ethermint/blob/2fad916e7179c604ae917b397e837b9f2b79125f/x/evm/keeper/state_transition.go#L288

@skosito
Copy link
Contributor Author

skosito commented Sep 11, 2024

Thanks for the clarification ,regarding the naming ,
I see the logs are added to the state DB. Would you be able to confirm what is the underlying database file which this gets added into ? application.db or tx_index.db
Cosmos logs are stored as part of block result so they end up in tx_index.db which is fine because we can define the config for tx_index.db separately . However if these logs end up in application.db , we should consider the implications on the state growth .

Actually it seems to be fine , the logs go the transient store , which is discarded , would be great if you could double check as well https://github.com/zeta-chain/ethermint/blob/2fad916e7179c604ae917b397e837b9f2b79125f/x/evm/keeper/state_transition.go#L288

yes should be ok i think

@skosito skosito enabled auto-merge September 11, 2024 16:40
@skosito skosito added this pull request to the merge queue Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend precompile contracts with emitted events
4 participants