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-15]sgdRegistry implementation #3845

Merged
merged 33 commits into from
May 30, 2023
Merged

Conversation

millken
Copy link
Contributor

@millken millken commented Apr 14, 2023

Description

base on #3844 #3816

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

@millken millken requested review from CoderZhi, dustinxie, Liuhaai and a team as code owners April 14, 2023 01:43
@codecov
Copy link

codecov bot commented Apr 14, 2023

Codecov Report

Merging #3845 (e943aa6) into master (e1f0636) will increase coverage by 0.01%.
The diff coverage is 60.90%.

❗ Current head e943aa6 differs from pull request most recent head 0087a81. Consider uploading reports for the commit 0087a81 to get more accurate results

@@            Coverage Diff             @@
##           master    #3845      +/-   ##
==========================================
+ Coverage   75.38%   75.39%   +0.01%     
==========================================
  Files         303      318      +15     
  Lines       25923    27297    +1374     
==========================================
+ Hits        19541    20581    +1040     
- Misses       5360     5660     +300     
- Partials     1022     1056      +34     
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%> (ø)
...tion/protocol/staking/contractstake_bucket_type.go 0.00% <0.00%> (ø)
api/web3server_marshal.go 93.21% <ø> (ø)
blockchain/config.go 74.54% <ø> (ø)
blockindex/contractstaking/dummy_indexer.go 0.00% <0.00%> (ø)
blockindex/sgd_indexer.go 2.48% <2.48%> (ø)
action/protocol/staking/contractstake_indexer.go 14.28% <14.28%> (ø)
... and 28 more

... and 4 files with indirect coverage changes

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

@@ -32,6 +32,9 @@ type (
BloomfilterIndexDBPath string `yaml:"bloomfilterIndexDBPath"`
CandidateIndexDBPath string `yaml:"candidateIndexDBPath"`
StakingIndexDBPath string `yaml:"stakingIndexDBPath"`
SGDIndexDBPath string `yaml:"sgdIndexDBPath"`
SGDIndexCacheSize int `yaml:"sgdIndexCacheSize"`
SGDPercentage uint64 `yaml:"sgdPercentage"`
Copy link
Member

Choose a reason for hiding this comment

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

no need for percentage, we'll have a tiered reward structure, like 50% for 100k volume, 60% for 200k volume, etc.

)

// NewSGDRegistry creates a new SGDIndexer
func NewSGDRegistry(kv db.KVStore, kvCache cache.LRUCache, percentage uint64) SGDIndexer {
Copy link
Member

Choose a reason for hiding this comment

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

as commented above, remove precentage
also remove kvCache, it can be generated inside here
you can use a builder config to pass in the parameters needed, refer to 02f8190#diff-c65dd5a657c73eb89458c69a82a25fc0993655650b3ad477136955c31e50e2bb

blockindex/sgd.go Outdated Show resolved Hide resolved
blockindex/sgd.go Outdated Show resolved Hide resolved
blockindex/sgd.go Outdated Show resolved Hide resolved
actType: actType,
sender: sender,
contract: contract,
createTime: blk.Header.Timestamp(),
Copy link
Member

Choose a reason for hiding this comment

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

this is part of newIndex()

blockindex/sgd.go Outdated Show resolved Hide resolved
blockindex/sgd.go Outdated Show resolved Hide resolved
blockindex/sgd.go Outdated Show resolved Hide resolved
// CheckContract
CheckContract(contract string) (address.Address, uint64, bool)
// GetSGDIndex
GetSGDIndex(contract string) (*indexpb.SGDIndex, error)
Copy link
Member

@dustinxie dustinxie Apr 19, 2023

Choose a reason for hiding this comment

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

no need to expose this func as part of interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

expose this func to get all the state of the contract, checkContract can only get receiver and percentage

blockindex/sgd.go Outdated Show resolved Hide resolved
blockindex/sgd.go Outdated Show resolved Hide resolved
chainservice/builder.go Outdated Show resolved Hide resolved

message SGDIndex {
string contract = 1;
string receiver = 2;
Copy link
Member

Choose a reason for hiding this comment

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

define these 2 as []byte, see comment below

if err != nil {
return err
}
sgdIndex.Approved = true
Copy link
Member

Choose a reason for hiding this comment

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

should verify sgdIndex.Approved = false here?

depends on the contract's logic, can the same contract by approved twice? pls check it

Copy link
Contributor Author

@millken millken May 18, 2023

Choose a reason for hiding this comment

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

contract can only be approved once, otherwise will be reverted

type (
// SGDRegistry is the interface for Sharing of Gas-fee with DApps
SGDRegistry interface {
blockdao.BlockIndexer
// CheckContract returns the contract's eligibility for SGD and percentage
CheckContract(context.Context, string) (address.Address, uint64, bool, error)
// FetchContracts returns all contracts that are eligible for SGD
FetchContracts(context.Context) ([]*indexpb.SGDIndex, error)
Copy link
Member

Choose a reason for hiding this comment

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

should not use *indexpb.SGDIndex, which is storage format

Copy link
Member

Choose a reason for hiding this comment

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

define a struct sgdIndex, and convert it to/from *indexpb.SGDIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, defined a SGDIndex

if kv == nil {
panic("nil kvstore")
}
if contract != "" {
Copy link
Member

Choose a reason for hiding this comment

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

if contract == "" should also err out

Copy link
Contributor Author

@millken millken May 23, 2023

Choose a reason for hiding this comment

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

in dev or testnet env, it is allowed to be left blank when we not deployed contracts

}
return nil, err
}
sgdIndexes := make([]*SGDIndex, 0, len(values))
Copy link
Member

Choose a reason for hiding this comment

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

sgdIndexPb := indexpb.SGDIndex{}
move to here, can re-use the same var in the for loop below

// SystemSGDContractAddress is the address of system sgd contract
SystemSGDContractAddress string `yaml:"sgdContractAddress"`
// SystemSGDContractHeight is the height of system sgd contract
SystemSGDContractHeight uint64 `yaml:"sgdContractHeight"`
Copy link
Member

Choose a reason for hiding this comment

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

yaml name should be same as var, with first letter change to small

@sonarcloud
Copy link

sonarcloud bot commented May 30, 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 2 Code Smells

No Coverage information No Coverage information
10.2% 10.2% Duplication

@dustinxie dustinxie merged commit 23645ff into iotexproject:master May 30, 2023
dustinxie added a commit that referenced this pull request Aug 8, 2024
dustinxie added a commit that referenced this pull request Aug 8, 2024
dustinxie added a commit that referenced this pull request Aug 8, 2024
dustinxie added a commit that referenced this pull request Aug 9, 2024
dustinxie added a commit that referenced this pull request Aug 10, 2024
dustinxie added a commit that referenced this pull request Aug 12, 2024
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.

3 participants