-
Notifications
You must be signed in to change notification settings - Fork 347
fix: change proof functions to return values instead of pointers #2358
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
2d1e1f8
a1e2e2c
47f748c
d0cb4b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,14 +209,18 @@ func (c *CompactBlock) Proofs() ([]*merkle.Proof, error) { | |
| c.proofsCache = make([]*merkle.Proof, 0, len(c.PartsHashes)) | ||
|
|
||
| root, proofs := merkle.ProofsFromLeafHashes(c.PartsHashes[:total]) | ||
| c.proofsCache = append(c.proofsCache, proofs...) | ||
| for i := range proofs { | ||
| c.proofsCache = append(c.proofsCache, &proofs[i]) | ||
| } | ||
|
|
||
| if !bytes.Equal(root, c.Proposal.BlockID.PartSetHeader.Hash) { | ||
| return c.proofsCache, fmt.Errorf("incorrect PartsHash: original root") | ||
| } | ||
|
|
||
| parityRoot, eproofs := merkle.ProofsFromLeafHashes(c.PartsHashes[total:]) | ||
| c.proofsCache = append(c.proofsCache, eproofs...) | ||
| for i := range eproofs { | ||
| c.proofsCache = append(c.proofsCache, &eproofs[i]) | ||
| } | ||
|
|
||
| if !bytes.Equal(c.BpHash, parityRoot) { | ||
| return c.proofsCache, fmt.Errorf("incorrect PartsHash: parity root") | ||
|
|
@@ -483,7 +487,7 @@ func RecoveryPartFromProto(r *protoprop.RecoveryPart) (*RecoveryPart, error) { | |
| Round: r.Round, | ||
| Index: r.Index, | ||
| Data: r.Data, | ||
| Proof: proof, | ||
| Proof: &proof, | ||
|
||
| } | ||
| return rp, rp.ValidateBasic() | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -164,7 +164,7 @@ func TestProofValidateBasic(t *testing.T) { | |
| []byte("watermelon"), | ||
| []byte("kiwi"), | ||
| }) | ||
| tc.malleateProof(proofs[0]) | ||
| tc.malleateProof(&proofs[0]) | ||
| err := proofs[0].ValidateBasic() | ||
| if tc.errStr != "" { | ||
| assert.Contains(t, err.Error(), tc.errStr) | ||
|
|
@@ -186,15 +186,15 @@ func TestVoteProtobuf(t *testing.T) { | |
| }{ | ||
| {"empty proof", &Proof{}, false}, | ||
| {"failure nil", nil, false}, | ||
| {"success", proofs[0], true}, | ||
| {"success", &proofs[0], true}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 47f748c. Updated the test case to handle the nil case separately and removed the dereference in the comparison, while maintaining the same test coverage. |
||
| } | ||
| for _, tc := range testCases { | ||
| pb := tc.v1.ToProto() | ||
|
|
||
| v, err := ProofFromProto(pb, false) | ||
| if tc.expPass { | ||
| require.NoError(t, err) | ||
| require.Equal(t, tc.v1, v, tc.testName) | ||
| require.Equal(t, *tc.v1, v, tc.testName) | ||
| } else { | ||
| require.Error(t, err) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -490,7 +490,7 @@ func (env *Environment) proveDataRootTuples(tuples []DataRootTuple, height int64 | |
| } | ||
| _, proofs := merkle.ProofsFromByteSlices(dataRootEncodedTuples) | ||
| //nolint:gosec | ||
| return proofs[height-int64(tuples[0].height)], nil | ||
| return &proofs[height-int64(tuples[0].height)], nil | ||
|
||
| } | ||
|
|
||
| // fetchDataRootTuples takes an end exclusive range of heights and fetches its | ||
|
|
||
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.
As you're changing everything to reduce pointers, you might as well change
proofsCacheto[]merkle.Proofinstead of changing loops below.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.
Fixed in 47f748c. Changed
proofsCachefield from[]*merkle.Proofto[]merkle.Proofand updated the loops to directly assign values instead of taking addresses.