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

[blockindex] restrict height for sgdindexer during write and read operation #3926

Merged
merged 5 commits into from
Aug 25, 2023

Conversation

envestcc
Copy link
Member

Description

Motivation:

  • Strictly limiting the blocks during PutBlock can avoid block skipping issues
  • Specifying the height during queries can help detect errors in the indexer at an earlier stage

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 Aug 22, 2023

Codecov Report

Merging #3926 (2bfaa6b) into master (e1f0636) will increase coverage by 0.67%.
Report is 82 commits behind head on master.
The diff coverage is 73.87%.

❗ Current head 2bfaa6b differs from pull request most recent head 08de6aa. Consider uploading reports for the commit 08de6aa to get more accurate results

@@            Coverage Diff             @@
##           master    #3926      +/-   ##
==========================================
+ Coverage   75.38%   76.05%   +0.67%     
==========================================
  Files         303      328      +25     
  Lines       25923    27924    +2001     
==========================================
+ Hits        19541    21238    +1697     
- Misses       5360     5593     +233     
- Partials     1022     1093      +71     
Files Changed Coverage Δ
action/protocol/execution/evm/evm.go 43.28% <0.00%> (-3.19%) ⬇️
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%> (ø)
action/receipt.go 82.17% <ø> (ø)
api/grpcserver.go 86.40% <0.00%> (ø)
api/loglistener.go 25.00% <0.00%> (ø)
api/websocket.go 4.10% <0.00%> (-1.07%) ⬇️
blockchain/config.go 74.54% <ø> (ø)
... and 65 more

... and 5 files with indirect coverage changes

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

if err != nil {
return nil, 0, err
}
receiver, percentage, ok, err := sgd.CheckContract(ctx, execution.Contract(), height)
Copy link
Member

Choose a reason for hiding this comment

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

should be height-1? pls confirm

if blk.Height() < sgd.startHeight {
if ignore, err := sgd.validateBlock(blk); err != nil {
return err
} else if ignore {
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 not very clean, i think just make it same as contractstaking.Indexer.PutBlock() which you fixed in #3924

@@ -285,9 +285,21 @@ func (sgd *sgdRegistry) StartHeight() uint64 {

// PutBlock puts a block into SGDIndexer
func (sgd *sgdRegistry) PutBlock(ctx context.Context, blk *block.Block) error {
if blk.Height() < sgd.startHeight {
tipHeight, err := sgd.Height()
Copy link
Member

Choose a reason for hiding this comment

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

wrap into a subfunc

Copy link
Member Author

Choose a reason for hiding this comment

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

wrap a function to calculate expectHeight

if height == 0 {
return nil
}
tipHeight, err := sgd.Height()
Copy link
Member

Choose a reason for hiding this comment

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

sgd.height()

@@ -481,6 +499,21 @@ func (sgd *sgdRegistry) FetchContracts(ctx context.Context) ([]*SGDIndex, error)
return sgdIndexes, nil
}

func (sgd *sgdRegistry) validateQueryHeight(height uint64) error {
// 0 means latest height
if height == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

will sm.Height() return 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

generally unlikely to occur, this is merely implemented as a feature to support querying the latest height data.

if err != nil {
return nil, 0, err
}
receiver, percentage, ok, err := sgd.CheckContract(ctx, execution.Contract(), height-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

if height == 0, height - 1 will overflow

Copy link
Member Author

Choose a reason for hiding this comment

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

a good reminder, but it is a hard-fork after Quebec at least, so height=0 will not occur.

Copy link
Member

Choose a reason for hiding this comment

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

if height == 0, height - 1 will overflow

validate the height >= 1 before calling CheckContract

@@ -285,14 +281,10 @@ func (sgd *sgdRegistry) StartHeight() uint64 {

// PutBlock puts a block into SGDIndexer
func (sgd *sgdRegistry) PutBlock(ctx context.Context, blk *block.Block) error {
tipHeight, err := sgd.Height()
expectHeight, err := sgd.expectHeight()
Copy link
Member

Choose a reason for hiding this comment

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

nit: also do this for contract staking indexer? to keep it consistent

@sonarcloud
Copy link

sonarcloud bot commented Aug 25, 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
6.6% 6.6% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@dustinxie dustinxie merged commit 66edd61 into iotexproject:master Aug 25, 2023
2 of 3 checks passed
dustinxie added a commit that referenced this pull request Aug 8, 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.

4 participants