Commit Graph

3988 Commits

Author SHA1 Message Date
Deirdre Connolly 60fb4f6bb0 Remove InventoryType::MsgCmpctBlock
From BIP-152, which is not implemented by Zcash.
2019-09-18 17:32:06 -04:00
Deirdre Connolly 3032da8b1b Remove defunct and dead try_read 2019-09-18 17:32:06 -04:00
Deirdre Connolly 65632e9f42 Correct comment about pzec bytes::Bytes 2019-09-18 17:32:06 -04:00
Deirdre Connolly 8edbc7b744 Resolve 'warning: unused that must be used' error 2019-09-18 17:32:06 -04:00
Deirdre Connolly 46984cbb27 Add `tx` message, along with `Transaction`, `Transaction(In|Out)put`, and `OutPoint` types 2019-09-18 17:32:06 -04:00
Henry de Valence e0cd099487 Fix type with updated tracing-subscriber
An updated tracing-subscriber version changed one of the public types;
because we hardcode the type instead of being generic over S:
Subscriber, this was actually a breaking change.  As noted in the
comment adjacent to this line, we would rather be generic over S, but
this requires fixing a bug in abscissa's proc-macros, so in the meantime
we hardcode the type.
2019-09-18 17:32:06 -04:00
Deirdre Connolly cc9da18554 Use an Option around optional Reject message data
And replace Timestamp with chrono::DateTime
2019-09-18 17:32:06 -04:00
Henry de Valence adc421f7fe Implement ZcashDeserialize for Message::Version.
This has a test that the serialization implementation round trips
correctly, but is very much a work in progress.  Issues with this code
include:

The deserialization logic for message headers is somewhat ugly because
of a lack of a convenient idiom for reading a few bytes at a time into a
fixed-size array.  Perhaps this could be fixed with an extension trait,
or avoided altogether by using `u32`s instead of `[u8; 4]`, even when
the latter is the "morally correct type".

Deserialization does an extra allocation, copying the body into a
temporary buffer.  This avoids two problems: 1) capping the number of
bytes that can be read by the `Read`er passed into the body parser and
2) allows making two passes over the body data, one to parse it and one
to compute the checksum.

We could avoid making two passes over the body by computing the checksum
simultaneously with the parsing. A convenient way to do this would be to
define a

```
struct ChecksumReader<R: Read> {
    inner: R,
    digest: Sha256,
}

impl<R: Read> Read for ChecksumReader<R> { /* ... */ }
```

and implement `Read` for `ChecksumReader` to forward reads from the
inner reader, copying data into the digest object as it does so.  (It
could also have a maximum length to enforce that we do not read past the
nominal end of the body).

A similar `ChecksumWriter` could be used during serialization, although
because the checksum is at the beginning rather than the end of the
message it does not help avoid an allocation there.  It could also be
generic over a `Digest` implementation, although because we need a
truncated double-SHA256 we would have to write a custom `Digest`
implementation, so this is probably not worthwhile unless we have other
checksum types.

Finally, this does very minimal testing -- just round-trip serialization
on a single message.  It would be good to build in support for
property-based testing, probably using `proptest`; if we could define
generation and shrinking strategies for every component type of every
message, we could do strong randomized testing of the serialization.
2019-09-18 17:32:06 -04:00
Henry de Valence 733d090b9b Add missing derives to newtypes. 2019-09-18 17:32:06 -04:00
Henry de Valence 32cf74db39 Move serialization to zebra-chain, rework traits.
The core serialization logic is now in zebra-chain and consists of two
pairs of traits:

These are analogues of the Serde `Serialize` and `Deserialize` traits,
but explicitly intended for consensus-critical serialization formats.
Thus some struct `Foo` may have derived `Serialize` and `Deserialize`
implementations for (internal) use with Serde, and explicitly-written
`ZcashSerialize` and `ZcashDeserialize` implementations for use in
consensus-critical contexts.  The consensus-critical implementations
provide `zcash`-prefixed `zcash_serialize` and `zcash_deserialize`
methods to make it clear in client contexts that the serialization is
consensus-critical.

These are utility traits, analogous to the `ReadBytesExt` and
`WriteBytesExt` traits provided by `byteorder`.  A generic
implementation is provided for any `io::Read` or `io::Write`, so that
bringing the traits into scope adds additional Zcash-specific traits to
generic readers and writers -- for instance, writing a `u64` in the
Bitcoin "CompactSize" format.
2019-09-18 17:32:06 -04:00
Henry de Valence 78b1aabed0 Deserialize Bitcoin-encoded strings. 2019-09-18 17:32:06 -04:00
Henry de Valence 715ed52617 Deserialize Bitcoin-encoded IP addresses. 2019-09-18 17:32:06 -04:00
Henry de Valence 3c32beb8f0 Add a &'static str error message to ParseError. 2019-09-18 17:32:06 -04:00
Henry de Valence d847dc1356 Start implementing serialization for Version. 2019-09-18 17:32:06 -04:00
Henry de Valence b98e1c7853 Add ZcashSerialization impls for some std types. 2019-09-18 17:32:06 -04:00
Henry de Valence 1f280b7bb8 Make MetaAddr fields public. 2019-09-18 17:32:06 -04:00
Henry de Valence 8a3cabc686 Define Magic newtype as `[u8; 4]`, not `u32`.
The magic value isn't a u32, it's a byte string, so specifying it as
such avoids ambiguity about endianness.
2019-09-18 17:32:06 -04:00
Henry de Valence 00cc1284ae Add a stub ZcashSerialization trait.
There are a few unresolved questions marked in the doc comment for the trait;
we can resolve them later and rework the trait as we map everything out.
2019-09-18 17:32:06 -04:00
Henry de Valence 73cd06b4dc Add derived impls to newtypes 2019-09-18 17:32:06 -04:00
Henry de Valence c3b7dcdfbe Add Read/WriteZcashExt extension traits.
Currently these just have write_compactsize and read_compactsize methods which
allow reading and writing u64s to any `Read` or `Write` implementation using
the Bitcoin "CompactSize" variable integer encoding.

These methods read and write u64s rather than defining a new `CompactSize`
type, because the `CompactSize` is just an encoding detail, not a different
type with any distinct meaning.
2019-09-18 17:32:06 -04:00
Henry de Valence 50f749a817 Try writing message headers. 2019-09-18 17:32:06 -04:00
Henry de Valence cf63f00171 Add a Magic type for network magics. 2019-09-18 17:32:06 -04:00
Henry de Valence 42cb9c1ff9 Add a `Sha256dChecksum` type for truncated double SHA256. 2019-09-18 17:32:06 -04:00
Henry de Valence b9af047a09 Introduce a `MetaAddr` type replacing `NetworkAddress`.
The `NetworkAddress` type was a `(Services, SocketAddr)` pair as used in the
`version` handshake message, described as the `net_addr` struct in the Bitcoin
wiki protocol documentation.  However, all of the other uses of the `net_addr`
struct are a `(Timestamp, Services, SocketAddr)` pair (where the timestamp is
the last-seen time of the peer), and the timestamp is omitted only during the
`version` messages, which are used only during the handshake, so it seems
better to include the timestamp field and omit it during serialization of
`version` packets.
2019-09-18 17:32:06 -04:00
Henry de Valence 1d0517fe56 Split parts of message.rs into constants.rs, types.rs 2019-09-18 17:32:06 -04:00
Henry de Valence eeb0ab7c43 fixup! Add InventoryType, InventoryVector, and Message::{Inventory, GetData, NotFound} 2019-09-18 17:32:06 -04:00
Deirdre Connolly a2e50833be Add InventoryType, InventoryVector, and Message::{Inventory, GetData, NotFound} 2019-09-18 17:32:06 -04:00
Henry de Valence 7fb71a7a9e Replace Timestamp with chrono::DateTime<Utc> 2019-09-18 17:32:06 -04:00
Deirdre Connolly fa8b5290b5 Add Reject message type and RejectReason enum 2019-09-18 17:32:06 -04:00
Deirdre Connolly a4a21138d0 Update user_agent docstring
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2019-09-18 17:32:06 -04:00
Deirdre Connolly c39d2c7510 Doc comments for various structures and fields
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2019-09-18 17:32:06 -04:00
Deirdre Connolly ac0d9732a0 WIP: Version message and various sub structures
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2019-09-18 17:32:06 -04:00
Henry de Valence 8c2b066885 Add more message variants. 2019-09-18 17:32:06 -04:00
Deirdre Connolly 42412ec2a8 Some line breaks for readability 2019-09-18 17:32:06 -04:00
Henry de Valence 80308f85e1 Add a skeleton enum for network messages. 2019-09-18 17:32:06 -04:00
Deirdre Connolly 162b37fe8d Tracing endpoint (#3)
* Add a TracingConfig and some components

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>

* Restructure, use dependency injection, initialize tracing

* Start a placeholder loop in start command

* Add hyper alpha.1, bump tokio to alpha.4

* Hello world endpoint using async/await from hyper 0.13 alpha

Also cleaned up some linter messages.

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

* Update to tracing_subscriber 0.1

* fmt

* add rust-toolchain

* Remove hyper::Version import

* wip: start filter_handler impl

* Add .rustfmt.toml

* rustfmt

* Tidy up .rustfmt.toml

* Add filter reloading handling.

* bump toolchain

* Remove generated hello world acceptance tests.

These test the behaviour of the autogenerated binary and work as examples of
how to test the behaviour of abscissa binaries.  Since we don't print "Hello
World" any more, they fail, but we don't yet have replacement behaviour to add
tests for, so they're removed for now.

* Clean up config file handling with Option::and_then.
2019-09-09 13:05:42 -07:00
Deirdre Connolly 8fe3403de0
Continuous integration (#2)
* Add CI workflow similar to other zebra

* Bump cache TTL to 24hours

* Expand image name to include full repo owner/repo-name/branch-name

* Force to lowercase because google container registry demands it

This may not be universally shell compatible

* Use bash as gcloud action container entrypoint
2019-09-05 13:08:48 -04:00
Henry de Valence ec363d2d41 Create workspace skeleton based on design.md 2019-08-29 14:46:54 -07:00