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

[contractstaking] fix invalid delta transfer #3924

Merged
merged 5 commits into from
Aug 17, 2023

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Aug 16, 2023

Description

Stake and Merge in one transaction will cause action deltaActionRemove on state deltaStateAdded, which is not allowed currently. But this scenario should be legal, so this transfer should be allowed instead.

Fixes #3921

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@envestcc envestcc marked this pull request as ready for review August 16, 2023 12:58
@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Merging #3924 (31125c8) into master (e1f0636) will increase coverage by 0.63%.
Report is 80 commits behind head on master.
The diff coverage is 73.42%.

❗ Current head 31125c8 differs from pull request most recent head 926ef56. Consider uploading reports for the commit 926ef56 to get more accurate results

@@            Coverage Diff             @@
##           master    #3924      +/-   ##
==========================================
+ Coverage   75.38%   76.01%   +0.63%     
==========================================
  Files         303      328      +25     
  Lines       25923    27859    +1936     
==========================================
+ Hits        19541    21176    +1635     
- Misses       5360     5590     +230     
- Partials     1022     1093      +71     
Files Changed Coverage Δ
action/protocol/execution/evm/evm.go 43.52% <0.00%> (-2.95%) ⬇️
action/protocol/execution/evm/evmstatedbadapter.go 66.77% <ø> (ø)
action/protocol/poll/consortium.go 0.00% <0.00%> (ø)
action/protocol/poll/staking_committee.go 43.85% <0.00%> (ø)
...tion/protocol/staking/contractstake_bucket_type.go 0.00% <0.00%> (ø)
action/receipt.go 82.17% <ø> (ø)
api/grpcserver.go 86.40% <0.00%> (ø)
api/loglistener.go 25.00% <0.00%> (ø)
api/websocket.go 4.10% <0.00%> (-1.07%) ⬇️
blockchain/config.go 74.54% <ø> (ø)
... and 65 more

... and 4 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@@ -27,6 +27,7 @@ var (
},
deltaStateAdded: {
deltaActionModify: deltaStateAdded,
deltaActionRemove: deltaStateUnchanged,
Copy link
Member

Choose a reason for hiding this comment

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

what about deltaStateRemoved? does it need a state-transition?

Copy link
Member

@dustinxie dustinxie Aug 16, 2023

Choose a reason for hiding this comment

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

as we chatted, also need to check blkHeight == currentHeight + 1 in PutBlock()?

Copy link
Member Author

Choose a reason for hiding this comment

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

what about deltaStateRemoved? does it need a state-transition?

no valid action could be triggered on deltaStateRemoved

Copy link
Member Author

Choose a reason for hiding this comment

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

as we chatted, also need to check blkHeight == currentHeight + 1 in PutBlock()?

Thx for reminding

Copy link
Member

Choose a reason for hiding this comment

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

add a test to validate, once a bucket is deleted, i.e., deltaStateRemoved, it cannot transition to any further state (in the same block)

@@ -121,9 +121,16 @@ func (s *Indexer) BucketTypes() ([]*BucketType, error) {

// PutBlock puts a block into indexer
func (s *Indexer) PutBlock(ctx context.Context, blk *block.Block) error {
if blk.Height() < s.contractDeployHeight || blk.Height() <= s.cache.Height() {
expectHeight := s.cache.Height() + 1
Copy link
Member

Choose a reason for hiding this comment

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

remove empty line

@envestcc envestcc requested a review from a team as a code owner August 17, 2023 09:35
@sonarcloud
Copy link

sonarcloud bot commented Aug 17, 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 1 Code Smell

No Coverage information No Coverage information
8.5% 8.5% Duplication

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

@dustinxie dustinxie merged commit 7a09f4b into iotexproject:master Aug 17, 2023
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

indexer lagging behind?
3 participants