-
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] contract indexer ignore blocks lower than height of contract deployment #3868
Conversation
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) | ||
} | ||
} | ||
} | ||
|
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.
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 Report
@@ 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
... and 4 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
0b3772a
to
ce0badb
Compare
@@ -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 |
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.
why are they put inside poll
?
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 { |
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.
startHeight
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.
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 |
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.
contractDeployHeight
9622f62
to
0b32065
Compare
SonarCloud Quality Gate failed. 0 Bugs No Coverage information |
Description
To optimize the startup check of the contract indexer, the main changes are as follows:
StartHeight()
method to prepare to join theBlockIndexerWithStartGroup
introduced in [blockdao] introduce blockindexer with start height #3869Fixes #(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: