-
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
[blockindex] restrict height for sgdindexer during write and read operation #3926
Conversation
Codecov Report
@@ 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
... and 5 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
action/protocol/execution/evm/evm.go
Outdated
if err != nil { | ||
return nil, 0, err | ||
} | ||
receiver, percentage, ok, err := sgd.CheckContract(ctx, execution.Contract(), height) |
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.
should be height-1
? pls confirm
blockindex/sgd_indexer.go
Outdated
if blk.Height() < sgd.startHeight { | ||
if ignore, err := sgd.validateBlock(blk); err != nil { | ||
return err | ||
} else if ignore { |
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.
this is not very clean, i think just make it same as contractstaking.Indexer.PutBlock()
which you fixed in #3924
blockindex/sgd_indexer.go
Outdated
@@ -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() |
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.
wrap into a subfunc
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.
wrap a function to calculate expectHeight
blockindex/sgd_indexer.go
Outdated
if height == 0 { | ||
return nil | ||
} | ||
tipHeight, err := sgd.Height() |
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.
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 { |
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.
will sm.Height()
return 0?
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.
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) |
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.
if height == 0, height - 1
will overflow
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.
a good reminder, but it is a hard-fork after Quebec at least, so height=0 will not occur.
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.
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() |
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.
nit: also do this for contract staking indexer? to keep it consistent
SonarCloud Quality Gate failed. 0 Bugs No Coverage information Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
Description
Motivation:
Fixes #(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: