Rust-Parity zcash: Parity-Zcash — Rust implementation of the Zcash protocol

The Parity Zcash client.

Build Status Snap Status

Gitter Gitter https://gitter.im/paritytech/parity-zcash

Blog: Parity teams up with Zcash Foundation for Parity Zcash client

Installing from source

Installing pzec from source requires rustc and cargo.

Minimal supported version is rustc 1.23.0 (766bd11c8 2018-01-01)

Install rustc and cargo

Both rustc and cargo are a part of rust tool-chain.

An easy way to install the stable binaries for Linux and Mac is to run this in your shell:

curl https://sh.rustup.rs -sSf | sh

Windows binaries can be downloaded from rust-lang website.

Install C and C++ compilers

You will need the cc and gcc compilers to build some of the dependencies.

On macOS

build-essential is a Debian package. On macOS you will need to make sure you have Xcode installed. If you already have Homebrew installed, you probably also already have the Xcode tools installed as well. If not, you can run the command below:

xcode-select --install

On Linux

sudo apt-get update
sudo apt-get install build-essential

Clone and build pzec

Now let's clone pzec and enter it's directory:

git clone https://github.com/paritytech/parity-zcash
cd parity-zcash

# builds pzec in release mode
cargo build -p pzec --release

pzec is now available at ./target/release/pzec.

Installing the snap

In any of the supported Linux distros:

sudo snap install parity-zcash --edge

Running tests

pzec has internal unit tests and it conforms to external integration tests.

Running unit tests

Assuming that repository is already cloned, we can run unit tests with this command:

cargo test --all

Going online

By default parity connects to Zcash seednodes. Full list is here.

To start syncing the main network, just start the client without any arguments:

./target/release/pzec

To start syncing the testnet:

./target/release/pzec --testnet

To not print any syncing progress add --quiet flag:

./target/release/pzec --quiet

Importing zcashd database

It it is possible to import existing zcashd database:

# where $ZCASH_DB is path to your zcashd database. By default:
# on macOS: "/Users/user/Library/Application Support/Zcash"
# on Linux: "~/.zcash"
./target/release/pzec import "$ZCASH_DB/blocks"

By default, import verifies the imported blocks. You can disable this, by adding the --verification-level=none option.

./target/release/pzec --verification-level=none import "$ZCASH_DB/blocks"

Command line interface

Full list of CLI options, which is available under pzec --help: see here

Logging

This is a section only for developers and power users.

You can enable detailed client logging by setting the environment variable RUST_LOG, e.g.,

RUST_LOG=verification=info ./target/release/pzec

pzec started with this environment variable will print all logs coming from verification module with verbosity info or higher. Available log levels are:

  • error
  • warn
  • info
  • debug
  • trace

It's also possible to start logging from multiple modules in the same time:

RUST_LOG=sync=trace,p2p=trace,verification=trace,db=trace ./target/release/pzec

Internal documentation

Once released, pzec documentation will be available here. Meanwhile it's only possible to build it locally:

cd parity-zcash
./tools/doc.sh
open target/doc/pzec/index.html

Comments

  • Do not save empty Sapling commitment tree states in DB
    Do not save empty Sapling commitment tree states in DB

    Mar 5, 2019

    ...until Sapling is activated. Origin: description of #47

    In-code TODO: https://github.com/paritytech/parity-zcash/pull/47/files#diff-e84e7a8516714d5178d4d3863a4ea5a0R308

    F7-optimisation ? P7-nicetohave ? 
    Reply
  • Constructing groth16 proofs
    Constructing groth16 proofs

    Mar 20, 2019

    • first for test
    • then for rpc
    Reply
  • Very short test chain
    Very short test chain

    Apr 16, 2019

    • regtest-like short chain which covers all (or most) key consensus features
    • to be served as an integration test
    • is fed directly to sync/import code
    • maybe shared between implementations (@kaplannie ?)
    • state-machine-like of acceptance evaluation
    Reply
  • Multiple errors on sync
    Multiple errors on sync

    Apr 17, 2019

    I have finally imported the blockchain :)

    Now, when I run pzec, I see multiple errors.

    2019-04-17 06:36:30  WARN sync Disconnecting from peer#1 due to misbehavior: Got 'headers' message without known blocks
    2019-04-17 06:36:30  WARN sync Last peer was marked as non-useful. Moving to saturated state.
    2019-04-17 06:36:39  WARN sync Last peer was marked as non-useful. Moving to saturated state.
    2019-04-17 06:36:39  WARN sync Disconnecting from peer#4 due to misbehavior: Got 'headers' message without known blocks
    2019-04-17 06:36:39  WARN sync Last peer was marked as non-useful. Moving to saturated state.
    2019-04-17 06:36:49  WARN sync Failed to get requested block from peer#3 in 5.68 seconds.
    2019-04-17 06:36:49  WARN sync Too many failures for peer#3. Excluding from synchronization.
    2019-04-17 06:36:49  WARN sync Disconnecting from peer#3 due to misbehavior: Too many failures.
    2019-04-17 06:36:49  WARN sync Too many header failures for peer#3. Excluding from synchronization.
    2019-04-17 06:36:50  WARN sync Previous header of the first header from peer#6 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:36:50  WARN sync Disconnecting from peer#6 due to misbehavior: Too many failures.
    2019-04-17 06:36:50  WARN sync Previous header of the first header from peer#7 `headers` message is unknown. First: 0004b371c02c41c61c189ce04ac147220daf796e9a60ce90cfee31e5a71dda2d. Previous: 0007104ccda289427919efc39dc9e4d499804b7bebc22df55f8b834301260602
    2019-04-17 06:36:50  WARN sync Disconnecting from peer#7 due to misbehavior: Too many failures.
    2019-04-17 06:37:23  WARN sync Disconnecting from peer#12 due to misbehavior: Error verifying header 001bb0d07e628cccfbf2998d27bf18bd0463a44b64bba5664ef786fa17bd5170 from `headers`: "Pow"
    2019-04-17 06:37:31  WARN sync Previous header of the first header from peer#14 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:37:31  WARN sync Disconnecting from peer#14 due to misbehavior: Too many failures.
    2019-04-17 06:37:40  WARN sync Previous header of the first header from peer#15 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:37:40  WARN sync Disconnecting from peer#15 due to misbehavior: Too many failures.
    2019-04-17 06:37:44  INFO sync Processed 120 blocks in 61.15 seconds (1.96 blk/s).	Peers: 6 (act: 6, idl: 0, bad: 1).	Chain: [sch:84 > req:0 > vfy:1064 > db:515558]
    2019-04-17 06:37:49  WARN sync Too many header failures for peer#13. Excluding from synchronization.
    2019-04-17 06:37:49  WARN sync Disconnecting from peer#13 due to misbehavior: Too many header failures.
    2019-04-17 06:37:50  WARN sync Previous header of the first header from peer#16 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:37:50  WARN sync Disconnecting from peer#16 due to misbehavior: Too many failures.
    2019-04-17 06:37:51  WARN sync Previous header of the first header from peer#19 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:37:51  WARN sync Disconnecting from peer#19 due to misbehavior: Too many failures.
    2019-04-17 06:37:51  WARN sync Previous header of the first header from peer#18 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:37:51  WARN sync Disconnecting from peer#18 due to misbehavior: Too many failures.
    2019-04-17 06:37:51  WARN sync Previous header of the first header from peer#17 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:37:51  WARN sync Disconnecting from peer#17 due to misbehavior: Too many failures.
    2019-04-17 06:38:00  WARN sync Previous header of the first header from peer#21 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:38:00  WARN sync Disconnecting from peer#21 due to misbehavior: Too many failures.
    2019-04-17 06:38:00  WARN sync Previous header of the first header from peer#20 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:38:00  WARN sync Disconnecting from peer#20 due to misbehavior: Too many failures.
    2019-04-17 06:38:00  WARN sync Previous header of the first header from peer#22 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:38:00  WARN sync Disconnecting from peer#22 due to misbehavior: Too many failures.
    2019-04-17 06:38:20  WARN sync Previous header of the first header from peer#25 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:38:20  WARN sync Disconnecting from peer#25 due to misbehavior: Too many failures.
    2019-04-17 06:38:20  WARN sync Previous header of the first header from peer#24 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:38:20  WARN sync Disconnecting from peer#24 due to misbehavior: Too many failures.
    2019-04-17 06:38:20  WARN sync Disconnecting from peer#26 due to misbehavior: Provided after dead-end block 001bb0d07e628cccfbf2998d27bf18bd0463a44b64bba5664ef786fa17bd5170
    2019-04-17 06:38:30  WARN sync Previous header of the first header from peer#28 `headers` message is unknown. First: 0003eb875fc001da4a57de8465f68a2730c24ca086f37c6f14780ac9ee3ea3d5. Previous: 00052461a5006c2e3b74ce48992a08695607912d5604c3eb8da25749b0900444
    2019-04-17 06:38:30  WARN sync Disconnecting from peer#28 due to misbehavior: Too many failures.
    2019-04-17 06:38:44  INFO sync Switched to saturated state.	Chain: [sch:0 > req:0 > vfy:1027 > db:515679]
    2019-04-17 06:39:09  WARN sync Disconnecting from peer#30 due to misbehavior: Got 'headers' message without known blocks
    2019-04-17 06:39:09  WARN sync Last peer was marked as non-useful. Moving to saturated state.
    2019-04-17 06:41:10  WARN sync Disconnecting from peer#32 due to misbehavior: Got 'headers' message without known blocks
    2019-04-17 06:41:10  WARN sync Last peer was marked as non-useful. Moving to saturated state.
    

    Is this normal?

    F3-annoyance ? P7-nicetohave ? 
    Reply
  • Thread 'Heavy verification' panicked
    Thread 'Heavy verification' panicked

    May 24, 2019

    2019-05-24 13:39:03  INFO sync Processed 3 blocks in 65.38 seconds (0.05 blk/s).	Peers: 10 (act: 0, idl: 10, bad: 0).	Chain: [sch:3040 > req:0 > vfy:1127 > db:533648]
    thread 'Heavy verification' panicked at 'internal error: entered unreachable code: Trying to re-verify known block: 0000000000bc082bfee78ba6f8b88215e6a2c1c9ed8afeab1ca6efd1801fa91f', verification/src/chain_verifier.rs:56:5
    stack backtrace:
       0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
                 at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
       1: std::sys_common::backtrace::print
                 at src/libstd/sys_common/backtrace.rs:70
                 at src/libstd/sys_common/backtrace.rs:58
       2: std::panicking::default_hook::{{closure}}
                 at src/libstd/panicking.rs:200
       3: std::panicking::default_hook
                 at src/libstd/panicking.rs:215
       4: <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
                 at src/libstd/panicking.rs:478
       5: std::panicking::continue_panic_fmt
                 at src/libstd/panicking.rs:385
       6: std::panicking::try::do_call
                 at src/libstd/panicking.rs:340
    Abort trap: 6
    
    F1-panic ? 
    Reply
  • no peers for the testnet
    no peers for the testnet

    Oct 7, 2019

    ❯ RUST_LOG=info RUST_BACKTRACE=1 ./target/release/pzec --testnet 
    2019-10-07 16:02:13  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:02:13  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:02:23  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:02:23  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:02:33  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:02:33  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:02:43  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:02:43  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:02:53  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:02:53  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:03:03  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:03:03  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:03:13  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:03:13  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:03:23  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:03:23  INFO p2p::p2p Outbound connections: (0/10)
    2019-10-07 16:03:33  INFO p2p::p2p Inbound connections: (0/10)
    2019-10-07 16:03:33  INFO p2p::p2p Outbound connections: (0/10)
    
    ~/.opt/parity-zcash master 1m 42s
    ❯ git log -n 1
    commit 0f6d26e048a56260b77400fc31986e405947e717 (HEAD -> master, origin/master, origin/HEAD)
    Merge: 94bd4a31 9e791e3d
    Author: Deirdre Connolly <[email protected]>
    Date:   Mon Jun 10 20:38:44 2019 -0400
    
        Merge pull request #132 from dconnolly/dependabot/cargo/slab-0.4.2
        
        Bump slab from 0.4.1 to 0.4.2
    
    F3-annoyance ? M2-config ? 
    Reply
  • Ignore zero-filled gaps in blk files
    Ignore zero-filled gaps in blk files

    Apr 11, 2019

    closes #82

    Looks like the blk-files structure slightly differs from what we were assuming earlier. Here you can find file having extra 7 zero bytes between blocks #248859 and #248860. Parsing blocks index file (the file that has pointers to blocks positions in blk files) has never been in our plans. So the only solution I could think of is to skip inter-block bytes until first non-zero byte is met. Block is always prefixed by magic and, iirc, magic is designed not to have zero bytes in it (on all BTC-like chains) => that should work (only if gaps are zero-filled, though).

    A0-pleasereview ? M4-core ⛓ 
    Reply
  • Mark allow(dead_code) on compute_hsig() for now
    Mark allow(dead_code) on compute_hsig() for now

    Mar 29, 2019

    Quiets the only warning from cargo test.

    Reply
  • Update + read + verfiy sapling commitment tree where required
    Update + read + verfiy sapling commitment tree where required

    Mar 5, 2019

    closes #27

    Could be reviewed commit-by-commit:

    • this one - updates commitment tree when block is inserted into db;
    • this one - introduces last (needs double check when we'll close #3) Sapling-related verification step - checks that final_sapling_root field of the block header matches computed;
    • this one - reads Sapling commitment tree state when getblocktemplate RPC is executed.

    There's a single quite important TODO left there - we do not need to save default (empty) commitment tree states until Sapling is really activated. This would either require db level to know about ConsensusParams or some other heuristic (probably - return default state if there's no state in db OR do not save state until non-default state is first met). I'll file a separate issue about that.

    A0-pleasereview ? 
    Reply
  • Cannot append block: Verification(
    Cannot append block: Verification("Transaction(1, Signature(0, EvalFalse))")

    Apr 11, 2019

    2019-04-11 22:11:00  TRACE import::blk Opening blk file: "/Users/rex/Library/Application Support/Zcash/blocks/blk00129.dat"
    2019-04-11 22:22:58  INFO sync Imported 413000 blocks
    2019-04-11 22:40:55  INFO sync Imported 414000 blocks
    2019-04-11 23:00:30  INFO sync Imported 415000 blocks
    2019-04-11 23:19:04  INFO sync Imported 416000 blocks
    2019-04-11 23:36:06  INFO sync Imported 417000 blocks
    2019-04-11 23:53:53  INFO sync Imported 418000 blocks
    2019-04-12 00:14:09  INFO sync Imported 419000 blocks
    Cannot append block: Verification("Transaction(1, Signature(0, EvalFalse))")
    

    https://www.dropbox.com/s/v3uk6lo9y99ll4z/blk00129.dat?dl=0

    F0-consensus ? 
    Reply
  • Thread panic at block 14b054be76b515b12efcfdfd6e5d6bfe39988f937f48768c61e5c01600000000
    Thread panic at block 14b054be76b515b12efcfdfd6e5d6bfe39988f937f48768c61e5c01600000000

    Mar 11, 2019

    git @ b0ebed0

    Reproducibility: always

    Steps: pzec import /Zcash/blocks

    What happened:

    ...
    2019-03-11 01:29:15  INFO sync Imported 230000 blocks
    2019-03-11 01:30:40  INFO sync Imported 231000 blocks
    2019-03-11 01:32:00  INFO sync Imported 232000 blocks
    2019-03-11 01:33:44  INFO sync Imported 233000 blocks
    2019-03-11 01:35:39  INFO sync Imported 234000 blocks
    2019-03-11 01:37:24  INFO sync Imported 235000 blocks
    thread 'main' panicked at 'Corrupted database - no sprout root for block 14b054be76b515b12efcfdfd6e5d6bfe39988f937f48768c61e5c01600000000', src/libcore/option.rs:1008:5
    stack backtrace:
       0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
                 at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
       1: std::sys_common::backtrace::print
                 at src/libstd/sys_common/backtrace.rs:71
                 at src/libstd/sys_common/backtrace.rs:59
       2: std::panicking::default_hook::{{closure}}
                 at src/libstd/panicking.rs:211
       3: std::panicking::default_hook
                 at src/libstd/panicking.rs:227
       4: <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get
                 at src/libstd/panicking.rs:491
       5: std::panicking::continue_panic_fmt
                 at src/libstd/panicking.rs:398
       6: std::panicking::try::do_call
                 at src/libstd/panicking.rs:325
       7: core::ptr::real_drop_in_place
                 at src/libcore/panicking.rs:95
       8: <T as core::any::Any>::get_type_id
                 at src/libcore/option.rs:1008
    Abort trap: 6
    

    Expected result: All blocks are imported.

    Reply
  • Update binary name and paths
    Update binary name and paths

    Dec 17, 2018

                                                                                                                                                                                                           
    Reply