privval: Switch to amino encoding in SignBytes#2459
Conversation
- currently only Vote is done
Codecov Report
@@ Coverage Diff @@
## develop #2459 +/- ##
===========================================
+ Coverage 61.72% 61.74% +0.02%
===========================================
Files 197 198 +1
Lines 16478 16380 -98
===========================================
- Hits 10171 10114 -57
+ Misses 5447 5440 -7
+ Partials 860 826 -34
|
7c8375c to
f7a38b3
Compare
- add error description on error
|
@xla: I've added Errors to the reply messages such that the remote validator can add those; but would it be OK to add proper error handling (and a bunch of known error codes) in a followup PR? |
|
@liamsi Of course! |
privval/socket.go
Outdated
| } | ||
|
|
||
| // Error allows (remote) validators to include meaningful error descriptions in their reply. | ||
| type Error struct { |
There was a problem hiding this comment.
s/Error/RemoteError or RemoteSignerError
| cmn.Fingerprint(vote.Signature), | ||
| CanonicalTime(vote.Timestamp)) | ||
| vote.Timestamp) | ||
| } |
There was a problem hiding this comment.
make this consistently formatted (each new line, or pairs were it makes sense)
privval/socket.go
Outdated
| // SignProposalMsg is a PrivValidatorSocket message containing a Proposal. | ||
| type SignProposalMsg struct { | ||
| // SignVoteReply is a PrivValidatorSocket message containing a signed vote along with a potenial error message. | ||
| type SignedVoteReply struct { |
There was a problem hiding this comment.
change to Request/Response instead.
privval/socket.go
Outdated
| res = &SignProposalMsg{r.Proposal} | ||
| case *SignHeartbeatMsg: | ||
| if err != nil { | ||
| res = &SignedProposalReply{nil, &Error{0, err.Error()}} |
There was a problem hiding this comment.
this decreased the test-coverage ... add tests for these new branches too
- contains all changes besides the test-coverage / error'ing branches
f7a38b3 to
dfcb818
Compare
- add tests for each newly introduced error'ing code path
0258834 to
3aa2914
Compare
xla
left a comment
There was a problem hiding this comment.
👏 Would be nice to add a changelog entry and review relevant docs.
privval/socket.go
Outdated
| } | ||
|
|
||
| *vote = *res.(*SignVoteMsg).Vote | ||
| resp := *res.(*SignedVoteResponse) |
There was a problem hiding this comment.
what if it's not SignedVoteResponse?
There was a problem hiding this comment.
This wasn't considered previously either, but yeah good catch! Will return an error in that case (and add a test-case). Thx.
privval/socket.go
Outdated
| } | ||
|
|
||
| *proposal = *res.(*SignProposalMsg).Proposal | ||
| resp := *res.(*SignedProposalResponse) |
privval/socket.go
Outdated
| } | ||
|
|
||
| *heartbeat = *res.(*SignHeartbeatMsg).Heartbeat | ||
| resp := *res.(*SignedHeartbeatResponse) |
|
|
| Round int `json:"round"` | ||
| Timestamp time.Time `json:"timestamp"` | ||
| VoteType byte `json:"type"` | ||
| } |
There was a problem hiding this comment.
I understand that this might be a first step towards solving #1622
This is very different from the agreed schema (#1622 (comment))
// vanilla protobuf / amino encoded
message Vote {
Version fixed32
Height sfixed64
Round sfixed32
VoteType fixed32
Timestamp Timestamp // << using protobuf definition
BlockID BlockID // << as already defined
ChainID string // at the end because length could vary a lot
}
The order and fixed size types are important so some fields can be serialized without having to deal with amino. This has been extensively discussed in #1622
privval/socket.go
Outdated
|
|
||
| // SignProposalMsg is a PrivValidatorSocket message containing a Proposal. | ||
| type SignProposalMsg struct { | ||
| // SignVoteReply is a PrivValidatorSocket message containing a signed vote along with a potenial error message. |
types/heartbeat.go
Outdated
| // It panics if the Heartbeat is nil. | ||
| func (heartbeat *Heartbeat) SignBytes(chainID string) []byte { | ||
| bz, err := cdc.MarshalJSON(CanonicalHeartbeat(chainID, heartbeat)) | ||
| bz, err := cdc.MarshalJSON(CanonicalizeHeartbeat(chainID, heartbeat)) |
| // NOTE: when this fails, you probably want to fix up consensus/replay_test too | ||
| t.Errorf("Got unexpected sign string for Vote. Expected:\n%v\nGot:\n%v", expected, signStr) | ||
| } | ||
| expected, err := cdc.MarshalBinary(CanonicalizeVote("test_chain_id", vote)) |
There was a problem hiding this comment.
It might be worth hard-coding a binary representation here as an extra assurance. Helps make sure we know exactly what this looks like for other implementers and in-case we ever break it!
414f396 to
8d99cb0
Compare
…ermint#2459) (tendermint#2464) This is an automatic backport of pull request tendermint#2459 done by [Mergify](https://mergify.com). --- <details> <summary>Mergify commands and options</summary> <br /> More conditions and actions can be found in the [documentation](https://docs.mergify.com/). You can also trigger Mergify actions by commenting on this pull request: - `@Mergifyio refresh` will re-evaluate the rules - `@Mergifyio rebase` will rebase this PR on its base branch - `@Mergifyio update` will merge the base branch into this PR - `@Mergifyio backport <destination>` will backport this PR on `<destination>` branch Additionally, on Mergify [dashboard](https://dashboard.mergify.com) you can: - look at your merge queues - generate the Mergify configuration with the config editor. Finally, you can contact us on https://mergify.com </details> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
…ermint#2459) (tendermint#2612) <hr>This is an automatic backport of pull request tendermint#2459 done by [Mergify](https://mergify.com). --------- Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
will resolve #2455