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

[blockdao] introduce blockindexer with start height #3869

Merged
merged 4 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 those indexer who don't need lower blocks, introducing a new feature in CheckIndexer.

If indexer implemented StartHeight() method, PutBlock will start at maximum between StartHeight with Height when indexer checking at startup

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

@codecov
Copy link

codecov bot commented May 26, 2023

Codecov Report

Merging #3869 (3810097) into master (e1f0636) will increase coverage by 0.41%.
The diff coverage is 67.12%.

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

@@            Coverage Diff             @@
##           master    #3869      +/-   ##
==========================================
+ Coverage   75.38%   75.79%   +0.41%     
==========================================
  Files         303      318      +15     
  Lines       25923    27150    +1227     
==========================================
+ Hits        19541    20578    +1037     
- Misses       5360     5517     +157     
- Partials     1022     1055      +33     
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 28 more

... and 5 files with indirect coverage changes

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

// PutBlock puts a block into the block indexer group
// for every indexer, if StartHeight <= block.Height && Height < block.Height, put the block
func (g *BlockIndexerWithStartGroup) PutBlock(ctx context.Context, blk *block.Block) error {
for _, indexer := range g.indexers {
Copy link
Member

Choose a reason for hiding this comment

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

could the height check logic be put inside each indexer?

Copy link
Member Author

Choose a reason for hiding this comment

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

For an indexer, the difference between adding to BlockDao and adding to BlockIndexerWithStartGroup is as follows:

  • When adding to BlockDao, blocks with heights greater than Height() will enter PutBlock().
  • When adding to BlockIndexerWithStartGroup, only blocks with heights greater than StartHeight() and greater than Height() will enter PutBlock().

Hence, it is preferable to place this logic here instead of duplicating it in each indexer.

@@ -261,6 +261,9 @@ func (builder *Builder) buildBlockDAO(forTest bool) error {
if builder.cs.contractStakingIndexer != nil {
indexers = append(indexers, builder.cs.contractStakingIndexer)
}
startGroupIndexer := blockdao.NewBlockIndexerWithStartGroup()
Copy link
Member

Choose a reason for hiding this comment

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

no indexers?

Copy link
Member Author

Choose a reason for hiding this comment

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

will be addressed in the subsequent pr

// BlockIndexerWithStartGroup defines a group of block indexers with start height
BlockIndexerWithStartGroup struct {
indexers []BlockIndexerWithStart
tipHeightFunc func() (uint64, error)
Copy link
Member

Choose a reason for hiding this comment

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

why need this?

}
}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

i think we don't need to change Start(), but need to change dao.checkIndexer

inside there, if it's a IndexerWithStart, then we only do the check indexer for blocks that's > each indexer's StartHeight

// first, for every indexer, use max of Height and StartHeight
// then, use the min of all indexers
// finally, use the min of the max and maxValidHeight
func (g *BlockIndexerWithStartGroup) Height() (uint64, error) {
Copy link
Member

Choose a reason for hiding this comment

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

why we need a common Height() for this indexer group?

@@ -261,6 +261,7 @@ func (builder *Builder) buildBlockDAO(forTest bool) error {
if builder.cs.contractStakingIndexer != nil {
indexers = append(indexers, builder.cs.contractStakingIndexer)
}

Copy link
Member

Choose a reason for hiding this comment

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

revert, so no need to change this file

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

No Coverage information No Coverage information
8.9% 8.9% Duplication

@envestcc envestcc merged commit 790c4f5 into iotexproject:master May 29, 2023
3 of 5 checks passed
@envestcc envestcc deleted the indexer_with_start branch May 29, 2023 14:45
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