Commit Graph

84 Commits

Author SHA1 Message Date
Alfredo Garcia c0a14ecc8c
move genesis parameters to zebra-chain (#1151) 2020-10-12 14:08:23 -07:00
teor e2d67fc9e7
Add metrics for the sled state (#1062) 2020-10-10 11:49:44 +10:00
Jane Lusby eaf5473efc
Add verification and state tracing events and spans (#1131) 2020-10-09 19:05:09 +10:00
Jane Lusby b3634fa3e7
Make the state service use broadcast channels (#1137)
And refactor error handling
2020-10-09 18:37:24 +10:00
Jane Lusby 855f9b5bcb
Implement MVP of NonFinalizedState and integrate it with the state service (#1101)
* implement most of the chain functions
* implement fork
* fix outpoint handling in Chain struct
* update expect for work
* split utxo into two sets
* update the Chain definition
* remove allow attribute in zebra-state/lib.rs
* merge ChainSet type into MemoryState
* Add error messages to asserts
* export proptest impls for use in downstream crates
* add testjob for disabled feature in zebra-chain
* try to fix github actions syntax
* add module doc comment
* update RFC for utxos
* add missing header
* working proptest for Chain
* propagate back results over channel
* Start updating RFC to match changes
* implement queued block pruning
* and now it syncs wooo!
* remove empty modules
* setup config for proptests
* re-enable missing_docs lint
* update RFC to match changes in impl
* add documentation
* use more explicit variable names
2020-10-08 13:07:32 +10:00
dependabot[bot] 1b7bf61f96 build(deps): bump thiserror from 1.0.20 to 1.0.21
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.20 to 1.0.21.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.20...1.0.21)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-07 18:25:33 -04:00
dependabot[bot] 08f363e1cb build(deps): bump futures from 0.3.5 to 0.3.6
Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.5 to 0.3.6.
- [Release notes](https://github.com/rust-lang/futures-rs/releases)
- [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.5...0.3.6)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-06 16:54:08 -04:00
Jane Lusby 86ed13060f
Add tests for `Chain` implementation (#1093)
* Begin work on RFC5 implementation

* I think this is necessary

* holy shit supertrait implemented via subtrait

* implement most of the chain functions

* change to slightly better name

* implement fork

* fix outpoint handling in Chain struct

* update expect for work

* resolve review comment

* split utxo into two sets

* update the Chain definition

* just a little more

* update comment

* Apply suggestions from code review

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

* apply changes from code review

* remove allow attribute in zebra-state/lib.rs

* Update zebra-state/src/memory_state.rs

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

* merge ChainSet type into MemoryState

* rename state impl types

* Add error messages to asserts

* checkpoint so I can split off arbitrary changes into a PR

* export proptest impls for use in downstream crates

* add testjob for disabled feature in zebra-chain

* run rustfmt

* try to fix github actions syntax

* differentiate name

* prove that github action tests zebra-chain build without features

* revert change from last commit now that test is running

* remove accidentally introduced newline

* checkpoint

* add module doc comment

* update RFC for utxos

* add missing header

* working proptest for Chain

* apply change from chain impl PR

* setup config for proptests

* Update zebra-chain/src/block/arbitrary.rs

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

* run rustfmt

Co-authored-by: teor <teor@riseup.net>
2020-10-02 15:51:51 -07:00
Jane Lusby 352721bd88
Implement RFC5: State updates `Chain` type (#1069)
* Begin work on RFC5 implementation

* I think this is necessary

* holy shit supertrait implemented via subtrait

* implement most of the chain functions

* change to slightly better name

* implement fork

* fix outpoint handling in Chain struct

* update expect for work

* resolve review comment

* split utxo into two sets

* update the Chain definition

* just a little more

* update comment

* Apply suggestions from code review

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

* apply changes from code review

* remove allow attribute in zebra-state/lib.rs

* Update zebra-state/src/memory_state.rs

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

* merge ChainSet type into MemoryState

* rename state impl types

* Add error messages to asserts

* add module doc comment

* update RFC for utxos

* add missing header

Co-authored-by: teor <teor@riseup.net>
2020-09-24 15:46:04 -07:00
Jane Lusby 0b4e974c9e
export proptest impls for use in downstream crates (#1092)
* export proptest impls for use in downstream crates

* add testjob for disabled feature in zebra-chain

* run rustfmt

* try to fix github actions syntax

* differentiate name

* prove that github action tests zebra-chain build without features

* revert change from last commit now that test is running

* remove accidentally introduced newline

* Update .github/workflows/ci.yml

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2020-09-23 18:52:52 -07:00
Henry de Valence 6dd7318d3b deps: use Tower 0.4 from git instead of 0.3.1.
This addresses at least three pain points:

- we were affected by bugs that were already fixed in git, but not in
  the released crate;
- we can use service combinators to transform requests and responses;
- we can use the hedge middleware.

The version in git is still marked as 0.3.1 but these changes will be
part of tower 0.4: https://github.com/tower-rs/tower/issues/431
2020-09-21 14:16:56 -07:00
Henry de Valence 9e2ff23d54 consensus, state: increase Buffer sizes
Using a Buffer with size 1 is a footgun because it allows only one
sender to call poll_ready at a time.  This is usually undesirable
because it means that a task or service that calls poll_ready but only
makes a service call later (potentially much later) will block all other
callers.
2020-09-21 09:26:39 -07:00
teor c349f75ffe Split a sentence in a state comment 2020-09-16 12:25:31 -04:00
Henry de Valence bbd8a069bb state: fix bug in SledState::commit_finalized
The previous code filled in block height 0 for a missing coinbase height
in `SledState::commit_finalized`, since the genesis block is the only
block without a coinbase height (because of a mistake when it was
created).

However, @teor2345 noticed that this is incorrect, because we already
parse the genesis block specially and fill in its coinbase height
correctly.  So instead, we can .expect it to be present, because we can
assume that all finalized blocks are valid.
2020-09-11 13:37:49 -07:00
Henry de Valence de2400031c state: merge SledState::{queue, process_queue}.
We never want to call one without the other, so just do them together.
2020-09-11 13:37:49 -07:00
Henry de Valence 526f771ceb state: update SledState docs. 2020-09-11 13:37:49 -07:00
Henry de Valence 8fb0e11674 fix: clippy-redundant closures, fmt 2020-09-11 13:37:49 -07:00
Henry de Valence 006596b9a9 state: remove unused variables 2020-09-11 13:37:49 -07:00
Henry de Valence f4db12efcb state: implement Request::Block with sled 2020-09-11 13:37:49 -07:00
Henry de Valence 5d8decd224 state: process CommitFinalizedBlock out of order 2020-09-11 13:37:49 -07:00
Henry de Valence b27ace87eb state: partial implementation of new sled layout 2020-09-11 13:37:49 -07:00
Henry de Valence f1f0b331ac state: make Response::Tip return (height, hash) 2020-09-11 13:37:49 -07:00
Henry de Valence 070013439e state: fill in RFC5-style Request, Response enums
The test transcripts need to be rewritten, so they are removed for now.
2020-09-11 13:37:49 -07:00
Henry de Valence 98d5351206 state: add rustdoc links 2020-09-11 13:37:49 -07:00
Henry de Valence 2ac8b5b9d4 state: create a new wrapper service
The new `StateService` type wraps a `SledState` and a `MemoryState`.
This will allow the sled-related code and the in-memory code to be kept
separate, with the top-level `StateService` making method calls to one
or the other, as appropriate.

This commit removes the existing Service impl for the SledService.  This
saves time in refactoring, and the code needs to be rewritten
anyways so there's no loss to deleting it now.
2020-09-11 13:37:49 -07:00
Henry de Valence 303b02d10a state: split into modules and reorganize
Closes #975.
2020-09-11 13:37:49 -07:00
dependabot[bot] 69032e1007 build(deps): bump sled from 0.34.3 to 0.34.4
Bumps [sled](https://github.com/spacejam/sled) from 0.34.3 to 0.34.4.
- [Release notes](https://github.com/spacejam/sled/releases)
- [Changelog](https://github.com/spacejam/sled/blob/master/CHANGELOG.md)
- [Commits](https://github.com/spacejam/sled/compare/v0.34.3...v0.34.4)

Signed-off-by: dependabot[bot] <support@github.com>
2020-09-11 13:08:16 -04:00
teor 9cf7de6253 Temporarily ignore failing state tests
This commit should be reverted when the state can handle out-of-order
blocks.
2020-09-09 15:37:59 -07:00
teor 1cd9f48d19 Add tests for in-order state AddBlock requests
Also fix a bug in the tests, where Mainnet and Testnet were swapped.
2020-09-09 15:37:59 -07:00
teor 8463b705c8 Panic when state blocks are inserted out of order
This panic ensures our state is not corrupted. Corrupt states can lead
to future panics when querying the chain.
2020-09-09 15:37:59 -07:00
teor 1285561c3f Perform serialised block writes to the state
As per the state design RFC 0005.
2020-09-09 15:37:59 -07:00
Alfredo Garcia 454e75e7c0
Rename old references to BlockHeaderHash and BlockHeight (#1002)
* rename some references

* Apply suggestions from code review

Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
Co-authored-by: teor <teor@riseup.net>

Co-authored-by: Deirdre Connolly <durumcrustulum@gmail.com>
Co-authored-by: teor <teor@riseup.net>
2020-09-04 15:40:48 -07:00
teor d3b6a73f7b Improve zebra-state logging and metrics 2020-09-02 12:09:50 -04:00
Jane Lusby ffdec0cb23
Remove in-memory state service (#974)
* Remove in-memory state service

* make the config compatible with toml again

* checkpoint commit to see how much I still have to revert

* back to the starting point...

* remove unused dependency

* reorganize error handling a bit

* need to make a new color-eyre release now

* reorder again because I have problems

* remove unnecessary helpers

* revert changes to config loading

* add back missing space

* Switch to released color-eyre version

* add back missing newline again...

* improve error message on unix when terminated by signal

* add context to last few asserts in acceptance tests

* instrument some of the helpers

* remove accidental extra space

* try to make this compile on windows

* reorg platform specific code

* hide on_disk module and fix broken link
2020-09-01 12:39:04 -07:00
Ramana Venkata ad0001f7f7
zebra-state: Add support for temporary sled databases (#939)
* Test config with persistent sled database
* Test ephemeral config
* Add misconfigured ephemeral test
2020-08-31 18:32:55 +10:00
dependabot[bot] 619c499ba6 build(deps): bump sled from 0.34.2 to 0.34.3
Bumps [sled](https://github.com/spacejam/sled) from 0.34.2 to 0.34.3.
- [Release notes](https://github.com/spacejam/sled/releases)
- [Changelog](https://github.com/spacejam/sled/blob/master/CHANGELOG.md)
- [Commits](https://github.com/spacejam/sled/commits)

Signed-off-by: dependabot[bot] <support@github.com>
2020-08-24 12:49:10 -04:00
teor f88d324911 fix: Use defaults for missing state config fields
Closes #890.
2020-08-24 15:34:46 +10:00
teor 6a3615e039
fix: Commit sled state in a transaction (#933)
Fixes a race condition between the height and hash tree updates, when
they are executed simultaneously with GetDepth. `get_tip` uses the height
tree, but `get` uses the hash tree.
2020-08-21 12:36:00 -07:00
teor 5afa24588a fix: Remove unused dependencies 2020-08-20 14:49:17 -04:00
Henry de Valence 103b663c40 chain: rename BlockHeight to block::Height 2020-08-17 11:46:34 -07:00
Henry de Valence 61dea90e2f chain: rename BlockHeaderHash to block::Hash
This is the first in a sequence of changes that change the block:: items
to not include Block as a prefix in their name, in accordance with the
Rust API guidelines.
2020-08-17 11:46:34 -07:00
Henry de Valence 948b067808 chain: move Network, NetworkUpgrade to parameters
Also, avoid using star-imports of the enum variants, which pollutes the
namespace.
2020-08-17 11:46:34 -07:00
Henry de Valence dad6340cd3 chain: move BlockHeight into block 2020-08-17 11:46:34 -07:00
Henry de Valence a79ce97957
Fix sync algorithm. (#887)
* checkpoint: reject older of duplicate verification requests.

If we get a duplicate block verification request, we should drop the older one
in favor of the newer one, because the older request is likely to have been
canceled.  Previously, this code would accept up to four duplicate verification
requests, then fail all subsequent ones.

* sync: add a timeout layer to block requests.

Note that if this timeout is too short, we'll bring down the peer set in a
retry storm.

* sync: restart syncing on error

Restart the syncing process when an error occurs, rather than ignoring it.
Restarting means we discard all tips and start over with a new block locator,
so we can have another chance to "unstuck" ourselves.

* sync: additional debug info

* sync: handle lookahead limit correctly.

Instead of extracting all the completed task results, the previous code pulled
results out until there were fewer tasks than the lookahead limit, then
stopped.  This meant that completed tasks could be left until the limit was
exceeded again.  Instead, extract all completed results, and use the number of
pending tasks to decide whether to extend the tip or wait for blocks to finish.

* network: add debug instrumentation to retry policy

* sync: instrument the spawned task

* sync: streamline ObtainTips/ExtendTips logic & tracing

This change does three things:

1.  It aligns the implementation of ObtainTips and ExtendTips so that they use
the same deduplication method.  This means that when debugging we only have one
deduplication algorithm to focus on.

2.  It streamlines the tracing output to not include information already
included in spans. Both obtain_tips and extend_tips have their own spans
attached to the events, so it's not necessary to add Scope: prefixes in
messages.

3.  It changes the messages to be focused on reporting the actual
events rather than the interpretation of the events (e.g., "got genesis hash in
response" rather than "peer could not extend tip").  The motivation for this
change is that when debugging, the interpretation of events is already known to
be incorrect, in the sense that the mental model of the code (no bug) does not
match its behavior (has bug), so presenting minimally-interpreted events forces
interpretation relative to the actual code.

* sync: hack to work around zcashd behavior

* sync: localize debug statement in extend_tips

* sync: change algorithm to define tips as pairs of hashes.

This is different enough from the existing description that its comments no
longer apply, so I removed them.  A further chunk of work is to change the sync
RFC to document this algorithm.

* sync: reduce block timeout

* state: add resource limits for sled

Closes #888

* sync: add a restart timeout constant

* sync: de-pub constants
2020-08-12 16:48:01 -07:00
Jane Lusby 3655581888
box the state service (#879)
* box the state service

* cleanup
2020-08-11 13:25:40 -07:00
teor 98659ac565 fix: Stop duplicating genesis hashes in the block locator
And add some tests to avoid future bugs.
2020-08-10 18:58:21 +10:00
teor 23469b2347 fix: Only ask for blocks within the reorg limit
Instead of creating a block locator all the way back to the genesis
block, only ask for blocks within the reorg limit (99 blocks).

Use the reorg limit as the final locator. (Or if the chain is less
than 99 blocks, use the genesis block.)

Fixes some instances of #818 at very small block heights.
2020-08-10 18:58:21 +10:00
teor 1d3dd35175 fix: Include the current tip in the block locator
The state service was providing block locators starting at the parent of
the current tip. Instead, include the current tip in the block locator.

Also handle an edge case where we could include the genesis block twice,
if the current tip height was a power of two.

Fixes an instance of #818 where we re-download the current tip.
2020-08-10 18:58:21 +10:00
Henry de Valence 4a03d76a41
Remove environment variables in favor of documented config options. (#827)
* Load tracing filter only from config and simplify logic.

* Configure the state storage in the config, not an environment variable.

This also changes the config so that the path is always set rather than being
optional, because Zebra always needs a place to store its config.
2020-08-05 11:48:08 -07:00
Alfredo Garcia 70597c1da3
Add testnet blocks to zebra_state (#770)
* add testnet blocks, use them in state tests

* remove mutex and just add more transcripts

Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-08-04 13:39:32 -07:00