Commit Graph

255 Commits

Author SHA1 Message Date
teor b0cd920fad feature: Use the Heartwood protocol version in zebra-network 2020-07-21 10:46:07 -07:00
teor 1b0c0f027f
Add Hard-Coded Checkpoint Lists (#674)
* Add checkpoint list generation scripts
* Limit the checkpoint block data size
* Limit the checkpoint height gap
* Add Mainnet and Testnet checkpoint lists
* Parse hard-coded checkpoint lists

The lists were generated using the following limits:
- 256 MB spacing, based on block byte size, and
- 2000 blocks.
2020-07-21 23:11:51 +10:00
Alfredo Garcia fe2a468417
add favicon to generated docs (#681) 2020-07-17 16:45:29 -07:00
teor c13907d1af fix: Combine two matches 2020-07-16 10:06:29 -07:00
teor b648375bbe fix: Hard-code the genesis previous block hash 2020-07-16 10:06:29 -07:00
teor 39e67c8748 feature: Check the genesis hash in checkpoint lists
And use the consensus parameters to get the genesis previous block hash.
2020-07-16 10:06:29 -07:00
teor 648d8daf12 feature: Initial consensus parameter module 2020-07-16 10:06:29 -07:00
teor 1915634d2b
Check for bad heights or hashes in checkpoint lists (#639)
* Add MIN and MAX for BlockHeight and LockTime
* Remove duplicate test cases
* fix a comment about the minimum lock time

The minimum LockTime::Time is 5 November 1985 00:53:20 UTC, so the first
day that only contains valid times is 6 November 1985 (in all timezones).

Similarly, the maximum LockTime::Time is 7 February 2106 06::28::15 UTC,
so the last day that only contains valid times in all time zones is
5 February 2106.

* fix: Reject checkpoint lists with bad hashes or heights

Reject the all-zeroes hash, because it is the parent hash of the genesis
block, and should never appear in a checkpoint list.

Reject checkpoint heights that are greater than the maximum block
height.
2020-07-16 15:09:22 +10:00
teor 851afad01f
fix: Resist CheckpointVerifier memory DoS attacks (#635)
* fix: Resist CheckpointVerifier memory DoS attacks

Allow a maximum of 2 queued blocks at each height, as a tradeoff between
efficient bad block rejection, and memory usage.

Closes #628.

* fix: Make max queued blocks at height equal to fanout

* fix: Just allocate all the capacity upfront

* fix: Use with_capacity(1) and reserve_exact(1)
2020-07-15 13:27:10 -07:00
teor a19fdd9f25 fix: Rename to is_time_valid_at 2020-07-15 09:16:54 -07:00
teor c2e4f7b0a5 refactor: Move the local clock check to a BlockHeader method 2020-07-15 09:16:54 -07:00
teor 5548dffd3b refactor: Move the coinbase first check to a Block method 2020-07-15 09:16:54 -07:00
teor 47bc02ea44 partial revert: Use &Block, not Arc<Block> 2020-07-15 09:16:54 -07:00
Jane Lusby 72ec79dd5e Update zebra-consensus/src/checkpoint/list.rs
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
2020-07-15 09:16:54 -07:00
teor 6f064e0154 refactor: Use Arc<Block> in BlockVerifier
Arc is a bit more flexible when using futures.

And improve the documentation for coinbase_is_first_check.

Closes #627.
2020-07-15 09:16:54 -07:00
teor 30effa6a46 doc: Improve checkpoint test comments
Closes #626.
2020-07-15 09:16:54 -07:00
teor e58c913897 refactor: Make max_height call max_height_in_range
Closes #630.
2020-07-15 09:16:54 -07:00
Alfredo Garcia 04b2eeedd0
Longer checkpoint gap test case (#643)
* create longer checkpoint test

* use futures unordered to syncronize background futures

Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-07-13 09:29:21 -07:00
teor 870a0be928 fix: Make sure checkpoint heights and hashes are unique
Previously, CheckpointList would silently ignore duplicate heights or
hashes.

Closes #632.
2020-07-10 10:53:32 -07:00
teor 8b5ec155f0
Consensus refactor (#629)
* Flatten consensus::verify::* to consensus::*
* Move consensus::*::tests into their own files
* Move CheckpointList into its own file
* Move Progress and Target into a types module

QueuedBlock and QueuedBlockList can stay in checkpoint.rs, because
they are tightly coupled to CheckpointVerifier.
2020-07-10 16:51:01 +10:00
Alfredo Garcia 5d6a5ca329
Add consensus coinbase checks (#593)
* add coinbase check and test case

Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-07-10 09:13:44 +10:00
Jane Lusby 765e1e61e7
fix spandoc instrumentation for await expressions (#618)
* fix spandoc instrumentation for await expressions

* depend on released version of spandoc
2020-07-09 17:43:44 -04:00
Deirdre Connolly 2cd58c8325
Add RedJubjub signature verifier service (#460)
Using tower-batch-based async pattern.

Now the Verifier is agnostic of redjubjub SigTypes.  Updated tests to
generate sigs of both types and batch verifies the whole batch.

Resolves #407
2020-07-08 17:23:00 -04:00
Deirdre Connolly 83f0747490 Remove straggler install_tracing()
This was removed in the PR but the actual squashed commit still had it. 🤔
2020-07-08 16:55:56 -04:00
teor f2052b398b
feature: Implement CheckpointVerifier (#524)
* Return Poll::Ready(Err(_)) when verification has finished
* Turn checkpoint::init() into CheckpointVerifier::new()
* Accept IntoIterator<...> for CheckpointVerifier::new()
* Add a CheckpointList type

* Replace the state service with oneshot channels.
* Reject redundant checkpoint blocks
* impl Drop for CheckpointVerifier

* Add fields for caching blocks, and managing verify chains.
* Add current checkpoint functions
* Use a checkpoint range
* Get full backtraces with Err::Try
* Add enums for verification progress and target block heights.

* Replace install_tracing() with zebra_test::init()
* Add a test that mixes good and bad blocks
* Add timeouts to the checkpoint test futures
2020-07-08 21:22:36 +10:00
Alfredo Garcia c8cbb08ae3
check equihash solution covers the block header (#607) 2020-07-08 20:58:20 +10:00
teor a706b65325
Consensus test tweaks (#538)
* Use spandoc correctly
* Refactor consensus test error handling
* Delete a checkpoint test that will soon be obsolete

* Only initialise tracing once for the block tests
* Use tracing in the checkpoint tests

* Move BlockVerifier and tests into block.rs

* Update a BlockVerifier comment
* Tweak some TODO comments
2020-06-25 10:14:23 +10:00
Jane Lusby 2abf4b93a8 consolidate test init functions into zebra-test (#541)
* consolidate test init logic into one place

* rustfmt

Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-06-24 11:47:18 -07:00
teor f40bfff7c0 consensus: Simplify error handling in a test
Part of #477.
2020-06-24 18:22:36 +10:00
teor f1ce4dcf14 consensus: Inline node_time_check() into callers
node_time_check() is a small function, so we inline it into its callers.
(And then rename node_time_check_helper() to node_time_check().)

Part of #477.
2020-06-24 18:22:36 +10:00
teor 59bc8d7167 consensus: Make BlockVerifier only call AddBlock on success
We don't want to call the state's AddBlock until we know the block is
valid. This avoids subtle bugs if the state is modified in call().

(in_memory currently modifies the state in call(), on_disk modifies the
state in the async block.)

Part of #477.
2020-06-24 18:22:36 +10:00
teor 8fde8c1a6b consensus: Add tests for block node time checks
Part of #477.
2020-06-24 18:22:36 +10:00
teor a41f4f68cf consensus: move verify::block to its own file
Part of #477.
2020-06-24 18:22:36 +10:00
teor d97c769869 consensus: Refactor the node time check for testing
Part of #477.
2020-06-24 18:22:36 +10:00
teor 3c27c11012 consensus: Check block times against the local clock
Part of #477.
2020-06-24 18:22:36 +10:00
teor f10bfd5806 consensus: Add a block time check function
Add a function that checks the block header miner times against the
node's local clock.

(We'll use this function in the next commit.)

Part of #477.
2020-06-24 18:22:36 +10:00
Henry de Valence 70241d3cad Fix broken git dependencies.
Pinning hashes means these won't break again in the future; they can always be updated.
2020-06-22 20:23:02 -07:00
Henry de Valence e8561d8f9e rename zebra-test-vectors to zebra-test 2020-06-22 20:23:02 -07:00
teor 03b8453b8a
Checkpoint Verifier Tests (#517)
* Add basic checkpoint verifier tests
* Refactor a checkpoint verifier condition
* Remove some outdated comments
2020-06-23 12:15:37 +10:00
Jane Lusby 246e7cd2a9
Start testing out new version of `eyre` and `color-eyre` in zebra (#526)
* port to new version of eyre without generics

* correctly setup color_eyre hooks

Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-06-22 15:36:23 -07:00
teor d8b48f885b
consensus: Add a checkpoint verifier stub (#502)
consensus: Add a checkpoint verifier stub

This stub only verifies blocks whose hashes are in the checkpoint
list.

It doesn't have tests, chain child verifies to their ancestors, or
support checkpoint maximum height queries.

Part of #429.
2020-06-22 08:51:43 +10:00
teor 26a58b23de state: Make Response::Added return the block header hash
Move block header hashing from zebra-consensus to zebra-state.
Handle zebra-state AddBlock errors in zebra-consensus BlockVerifier.
Add unit tests for BlockVerifier state error handling.

Part of #428.
2020-06-12 09:46:18 -07:00
Henry de Valence cbb50ea506 Simplify `where` bounds on services.
Placing bounds on the service's future is less ideal, because the future is
already constrained by the `Service` trait, so the bounds can be expressed more
directly and simply by bounding the service itself.

If the verification service already has to have a generic parameter for the
future (the `ZSF`), it could instead be generic over `S`, the storage service.
This has the upside that it's no longer required for the verification service
to box the storage service, so we don't add any extra layers of indirection,
and the where bounds become more straightforward, since they're centered on the
requirements for the storage service itself, not the future it returns.
Finally, we can simplify the bounds by using the request / response types
directly rather than defining wrapper types.
2020-06-12 09:46:18 -07:00
Henry de Valence adf0769ac2 Get the round trip test to pass.
The reason the test failed is that the future returned by `call` on the state
service was immediately dropped, rather than being driven to completion.
Instead, we link the state update future with the verification future by
.awaiting it in an async block.

Note that the state update future is constructed outside of the async block
returned by the verification service.  Why?  Because calling
`self.state_service.call` requires mutable access to `state_service`, which we
only have in the body of the verification service's `call` method, and not
during execution of the async block it returns (which could happen at some
later point, or never).

In Tower's model, the `call` method itself only does the work necessary to
construct a future that represents completion of the service call, and the rest
of the work is done in the future itself.  In particular, the fact that
`Service::call` takes `&mut self` means two things:

1. the service's state can be mutated while setting up the future, but not
during the future's subsequent execution,

2. any nested service calls made *by* the service *to* sub-services (e.g., the
verification service calling the state service) must either be made upfront,
while constructing the response future, or must be made to a clone of the
sub-service owned by the the response future.
2020-06-12 09:46:18 -07:00
teor 15bc64aed9 consensus: add a (failing) verify round-trip test
This test doesn't work, because the futures are not used correctly.

Part of #428.
2020-06-12 09:46:18 -07:00
teor c2590ce526 consensus: Make future handling a little nicer
Part of #428.
2020-06-12 09:46:18 -07:00
teor 7b8707be1e consensus: Add a simple block verify test
Part of #428.
2020-06-12 09:46:18 -07:00
teor d0a833f3fb consensus: Make the state service pluggable in block verification
We want to allow different state service implementations, and wrapped
state services. So we make verify::init() take a state_service, and
store that service in the BlockVerifier state_service field.

Part of #428.
2020-06-12 09:46:18 -07:00
teor 4181c8a5d5 consensus: Make BlockVerifier respond with the BlockHeaderHash
Part of #428.
2020-06-12 09:46:18 -07:00
teor c019726fb1 consensus: Add a script verifier stub
Part of #428.
2020-06-12 09:46:18 -07:00
teor af1d64b218 consensus: Add a transaction verification stub
Part of #428.
2020-06-12 09:46:18 -07:00
teor 997201c9c7 consensus: Add a mempool stub 2020-06-12 09:46:18 -07:00
teor 8f2ddef0a4 consensus: Add a block verification service
Part of #428.
2020-06-12 09:46:18 -07:00
Henry de Valence ff3efd504c Add Zebra logo to all workspace crates.
Also add html_root_url attributes.
2020-02-26 21:25:35 -08:00
Henry de Valence ec363d2d41 Create workspace skeleton based on design.md 2019-08-29 14:46:54 -07:00