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

[IIP-13] introduce read contract staking buckets (2/3 split by 3853) #3862

Merged
merged 6 commits into from
May 23, 2023

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented May 19, 2023

Description

For #3853 is too large to review, it has been splited into three small pr. This is the second one.
It's based on #3861

Fixes #(issue)

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

@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #3862 (515c1a6) into master (e1f0636) will decrease coverage by 0.23%.
The diff coverage is 41.99%.

❗ Current head 515c1a6 differs from pull request most recent head a7d64e9. Consider uploading reports for the commit a7d64e9 to get more accurate results

@@            Coverage Diff             @@
##           master    #3862      +/-   ##
==========================================
- Coverage   75.38%   75.16%   -0.23%     
==========================================
  Files         303      306       +3     
  Lines       25923    26160     +237     
==========================================
+ Hits        19541    19662     +121     
- Misses       5360     5479     +119     
+ Partials     1022     1019       -3     
Impacted Files 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%> (ø)
action/protocol/staking/staking_statereader.go 0.00% <0.00%> (ø)
api/web3server_marshal.go 93.21% <ø> (ø)
blockindex/sgd_indexer.go 0.00% <0.00%> (ø)
action/protocol/staking/protocol.go 60.50% <16.66%> (+0.62%) ⬆️
api/web3server_utils.go 69.20% <16.66%> (-3.67%) ⬇️
action/protocol/rewarding/fund.go 64.70% <23.07%> (-18.91%) ⬇️
... and 11 more

... and 3 files with indirect coverage changes

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

return cache
}

func (s *contractStakingCache) GetHeight() uint64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to Height

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return s.height
}

func (s *contractStakingCache) GetCandidateVotes(candidate address.Address) *big.Int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to CandidateVotes

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return votes
}

func (s *contractStakingCache) GetBuckets() ([]*Bucket, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to Buckets

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return vbs, nil
}

func (s *contractStakingCache) GetBucket(id uint64) (*Bucket, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to Bucket

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return s.getBucket(id)
}

func (s *contractStakingCache) GetBucketsByCandidate(candidate address.Address) ([]*Bucket, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to BucketsByCandidate

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return vbs, nil
}

func (s *contractStakingCache) GetTotalBucketCount() uint64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to TotalBucketCount

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

return s.totalBucketCount
}

func (s *contractStakingCache) GetActiveBucketTypes() map[uint64]*BucketType {
Copy link
Collaborator

Choose a reason for hiding this comment

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

rename to ActiveBucketTypes

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

const (
// StakingContractAddress is the address of system staking contract
// TODO (iip-13): replace with the real system staking contract address
StakingContractAddress = "io19ys8f4uhwms6lq6ulexr5fwht9gsjes8mvuugd"
Copy link
Collaborator

Choose a reason for hiding this comment

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

load from config

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member Author

Choose a reason for hiding this comment

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

will be implemented in the integrate PR

Comment on lines 33 to 35
// kvstore: persistent storage, used to initialize index cache at startup
// cache: in-memory index for clean data, used to query index data
// dirty: the cache to update during event processing, will be merged to clean cache after all events are processed. If errors occur during event processing, dirty cache will be discarded.
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment above variables

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

// Main functions:
// 1. handle contract staking contract events when new block comes to generate index data
// 2. provide query interface for contract staking index data
// Generate index data flow:
Copy link
Collaborator

Choose a reason for hiding this comment

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

flow explanation should not be here

Copy link
Member Author

Choose a reason for hiding this comment

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

removed and should be added in #3863 at PutBlock

propertyBucketTypeMap: make(map[int64]map[uint64]uint64),
candidateBucketMap: make(map[string]map[uint64]bool),
}
return cache
Copy link
Member

Choose a reason for hiding this comment

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

nit:

cache := contractStakingCache{
return &cache

@sonarcloud
Copy link

sonarcloud bot commented May 22, 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

No Coverage information No Coverage information
0.0% 0.0% Duplication

@millken
Copy link
Contributor

millken commented May 23, 2023

add integration testing,improve test coverage

@envestcc
Copy link
Member Author

add integration testing,improve test coverage

tests are added in next PR #3863

}

func (s *contractStakingCache) mustGetBucketInfo(id uint64) *bucketInfo {
bt, ok := s.bucketInfoMap[id]
Copy link
Contributor

Choose a reason for hiding this comment

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

use getBucketInfo

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

}

func (s *contractStakingCache) mustGetBucketType(id uint64) *BucketType {
bt, ok := s.bucketTypeMap[id]
Copy link
Contributor

Choose a reason for hiding this comment

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

use getBucketType

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

// 1. handle contract staking contract events when new block comes to generate index data
// 2. provide query interface for contract staking index data
Indexer struct {
kvstore db.KVStore // persistent storage, used to initialize index cache at startup
Copy link
Contributor

Choose a reason for hiding this comment

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

kvstore and contractAddress where is it used?

Copy link
Member Author

Choose a reason for hiding this comment

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

will be used in next PR #3863

@envestcc envestcc merged commit fc7f4d5 into iotexproject:master May 23, 2023
@envestcc envestcc deleted the iip13_v2_2 branch May 23, 2023 12:57
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.

4 participants