Fix virtual channel proposal id generation#300
Merged
matthiasgeihs merged 2 commits intohyperledger-labs:mainfrom Jan 20, 2022
Merged
Fix virtual channel proposal id generation#300matthiasgeihs merged 2 commits intohyperledger-labs:mainfrom
matthiasgeihs merged 2 commits intohyperledger-labs:mainfrom
Conversation
03455f8 to
1d2e587
Compare
9407242 to
f162df9
Compare
matthiasgeihs
suggested changes
Jan 19, 2022
Contributor
matthiasgeihs
left a comment
There was a problem hiding this comment.
I think we can achieve the same thing by using VirtualChannelProposal.Encode.
Comment on lines
+612
to
+613
| // ProposalID returns the identifier of this channel proposal. | ||
| func (p VirtualChannelProposal) ProposalID() (propID ProposalID) { | ||
| hasher := newHasher() | ||
| if err := perunio.Encode(hasher, | ||
| p.Base(), | ||
| p.Proposer, | ||
| wire.Addresses(p.Peers), | ||
| ); err != nil { | ||
| log.Panicf("proposal ID base encoding: %v", err) | ||
| } | ||
| for i := range p.Parents { | ||
| if err := perunio.Encode(hasher, p.Parents[i]); err != nil { | ||
| log.Panicf("proposal ID base encoding: %v", err) | ||
| } | ||
| } | ||
| for i := range p.IndexMaps { | ||
| for j := range p.IndexMaps { | ||
| if err := perunio.Encode(hasher, (p.IndexMaps[i][j])); err != nil { | ||
| log.Panicf("proposal ID base encoding: %v", err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| copy(propID[:], hasher.Sum(nil)) | ||
| return | ||
| } |
Contributor
There was a problem hiding this comment.
We can reuse the VirtualChannelProposal.Encode method:
Suggested change
| // ProposalID returns the identifier of this channel proposal. | |
| func (p VirtualChannelProposal) ProposalID() (propID ProposalID) { | |
| hasher := newHasher() | |
| if err := perunio.Encode(hasher, | |
| p.Base(), | |
| p.Proposer, | |
| wire.Addresses(p.Peers), | |
| ); err != nil { | |
| log.Panicf("proposal ID base encoding: %v", err) | |
| } | |
| for i := range p.Parents { | |
| if err := perunio.Encode(hasher, p.Parents[i]); err != nil { | |
| log.Panicf("proposal ID base encoding: %v", err) | |
| } | |
| } | |
| for i := range p.IndexMaps { | |
| for j := range p.IndexMaps { | |
| if err := perunio.Encode(hasher, (p.IndexMaps[i][j])); err != nil { | |
| log.Panicf("proposal ID base encoding: %v", err) | |
| } | |
| } | |
| } | |
| copy(propID[:], hasher.Sum(nil)) | |
| return | |
| } | |
| // ProposalID returns the identifier of this channel proposal. | |
| func (p VirtualChannelProposal) ProposalID() (propID ProposalID) { | |
| hasher := newHasher() | |
| if err := perunio.Encode(hasher, p); err != nil { | |
| log.Panicf("encoding proposal: %v", err) | |
| } | |
| copy(propID[:], hasher.Sum(nil)) | |
| return | |
| } |
Author
Author
There was a problem hiding this comment.
As it was the only suggestion, I squashed the review commit and rebased the branch onto develop.
e5f0d02 to
4576ba2
Compare
added 2 commits
January 19, 2022 16:14
- Previously, the proposal ID for a virtual channel was generated using the ProposalID method defined on BaseChannelProposal. - Hence, not all parameters of the virtual channel proposal were used. - Fix it by defining a ProposalID method on the virtual channel. - Also, remove the ProposalID method on the BaseChannelProposal, as it is not needed. Signed-off-by: Manoranjith <ponraj.manoranjitha@in.bosch.com>
- Use the Encode method for encoding the proposal, before hashing it. Signed-off-by: Manoranjith <ponraj.manoranjitha@in.bosch.com>
4576ba2 to
2b3f79e
Compare
matthiasgeihs
approved these changes
Jan 20, 2022
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previously, the proposal ID for a virtual channel was generated using
the ProposalID method defined on BaseChannelProposal.
Hence, not all parameters of the virtual channel proposal were used.
Fix it by defining a ProposalID method on the virtual channel.
Also, remove the ProposalID method on the BaseChannelProposal, as it
is not needed.
Fixes #299.