Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Sign integration test & catch up with latest tm-core develop#55

Merged
liamsi merged 25 commits intomasterfrom
sign_integration_test
Oct 20, 2018
Merged

Sign integration test & catch up with latest tm-core develop#55
liamsi merged 25 commits intomasterfrom
sign_integration_test

Conversation

@liamsi
Copy link
Contributor

@liamsi liamsi commented Sep 19, 2018

ready for a first review
resolves #44

Todos:

- fix decoding issue
- remove json cannonicalization
- catch up with latest changes on master
- fix decoding issue
- remove json cannonicalization & refactor code towards amino encoding
instead
- add sign_bytes to TendermintSign trait; equivalent to tendermint's
Signable interface
- add TendermintResponse trait (extending TendermintSign) to build a
response from a request
- implement sign_bytes and set_signature for Heartbeat
- verify heartbeat response in test_handle_sign_request
- catch up with changes from master
- catch up with changes from master
- minor clean up
 - make the test work: don't include the signature, when calling
sign_bytes
 - refactor code to be more idiomatic
 - remove some debug output
- sign using the "first" signer
 - test via integration test (decoding problem)
 - add amino roundtrip encode/decode test for SignVoteRequest (fails)
- update CanonicalVote to new field order & fixed size
@liamsi liamsi force-pushed the sign_integration_test branch from b1616cd to 18d49a5 Compare October 18, 2018 08:05
@liamsi liamsi force-pushed the sign_integration_test branch from 18d49a5 to 6f51dc9 Compare October 18, 2018 08:17
 - move extracting length into separate function
 - silence some warning about imports
@liamsi liamsi force-pushed the sign_integration_test branch from 6d6aed1 to 0eb39de Compare October 19, 2018 07:29
@liamsi liamsi changed the title [WIP]: Sign integration test Sign integration test & catch up with latest tm-core develop Oct 19, 2018
@liamsi liamsi force-pushed the sign_integration_test branch from 0dfcdd3 to 7fe38a7 Compare October 19, 2018 12:07
@liamsi liamsi force-pushed the sign_integration_test branch from 7fe38a7 to 90790ef Compare October 19, 2018 12:11
- rudimentary `get_public_key` method that returns the *only* pub key
 or an error
- add method get_only_signing_pubkey to achive aboveMichel
- add PingRequest to integration test
- some minor cleanup
@liamsi liamsi force-pushed the sign_integration_test branch from 90790ef to 44e48eb Compare October 19, 2018 12:14
Copy link
Contributor

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Generally looks good. I left some optional suggested improvements as line notes.


/// Sign a message using the secret key associated with the given public key
/// (if it is in our keyring)
pub fn sign(public_key: &PublicKey, msg: &[u8]) -> Result<Ed25519Signature, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative signature for this which can handle both cases without splitting them into separate functions:

pub fn sign(public_key: Option<&PublicKey>, msg: &[u8]) -> Result<Ed25519Signature, Error>

src/rpc.rs Outdated
PingRequest, PingResponse, PoisonPillMsg, PubKeyMsg, SignHeartbeatRequest, SignProposalRequest,
SignVoteRequest, SignedHeartbeatResponse, SignedProposalResponse, SignedVoteResponse,
TendermintSignable, HEARTBEAT_AMINO_NAME, PING_AMINO_NAME, POISON_PILL_AMINO_NAME,
PROPOSAL_AMINO_NAME, PUBKEY_AMINO_NAME, VOTE_AMINO_NAME,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can probably just use types::* here

src/rpc.rs Outdated
let rem: Vec<u8> = buff.clone().into_inner();
let rem: Vec<u8> =
buff.clone().into_inner()[..(len.checked_add(1).unwrap() as usize)].to_vec();
if amino_pre == *PP_PREFIX {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I missed this in previous review, but all of these if amino_pres look like a good case for a match expression

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The match wouldn't be simply

match amino_pre {
    PP_PREFIX => return Ok(Request::PoisonPill(PoisonPillMsg {})),
    ...

but something slightly more clumsy like

match amino_pre {
    ref pp if *pp == *PP_PREFIX => return Ok(Request::PoisonPill(PoisonPillMsg {})),
    ...

but I guess this is still more idiomatic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't you do:

match amino_pre.as_ref() {
     PP_PREFIX => Ok(Request::PoisonPill(PoisonPillMsg {})),
     ...

...or thereabouts?

Copy link
Contributor Author

@liamsi liamsi Oct 20, 2018

Choose a reason for hiding this comment

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

Thanks! I've tried this (and variants of this), it yields:

- a static `PP_PREFIX` is defined here
...
95 |               PP_PREFIX => Ok(Request::PoisonPill(PoisonPillMsg {})),
   |               ^^^^^^^^^ cannot be named the same as a static
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0530]: match bindings cannot shadow statics
  --> src/rpc.rs:96:13

@liamsi liamsi force-pushed the sign_integration_test branch from a018b4c to 54338fe Compare October 19, 2018 21:32
Copy link
Contributor

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Looks good now, thanks!

@liamsi
Copy link
Contributor Author

liamsi commented Oct 20, 2018

Thanks a lot @tarcieri! I'll merge this and open issues for the left TODOs (#55 (comment))

@liamsi liamsi merged commit 41eed35 into master Oct 20, 2018
@tarcieri tarcieri deleted the sign_integration_test branch October 20, 2018 15:39
tarcieri pushed a commit that referenced this pull request Oct 21, 2018
Now that #55 is landed, we can re-enable `#![deny(warnings)]` which is a
best practice.

This commit does that, and peppers remaining unused code with
`#![allow(dead_code)]`.

Additionally, to ensure `#![deny(missing_docs)]` is enforced and to
follow (evolving) Abscissa conventions, this refactors the app as a
library with a small `main.rs` stub.
@tony-iqlusion tony-iqlusion mentioned this pull request Nov 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement get_public_key Add Ping(Request | Response) message handling Implement signing and add back integration test

2 participants