-
Notifications
You must be signed in to change notification settings - Fork 297
fix(rpc): guard TxsResults length before indexing by block tx position
#2175
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
Open
JayT106
wants to merge
9
commits into
main
Choose a base branch
from
fix/rpc-txsresults-length-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5cae236
fix(rpc): guard TxsResults length before indexing by block tx position
JayT106 9a6b270
trim comment
JayT106 9b4022f
fix(rpc): correct changelog PR link and unassigned blockNum in log
JayT106 a3e7287
test(rpc): assert full mismatched tx results error message
JayT106 ca8bc9a
test(rpc): restructure TxsResults length test as suite.Suite table
JayT106 c4ef9b1
Merge branch 'main' into fix/rpc-txsresults-length-guard
JayT106 452a005
refactor(rpc): clarify getBlockDetail error semantics and checkTxsRes…
JayT106 cb98384
Merge branch 'main' into fix/rpc-txsresults-length-guard
JayT106 bb380de
refactor(rpc): drop getBlockDetail comment
JayT106 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package rpc | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| abci "github.com/cometbft/cometbft/abci/types" | ||
| coretypes "github.com/cometbft/cometbft/rpc/core/types" | ||
| cmttypes "github.com/cometbft/cometbft/types" | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| func newResBlock(t *testing.T, numTxs int) *coretypes.ResultBlock { | ||
| t.Helper() | ||
| txs := make(cmttypes.Txs, numTxs) | ||
| for i := range txs { | ||
| txs[i] = cmttypes.Tx{byte(i)} | ||
| } | ||
| return &coretypes.ResultBlock{ | ||
| Block: &cmttypes.Block{ | ||
| Header: cmttypes.Header{Height: 100}, | ||
| Data: cmttypes.Data{Txs: txs}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func newBlockRes(t *testing.T, numResults int) *coretypes.ResultBlockResults { | ||
| t.Helper() | ||
| results := make([]*abci.ExecTxResult, numResults) | ||
| for i := range results { | ||
| results[i] = &abci.ExecTxResult{} | ||
| } | ||
| return &coretypes.ResultBlockResults{TxsResults: results} | ||
| } | ||
|
|
||
| type CheckTxsResultsLengthTestSuite struct { | ||
| suite.Suite | ||
| } | ||
|
|
||
| func TestCheckTxsResultsLengthTestSuite(t *testing.T) { | ||
| suite.Run(t, new(CheckTxsResultsLengthTestSuite)) | ||
| } | ||
|
|
||
| func (s *CheckTxsResultsLengthTestSuite) TestCheckTxsResultsLength() { | ||
| testCases := []struct { | ||
| name string | ||
| numTxs int | ||
| numRes int | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "matching lengths returns no error", | ||
| numTxs: 3, | ||
| numRes: 3, | ||
| }, | ||
| { | ||
| name: "fewer tx results than txs returns error instead of panicking", | ||
| numTxs: 3, | ||
| numRes: 2, | ||
| wantErr: "mismatched tx results length at height 100: block has 3 txs, but got 2 tx results", | ||
| }, | ||
| { | ||
| name: "more tx results than txs returns error", | ||
| numTxs: 2, | ||
| numRes: 3, | ||
| wantErr: "mismatched tx results length at height 100: block has 2 txs, but got 3 tx results", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| s.Run(tc.name, func() { | ||
| t := s.T() | ||
| err := checkTxsResultsLength(newResBlock(t, tc.numTxs), newBlockRes(t, tc.numRes)) | ||
| if tc.wantErr == "" { | ||
| require.NoError(t, err) | ||
| return | ||
| } | ||
| require.EqualError(t, err, tc.wantErr) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
You are still returning resBlock and blockRes which could be missuses, perhaps some refactoring could be done to clarify the semantic of
resBlockandresBlock?Do we allow them to have different length or not?
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.
renamed to
blockandblockResults, and for the returning only return theerrinfo.This is to match with the consensus raw data check, the length should always the same. if the data mismatch, meaning we need to migrate/patch the data like fix-unlucky-tx in v0.7 before.