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

Fix Cross Compile Build/Ledger Build Tag #1674

Merged
merged 6 commits into from
Jul 14, 2018
Merged

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Jul 13, 2018

Changelog

  • Cleaned up Makefile formatting a bit
  • Added check-ledger target used by install and build-linux
  • Fixed cross-compilation by having ledger support turned off by default (build-linux only)
  • Refactored ledger/device implementation in crypto/ to use an interface and built tag.

To build with ledger support: $ LEDGER_ENABLED=true|false make install

closes: #1581


  • Updated all relevant documentation (docs/)
  • Updated all relevant code comments
  • Wrote tests
  • Updated CHANGELOG.md
  • Updated cmd/gaia and examples/

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@cwgoes
Copy link
Contributor

cwgoes commented Jul 13, 2018

This should be non-breaking, correct?

@alexanderbez
Copy link
Contributor Author

@cwgoes ledger is disabled by default. We can have it enabled by default except when cross-compiling (aka, build-linux). Is this preferable?

@cwgoes
Copy link
Contributor

cwgoes commented Jul 13, 2018

We can have it enabled by default except when cross-compiling (aka, build-linux). Is this preferable?

Yes, I think so.

Makefile Outdated
ifdef GCC
BUILD_TAGS += ledger
else
$(error "gcc not installed for ledger support, please install")
Copy link
Contributor

Choose a reason for hiding this comment

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

Will clang work too?

Copy link
Contributor

Choose a reason for hiding this comment

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

(or does CGO require gcc anyways?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it requires gcc afaik.

crypto/ledger.go Outdated
// If ledger support (build tag) has been enabled, automically attempt to load
// and set the ledger device, ledgerDevice, if it has not already been set.
func init() {
if ledgerDevice == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to check this - init() will only be called once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, init will only be called once. Alternatively, you could wrap it in a once.Do(...) call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nvm, I see you're point. The old code was this way -- I'll remove it 👍

)

func TestRealLedgerSecp256k1(t *testing.T) {
var ledgerEnabledEnv = "LEDGER_ENABLED"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, do we want to use the same environment variable here? e.g. we want CI to build with Ledger support, but it can't run the tests that require having a Ledger plugged in

@codecov
Copy link

codecov bot commented Jul 13, 2018

Codecov Report

Merging #1674 into master will decrease coverage by 0.07%.
The diff coverage is 10%.

@@            Coverage Diff             @@
##           master    #1674      +/-   ##
==========================================
- Coverage   62.15%   62.07%   -0.08%     
==========================================
  Files         117      116       -1     
  Lines        6938     6929       -9     
==========================================
- Hits         4312     4301      -11     
- Misses       2384     2385       +1     
- Partials      242      243       +1

@cwgoes
Copy link
Contributor

cwgoes commented Jul 13, 2018

TEST_WITH_LEDGER=1 go test ./crypto/... fails with:

--- FAIL: TestRealLedgerSecp256k1 (0.00s)
	Error Trace:	ledger_test.go:23
	Error:      	Expected nil, but got: &errors.errorString{s:"failed to create PrivKeyLedgerSecp256k1: missing ledger device"}
	Test:       	TestRealLedgerSecp256k1
	Messages:   	failed to create PrivKeyLedgerSecp256k1: missing ledger device
FAIL
FAIL	github.com/cosmos/cosmos-sdk/crypto	0.026s

Ledger app is running, and gaiacli keys add --ledger works fine.


check-ledger:
ifeq ($(LEDGER_ENABLED),true)
ifndef GCC
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mhmmm, not sure? But feel free to update it if it makes sense :-)

@alexanderbez
Copy link
Contributor Author

alexanderbez commented Jul 13, 2018

@cwgoes ahh indeed. `init() isn't being called. Fixing...

EDIT: Ahh, wait. That test needs to run with the ledger build tag :-/

crypto/ledger.go Outdated
@@ -0,0 +1,18 @@
// +build ledger
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be cgo,ledger just so that this doesn't work if ledger flag is set but cgo isn't installed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes 👍

@cwgoes
Copy link
Contributor

cwgoes commented Jul 13, 2018

Ahh, wait. That test needs to run with the ledger build tag

Any idea how to do that?

@ValarDragon
Copy link
Contributor

Yeah, you just add // +build ledger at the top of the test file, and run go test -v tags=ledger when running tests in that directory. Output:

=== RUN   TestKeyEncodings
--- PASS: TestKeyEncodings (0.05s)
=== RUN   TestNilEncodings
--- PASS: TestNilEncodings (0.00s)
=== RUN   TestRealLedgerSecp256k1
--- FAIL: TestRealLedgerSecp256k1 (0.15s)
        Error Trace:    ledger_test.go:29
	Error:      	Expected nil, but got: &errors.errorString{s:"invalid status 6a80"}
	Test:       	TestRealLedgerSecp256k1
=== RUN   TestRealLedgerErrorHandling
--- FAIL: TestRealLedgerErrorHandling (0.15s)
        Error Trace:    ledger_test.go:67
	Error:      	An error is expected but got nil.
	Test:       	TestRealLedgerErrorHandling
=== RUN   ExamplePrintRegisteredTypes
--- PASS: ExamplePrintRegisteredTypes (0.00s)
FAIL
exit status 1
FAIL	github.com/cosmos/cosmos-sdk/crypto	0.478s=== RUN   TestKeyEncodings
--- PASS: TestKeyEncodings (0.05s)
=== RUN   TestNilEncodings
--- PASS: TestNilEncodings (0.00s)
=== RUN   TestRealLedgerSecp256k1
--- FAIL: TestRealLedgerSecp256k1 (0.15s)
        Error Trace:    ledger_test.go:29
	Error:      	Expected nil, but got: &errors.errorString{s:"invalid status 6a80"}
	Test:       	TestRealLedgerSecp256k1
=== RUN   TestRealLedgerErrorHandling
--- FAIL: TestRealLedgerErrorHandling (0.15s)
        Error Trace:    ledger_test.go:67
	Error:      	An error is expected but got nil.
	Test:       	TestRealLedgerErrorHandling
=== RUN   ExamplePrintRegisteredTypes
--- PASS: ExamplePrintRegisteredTypes (0.00s)
FAIL
exit status 1
FAIL	github.com/cosmos/cosmos-sdk/crypto	0.478s

@alexanderbez
Copy link
Contributor Author

alexanderbez commented Jul 13, 2018

@ValarDragon you don't have to add it to the test file file. Doing the following should suffice:

$ TEST_WITH_LEDGER=1 GOCACHE=off go test -tags "ledger" -timeout 30s github.com/cosmos/cosmos-sdk/crypto -run ^TestRealLedgerSecp256k1$

@cwgoes
Copy link
Contributor

cwgoes commented Jul 14, 2018

@ValarDragon and I made a few minor modifications to update the testsuite for the real Ledger.

Copy link
Contributor

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

LGTM
Has cross compilation been tested?

@alexanderbez
Copy link
Contributor Author

@ValarDragon cross compilation works (without ledger), but could use some actual testing. Maybe running a local test net?

@cwgoes
Copy link
Contributor

cwgoes commented Jul 14, 2018

Maybe running a local test net?

Good idea - also, we need to backport this to v0.21.0 - #1683.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Tested ACK

Merging so Voyager can build (we can definitely test on an internal testnet too).

@cwgoes cwgoes merged commit bb1f1a2 into master Jul 14, 2018
@cwgoes cwgoes deleted the bez/1581-ledger-build branch July 14, 2018 02:17
cwgoes pushed a commit that referenced this pull request Jul 14, 2018
* Merge pull request #1674: Fix Cross Compile Build/Ledger Build Tag
* Merge pull request #1674: Fix Cross Compile Build/Ledger Build Tag
* Remove incorrect Ledger test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants