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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address comments
  • Loading branch information
envestcc committed Aug 23, 2023
commit 585f37db28d449ff13efbe70841de3bc2de38100
2 changes: 1 addition & 1 deletion action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func processSGD(ctx context.Context, sm protocol.StateManager, execution *action
if err != nil {
return nil, 0, err
}
receiver, percentage, ok, err := sgd.CheckContract(ctx, execution.Contract(), height)
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

if err != nil || !ok {
return nil, 0, err
}
Expand Down
25 changes: 25 additions & 0 deletions blockindex/sgd_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ func TestNewSGDRegistry(t *testing.T) {
r.Equal(receiverAddress, receiver)
r.True(isApproved)
r.Equal(_sgdPercentage, percentage)

t.Run("heightRestriction", func(t *testing.T) {
cases := []struct {
height uint64
isErr bool
}{
{0, false},
{1, true},
{2, false},
{3, true},
}
for i := range cases {
if cases[i].isErr {
_, err = sgdRegistry.FetchContracts(ctx, cases[i].height)
r.ErrorContains(err, "invalid height")
_, _, _, err = sgdRegistry.CheckContract(ctx, registerAddress.String(), cases[i].height)
r.ErrorContains(err, "invalid height")
} else {
_, err = sgdRegistry.FetchContracts(ctx, cases[i].height)
r.Nil(err)
_, _, _, err = sgdRegistry.CheckContract(ctx, registerAddress.String(), cases[i].height)
r.Nil(err)
}
}
})
})
t.Run("disapproveContract", func(t *testing.T) {
builder := block.NewTestingBuilder()
Expand Down