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

tests(rpc): Add fixed test vectors for z_getsubtreesbyindex from zcashd to zebra #7515

Merged
merged 12 commits into from
Sep 20, 2023

Conversation

oxarbitrage
Copy link
Contributor

@oxarbitrage oxarbitrage commented Sep 9, 2023

Depends-On: #7555

Motivation

We want to test the z_getsubtreesbyindex against fixed test vectors obtained from zcashd and see if they match zebra.

Close #7446

Solution

The idea is to add json outputs from zcashd into the zebra-test crate and then create a test that could compare this fixed outputs with answers from zebrad made in real time.

In order to test this in high heights we need a pretty much synchronized cache state for zebra.

Locally, i run this test as:

export ZEBRA_CACHED_STATE_DIR="/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zebra"
export RUST_LOG="info"
cargo test rpc_z_getsubtreesbyindex_zcashd_test_vectors -- --nocapture --ignored

Review

This is not ready yet because i don't have the right outputs from zcashd. In order to use the getsubtreesbyindex i had to reindex and that actually ended up downloading all the blocks again so i have a couple of days at least to be in sync again with zcashd.

But i pushed so other people can take a look to the overall structure and let me know if this is a good or bad idea. Thanks!

Reviewer Checklist

  • Will the PR name make sense to users?
    • Does it need extra CHANGELOG info? (new features, breaking changes, large changes)
  • Are the PR labels correct?
  • Does the code do what the ticket and PR says?
    • Does it change concurrent code, unsafe code, or consensus rules?
  • How do you know it works? Does it have tests?

Follow Up Work

@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Sep 9, 2023
teor2345

This comment was marked as resolved.

@teor2345

This comment was marked as resolved.

@oxarbitrage

This comment was marked as resolved.

@oxarbitrage
Copy link
Contributor Author

I added the tests mentioned here to this PR.

All the responses for the test vectors added by now are the same as zcashd:

oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ ./zcash-rpc-diff 6666 z_getsubtreesbyindex sapling 0 1
Checking first node release info...
Checking second node release info...
Connected to zebrad v1.2.0+24.g199c2bb.modified (port 6666) and zcashd v5.6.1 (./zcash-cli -rpccookiefile=/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash/.cookie zcash.conf port).

Checking zebrad v1.2.0+24.g199c2bb.modified network and tip height...
Checking zcashd v5.6.1 network and tip height...

WARNING: comparing RPC responses from different heights:
zebrad v1.2.0+24.g199c2bb.modified is at: 2228238
zcashd v5.6.1 is at: 2228239

Request:
z_getsubtreesbyindex sapling 0 1

Querying zebrad v1.2.0+24.g199c2bb.modified main chain at height >=2228238...

real	0m0,002s
user	0m0,002s
sys	0m0,000s

Querying zcashd v5.6.1 main chain at height >=2228239...

real	0m0,006s
user	0m0,005s
sys	0m0,000s


Response diff between zebrad v1.2.0+24.g199c2bb.modified and zcashd v5.6.1:
RPC responses were identical

/tmp/tmp.R63LEBv9BJ.rpc-diff/zebrad-main-2228238-z_getsubtreesbyindex.json, limited to 40 lines:
{
  "pool": "sapling",
  "start_index": 0,
  "subtrees": [
    {
      "root": "754bb593ea42d231a7ddf367640f09bbf59dc00f2c1d2003cc340e0c016b5b13",
      "end_height": 558822
    }
  ]
}
oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ ./zcash-rpc-diff 6666 z_getsubtreesbyindex sapling 0 11
Checking first node release info...
Checking second node release info...
Connected to zebrad v1.2.0+24.g199c2bb.modified (port 6666) and zcashd v5.6.1 (./zcash-cli -rpccookiefile=/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash/.cookie zcash.conf port).

Checking zebrad v1.2.0+24.g199c2bb.modified network and tip height...
Checking zcashd v5.6.1 network and tip height...

WARNING: comparing RPC responses from different heights:
zebrad v1.2.0+24.g199c2bb.modified is at: 2228238
zcashd v5.6.1 is at: 2228239

Request:
z_getsubtreesbyindex sapling 0 11

Querying zebrad v1.2.0+24.g199c2bb.modified main chain at height >=2228238...

real	0m0,002s
user	0m0,001s
sys	0m0,000s

Querying zcashd v5.6.1 main chain at height >=2228239...

real	0m0,002s
user	0m0,000s
sys	0m0,001s


Response diff between zebrad v1.2.0+24.g199c2bb.modified and zcashd v5.6.1:
RPC responses were identical

/tmp/tmp.g132P9v08V.rpc-diff/zebrad-main-2228238-z_getsubtreesbyindex.json, limited to 40 lines:
{
  "pool": "sapling",
  "start_index": 0,
  "subtrees": [
    {
      "root": "754bb593ea42d231a7ddf367640f09bbf59dc00f2c1d2003cc340e0c016b5b13",
      "end_height": 558822
    },
    {
      "root": "03654c3eacbb9b93e122cf6d77b606eae29610f4f38a477985368197fd68e02d",
      "end_height": 670209
    },
    {
      "root": "e2bf698f5ac10b44da560d11a5e1d5c191a82a968a2be0a6948aa8748b545160",
      "end_height": 780364
    },
    {
      "root": "e71be1fd3963a2d700ed374d01fdd4a70d8dda8189a8f6602e5fe66c2c66a11d",
      "end_height": 839994
    },
...
      "end_height": 1056197
    },
    {
      "root": "163838d11a0525898f410397ae6ec627fa18b3184a021e088806947b3c5ca718",
      "end_height": 1109360
    },
    {
      "root": "089a1f9d50a037cc66aba4400b1703bcbb66f5f2993fd0dd3bb726e359409167",
      "end_height": 1169471
    },
    {
      "root": "0fc8a6ad74e65764d9bc2fcd13866b994731dfda821e6618a1a308bb1eccf51a",
      "end_height": 1256932
    },
    {
      "root": "cdd92a1e884cf1914dae8345423203832ec7bbf9d95ae50b82e4327b39d6d912",
      "end_height": 1363036
    }
  ]
}
oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ ./zcash-rpc-diff 6666 z_getsubtreesbyindex sapling 17 1
Checking first node release info...
Checking second node release info...
Connected to zebrad v1.2.0+24.g199c2bb.modified (port 6666) and zcashd v5.6.1 (./zcash-cli -rpccookiefile=/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash/.cookie zcash.conf port).

Checking zebrad v1.2.0+24.g199c2bb.modified network and tip height...
Checking zcashd v5.6.1 network and tip height...

WARNING: comparing RPC responses from different heights:
zebrad v1.2.0+24.g199c2bb.modified is at: 2228238
zcashd v5.6.1 is at: 2228239

Request:
z_getsubtreesbyindex sapling 17 1

Querying zebrad v1.2.0+24.g199c2bb.modified main chain at height >=2228238...

real	0m0,004s
user	0m0,004s
sys	0m0,000s

Querying zcashd v5.6.1 main chain at height >=2228239...

real	0m0,002s
user	0m0,002s
sys	0m0,000s


Response diff between zebrad v1.2.0+24.g199c2bb.modified and zcashd v5.6.1:
RPC responses were identical

/tmp/tmp.QvmdYXCO7r.rpc-diff/zebrad-main-2228238-z_getsubtreesbyindex.json, limited to 40 lines:
{
  "pool": "sapling",
  "start_index": 17,
  "subtrees": [
    {
      "root": "89ac51fcf846eacb2e7bca32d9bf3793792d2d952c1fec11e52b56d7674c1c36",
      "end_height": 1703171
    }
  ]
}
oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ ./zcash-rpc-diff 6666 z_getsubtreesbyindex sapling 1090 6
Checking first node release info...
Checking second node release info...
Connected to zebrad v1.2.0+24.g199c2bb.modified (port 6666) and zcashd v5.6.1 (./zcash-cli -rpccookiefile=/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash/.cookie zcash.conf port).

Checking zebrad v1.2.0+24.g199c2bb.modified network and tip height...
Checking zcashd v5.6.1 network and tip height...

WARNING: comparing RPC responses from different heights:
zebrad v1.2.0+24.g199c2bb.modified is at: 2228238
zcashd v5.6.1 is at: 2228239

Request:
z_getsubtreesbyindex sapling 1090 6

Querying zebrad v1.2.0+24.g199c2bb.modified main chain at height >=2228238...

real	0m0,005s
user	0m0,000s
sys	0m0,004s

Querying zcashd v5.6.1 main chain at height >=2228239...

real	0m0,030s
user	0m0,003s
sys	0m0,000s


Response diff between zebrad v1.2.0+24.g199c2bb.modified and zcashd v5.6.1:
RPC responses were identical

/tmp/tmp.R7U1U2vWZZ.rpc-diff/zebrad-main-2228238-z_getsubtreesbyindex.json, limited to 40 lines:
{
  "pool": "sapling",
  "start_index": 1090,
  "subtrees": [
    {
      "root": "507ebccc63e2ca45bd254975ca2b75f2a221a0167d514077472dc7ef1e04a638",
      "end_height": 1857525
    },
    {
      "root": "0240b333e243a38583b692b9ce5b2fbdfde41cfdd3f3067b5c7d94fda5387666",
      "end_height": 1860908
    },
    {
      "root": "bf299f8446bea806854e9b363ed890f83423cececd53293c81df92ff112aa43f",
      "end_height": 1866377
    },
    {
      "root": "4a4778e6242b3e708f040b4a373c8cdedd14c5c415ab20f32e46430507b1a346",
      "end_height": 1889548
    },
    {
      "root": "c1cffa22d637cb194102a1b02a57d2b47c67f54094f6773a38b2e53d3becb45f",
      "end_height": 1997495
    },
    {
      "root": "0ee7328354ad588ee9581b25a3e2b94dbb03db647b79538c8805d793c61b822d",
      "end_height": 2056616
    }
  ]
}
oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ ./zcash-rpc-diff 6666 z_getsubtreesbyindex orchard 0 1
Checking first node release info...
Checking second node release info...
Connected to zebrad v1.2.0+24.g199c2bb.modified (port 6666) and zcashd v5.6.1 (./zcash-cli -rpccookiefile=/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash/.cookie zcash.conf port).

Checking zebrad v1.2.0+24.g199c2bb.modified network and tip height...
Checking zcashd v5.6.1 network and tip height...

WARNING: comparing RPC responses from different heights:
zebrad v1.2.0+24.g199c2bb.modified is at: 2228238
zcashd v5.6.1 is at: 2228239

Request:
z_getsubtreesbyindex orchard 0 1

Querying zebrad v1.2.0+24.g199c2bb.modified main chain at height >=2228238...

real	0m0,002s
user	0m0,002s
sys	0m0,000s

Querying zcashd v5.6.1 main chain at height >=2228239...

real	0m0,002s
user	0m0,001s
sys	0m0,000s


Response diff between zebrad v1.2.0+24.g199c2bb.modified and zcashd v5.6.1:
RPC responses were identical

/tmp/tmp.Yijqpe8TRh.rpc-diff/zebrad-main-2228238-z_getsubtreesbyindex.json, limited to 40 lines:
{
  "pool": "orchard",
  "start_index": 0,
  "subtrees": [
    {
      "root": "d4e323b3ae0cabfb6be4087fec8c66d9a9bbfc354bf1d9588b6620448182063b",
      "end_height": 1707429
    }
  ]
}
oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ ./zcash-rpc-diff 6666 z_getsubtreesbyindex orchard 338 1
Checking first node release info...
Checking second node release info...
Connected to zebrad v1.2.0+24.g199c2bb.modified (port 6666) and zcashd v5.6.1 (./zcash-cli -rpccookiefile=/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash/.cookie zcash.conf port).

Checking zebrad v1.2.0+24.g199c2bb.modified network and tip height...
Checking zcashd v5.6.1 network and tip height...

WARNING: comparing RPC responses from different heights:
zebrad v1.2.0+24.g199c2bb.modified is at: 2228238
zcashd v5.6.1 is at: 2228239

Request:
z_getsubtreesbyindex orchard 338 1

Querying zebrad v1.2.0+24.g199c2bb.modified main chain at height >=2228238...

real	0m0,002s
user	0m0,000s
sys	0m0,001s

Querying zcashd v5.6.1 main chain at height >=2228239...

real	0m0,002s
user	0m0,001s
sys	0m0,000s


Response diff between zebrad v1.2.0+24.g199c2bb.modified and zcashd v5.6.1:
RPC responses were identical

/tmp/tmp.aZVC2z7zpl.rpc-diff/zebrad-main-2228238-z_getsubtreesbyindex.json, limited to 40 lines:
{
  "pool": "orchard",
  "start_index": 338,
  "subtrees": [
    {
      "root": "52c8d1ea6ef49c6e0d6bb6fef4520e1e3851895a04b52bfac1b1cc0fbbb3f709",
      "end_height": 1888929
    }
  ]
}
oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ ./zcash-rpc-diff 6666 z_getsubtreesbyindex orchard 585 1
Checking first node release info...
Checking second node release info...
Connected to zebrad v1.2.0+24.g199c2bb.modified (port 6666) and zcashd v5.6.1 (./zcash-cli -rpccookiefile=/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash/.cookie zcash.conf port).

Checking zebrad v1.2.0+24.g199c2bb.modified network and tip height...
Checking zcashd v5.6.1 network and tip height...

WARNING: comparing RPC responses from different heights:
zebrad v1.2.0+24.g199c2bb.modified is at: 2228238
zcashd v5.6.1 is at: 2228240

Request:
z_getsubtreesbyindex orchard 585 1

Querying zebrad v1.2.0+24.g199c2bb.modified main chain at height >=2228238...

real	0m0,002s
user	0m0,001s
sys	0m0,000s

Querying zcashd v5.6.1 main chain at height >=2228240...

real	0m0,002s
user	0m0,000s
sys	0m0,001s


Response diff between zebrad v1.2.0+24.g199c2bb.modified and zcashd v5.6.1:
RPC responses were identical

/tmp/tmp.9jfRh8iB2V.rpc-diff/zebrad-main-2228238-z_getsubtreesbyindex.json, limited to 40 lines:
{
  "pool": "orchard",
  "start_index": 585,
  "subtrees": [
    {
      "root": "43c86869520ada7a2cd0deeecf3650f337f90bd4328b16144b0a278ad9fdaa08",
      "end_height": 2000126
    }
  ]
}
oxarbitrage@oxarbitrage:/media/oxarbitrage/4eb53770-4e4f-4d80-a830-0914f3f5b89a/chain/zcash$ 

@oxarbitrage oxarbitrage marked this pull request as ready for review September 16, 2023 00:25
@oxarbitrage oxarbitrage requested review from a team as code owners September 16, 2023 00:25
@oxarbitrage oxarbitrage requested review from teor2345 and removed request for a team September 16, 2023 00:25
@oxarbitrage oxarbitrage self-assigned this Sep 16, 2023
@oxarbitrage oxarbitrage added C-testing Category: These are tests and removed C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG labels Sep 16, 2023
@oxarbitrage oxarbitrage added A-rpc Area: Remote Procedure Call interfaces lightwalletd any work associated with lightwalletd P-Medium ⚡ labels Sep 16, 2023
@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Sep 16, 2023
@teor2345

This comment was marked as resolved.

@teor2345

This comment was marked as resolved.

teor2345
teor2345 previously approved these changes Sep 17, 2023
Copy link
Contributor

@teor2345 teor2345 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!

There's a few tricky things about how the test is run, and when we run it. I think I've fixed them in PR #7566, but we'll need to do something similar here.

docker/entrypoint.sh Outdated Show resolved Hide resolved
zebrad/Cargo.toml Show resolved Hide resolved
zebrad/tests/acceptance.rs Outdated Show resolved Hide resolved
zebrad/tests/acceptance.rs Show resolved Hide resolved
zebrad/tests/acceptance.rs Show resolved Hide resolved
@oxarbitrage
Copy link
Contributor Author

Locally this test hanged with the latest changes but i want to check in the CI.

docker/entrypoint.sh Outdated Show resolved Hide resolved
docker/entrypoint.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

Looks like that worked!

mergify bot added a commit that referenced this pull request Sep 20, 2023
@mergify mergify bot merged commit 80da28b into main Sep 20, 2023
@mergify mergify bot deleted the issue7446 branch September 20, 2023 23:40
arya2 pushed a commit that referenced this pull request Sep 29, 2023
…ashd to zebra (#7515)

* add fixed test vectors for `z_getsubtreesbyindex`

* change to snapshots

* add test to docker

* remove assert lines from snapshots

* add more tests

* change test description

* change test name

* run both tests together

* wait for state version update in test

* Run one test at a time to avoid state locking issues

---------

Co-authored-by: teor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Area: Remote Procedure Call interfaces C-testing Category: These are tests C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG lightwalletd any work associated with lightwalletd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add format checks with fixed subtree values from zcashd
2 participants