Commit Graph

2244 Commits

Author SHA1 Message Date
Henry de Valence 47cafc630f Remove version fields from GetBlocks, GetHeaders.
These are instead set by the negotiated version.
2020-02-14 18:23:41 -05:00
Henry de Valence 44b299d15c Parse block heights in coinbase transactions.
BIP34, which is included in Zcash, encodes the block height into each
block by adding it into the unused BitcoinScript field of the block's
coinbase transaction.  However, this is done just by requiring that the
script pushes the block height onto the stack when it executes, and
there are multiple different ways to push data onto the stack in
BitcoinScript.  Also, the genesis block does not include the block
height, by accident.

Because we want to *parse* transactions into an algebraic data type that
encodes their structural properties, rather than allow possibly-invalid
data to float through the internals of our node, we want to extract the
block height upfront and store it separately from the rest of the
coinbase data, which is inert.  So the serialization code now contains
just enough logic to parse BitcoinScript-encoded block heights, and
special-case the encoding of the genesis block.

Elsewhere in the source code, the `LockTime` struct requires that we
must use block heights less than 500,000,000 (above which the number is
interpreted as a unix timestamp, not a height).  To unify invariants, we
ensure that the parsing logic works with block heights up to
500,000,000, even though these are unlikely to ever be used for Zcash.
2020-02-14 18:23:41 -05:00
Henry de Valence 5059c23e99 Add test vectors for genesis & early blocks. 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
dependabot-preview[bot] be56e10abe Bump tracing-futures from 0.2.1 to 0.2.2
Bumps [tracing-futures](https://github.com/tokio-rs/tracing) from 0.2.1 to 0.2.2.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-futures-0.2.1...tracing-futures-0.2.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-14 17:48:44 -05:00
dependabot-preview[bot] fdd90cb1d5 Bump thiserror from 1.0.10 to 1.0.11
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 1.0.10 to 1.0.11.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](https://github.com/dtolnay/thiserror/compare/1.0.10...1.0.11)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-14 16:40:50 -05:00
Deirdre Connolly 99e3b16476 Make Memo a wrapper for Box<[u8; 512]> 2020-02-13 15:04:04 -05:00
Deirdre Connolly ea8fa5ef46 Not public for the moment 2020-02-13 15:04:04 -05:00
Deirdre Connolly 01fcce53f4 Move memo to its own module under note_encryption, turn try_from into a match cmp 2020-02-13 15:04:04 -05:00
Deirdre Connolly 54b1172dc8 Avoid a few heap allocations that aren't strictly needed 2020-02-13 15:04:04 -05:00
Deirdre Connolly 2468acb9db Add some docs to clarify that a Memo is a 'plaintext' type, the parent note will be encrypted 2020-02-13 15:04:04 -05:00
Deirdre Connolly d7ccf255e1 Update memo link to spec
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2020-02-13 15:04:04 -05:00
Deirdre Connolly 362f773762 Tidy tests 2020-02-13 15:04:04 -05:00
Deirdre Connolly 30a7647682 Move over various EncryptedCiphertext types from transaction/ module 2020-02-13 15:04:04 -05:00
Deirdre Connolly ecaaa21d1c Improve test for Memo::from support 2020-02-13 15:04:04 -05:00
Deirdre Connolly b8f7487e54 Use AsRef<[u8]>> in From impl 2020-02-13 15:04:04 -05:00
Deirdre Connolly 8572c70716 impl From<String> for Memo
I want From<str> but need Sized
2020-02-13 15:04:04 -05:00
Deirdre Connolly d4d1cf8d7b Add memo type with Debug impl and some test cases 2020-02-13 15:04:04 -05:00
Henry de Valence 3c9b5612f3 Update zebrad docs and README. 2020-02-12 12:50:55 -08:00
Henry de Valence abcc0a6773 Add basic retry policies to zebra-network.
This should be removed when https://github.com/tower-rs/tower/pull/414 lands
but is good enough for our purposes for now.
2020-02-11 15:23:19 -05:00
Henry de Valence 5191b9d1d5 Try building internal docs. 2020-02-10 18:12:43 -08:00
dependabot-preview[bot] ef978756cb Bump hex from 0.4.0 to 0.4.1
Bumps [hex](https://github.com/KokaKiwi/rust-hex) from 0.4.0 to 0.4.1.
- [Release notes](https://github.com/KokaKiwi/rust-hex/releases)
- [Commits](https://github.com/KokaKiwi/rust-hex/compare/v0.4...v0.4.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-10 12:25:20 -05:00
Henry de Valence befdb46dc3 Clean some warnings in the Bitcoin codec.
This doesn't clean the warnings about unused items in the builder, since
those are unused for a reason (the implementation that should use them
is missing).
2020-02-10 09:03:56 -08:00
Henry de Valence 2082672b3c Remove Response::Error.
Error handling is already handled by Result; we don't need an "inner"
error variant duplicating the outer one.
2020-02-10 09:03:56 -08:00
Henry de Valence 29f901add3 Rename Response::Ok to Response::Nil.
This is a better name because it signals "no data in response" rather
than "Ok", which is semantically mixed with `Ok/Err` of `Result`.
2020-02-10 09:03:56 -08:00
Henry de Valence 5929e05e52 Remove `PushPeers` and ignore unsolicited `addr` messages.
PushPeers is more complicated to thread into the rest of our
architecture (we would need to establish a data path connecting our
service handling inbound requests to the network layer's auto-crawler),
and since we crawl the network automatically anyways, we don't actually
need to accept them in order to get updated address information.

The only possible problem with this approach is that zcashd refuses to
answer multiple address requests from the same connection, ostensibly
for fingerprinting prevention (although it's totally happy to give
exactly the same information, as long as you hang up and reconnect
first, lol).  It's unclear how this will interact with our design -- on
the one hand, it could mean that we don't get new addr information when
we ask, but on the other hand, we may have enough churn in our
connection pool that this isn't a problem anyways.
2020-02-10 09:03:56 -08:00
Henry de Valence 2c0f48b587 Refactor connection logic and try a block request.
Attempting to implement requests for block data revealed a problem with
the previous connection logic.  Block data is requested by sending a
`getdata` message with hashes of the requested blocks; the peer responds
with a sequence of `block` messages with the blocks themselves.

However, this wasn't possible to handle with the previous connection
logic, which could only convert a single Bitcoin message into a
Response.  Instead, we factor out the message handling logic into a
Handler, which can statefully accumulate arbitrary data into a Response
and signal completion.  This is still pretty ugly but it does work.

As a side effect, the HeartbeatNonceMismatch error is removed; because
the Handler now tries to process messages until it comes to a Response,
it just ignores mismatched nonces (and will eventually time out).

The previous Mempool and Transaction requests were removed but could be
re-added in a different form later.  Also, the `Get` prefixes are
removed from `Request` to tidy the name.
2020-02-10 09:03:56 -08: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
Deirdre Connolly 824f206dbe Add several Debug impls for existing types
Resolves #237
2020-02-07 21:30:48 -08:00
Deirdre Connolly 866acde6e8 Add BLOCK_MAINNET_415000_BYTES test vector and a test to deserialize it
And println! it, for human eyeballs checking.

Resolves #218

Also changes the header constant to use _BYTES.
2020-02-07 13:42:21 -08:00
dependabot-preview[bot] d6c2b7ac32 Bump futures from 0.3.3 to 0.3.4
Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.3 to 0.3.4.
- [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.3...0.3.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-07 10:28:32 -06:00
dependabot-preview[bot] 0392d8fa5d Bump byteorder from 1.3.2 to 1.3.4
Bumps [byteorder](https://github.com/BurntSushi/byteorder) from 1.3.2 to 1.3.4.
- [Release notes](https://github.com/BurntSushi/byteorder/releases)
- [Changelog](https://github.com/BurntSushi/byteorder/blob/master/CHANGELOG.md)
- [Commits](https://github.com/BurntSushi/byteorder/compare/1.3.2...1.3.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-07 10:24:49 -06: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 b0f61c4dd2 Remove outdated comment (we use tokio codecs now) 2020-02-05 19:44:35 -05:00
Henry de Valence ab94acf7da fmt 2020-02-05 19:44:35 -05:00
Henry de Valence eeb4a2470b Remove version fields from Block, Tx messages.
These are included in the Block, Transaction objects themselves, so the
previous code ended up trying to deserialize two version fields per
object.

Closes #226.
2020-02-05 19:44:35 -05:00
Henry de Valence 51c744b1ae Update network version number. 2020-02-05 14:06:35 -08:00
Henry de Valence 9273f83761 Remove tracing-subscriber.
We don't need to handle the subscriber directly since we upstreamed this
functionality into Abscissa.
2020-02-05 14:05:46 -08:00
Henry de Valence 8d58dd804f Note that tracing causes clippy false positives
Thanks @hawkw for pointing this out.
2020-02-05 12:42:32 -08:00
Henry de Valence f04f4f0b98 Apply clippy fixes 2020-02-05 12:42:32 -08:00
Henry de Valence a0d0d297d9 Try clippy in CI 2020-02-05 12:42:32 -08:00
dependabot-preview[bot] 979cf7ac6d Bump indexmap from 1.3.1 to 1.3.2
Bumps [indexmap](https://github.com/bluss/indexmap) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/bluss/indexmap/releases)
- [Commits](https://github.com/bluss/indexmap/compare/1.3.1...1.3.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-05 14:14:51 -05:00
dependabot-preview[bot] e2e63f9b9d Bump futures from 0.3.1 to 0.3.3
Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.1 to 0.3.3.
- [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.1...0.3.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-04 21:14:26 -08:00
Henry de Valence b24f53f4a1 Add From impls for InventoryHash 2020-02-04 17:48:36 -08:00
Deirdre Connolly b860461644 Update test block header hash 2020-02-04 18:04:53 -05:00
Deirdre Connolly 6dedb7e101 Write and read the equihash solution compactsize on (de)serialize 2020-02-04 18:04:53 -05:00
Deirdre Connolly a79969b38f Add comment around sha256d_flush test 2020-02-04 18:04:53 -05:00
Deirdre Connolly 4fcb66ad3b Read and write the block header version, which is fixed at 4 2020-02-04 18:04:53 -05:00