Commit Graph

53 Commits

Author SHA1 Message Date
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
Deirdre Connolly dd1b9166b0 Implement Zcash(De)Serialize for BlockHeaderHash, use general read_list for getheaders/headers 2019-10-09 22:25:37 -04:00
Henry de Valence 47513b1ae7 Suppress warnings from stub functions.
This just replaces a bunch of variable names with underscored variants
while the function bodies are still `unimplemented!()`.
2019-09-30 21:32:57 -04:00
Deirdre Connolly 29591df47e Use the BlockHeaderHash from zebra-chain in the Inv message parsing 2019-09-27 19:22:34 -07:00
Deirdre Connolly 4e85bdb51b Explain in BlockHeaderHash docstrings block hash vs block header hash 2019-09-26 23:41:25 -04:00
Deirdre Connolly df5a5f56dd Add equihash_solution to the lib.rs, impl Zcash(De)Serialize for Block 2019-09-26 23:41:25 -04:00
Deirdre Connolly 3f2a1b4f2c Move around MerkleTree* structs 2019-09-26 23:41:25 -04:00
Deirdre Connolly 677d53897f Use Vec<u8> for the equihash solution instead of [u8; 1344] for now 2019-09-26 23:41:25 -04:00
Deirdre Connolly c4547ea806 Derive Clone, Debug, Default, Eq, and PartialEq for new structs 2019-09-26 23:41:25 -04:00
Deirdre Connolly 38015c11a6 Add stubbed-out *NoteCommitmentTree* structs 2019-09-26 23:41:25 -04:00
Deirdre Connolly 90e5ae2f4b Add improved doc comments 2019-09-26 23:41:25 -04:00
Deirdre Connolly cecbb1cc0a Fill out the Block Message type
Should we serialize out `Block` or leave explicit like so? ¯\_(ツ)_/¯
2019-09-26 23:41:25 -04:00
Deirdre Connolly 0f84a6d38e Implement Zcash(De)serialize traits specifically for MerkleTree<Transaction>
This is a general placeholder for now.
2019-09-26 23:41:25 -04:00