Commit Graph

53 Commits

Author SHA1 Message Date
teor afbe807060
change(docs): Replace doc.zebra.zfnd.org API documentation with docs.rs (#7886)
* Simple replacements of doc.zebra.zfnd.org with docs.rs

* Manual fixes for specific main/internal/external docs

* Point developer docs to doc-internal.zebra.zfnd.org

* fastmod --glob '\!.git' -- doc.zebra.zfnd.org/zebrad docs.rs/zebrad/latest/zebrad

* Manually remove any remaining doc.zfnd.zebra.org links

* Remove the external docs job

* Add changelog entry and fix links

* Fix links that were broken before this PR
2023-11-01 22:09:40 +00:00
teor 512dd9bc5d
change(doc): Document how to upgrade the database format (#7261)
* Move the state format into a new doc

* Add upgrade instructions

* Link to the format upgrade docs from the upgrade code

* Fix typo

Co-authored-by: Marek <mail@marek.onl>

---------

Co-authored-by: Marek <mail@marek.onl>
2023-07-20 01:50:25 +00:00
Marek 32faa94fb4
fix(state): Update column family names to match Zebra's database design (#4639)
* Rename `block_by_height` to `block_header_by_height` in fin state

* Rename `tx_by_hash` to `tx_loc_by_hash` in both (non & fin) states

* Rename `utxo_by_outpoint` to `utxo_by_out_loc` in finalized state

* Reorder the column families so that they match the docs

* Update `struct Chain` in the RFCs

* Increment `DATABASE_FORMAT_VERSION` to 25

* Remove obsolete docs from `0004-asynchronous-script-verification.md`

* Remove an obsolete `TODO` from `disk_db.rs`

* Delete unused snapshots

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-06-30 23:00:23 +00:00
teor 12426fe078
Fix incorrect AddressBalance name in diagram (#4342)
* Fix incorrect AddressLocation size in diagram

* Actually the name is wrong
2022-05-06 11:10:21 -03:00
Conrado Gouvea ff0122044f
change(doc): add transaction index diagram to RFC-0005 (#4330)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-05-06 03:32:55 +00:00
teor b895b8973a
change(rfc): Cleanup transparent address index database design (#4019)
* Rename location-based column families

* Use more consistent terminology for database changes

* Remove AddressLocation from utxo_by_out_loc
2022-04-01 20:40:43 +00:00
teor 98ec995d56
fix(design): update state RFC to put ordered list values in RocksDB keys (#3997)
* Update RFC to use BTreeSets for ordered lists

* Update to put value sets in the rocksdb key

* Clarify some workding

* Update type name
2022-03-30 23:42:09 +00:00
teor 7d4c92f7d6
fix(doc): Fix bugs in the lightwalletd database design (#3964)
* Re-order column families in design in dependency order

* Minor RFC design tweaks and fixes

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-03-27 22:59:43 +00:00
teor 2b51f9098d
change(doc): Simplify the database design using prefix iterators (#3916)
* Simplify the database design using prefix iterators

* Fix typos and missed changes

Co-authored-by: Marek <mail@marek.onl>

Co-authored-by: Marek <mail@marek.onl>
2022-03-21 22:38:23 +00:00
teor 419770409a
doc(db): update database design for read-only state service (#3843)
* Add a TODO for a history tree concurrent write issue

* Update database design for read-only state service
2022-03-12 00:37:01 +00:00
teor 081cda7990
3. refactor(db): add disk serialization types for transactions (#3741)
* refactor(db): simplify block height serialization

* refactor(db): make height serialization length generic

* refactor(db): create a TransactionIndex type

This changes the names of some snapshot types,
but doesn't change any data.

* refactor(db): create transparent OutputIndex and OutputLocation types

This keeps the same serialization, to avoid changing the database version.

* doc(rfc/db): make transparent database type names consistent

* doc(rfc/db): fix a bug in the Utxo.is_coinbase derivation

* fix(db): use the correct serialized size for OutputLocation
2022-03-09 01:22:00 +00:00
teor ea7253ee5b
fix(rfc): rename some lightwalletd database types (#3567)
* fix(rfc): rename some lightwalletd database types

```
fastmod BlockTransactionCount HeightTransactionCount
fastmod FirstOutLocation TransparentAddrLoc
```

* fix(rfc): make lightwalletd column family names consistent

* feat(rfc): add sub-headings to the RocksDB column family list

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-02-17 22:41:15 +00:00
teor 9101e9a815
Revert "Updated utxo_by_outpoint column value type in documentation (#3376)" (#3385)
This reverts commit a007a49489.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-01-24 19:48:04 +00:00
Conrado Gouvea a007a49489
Updated utxo_by_outpoint column value type in documentation (#3376) 2022-01-20 19:24:57 +00:00
Conrado Gouvea 4aeabd0b52
Fix interstitial sprout anchors check (#3283)
* Fix interstitial Sprout anchors check

* Update state docs; add sprout_trees_by_anchor to comparisons

* Update book/src/dev/rfcs/0005-state-updates.md

Co-authored-by: Marek <mail@marek.onl>

* Rename `interstitial_roots` to `interstitial_trees`

* Document consensus rules

* Refactor the docs

* Improve the docs for consensus rules

* Update reference to cached state

* Update zebra-state/src/service/check/anchors.rs

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

* Fix formatting

Co-authored-by: Marek <mail@marek.onl>
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2022-01-18 20:18:49 +00:00
teor 361125079e
Draft design for lightwalletd database support (#3137)
* Draft design for lightwalletd database support

* Explain how to create blocks from headers and transactions

* Make keys smaller to improve database performance

* Support transparent address balances and UTXOs

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2021-12-22 06:09:53 +00:00
teor 62c78ad939
Update the State RFC to match the current database format (#3139)
* Update the State RFC to match the current database format

* Formatting and name fixes

* Remove redundant generic parameter

* Remove redundant generics

* Fix history tree types

Co-authored-by: Conrado Gouvea <conrado@zfnd.org>

* Fix spacing

Co-authored-by: Conrado Gouvea <conrado@zfnd.org>
2021-12-10 13:35:35 +00:00
Dimitris Apostolou afb8b3d477
Fix typos (#3055)
Co-authored-by: Janito Vaqueiro Ferreira Filho <janito.vff@gmail.com>
2021-11-12 19:30:22 +00:00
teor ccf93cf5c6
Update state RFC for incremental trees, value pools, and RocksDB (#2456)
* Update state RFC for double-spends and other recent designs

* Update the value pool column family name

* Mark incremental note commitment trees as tentative

* Change history tree type

* Apply suggestions from code review
2021-07-12 10:33:02 -03:00
teor 0be7470601
Modify UTXO and state designs for transparent coinbase output checks (#2413)
* Modify UTXO and state designs for transparent coinbase output checks

* Add missing word

* Clarify unspent transparent transaction outputs

And add a definition for OutPoint

* Fix coinbase flag derivation

* Rename SpendPools to SpendRestriction

* Replace coinbase_height with Coinbase.height

And clarify a height to spend_height

* Make block height italic to match spec formatting

* Provide a value for MIN_TRANSPARENT_COINBASE_MATURITY

* Add new v1-4 transaction ID consensus rule

* Make the design match the existing Utxo code

This minimises the changes we'll need to make.

* Add a justification for parallel coinbase verification

* Change to Response::SpendableUtxo

To avoid confusion.

* Update the state RFC to match the current design

* Move a change to another PR to avoid conflicts

* Fix spacing

* Clarify the future returned by `PendingUtxos::queue(u)`

* Add missing PendingUtxos::queue arguments
2021-07-09 07:11:43 +10:00
Alfredo Garcia a9fe0d9d3e
Make sure the mandatory checkpoint includes Canopy activation (#2235)
* Make sure the Canopy activation block is a finalized checkpoint block

This enables ZIP-221 chain history from Canopy activation onwards.

* Clarify that the mandatory checkpoint test includes Canopy activation

The test was correct, but the docs and assertion message did not include activation.

* Document that the mandatory checkpoint includes Canopy activation

Co-authored-by: teor <teor@riseup.net>
2021-06-03 10:24:08 +10:00
Alfredo Garcia 1685611592
Store orchard nullifiers into the state (#2185)
* add nullifier methods to orchard
* store orchard nullifiers
* bump database version
* update `IntoDisk`
* support V5 in `UpdateWith`
* add a test for finalized state
* Use the latest network upgrade in state proptests
2021-06-01 17:53:13 +10:00
teor 9da220517b Update docs for Sapling to Canopy checkpoint change 2021-03-18 10:13:47 +10:00
teor fc7d37c984
RFC: Contextual Difficulty (#1246)
* Difficulty Contextual RFC: Introduction
Add a header, summary, and motivation

* Difficulty RFC: Add draft definitions
And update the state RFC definitions to match.

* Difficulty RFC: Add relevant chain
* Difficulty RFC: draft guide-level explanation
Outline the core calculations and checks.

* Difficulty RFC: Revised based on spec fixes
Update the design based on the spec bugs in #1276, #1277, and
zcash/zips#416.

These changes make the difficulty filter into a context-free check,
so we remove it from this contextual validation RFC.

* Difficulty RFC: Explain how Zebra's calculations can match the spec
* Difficulty RFC: write most of the reference section
Includes most of the implementation, modules for each function, and
draft notes for some of the remaining parts of the RFC.

* Difficulty RFC: Add an AdjustedDifficulty struct
* Difficulty RFC: Summarise module structure in the one place
* Difficulty RFC: Create implementation notes subsections
* Difficulty RFC: add consensus critical order of operations
* Difficulty RFC: Use the ValidateContextError type
* Difficulty RFC: make the median_time arg mut owned

We have to clone the data to pass a fixed-length array to a function,
so we might as well sort that array to find the median, and avoid a
copy.
2020-11-26 11:45:01 +10:00
Deirdre Connolly 2a21c86b91 I before E except after C (or uh, not-english) 2020-11-24 22:23:57 -05:00
Jane Lusby 4c9bb87df2
zebra-state: replace sled with rocksdb (#1325)
## Motivation

Prior to this PR we've been using `sled` as our database for storing persistent chain data on the disk between boots. We picked sled over rocksdb to minimize our c++ dependencies despite it being a less mature codebase. The theory was if it worked well enough we'd prefer to have a pure rust codebase, but if we ever ran into problems we knew we could easily swap it out with rocksdb.

Well, we ran into problems. Sled's memory usage was particularly high, and it seemed to be leaking memory. On top of all that, the performance for writes was pretty poor, causing us to become bottle-necked on sled instead of the network.

## Solution

This PR replaces `sled` with `rocksdb`. We've seen a 10x improvement in memory usage out of the box, no more leaking, and much better write performance. With this change writing chain data to disk is no longer a limiting factor in how quickly we can sync the chain.

The code in this pull request has:
  - [x] Documentation Comments
  - [x] Unit Tests and Property Tests

## Review

@hdevalence
2020-11-18 18:05:06 -08:00
Jane Lusby 104b5406d5 Update book/src/dev/rfcs/0005-state-updates.md
Co-authored-by: teor <teor@riseup.net>
2020-11-12 09:14:52 -05:00
Jane Lusby 74af22e5ca Add unit tests for 2020-11-12 09:14:52 -05:00
Jane Lusby 34f50d7ebb
Fix inconsistencies related to best chain order in RFC and state impl (#1267)
Prior to this PR we realized that the RFC had been drafted with the assumption that chains would be ordered from best to worst in `NonFinalizedState`. This assumption was incorrect, since `BTreeSet` only ever orders values in ascending order. This discrepancy was noticed and fixed in the code, but there were still some inconsistencies that needed to be cleaned up.

This PR updates all the incorrect or confusing comments about chain ordering in the RFC and code.
2020-11-09 15:53:16 -08:00
teor 776e49ff0c State RFC: clarify difficulty
The difficulty validation RFC will introduce a definition of
per-block difficulty. Make it clear that the state RFC
definition is cumulative difficulty.
2020-10-30 19:12:32 -04:00
teor f338048012 Clarify edge case 2020-10-29 15:41:45 -04:00
teor b742657e45 State RFC: Clarify genesis sprout anchors 2020-10-29 15:41:45 -04:00
teor b4ce442cea
State RFC: Use escaped concatenation operator
And use BE32 consistently
2020-10-27 20:50:29 +10:00
teor adbdb3c76e
Note that `blocks_by_height` is also a bijection 2020-10-27 20:13:49 +10:00
teor 7ea92283a7
Fix a State RFC rendering issue 2020-10-27 20:07:43 +10:00
teor 08910e0378
State RFC: fix block height contextual validation 2020-10-27 19:29:32 +10:00
Jane Lusby 971765ab30
Handle duplicate blocks in zebra-state (#1198)
## Motivation

The zebra-state service needs to be able to handle duplicate blocks.

## Solution

This implements changes already outlined by [The State
RFC](https://zebra.zfnd.org/dev/rfcs/0005-state-updates.html). We check for
successfully committed blocks first, since interacting with the queued blocks
struct at this point just complicates the implimentation. If the block has not
already been committed we then check if the block has already been queued, if
not we handle the block normally (normally here being the bit we already had
implemented).

## Documentation Changes

- [x] Update the state RFC to match the ways this fix departs from the design
	- the main thing is that I switched the order of checking for duplicates
- [x] ~~Add newly added functions to the state rfc~~ Decided not to do this because they're minor getters that don't influence the rest of the design and aren't exposed as part of the API
- [x] Document newly added functions inline

## Testing

## Related Issues

- fixes https://github.com/ZcashFoundation/zebra/issues/1182
- tracking issue https://github.com/ZcashFoundation/zebra/issues/1049

Co-authored-by: teor <teor@riseup.net>
2020-10-26 13:54:19 -07:00
teor fb079c2ca1
Replace BlockHeaderHash with block::Hash 2020-10-26 22:27:57 +10:00
teor a9102e8d6d
Fix State RFC rendering ambiguities 2020-10-26 22:02:45 +10:00
teor 0935b3305a
Fix more state RFC function heading sizes 2020-10-26 21:14:14 +10:00
teor 7bf2fdd6d7
Fix a header level in the state RFC 2020-10-26 21:11:26 +10:00
Alfredo Garcia 21ad6ffc47
Reverse displayed endianness of transaction and block hashes (#1171)
* Reverse displayed endianness of transaction and block hashes
* fix zebra-checkpoints utility for new hash order
* Stop using "zebrad revhex" in zebrad-hash-lookup
* Rebuild checkpoint lists in new hash order
This change also adds additional checkpoints to the end of each list.

* Replace TransactionHash with transaction::Hash
This change should have been made in #905, but we missed Debug impls
and some docs.

Co-authored-by: Ramana Venkata <vramana@users.noreply.github.com>
Co-authored-by: teor <teor@riseup.net>
2020-10-22 07:54:02 +10:00
teor fd0fac3a61
State RFC: Handle duplicate block edge cases (#1136)
Handle the following duplicate block edge cases:
* duplicate in finalized state
* duplicate in queue

* Handle the broadcast channel correctly
2020-10-10 11:50:12 +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
Dimitris Apostolou 36279621f0 Fix typos 2020-10-06 12:16:41 +10:00
teor b05273ac16
State RFC: remove duplicate validation steps (#1123) 2020-10-05 19:03:17 -07: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
teor 5ed27dc8a1 State RFC - handle duplicates of finalized blocks 2020-09-29 12:19:56 +10:00
teor df9252c759 Refactor out push_block_on_chain
And tidy up some error handling and panics
2020-09-29 12:19:56 +10:00
teor b264e24cd0 Panic on all commit_block errors 2020-09-29 12:19:56 +10:00