Commit Graph

2768 Commits

Author SHA1 Message Date
Deirdre Connolly 53067d7370 Update comment to doc comment
Co-authored-by: teor <teor@riseup.net>
2021-06-30 16:26:08 -04:00
Deirdre Connolly 2734357671 Remove empty doc comment line
Co-authored-by: teor <teor@riseup.net>
2021-06-30 16:26:08 -04:00
Deirdre Connolly d5687720c2 Batch match and multiscalar multiplication for redpallas
Resolves #2098
2021-06-30 16:26:08 -04:00
dependabot[bot] b59121b09e build(deps): bump indexmap from 1.6.2 to 1.7.0
Bumps [indexmap](https://github.com/bluss/indexmap) from 1.6.2 to 1.7.0.
- [Release notes](https://github.com/bluss/indexmap/releases)
- [Commits](https://github.com/bluss/indexmap/compare/1.6.2...1.7.0)

---
updated-dependencies:
- dependency-name: indexmap
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-30 13:36:35 -04:00
dependabot[bot] 83876da183 build(deps): bump uint from 0.9.0 to 0.9.1
Bumps [uint](https://github.com/paritytech/parity-common) from 0.9.0 to 0.9.1.
- [Release notes](https://github.com/paritytech/parity-common/releases)
- [Commits](https://github.com/paritytech/parity-common/compare/uint-v0.9.0...uint-v0.9.1)

---
updated-dependencies:
- dependency-name: uint
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-30 13:28:18 -04:00
Conrado Gouvea c101c12e5f
return errors in state methods (#2417) 2021-06-30 13:52:31 +10:00
Janito Vaqueiro Ferreira Filho b68202c68a
Security: Zebra should stop gossiping unreachable addresses to other nodes, Action: re-deploy all nodes (#2392)
* Rename some methods and constants for clarity

Using the following commands:

```
fastmod '\bis_ready_for_attempt\b' is_ready_for_connection_attempt
  # One instance required a tweak, because of the ASCII diagram.
fastmod '\bwas_recently_live\b' has_connection_recently_responded
fastmod '\bwas_recently_attempted\b' was_connection_recently_attempted
fastmod '\bwas_recently_failed\b' has_connection_recently_failed
fastmod '\bLIVE_PEER_DURATION\b' MIN_PEER_RECONNECTION_DELAY
```

* Use `Instant::elapsed` for conciseness

Instead of `Instant::now().saturating_duration_since`. They're both
equivalent, and `elapsed` only panics if the `Instant` is somehow
synthetically generated.

* Allow `Duration32` to be created in other crates

Export the `Duration32` from the `zebra_chain::serialization` module.

* Add some new `Duration32` constructors

Create some helper `const` constructors to make it easy to create
constant durations. Add methods to create a `Duration32` from seconds,
minutes and hours.

* Avoid gossiping unreachable peers

When sanitizing the list of peers to gossip, remove those that we
haven't seen in more than three hours.

* Test if unreachable addresses aren't gossiped

Create a property test with random addreses inserted into an
`AddressBook`, and verify that the sanitized list of addresses does not
contain any addresses considered unreachable.

* Test if new alternate address isn't gossipable

Create a new alternate peer, because that type of `MetaAddr` does not
have `last_response` or `untrusted_last_seen` times. Verify that the
peer is not considered gossipable.

* Test if local listener is gossipable

The `MetaAddr` representing the local peer's listening address should
always be considered gossipable.

* Test if gossiped peer recently seen is gossipable

Create a `MetaAddr` representing a gossiped peer that was reported to be
seen recently. Check that the peer is considered gossipable.

* Test peer reportedly last seen in the future

Create a `MetaAddr` representing a peer gossiped and reported to have
been last seen in a time that's in the future. Check that the peer is
considered gossipable, to check that the fallback calculation is working
as intended.

* Test gossiped peer reportedly seen long ago

Create a `MetaAddr` representing a gossiped peer that was reported to
last have been seen a long time ago. Check that the peer is not
considered gossipable.

* Test if just responded peer is gossipable

Create a `MetaAddr` representing a peer that has just responded and
check that it is considered gossipable.

* Test if recently responded peer is gossipable

Create a `MetaAddr` representing a peer that last responded within the
duration a peer is considered reachable. Verify that the peer is
considered gossipable.

* Test peer that responded long ago isn't gossipable

Create a `MetaAddr` representing a peer that last responded outside the
duration a peer is considered reachable. Verify that the peer is not
considered gossipable.
2021-06-29 05:12:27 +00:00
Alfredo Garcia 1624377da7
Legacy chain check and tests (#2366)
* add legacy chain check and tests
* improve has_network_upgrade check
* add docs to legacy_chain_check()
* change arbitrary module structure
* change the panic message
* move legacy chain acceptance into existing tests
* use a reduced_branch_id_strategy()
* add docs to strategy function
* add argument to check for legacy chain into sync_until()
2021-06-29 15:03:51 +10:00
teor 4c321f6fa1 Skip IPv6 network tests in google cloud workflows
Also consistently use the zebra-test:latest docker image.
2021-06-28 23:34:57 -04:00
teor efb2ffbf33 Stop ignoring failed cached state tests
Previously, Zebra's cached state workflows would run all of Zebra's
tests, but they would ignore the results for most tests. They would only
fail if the mainnet cached state test failed.

After this fix, the tests fail if any test or build step fails.
2021-06-28 23:34:57 -04:00
teor 17e94bd241
Stop skipping the cached sync tests in CI (#2402)
This is a bugfix on PR #2314, which changed the name of the test
function in the code, but didn't change the CI workflow.
2021-06-29 12:49:42 +10:00
teor 9d2d8c8215
Fix intermittent errors in the groth16 verifier tests (#2412) 2021-06-29 12:48:50 +10:00
teor 9cb7ee4d0e
Release Blocker? Disable IPv6 tests when $ZEBRA_SKIP_IPV6_TESTS is set (#2405)
* Disable IPv6 tests when $ZEBRA_SKIP_IPV6_TESTS is set

This allows users to disable IPv6 tests in environments where IPv6 is not
configured.

* Add network test env var constants

* Replace env strings with constants

fastmod '"ZEBRA_SKIP_NETWORK_TESTS"' zebra_test::net::ZEBRA_SKIP_NETWORK_TESTS
fastmod '"ZEBRA_SKIP_IPV6_TESTS"' zebra_test::net::ZEBRA_SKIP_IPV6_TESTS

* Add functions to skip network tests

* Replace test network env var checks with test function

fastmod --fixed-strings 'env::var_os(zebra_test::net::ZEBRA_SKIP_NETWORK_TESTS).is_some()' 'zebra_test::net::zebra_skip_network_tests()'
fastmod --fixed-strings 'env::var_os(zebra_test::net::ZEBRA_SKIP_IPV6_TESTS).is_some()' 'zebra_test::net::zebra_skip_ipv6_tests()'

* Remove redundant logging and use statements
2021-06-29 11:20:32 +10:00
teor 7c44ee2ebe
Release Blocker: Stop trying to verify coinbase inputs using the script verifier (#2404)
* Stop trying to verify coinbase inputs using the script verifier

And create tests to catch similar bugs earier.

* Use Testnet in NU5 tests that temporarily should_panic

We've marked these tests as should_panic until there is a NU5 activation
height. But Testnet will have an activation height first, so we should
prefer it in the tests. (Or use both networks.)
2021-06-29 10:49:40 +10:00
teor 7586699f86
Support a minimum protocol version during initial block download (#2395)
* Support a min protocol version during initial block download

But don't actually use the state height yet.

Also rename some functions and constants.

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
2021-06-29 10:49:03 +10:00
Alfredo Garcia c06cd19239
Update `has_inputs_and_outputs()` for new consensus rules (#2398)
* update the has_inputs_and_outputs() to new rules

* apply clippy suggestions

* add some TODOs
2021-06-29 08:28:49 +10:00
teor 19fa36049f
Provide a height in each transaction verification request (#2400)
Block transactions already had a height, but mempool transactions didn't.

This PR adds a height to mempool transactions, and deletes redundant and
unused fields. It also adds an accessor method for that height.
2021-06-28 13:28:48 -03:00
dependabot[bot] df426cba9e build(deps): bump tracing-subscriber from 0.2.18 to 0.2.19
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.18 to 0.2.19.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.18...tracing-subscriber-0.2.19)

---
updated-dependencies:
- dependency-name: tracing-subscriber
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-28 11:25:55 -04:00
teor 0d5e5bec3c
Improve docs and panic messages for zebra_test::command (#2406) 2021-06-28 10:35:56 -03:00
Deirdre Connolly bb974fd282
Orchard note commitment tree test vectors (#2384)
* Orchard note commitment tree and hash test vectors?

* Add failing sinsemilla test vector test

* Support incomplete Pallas addition, all the way down

* Fix sinsemilla sub function S(j), add note commitment tree empty root tests

* Clippy nightly lints

* allow(clippy::derive_hash_xor_eq) for orchard::tree

* Update zebra-chain/src/orchard/sinsemilla.rs

Co-authored-by: Conrado Gouvea <conrado@zfnd.org>
2021-06-25 16:27:47 +00:00
Janito Vaqueiro Ferreira Filho fdeb6d5ec8
Refactor Sprout Join Split validation by transaction verifier (#2371)
* Refactor to create `verify_sprout_shielded_data`

Move the join split verification code into a new
`verify_sprout_shielded_data` helper method that returns an
`AsyncChecks` set.

* Test if signed V4 tx. join splits are accepted

Create a fake V4 transaction with a dummy join split, and sign it
appropriately. Check if the transaction verifier accepts the
transaction.

* Test if unsigned V4 tx. joinsplit data is rejected

Create a fake V4 transaction with a dummy join split. Do NOT sign this
transaction's join split data, and check that the verifier rejects the
transaction.

* Join tests to share Tokio runtime

Otherwise one of the tests might fail incorrectly because of a
limitation in the test environment. `Batch` services spawn a task in the
Tokio runtime, but separate tests can have separate runtimes, so sharing
a `Batch` service can lead to the worker task only being available for
one of the tests.
2021-06-25 00:47:39 +00:00
teor df7075e962
ZIP-213: Explain how Zebra validates shielded coinbase outputs like other shielded outputs (#2382)
* Describe how a ZIP-213 rule is implemented in the transaction verifier

* Move the only coinbase-specific check outside the ZIP-213 block

This change isn't required to implement the ZIP-213 rule, but it makes
it easier to identify the specific checks for coinbase transactions.

* Add a note about coinbase in the mempool

Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
2021-06-24 23:53:32 +00:00
teor 22f2f06bad
Remove "solution" from the ticket template (#2385)
We want developers to do detailed designs and solutions in
RFCs and code comments, rather than tickets.
2021-06-24 10:43:27 +01:00
teor 5bce941e70
Enable V5 transaction test vectors in the groth16 tests (#2383)
This also simplifies the code.
2021-06-24 16:28:23 +10:00
teor 1b6688f139
README: update known issues and add inbound network ports (#2373)
* README: update known issues

* Add ticket numbers

* Add network ports to README

* Make heading a bit clearer

* Update zebra listener address docs

Explain how Zebra currently uses listener addresses,
after recent changes.
2021-06-23 08:10:21 -03:00
teor d18d118a20
Remove unicode in Zebra's user agent (#2376) 2021-06-23 08:45:25 +01:00
Conrado Gouvea 9688811e35
Update multiple crates to ensure bitvec 0.22.3 is being used (#2351)
* Update multiple crates to ensure bitvec 0.22.3 is being used and avoid package conflicts

* Add documentation to zebra-chain::sapling to indicate that ZIP-216 rules are enforced by jubjub

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
2021-06-23 13:16:22 +10:00
Janito Vaqueiro Ferreira Filho 8ed50e578d
Validate transparent inputs and outputs in V5 transactions (#2302)
* Add missing documentation

Document methods to describe what they do and why.

* Create an `AsyncChecks` type alias

Make it simpler to write the `FuturesUnordered` type with boxed futures.
This will also end up being used more when refactoring to return the
checks so that the `call` method can wait on them.

* Create `verify_transparent_inputs_and_outputs`

Refactors the verification of the transparent inputs and outputs into a
separate method.

* Refactor transparent checks to use `call_all`

Instead of pushing the verifications into a stream of unordered futures,
use the `ServiceExt::call_all` method to build an equivalent stream
after building a stream of requests.

* Replace `CallAll` with `FuturesUnordered`

Make it more consistent with the rest of the code, and make sure that
the `len()` method is available to use for tracing.

Co-authored-by: teor <teor@riseup.net>

* Refactor to move wait for checks into a new method

Allow the code snipped to be reused by other transaction
version-specific check methods.

* Verify transparent inputs in V5 transactions

Use the script verifier to check the transparent inputs in a V5
transaction.

* Check `has_inputs_and_outputs` for all versions

Check if a transaction has inputs and outputs, independently of the
transaction version.

* Wait for checks in `call` method

Refactor to move the repeated code into the `call` method. Now the
validation methods return the set of asynchronous checks to wait for.

* Add helper function to mock transparent transfers

Creates a fake source UTXO, and then the input and output that represent
spending that UTXO. The initial UTXO can be configured to have a script
that either accepts or rejects any spend attempt.

* Test if transparent V4 transaction is accepted

Create a fake V4 transaction that includes a fake transparent transfer
of funds. The transfer uses a script to allow any UTXO to spend it.

* Test transaction V4 rejection based on script

Create a fake transparent transfer where the source UTXO has a script
that rejects spending. The script verifier should not accept this
transaction.

* Test if transparent V5 transaction is accepted

Create a mock V5 transaction that includes a transparent transfer of
funds. The transaction should be accepted by the verifier.

* Test transaction V5 rejection based on script

Create a fake transparent transfer where the source UTXO has a script
that rejects spending. The script verifier should not accept this
transaction.

* Update `Request::upgrade` getter documentation

Simplify it so that it won't become updated when #1683 is fixed.

Co-authored-by: teor <teor@riseup.net>
2021-06-23 11:54:00 +10:00
Deirdre Connolly e7b4abcbad
Add a note about maybe using the tui crate for zebra-cli (#2367) 2021-06-23 08:12:07 +10:00
teor bcd5f2c50d
Gossip dynamic local listener ports to peers (#2277)
* Gossip dynamically allocated listener ports to peers

Previously, Zebra would either gossip port `0`, which is invalid, or skip
gossiping its own dynamically allocated listener port.

* Improve "no configured peers" warning

And downgrade from error to warning, because inbound-only nodes are a
valid use case.

* Move random_known_port to zebra-test

* Add tests for dynamic local listener ports and the AddressBook

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
2021-06-23 07:59:06 +10:00
Pili Guerra e87933e167
Add CHANGELOG.md file to the zebra git repo (#2346)
* Add new CHANGELOG.md file to zebra git repo

* Update Release Checklist to add updates to CHANGELOG.md

* Add some explanation about the CHANGELOG.md file

* Fix headings to make them consistent with Keep a changelog format

* Small fix for clarity

* Add release dates to changelog

* Change order of steps to update the changelog
2021-06-22 14:31:30 +01:00
teor 1a57023eac
Security: Use canonical SocketAddrs to avoid duplicate peer connections, Feature: Send local listener to peers (#2276)
* Always send our local listener with the latest time

Previously, whenever there was an inbound request for peers, we would
clone the address book and update it with the local listener.

This had two impacts:
- the listener could conflict with an existing entry,
  rather than unconditionally replacing it, and
- the listener was briefly included in the address book metrics.

As a side-effect, this change also makes sanitization slightly faster,
because it avoids some useless peer filtering and sorting.

* Skip listeners that are not valid for outbound connections

* Filter sanitized addresses Zebra based on address state

This fix correctly prevents Zebra gossiping client addresses to peers,
but still keeps the client in the address book to avoid reconnections.

* Add a full set of DateTime32 and Duration32 calculation methods

* Refactor sanitize to use the new DateTime32/Duration32 methods

* Security: Use canonical SocketAddrs to avoid duplicate connections

If we allow multiple variants for each peer address, we can make multiple
connections to that peer.

Also make sure sanitized MetaAddrs are valid for outbound connections.

* Test that address books contain the local listener address

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
2021-06-22 02:16:59 +00:00
Alfredo Garcia 7638c43a7c
Move network_upgrade check into zebra-chain (#2354)
* move network_upgrade check into zebra-chain

* fix the errors

* rename function

* typo fix

* rename the check function

* make changes from last code review
2021-06-22 12:06:52 +10:00
Alfredo Garcia 76ad543ec5 remove assert 2021-06-21 21:46:09 -04:00
Alfredo Garcia 22cf3eed9e add path() to FinalizedState 2021-06-21 21:46:09 -04:00
teor 716fa23e86
Document shared to per-spend anchor conversion (#2363) 2021-06-22 11:41:35 +10:00
teor 3bd52f89a5 Upgrade to pin_project 1.0.7 to resolve nightly warnings
Except for tower-fallback, which has code that is incompatible with
pin_project 1.0.
2021-06-21 15:52:39 -04:00
dependabot[bot] b3849695a4 build(deps): bump secp256k1 from 0.20.2 to 0.20.3
Bumps [secp256k1](https://github.com/rust-bitcoin/rust-secp256k1) from 0.20.2 to 0.20.3.
- [Release notes](https://github.com/rust-bitcoin/rust-secp256k1/releases)
- [Changelog](https://github.com/rust-bitcoin/rust-secp256k1/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-bitcoin/rust-secp256k1/compare/secp256k1-0.20.2...secp256k1-0.20.3)

---
updated-dependencies:
- dependency-name: secp256k1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-21 15:45:48 -04:00
dependabot[bot] 17d9b898ea build(deps): bump bech32 from 0.8.0 to 0.8.1
Bumps [bech32](https://github.com/rust-bitcoin/rust-bech32) from 0.8.0 to 0.8.1.
- [Release notes](https://github.com/rust-bitcoin/rust-bech32/releases)
- [Commits](https://github.com/rust-bitcoin/rust-bech32/compare/v0.8.0...v0.8.1)

---
updated-dependencies:
- dependency-name: bech32
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-21 15:43:29 -04:00
teor 30b3212261 Reference Zebra ticket 2021-06-18 14:45:18 -04:00
teor f15aa52751 Client RFC: add BlazeSync and cap-std 2021-06-18 14:45:18 -04:00
Conrado Gouvea c9e93a75f7
Replace primitives_types with uint (#2350) 2021-06-18 15:35:05 -03:00
teor 7d1c1fb84e
Document required request timeouts due to data dependencies (#2337)
* Document required request timeouts due to data dependencies

* Update AwaitUTXO docs
2021-06-18 14:43:05 -03:00
teor 2396950641
Add property test strategies for V5 transactions (#2347)
Add proptest strategies that:
- set the initial block height
- set the transaction version
- make all V5 transaction network upgrade fields valid
2021-06-18 14:40:08 -03:00
teor 4d22a0bae9
Security: Limit reconnection rate to individual peers (#2275)
* Security: Limit reconnection rate to individual peers

Reconnection Rate

Limit the reconnection rate to each individual peer by applying the
liveness cutoff to the attempt, responded, and failure time fields.
If any field is recent, the peer is skipped.

The new liveness cutoff skips any peers that have recently been attempted
or failed. (Previously, the liveness check was only applied if the peer
was in the `Responded` state, which could lead to repeated retries of
`Failed` peers, particularly in small address books.)

Reconnection Order

Zebra prefers more useful peer states, then the earliest attempted,
failed, and responded times, then the most recent gossiped last seen
times.

Before this change, Zebra took the most recent time in all the peer time
fields, and used that time for liveness and ordering. This led to
confusion between trusted and untrusted data, and success and failure
times.

Unlike the previous order, the new order:
- tries all peers in each state, before re-trying any peer in that state,
  and
- only checks the the gossiped untrusted last seen time
  if all other times are equal.

* Preserve the later time if changes arrive out of order

* Update CandidateSet::next documentation

* Update CandidateSet state diagram

* Fix variant names in comments

* Explain why timestamps can be left out of MetaAddrChanges

* Add a simple test for the individual peer retry limit

* Only generate valid Arbitrary PeerServices values

* Add an individual peer retry limit AddressBook and CandidateSet test

* Stop deleting recently live addresses from the address book

If we delete recently live addresses from the address book, we can get a
new entry for them, and reconnect too rapidly.

* Rename functions to match similar tokio API

* Fix docs for service sorting

* Clarify a comment

* Cleanup a variable and comments

* Remove blank lines in the CandidateSet state diagram

* Add a multi-peer proptest that checks outbound attempt fairness

* Fix a comment typo

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>

* Simplify time maths in MetaAddr

* Create a Duration32 type to simplify calculations and comparisons

* Rename variables for clarity

* Split a string constant into multiple lines

* Make constants match rustdoc order

Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
2021-06-18 09:30:44 -03:00
Pili Guerra 6396ac27d8
Update versions for zebra v1.0.0-alpha.11 release (#2334)
* Update versions for zebra v1.0.0-alpha.11 release

* Update Cargo.lock
2021-06-18 10:37:58 +01:00
teor ff7c1c4523
Depend on a specific git commit for zcash_history (#2345) 2021-06-18 09:32:21 +00:00
Alfredo Garcia 544d182d25
Add and use a function for mandatory checkpoint (#2314)
* add `mandatory_checkpoint_height()` function

* use mandatory checkpoint instead of canopy in acceptance tests
2021-06-18 10:05:28 +10:00
Conrado P. L. Gouvea 1cb10ec9e7 update librustzcash, change zcash_history to work with it 2021-06-17 14:26:31 -04:00
dependabot[bot] e7010adbe1 build(deps): bump vergen from 5.1.8 to 5.1.9
Bumps [vergen](https://github.com/rustyhorde/vergen) from 5.1.8 to 5.1.9.
- [Release notes](https://github.com/rustyhorde/vergen/releases)
- [Commits](https://github.com/rustyhorde/vergen/compare/5.1.8...5.1.9)

---
updated-dependencies:
- dependency-name: vergen
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-17 14:20:48 -04:00