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 indexer ignore blocks lower than height of contract deployment #3868

Merged
merged 2 commits into from
May 29, 2023

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented May 26, 2023

Description

To optimize the startup check of the contract indexer, the main changes are as follows:

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 requested review from CoderZhi, dustinxie, Liuhaai and a team as code owners May 26, 2023 09:57
Comment on lines 354 to 370
func BenchmarkIndexer_PutBlockBeforeContractHeight(b *testing.B) {
// Create a new Indexer with a contract height of 100
indexer := &Indexer{contractHeight: 100}

// Create a mock block with a height of 50
blk := &block.Block{}

// Run the benchmark
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := indexer.PutBlock(context.Background(), blk)
if err != nil {
b.Fatal(err)
}
}
}

Copy link
Member Author

Choose a reason for hiding this comment

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

The Benchmark Report:

❯ go test -benchmem -run=^$ -bench ^BenchmarkIndexer_PutBlockBeforeContractHeight$ github.com/iotexproject/iotex-core/blockindex/contractstaking
goos: darwin
goarch: arm64
pkg: github.com/iotexproject/iotex-core/blockindex/contractstaking
BenchmarkIndexer_PutBlockBeforeContractHeight-10        522791816                2.249 ns/op           0 B/op          0 allocs/op
PASS
ok      github.com/iotexproject/iotex-core/blockindex/contractstaking   1.687s

Currently, the mainnet height is approximately 23878680. The estimated time for the startup check is 23878680 * 2.249 ns = 0.0537 s. This result is acceptable

@codecov
Copy link

codecov bot commented May 26, 2023

Codecov Report

Merging #3868 (9768158) into master (e1f0636) will increase coverage by 0.24%.
The diff coverage is 66.98%.

❗ Current head 9768158 differs from pull request most recent head 0b32065. Consider uploading reports for the commit 0b32065 to get more accurate results

@@            Coverage Diff             @@
##           master    #3868      +/-   ##
==========================================
+ Coverage   75.38%   75.63%   +0.24%     
==========================================
  Files         303      318      +15     
  Lines       25923    27145    +1222     
==========================================
+ Hits        19541    20530     +989     
- Misses       5360     5562     +202     
- Partials     1022     1053      +31     
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 0.00% <0.00%> (ø)
action/protocol/staking/contractstake_indexer.go 14.28% <14.28%> (ø)
... and 27 more

... and 4 files with indirect coverage changes

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

@@ -82,8 +82,9 @@ func defaultConfig() Genesis {
ProbationEpochPeriod: 6,
ProbationIntensityRate: 90,
UnproductiveDelegateMaxCacheSize: 20,
// TODO (iip-13): replace the following with the address on mainnet
LiquidStakingContractAddress: "io1uw3gvmhrjz5mwxpd966wxxt6fn5uuvwfpynrwj",
// TODO (iip-13): replace the following with the address and height on mainnet
Copy link
Member

Choose a reason for hiding this comment

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

why are they put inside poll?

@Liuhaai
Copy link
Member

Liuhaai commented May 26, 2023

others look good to me

}
)

// NewContractStakingIndexer creates a new contract staking indexer
func NewContractStakingIndexer(kvStore db.KVStore, contractAddr string) *Indexer {
func NewContractStakingIndexer(kvStore db.KVStore, contractAddr string, contractHeight uint64) *Indexer {
Copy link
Member

Choose a reason for hiding this comment

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

startHeight

Copy link
Member

Choose a reason for hiding this comment

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

or contractDeployHeight

@@ -51,11 +51,12 @@ type (
kvstore db.KVStore // persistent storage, used to initialize index cache at startup
cache *contractStakingCache // in-memory index for clean data, used to query index data
contractAddress string // stake contract address
contractHeight uint64 // height of the contract deployment
Copy link
Member

Choose a reason for hiding this comment

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

contractDeployHeight

@sonarcloud
Copy link

sonarcloud bot commented May 29, 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
4.4% 4.4% Duplication

@envestcc envestcc merged commit 4bbba8d into iotexproject:master May 29, 2023
@envestcc envestcc deleted the staking_ignore_blocks branch May 29, 2023 14:20
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