Zebra/zebra-chain/src
teor d7eb01d7f0
Add value pool/balances to non-finalized state (#2656)
* add value balances to non finalized state

* fix 2 tests

* fix remaining constrain issues in tests

* extend value pool test to non finalized

* WIP: fix tests after adding value pools to non-finalized state (#2647)

* Update Chain::eq_internal_state with Chain.value_balance

Also increase the number of cases in its tests,
because they didn't detect this bug.

* Calculate the chain value pool change before `Chain::push`

Code
- store the chain value pool change in `ContextuallyValidBlock`
- convert `PreparedBlock` to `ContextuallyValidBlock` using `with_block_and_spent_utxos`
  (rather than `from` or `into`)
- replace `block_utxos` with `new_outputs` in `PreparedBlock`
- replace `block_utxos` with `chain_value_pool_change` in `ContextuallyValidBlock`

Tests
- create test methods for `PreparedBlock` and `ContextuallyValidBlock`
- use `test_with_zero_chain_pool_change` or `test_with_zero_spent_utxos`
  to make tests pass

* fix conflicts

* build `set_current_value_pool()` only for tests

* remove redundant cfgs

* change cfg of set_current_value_pool()

* Clarify some chain field documentation

* Fix bugs in the non-finalized chain value pool calculations

1. Only revert the chain value pool balances when the tip is popped.
   Don't modify them when the root is finalized.

2. Only update or revert the chain value pool balances once per block.
   (Previously, the block changes were multiplied by the number of *transactions*.)

And make corresponding changes to method names and documentation.

* Add extra proptests to try to identify value balance failures

* Simplify some transaction generation code

* Add extra debugging info to value balance errors

* Actually update non-finalized chain value pools in `UpdateWith`

Previously, we were dropping the updated value pools in the `Ok` result.
So the initial (finalized) chain value pool balances were never modified.

* Rename and document value balance add methods

The names and documentation of these methods were confusing.

* Create genesis-based proptests that check chain value pools

* Increase coverage for some test vectors

* Test each chain value balance calculation for blocks 0-10

* Make continuous blockchain test errors easier to debug

* Test the exact transparent pool values for the first few blocks

Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
2021-08-25 10:57:07 -03:00
..
amount Check remaining transaction value & make value balance signs match the spec (#2566) 2021-08-09 14:22:26 -03:00
block ZIP-221/244 auth data commitment validation in checkpoint verifier (#2633) 2021-08-23 14:17:33 +00:00
history_tree Refactor HistoryTree into NonEmptyHistoryTree and HistoryTree (#2582) 2021-08-10 09:51:50 -03:00
orchard Add orchard binding_verification_key (#2441) 2021-08-16 15:16:25 -04:00
parameters ZIP-221/244 auth data commitment validation in checkpoint verifier (#2633) 2021-08-23 14:17:33 +00:00
primitives Implement ZIP-244 authorizing data commitment (auth_digest) (#2547) 2021-08-13 12:58:04 -04:00
sapling Cache note commitment tree roots (#2584) 2021-08-10 10:33:34 -03:00
serialization Implement a WtxId struct, and use it in Zebra's external network protocol (#2618) 2021-08-16 21:26:08 +00:00
sprout Refactor value balances to support generated data modification (#2596) 2021-08-10 14:42:02 +00:00
transaction Add value pool/balances to non-finalized state (#2656) 2021-08-25 10:57:07 -03:00
transparent Check remaining transaction value & make value balance signs match the spec (#2566) 2021-08-09 14:22:26 -03:00
value_balance Split ValueBalance methods into NegativeAllowed and NonNegative (#2649) 2021-08-20 13:30:38 +00:00
work Replace primitives_types with uint (#2350) 2021-06-18 15:35:05 -03:00
amount.rs Check remaining transaction value & make value balance signs match the spec (#2566) 2021-08-09 14:22:26 -03:00
block.rs ZIP-221/244 auth data commitment validation in checkpoint verifier (#2633) 2021-08-23 14:17:33 +00:00
fmt.rs Add a TypeNameToDebug formatter to zebra_chain (#2466) 2021-07-09 12:40:19 +10:00
history_tree.rs Improve some test errors (#2643) 2021-08-19 19:44:02 +00:00
lib.rs Add ZIP-221 (history tree) to finalized state (#2553) 2021-08-05 10:02:37 -03:00
orchard.rs Orchard data in V5 parsing (#2116) 2021-05-21 00:42:06 +00:00
parameters.rs Cleanup a few arbitrary impls (#2222) 2021-05-28 09:49:28 -03:00
primitives.rs Add ZIP-244 signature hash support (#2165) 2021-07-07 08:27:10 +10:00
sapling.rs Update multiple crates to ensure bitvec 0.22.3 is being used (#2351) 2021-06-23 13:16:22 +10:00
serialization.rs Security: Zebra should stop gossiping unreachable addresses to other nodes, Action: re-deploy all nodes (#2392) 2021-06-29 05:12:27 +00:00
shutdown.rs Fix shutdown panics (#1637) 2021-02-03 19:03:28 +10:00
sprout.rs Move the preallocate tests into their own files (#1977) 2021-04-07 12:32:27 +10:00
transaction.rs Create types for unmined transactions and their IDs (#2634) 2021-08-18 15:52:42 +10:00
transparent.rs Generate test chains with valid chain value pools (#2597) 2021-08-12 12:38:16 +00:00
value_balance.rs Add value pool/balances to non-finalized state (#2656) 2021-08-25 10:57:07 -03:00
work.rs Replace primitives_types with uint (#2350) 2021-06-18 15:35:05 -03:00