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] contract staking struct definition (1/3 split by 3853) #3861

Merged
merged 2 commits into from May 22, 2023

Conversation

envestcc
Copy link
Member

Description

For #3853 is too large to review, it has been splited into three small pr. This is the first one.

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

@envestcc envestcc changed the title [IIP-13] contract staking struct definition [IIP-13] contract staking struct definition (1/3 split by 3853) May 19, 2023
@envestcc envestcc marked this pull request as ready for review May 19, 2023 17:35
@codecov
Copy link

codecov bot commented May 19, 2023

Codecov Report

Merging #3861 (ded3b37) into master (e1f0636) will decrease coverage by 0.20%.
The diff coverage is 41.99%.

❗ Current head ded3b37 differs from pull request most recent head 7a745bd. Consider uploading reports for the commit 7a745bd to get more accurate results

@@            Coverage Diff             @@
##           master    #3861      +/-   ##
==========================================
- Coverage   75.38%   75.18%   -0.20%     
==========================================
  Files         303      306       +3     
  Lines       25923    26166     +243     
==========================================
+ Hits        19541    19672     +131     
- Misses       5360     5476     +116     
+ Partials     1022     1018       -4     
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 6 files with indirect coverage changes

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

}

// Serialize serializes the bucket type
func (bt *BucketType) Serialize() []byte {
Copy link
Member

Choose a reason for hiding this comment

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

public funs are laid above private funcs

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

Comment on lines 16 to 25
Index uint64
Candidate address.Address
Owner address.Address
StakedAmount *big.Int
StakedDurationBlockNumber uint64
CreateBlockHeight uint64
StakeStartBlockHeight uint64
UnstakeStartBlockHeight uint64
AutoStake bool
ContractAddress string
Copy link
Collaborator

Choose a reason for hiding this comment

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

comments

Comment on lines 64 to 68
bi.Owner, err = address.FromString(p.Owner)
if err != nil {
return err
}
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

    delegate, err = address.FromString(p.Delegate)
    if err != nil {
        return err
    }
    owner, err := address.FromString(p.Owner)
    if err != nil {
        return err
    }
    bi.TypeIndex = p.TypeIndex
    bi.CreatedAt = p.CreatedAt
    bi.UnlockedAt = p.UnlockedAt
    bi.UnstakedAt = p.UnstakedAt
    bi.Delegate = delegate
    bi.Owner = owner
    return nil

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


func (bt *BucketType) loadProto(p *contractstakingpb.BucketType) error {
var ok bool
bt.Amount, ok = big.NewInt(0).SetString(p.Amount, 10)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same 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.

fixed

StakeStartBlockHeight uint64
UnstakeStartBlockHeight uint64
AutoStake bool
ContractAddress string
Copy link
Member

@dustinxie dustinxie May 22, 2023

Choose a reason for hiding this comment

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

nit: is this necessary?
in other words, this is for the possibility that there's another LSD staking contract in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah

UnstakeStartBlockHeight uint64
AutoStake bool
ContractAddress string
}
Copy link
Member

Choose a reason for hiding this comment

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

no Serialize and Deserialize code 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.

useless for Bucket, which is only in memory

@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 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@envestcc envestcc merged commit 20e6921 into iotexproject:master May 22, 2023
4 of 5 checks passed
@envestcc envestcc deleted the iip13_v2 branch May 22, 2023 13:43
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.

None yet

4 participants