-
Notifications
You must be signed in to change notification settings - Fork 324
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
Conversation
Codecov Report
@@ 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
... 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to Height
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to CandidateVotes
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to Buckets
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to Bucket
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to BucketsByCandidate
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to TotalBucketCount
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to ActiveBucketTypes
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load from config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
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
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment above variables
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use getBucketInfo
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use getBucketType
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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.
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
Test Configuration:
Checklist: