Commit Graph

65 Commits

Author SHA1 Message Date
Deirdre Connolly 25f63518f4 Allow clippy::unit_arg because of derive(Arbitrary) 2020-08-17 11:46:34 -07:00
Henry de Valence d57390d265 chain: doc tweaks (mostly block::) 2020-08-17 11:46:34 -07:00
Henry de Valence 2712c4b72a chain: rename BlockHeader to block::Header 2020-08-17 11:46:34 -07: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 04ba696515 chain: remove block::block 2020-08-17 11:46:34 -07:00
Henry de Valence ce1e81b274 chain: move merkle_tree to block::merkle.
This Merkle tree is the SHA256d one used only for including transactions
in a block, so it should be kept there in order to not be confused with
other Merkle trees (like the note commitment trees).
2020-08-17 11:46:34 -07:00
Henry de Valence 196e841cd9 chain: rename LightClientRootHash to RootHash
It's not accurate to call it a LightClientRootHash, because it's not
always a root has for a light client -- sometimes it's a different kind
of root hash.
2020-08-17 11:46:34 -07:00
Henry de Valence b296d1e2a3 chain: move Block into a leaf module.
This might make things a little easier to rearrange.  In the future it
would probably be good to change to block::Hash, block::Header, etc.
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 855b89dec4 chain: create a new work module for proof-of-work
This extracts the `difficulty` module from `block` and the
`equihash_solution` module from the crate root.  The PoW calculations
are significantly more complicated than the other block code and pretty
dissimilar from it, so it makes more sense to create a common proof of
work module.

The `EquihashSolution` and `EQUIHASH_SOLUTION_SIZE` are renamed to
`equihash::Solution` and `equihash::SOLUTION_SIZE` and imported that
way, except in `block/header.rs`, to avoid a conflict with the
`equihash` crate.  In the future it would be better to encapsulate the
equihash solution check into the `equihash::Solution` type so that
callers only need to import our `work::equihash`.

The test organization leaves a little to be desired but I think that
this can be improved as we fill out the proof of work implementation.
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 07917421cb
Correct coinbase check (#898)
* chain: add Transaction::is_coinbase()

This matches the check in zcashd/src/primitives/transaction.h:682
(CTransaction::IsCoinBase).

* chain: correct Block::is_coinbase_first

This matches zcashd/src/main.cpp:3968-3974 in CheckBlock.

Previously, the check allowed the first transaction to have multiple coinbase inputs.

* chain: return slices from Transaction::inputs()/outputs()

They're slices internally so we might as well just expose them that way.
2020-08-13 14:04:43 -07:00
Henry de Valence 36093b4721 Tweak light client root hash definition.
This changes the `light_client_root_hash` field to `light_client_root_bytes` to
hint that it's unparsed, and makes it public to match the rest of the
`BlockHeader` fields.  The `LightClientRootHash` serialization methods are
hidden from the public API, so that the `LightClientRootHash` has to be
constructed by the method on the `Block`.
2020-08-11 19:13:50 -04:00
teor 7afd76f5fb feature: Add light_client_root_hash(network) to Block
* use the right variant in LightClientRootHash::from_bytes()
* make block.header.light_client_root_hash pub(super)
* add tests for LightClientRootHash and block.light_client_root_hash
2020-08-10 18:54:42 +10:00
teor c4eb136426 feature: Add a LightClientRootHash type 2020-08-10 18:54:42 +10:00
teor c4dec3fb36 feature: Make a CompactDifficulty wrapper
Wrap the compact difficulty "bits" field in a CompactDifficulty struct,
and rename the header field for clarity.
2020-08-03 10:28:31 +10:00
Jane Lusby 7d4e717182
Add block locator request to state layer (#712)
* Add block locator request to state layer

* pass genesis in request

* Update zebrad/src/commands/start/sync.rs

* fix errors
2020-07-22 18:01:31 -07:00
teor 5548dffd3b refactor: Move the coinbase first check to a Block method 2020-07-15 09:16:54 -07:00
Alfredo Garcia db30e53470
Create a test for block size (#558)
* add block size limit test
* calculate max_transactions_in_block and max_inputs_in_tx
* abstract block generation
* move all test vectors to zebra-test
2020-07-07 10:37:32 +10:00
Alfredo Garcia 9cbd369a59
Refactor block module to have submodules (#512)
* create hash submodule for block

* create header submodule for block

* create serialize submodule for block

* add newline to hash.rs (fmt)

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

Co-authored-by: Jane Lusby <jlusby42@gmail.com>

Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2020-06-25 09:18:05 -07:00
teor a9efb8715e chain: Update the note about time truncation 2020-06-24 18:22:36 +10:00
teor 3f5e2695e3 chain: Tweak the version and time test bounds
Use MAX constants for the block header version and time arbitrary test
ranges. Reduces the block header time arbitrary test range from 2**32 to
2**32-1 (u32::MAX). (2**32 is an invalid time value, which gets
truncated to 0 during serialization.)

Also add some comments about DateTime conversions.

Part of #477.
2020-06-24 18:22:36 +10:00
Henry de Valence a023ba9b16
Add serde bounds to zebra-chain structures. (#231) 2020-06-15 15:08:14 -07:00
teor 210e11a86d chain: Check the maximum block size when parsing
The maximum block size is 2,000,000 bytes. This commit also limits the
maximum transaction size in parsed blocks. (See #484 for the
corresponding limit on mempool transactions.)

The proptests might test the maximum block size, but they are
randomised. So we also want to explicitly test large block sizes.
(See #482 for these test cases and tests.)

Part of #477.
2020-06-15 11:00:48 -07:00
Jane Lusby 9f802cd8dd Wrap Transaction in Arc 2020-06-06 18:13:17 -04:00
teor f1de07889c Fix a typo in a comment in block.rs 2020-06-04 04:49:23 -04:00
Jane Lusby e9af80b875
Add initial version of zebra-state (#414)
* rename zebra-storage to zebra-state

* Setup initial skeleton for zebra-state

* add test

* Apply suggestions from code review

Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>

* move shared test vectors to a common crate

Co-authored-by: Jane Lusby <jane@zfnd.org>
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-06-02 16:16:17 -07:00
Jane Lusby b6b35364f3 cleanup warnings throughout codebase 2020-05-27 15:42:29 -04:00
Henry de Valence 6ec934a8d7 impl FromStr for BlockHeaderHash
This is very convenient for putting block hashes in the source code.
2020-03-18 21:34:02 -04:00
Henry de Valence dd8ba287bf Correct block version parsing. 2020-03-18 21:34:02 -04:00
Henry de Valence c4d72177c2 Add a Block::coinbase_height() method. 2020-02-14 18:23:41 -05:00
Henry de Valence 4957567409 Represent coinbase inputs explicitly.
Coinbase inputs are handled differently from other inputs and have
different consensus rules, so they should be represented differently in
the source code.  This lets us discard extraneous details (for instance,
it's not necessary to maintain the all-zero hash) and specialize logic.
2020-02-14 18:23:41 -05:00
Henry de Valence 3c6fda8e0b Make the BlockHeaderHash conversions work on borrows. 2020-02-10 09:03:56 -08:00
Henry de Valence 5f6bf188ff Derive Hash for BlockHeaderHash.
This allows using BlockHeaderHashes in HashSets, HashMaps, etc.
2020-02-10 09:03:56 -08:00
Henry de Valence ebf60b8840 Make BlockHeader fields public. 2020-02-10 09:03:56 -08:00
Henry de Valence 972d16518f Make ZcashSerialize infallible mod its Writer.
Closes #158.

As discussed on the issue, this makes it possible to safely serialize
data into hashes, and encourages serializable data to make illegal
states unrepresentable.
2020-02-05 19:48:43 -05:00
Henry de Valence f04f4f0b98 Apply clippy fixes 2020-02-05 12:42:32 -08:00
Deirdre Connolly 4fcb66ad3b Read and write the block header version, which is fixed at 4 2020-02-04 18:04:53 -05:00
Deirdre Connolly 9b6a9d8e86 Remove debugging variable assignments 2020-02-04 18:04:53 -05:00
Deirdre Connolly 36e9bb162f Move block type tests and proptest support impls to block::tests 2020-02-04 18:04:53 -05:00
Deirdre Connolly 6508540a92 Remove derive(Arbitrary) on BlockHeader 2020-02-04 18:04:53 -05:00
Deirdre Connolly b758a8f753 Extend blockheaderhash unit test to check a single (de)serialization case roundtrip 2020-02-04 18:04:53 -05:00
Deirdre Connolly dab99ba861 Impl Zcash(De)Serialization for Block 2020-02-04 18:04:53 -05:00
Deirdre Connolly f5c135ee1b Use updated EquihashSolution in BlockHeader 2020-02-04 18:04:53 -05:00
Deirdre Connolly e82cf0f5a8 Add BlockHeaderHash (de)serialization roundtrip proptest 2020-02-04 18:04:53 -05:00
Deirdre Connolly 69164a6943 Add test for BlockHeaderHash::from(BlockHeader) 2020-02-04 18:04:53 -05:00
Deirdre Connolly 29e1be2442 Impl Zcash(De)Serialize for BlockHeader 2020-02-04 18:04:53 -05:00
Deirdre Connolly 65d988471a Implement custom Debug for Sha256dChecksum
Relates to #63
2019-10-17 09:33:10 -07:00
Deirdre Connolly 539a16979b Implement custom Debug impl for BlockHeaderHash
Includes a testcase and write_all implementation for Sha256dWriter.

Related to #63
2019-10-17 09:33:10 -07:00