Commit Graph

5309 Commits

Author SHA1 Message Date
dependabot-preview[bot] cd8e67b47c Bump hex from 0.4.1 to 0.4.2
Bumps [hex](https://github.com/KokaKiwi/rust-hex) from 0.4.1 to 0.4.2.
- [Release notes](https://github.com/KokaKiwi/rust-hex/releases)
- [Commits](https://github.com/KokaKiwi/rust-hex/compare/v0.4.1...v0.4.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-18 10:09:13 -08:00
Henry de Valence 7f91099172 Put grafana on port 3030. 2020-02-14 20:14:05 -05:00
Henry de Valence 8bff6ada6c Prevent a crash serializing configs. 2020-02-14 20:14:05 -05:00
Henry de Valence 00edcae0c2 Add metrics for the crawler and candidate set. 2020-02-14 20:14:05 -05:00
Henry de Valence cb9c9e1676 Tell Prometheus to scrape more aggressively 2020-02-14 20:14:05 -05:00
Henry de Valence c19e9916b5 Persist Prometheus data 2020-02-14 20:14:05 -05:00
Henry de Valence 34ca18eed8 Add prometheus config, notes.
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2020-02-14 20:14:05 -05:00
Henry de Valence 75d3d44fb3 Metrics MVP: add two metrics and export them to Prometheus.
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2020-02-14 20:14:05 -05:00
Henry de Valence b443d7a4be Fix clippy lints. 2020-02-14 18:23:41 -05:00
Henry de Valence 8000f888fd Connect to multiple peers concurrently.
The previous outbound peer connection logic got requests to connect to new
peers and processed them one at a time, making single connection attempts
and retrying if the connection attempt failed.  This was quite slow, because
many connections fail, and we have to wait for timeouts.  Instead, this logic
connects to new peers concurrently (up to 50 at a time).
2020-02-14 18:23:41 -05:00
Henry de Valence 7ba007f23d Exercise network functionality by downloading lots of blocks.
(Don't check any information about them, just blindly download).
2020-02-14 18:23:41 -05:00
Henry de Valence d887faf16f Add PartialOrd, Ord to BlockHeight. 2020-02-14 18:23:41 -05:00
Henry de Valence c4d72177c2 Add a Block::coinbase_height() method. 2020-02-14 18:23:41 -05:00
Henry de Valence 56d7391f6d Add convenience methods to Transaction.
Because we represent each transaction version as a different variant of the
Transaction enum, we end up in a situation where fields that are common to
different transaction versions are awkward to access, requiring a match
statement with identical match arms.

To fix this, this commit adds the following convenience methods:

* `Transaction::inputs() -> impl Iterator<Item=&TransparentInput>`;
* `Transaction::outputs() -> impl Iterator<Item=&TransparentOutput>`;
* `Transaction::lock_time() -> LockTime`;
* `Transaction::expiry_height() -> Option<ExpiryHeight>`;

The last returns an `Option` because the field is only present in V3 and V4
transactions.

There are some remaining fields that do not get common accessors, because it
probably doesn't make sense to access independently of knowing the transaction
version: `joinsplit_data`, `shielded_data`, `value_balance`.
2020-02-14 18:23:41 -05:00
Henry de Valence 7049f9d891 Add a FindBlocks request to get initial block hashes.
Bitcoin does this either with `getblocks` (returns up to 500 following block
hashes) or `getheaders` (returns up to 2000 following block headers, not
just hashes).  However, Bitcoin headers are much smaller than Zcash
headers, which contain a giant Equihash solution block, and many Zcash
blocks don't have many transactions in them, so the block header is
often similarly sized to the block itself.  Because we're
aiming to have a highly parallel network layer, it seems better to use
`getblocks` to implement `FindBlocks` (which is necessarily sequential)
and parallelize the processing of the block downloads.
2020-02-14 18:23:41 -05:00
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