Skip to content

privval: Switch to amino encoding in SignBytes#2459

Merged
ebuchman merged 11 commits intodevelopfrom
mvp_amino_signbytes
Sep 28, 2018
Merged

privval: Switch to amino encoding in SignBytes#2459
ebuchman merged 11 commits intodevelopfrom
mvp_amino_signbytes

Conversation

@liamsi
Copy link
Contributor

@liamsi liamsi commented Sep 21, 2018

will resolve #2455

  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

@liamsi liamsi changed the base branch from master to develop September 21, 2018 12:06
@codecov-io
Copy link

codecov-io commented Sep 21, 2018

Codecov Report

Merging #2459 into develop will increase coverage by 0.02%.
The diff coverage is 93.33%.

@@             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
Impacted Files Coverage Δ
privval/socket.go 75.8% <100%> (+4.31%) ⬆️
privval/priv_validator.go 71.02% <66.66%> (+1.57%) ⬆️
lite/dbprovider.go 59.18% <0%> (-18.37%) ⬇️
libs/bech32/bech32.go 42.85% <0%> (-10.99%) ⬇️
lite/dynamic_verifier.go 56.25% <0%> (-5.94%) ⬇️
libs/autofile/autofile.go 74.64% <0%> (-4.3%) ⬇️
p2p/peer.go 58.64% <0%> (-4.09%) ⬇️
cmd/tendermint/commands/lite.go 13.15% <0%> (-2.23%) ⬇️
consensus/wal.go 61.24% <0%> (-1.56%) ⬇️
consensus/reactor.go 72.1% <0%> (-1.03%) ⬇️
... and 20 more

@liamsi liamsi force-pushed the mvp_amino_signbytes branch from 7c8375c to f7a38b3 Compare September 21, 2018 12:11
 - add error description on error
@xla xla changed the title [WIP]: Switch to amino encoding in SignBytes [WIP] privval: Switch to amino encoding in SignBytes Sep 21, 2018
@xla xla added the T:validator Type: Validator related label Sep 21, 2018
@liamsi
Copy link
Contributor Author

liamsi commented Sep 21, 2018

@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?

@xla
Copy link
Contributor

xla commented Sep 21, 2018

@liamsi Of course!

@liamsi liamsi changed the title [WIP] privval: Switch to amino encoding in SignBytes privval: Switch to amino encoding in SignBytes Sep 21, 2018
}

// Error allows (remote) validators to include meaningful error descriptions in their reply.
type Error struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Error/RemoteError or RemoteSignerError

cmn.Fingerprint(vote.Signature),
CanonicalTime(vote.Timestamp))
vote.Timestamp)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this consistently formatted (each new line, or pairs were it makes sense)

// 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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to Request/Response instead.

res = &SignProposalMsg{r.Proposal}
case *SignHeartbeatMsg:
if err != nil {
res = &SignedProposalReply{nil, &Error{0, err.Error()}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this decreased the test-coverage ... add tests for these new branches too

 - contains all changes besides the test-coverage / error'ing branches
@liamsi liamsi force-pushed the mvp_amino_signbytes branch from f7a38b3 to dfcb818 Compare September 21, 2018 17:05
 - add tests for each newly introduced error'ing code path
@liamsi liamsi force-pushed the mvp_amino_signbytes branch from 0258834 to 3aa2914 Compare September 21, 2018 21:07
xla
xla previously requested changes Sep 21, 2018
Copy link
Contributor

@xla xla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Would be nice to add a changelog entry and review relevant docs.

}

*vote = *res.(*SignVoteMsg).Vote
resp := *res.(*SignedVoteResponse)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if it's not SignedVoteResponse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't considered previously either, but yeah good catch! Will return an error in that case (and add a test-case). Thx.

}

*proposal = *res.(*SignProposalMsg).Proposal
resp := *res.(*SignedProposalResponse)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

}

*heartbeat = *res.(*SignHeartbeatMsg).Heartbeat
resp := *res.(*SignedHeartbeatResponse)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@liamsi
Copy link
Contributor Author

liamsi commented Sep 22, 2018

addressed @melekes comments and updated changelog / docs (@xla)

@liamsi
Copy link
Contributor Author

liamsi commented Sep 22, 2018

TestWaitChan seems to fail non-deterministically (unrelated to the changes in that commit, which are only in *.md files). This seems to be known: #2227

Round int `json:"round"`
Timestamp time.Time `json:"timestamp"`
VoteType byte `json:"type"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


// 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SignedVoteResponse

// 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MarshalBinary?

// 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #2508 for this

@ebuchman ebuchman merged commit fc07374 into develop Sep 28, 2018
@ebuchman ebuchman deleted the mvp_amino_signbytes branch September 28, 2018 23:57
iKapitonau pushed a commit to scrtlabs/tendermint that referenced this pull request Jul 10, 2024
…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>
cboh4 pushed a commit to scrtlabs/tendermint that referenced this pull request Apr 7, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T:validator Type: Validator related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants