Skip to content
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

privval: Switch to amino encoding in SignBytes #2459

Merged
merged 11 commits into from Sep 28, 2018
Merged

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

 - 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

types/vote.go Outdated
@@ -108,7 +108,7 @@ func (vote *Vote) String() string {
vote.Height, vote.Round, vote.Type, typeString,
cmn.Fingerprint(vote.BlockID.Hash),
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
 - add tests for each newly introduced error'ing code path
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.

@@ -160,7 +160,13 @@ func (sc *SocketPV) SignVote(chainID string, vote *types.Vote) error {
return err
}

*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.

@@ -179,8 +185,13 @@ func (sc *SocketPV) SignProposal(
if err != nil {
return err
}

*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

@@ -199,8 +210,14 @@ func (sc *SocketPV) SignHeartbeat(
if err != nil {
return err
}

*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

Vote *types.Vote
}

// 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

@@ -23,7 +23,7 @@ type Heartbeat struct {
// SignBytes returns the Heartbeat bytes for signing.
// 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
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.

None yet

6 participants