Building Libra in OSX

Building Libra in OSX

So I tried building Libra in my macbook laptop, and it was pretty straightforward. And if you encounter any issues while building it, you can search for it in the issues section of Libra's github repo.

Fair warning though, running the build takes a while. So if you get bored waiting for your commands to finish, you might want to read up on its white paper - https://developers.libra.org/docs/assets/papers/the-libra-blockchain.pdf

Warning #2: Libra is not really cryptocurrency in the "traditional" sense. Its blockchain is not a chain of blocks (weird right?), not really decentralized, cant be mined, and all other weird stuff. But who knows, maybe this approach is what would finally work!

Anyway.....

Here are the commands that I executed

$ git clone https://github.com/libra/libra.git

$ cd libra

$ bash ./scripts/dev_setup.sh

$ cargo build

Nice!!! But let's see if the tests pass

$ cargo test 

When running cargo test though, I encountered these errors

...
thread 'chained_bft::chained_bft_smr_test::basic_start_test' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5

---- chained_bft::liveness::rotating_proposer_test::test_fixed_proposer stdout ----
thread 'chained_bft::liveness::rotating_proposer_test::test_fixed_proposer' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5

---- chained_bft::liveness::rotating_proposer_test::test_rotating_proposer stdout ----
thread 'chained_bft::liveness::rotating_proposer_test::test_rotating_proposer' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5

---- chained_bft::liveness::rotating_proposer_test::test_rotating_proposer_with_three_contiguous_rounds stdout ----
thread 'chained_bft::liveness::rotating_proposer_test::test_rotating_proposer_with_three_contiguous_rounds' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5

---- chained_bft::network_tests::test_network_api stdout ----
thread 'chained_bft::network_tests::test_network_api' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5

---- chained_bft::network_tests::test_rpc stdout ----
thread 'chained_bft::network_tests::test_rpc' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5

---- state_synchronizer::sync_test::test_download_retry stdout ----
thread 'state_synchronizer::sync_test::test_download_retry' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5

---- state_synchronizer::sync_test::test_download_failure stdout ----
thread 'state_synchronizer::sync_test::test_download_failure' panicked at 'Failed to create Tokio runtime!: Os { code: 24, kind: Other, message: "Too many open files" }', src/libcore/result.rs:999:5


failures:
    chained_bft::chained_bft_smr_test::basic_block_retrieval
    chained_bft::chained_bft_smr_test::basic_commit_and_restart
    chained_bft::chained_bft_smr_test::basic_start_test
    chained_bft::chained_bft_smr_test::basic_state_sync
    chained_bft::chained_bft_smr_test::block_retrieval_with_timeout
    chained_bft::chained_bft_smr_test::start_with_proposal_test
    chained_bft::chained_bft_smr_test::state_sync_on_timeout
    chained_bft::event_processor_test::basic_restart_test
    chained_bft::event_processor_test::process_block_retrieval
    chained_bft::event_processor_test::process_new_round_msg_test
    chained_bft::event_processor_test::process_old_proposal_test
    chained_bft::event_processor_test::process_proposer_mismatch_test
    chained_bft::event_processor_test::process_round_mismatch_test
    chained_bft::event_processor_test::process_successful_proposal_test
    chained_bft::event_processor_test::process_timeout_certificate_test
    chained_bft::event_processor_test::process_votes_basic_test
    chained_bft::liveness::local_pacemaker_test::test_basic_qc
    chained_bft::liveness::local_pacemaker_test::test_basic_timeout
    chained_bft::liveness::local_pacemaker_test::test_timeout_certificate
    chained_bft::liveness::rotating_proposer_test::test_fixed_proposer
    chained_bft::liveness::rotating_proposer_test::test_rotating_proposer
    chained_bft::liveness::rotating_proposer_test::test_rotating_proposer_with_three_contiguous_rounds
    chained_bft::network_tests::test_network_api
    chained_bft::network_tests::test_rpc
    state_synchronizer::sync_test::test_download_failure
    state_synchronizer::sync_test::test_download_retry

test result: FAILED. 45 passed; 26 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '-p consensus --lib'

Ok, test failures. Let's see what we have here.

The key phrase there that caught my eye was "Too many open files", which I then looked up in Libra's github repo. This then lead me to https://github.com/libra/libra/issues/81. To fix (i.e. workaround), you would need to increase the number of descriptors

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1418
virtual memory          (kbytes, -v) unlimited

From there, my open files (-n) is only 256. In the github issue, it was recommended to increase it to 4096.

$ ulimit -n 4096

After executing that, I got it to pass!

Viola! Works!

So what's next? - I guess I'll try making a transaction - https://developers.libra.org/docs/my-first-transaction ;)