Commit Graph

90 Commits

Author SHA1 Message Date
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
Henry de Valence 79c36a979c Use try_bind when building tracing endpoint.
Prior to this commit, the tracing endpoint would attempt to bind the
given address or panic; now, if it is unable to bind the given address
it displays an error but continues running the rest of the application.
This means that we can spin up multiple Zebra instances for load
testing.
2019-09-30 21:30:36 -04:00
Henry de Valence 1323fa7af7 Update zebra-chain/src/transaction.rs 2019-09-27 19:22:34 -07:00
Deirdre Connolly 2739970113 Fill out TransactionHash and rename
Resolves #35
2019-09-27 19:22:34 -07:00
Deirdre Connolly b21b09bf8e Moved stub TxHash into zebra_chain::transaction 2019-09-27 19:22:34 -07:00
Deirdre Connolly 29591df47e Use the BlockHeaderHash from zebra-chain in the Inv message parsing 2019-09-27 19:22:34 -07:00
Henry de Valence 0a85be285d Add addr, getaddr serialization. 2019-09-27 20:41:45 -04:00
Henry de Valence 9f43d0987b nit: suppress async_await nightly warning. 2019-09-27 20:41:45 -04:00
Henry de Valence b426630613 Clarify comment in decoder state. 2019-09-27 20:41:45 -04:00
Henry de Valence 422c783a47 Rename Message::Inventory -> Message::Inv
I don't feel super strongly about this change, so I'm happy to drop it,
but it makes the parsing match statements line up nicely and aligns
naming with the naming used in Bitcoin.
2019-09-27 20:41:45 -04:00
Henry de Valence 958fca8e68 Parse inv messages, refactor inventory vectors.
This removes the inventory vector structs from `zebra-chain` (as they
are really part of the network protocol) and refactors them into a
single `InventoryHash` type.  This corresponds to Bitcoin's "inventory
vector" but with a different, better name (it's not a vector, it's just
a typed hash of some other item).
2019-09-27 20:41:45 -04:00
Henry de Valence 64b210b53c Add a read_32_bytes helper method.
These are starting to stack up but I think until generic arrays arrive
the cure is worse than the disease :S
2019-09-27 20:41:45 -04:00
Henry de Valence 44b855aab8 Remove unused import in connect stub. 2019-09-27 20:41:45 -04:00
Henry de Valence ab06750db3 zebra-network: move types -> protocol::types
These types are used for protocol messages, so it makes more sense to
keep them scoped with the protocol handling, rather than other
networking logic.
2019-09-27 20:41:45 -04:00
Deirdre Connolly 19258d6f54 Remove duplicate from MerkleTree 2019-09-26 23:41:25 -04:00
Deirdre Connolly b4b72829b2 Sanity: checked 2019-09-26 23:41:25 -04:00
Deirdre Connolly 6236909210 Update zebra-chain/src/transaction.rs
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-09-26 23:41:25 -04:00
Deirdre Connolly 4e85bdb51b Explain in BlockHeaderHash docstrings block hash vs block header hash 2019-09-26 23:41:25 -04:00
Deirdre Connolly 35f03dc55d Make Message.Block just point at a Block type, in codec call block.zcash_serialize() 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 f4a6fec2d8 Comment out EquihashSolution::fmt for now 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 d77dfb2344 Remove unused imports 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
Deirdre Connolly 7340c7d9ce Adding BlockHeader, BlockHash, MerkleRootHash, Sha256dWriter 2019-09-26 23:41:25 -04:00
Deirdre Connolly 00494d4963 Block and BlockHeader types 2019-09-26 23:41:25 -04:00
Henry de Valence fe95ad3824 Suppress unused import warning in ReadZcashExt. 2019-09-25 14:59:47 -07:00
Henry de Valence 48a5054c87 Delete unused variable.
This is no longer required because the body reader methods have access
to the version via the codec state.
2019-09-25 14:59:47 -07:00
Henry de Valence 0196c2c4cd Place header encoding prior to body encoding. 2019-09-25 14:59:47 -07:00
Henry de Valence 94a07b05cc Move HEADER_LEN constant to top of file. 2019-09-25 14:59:47 -07:00
Henry de Valence 28904e01c7 Trace the decoded message in the decoder. 2019-09-25 14:59:47 -07:00
Henry de Valence ea1b60d8e3 Make message body reader fns part of Codec. 2019-09-25 14:59:47 -07:00
Henry de Valence 4e1285b568 Refactor message serialization as a tokio codec.
This provides a significantly cleaner API to consumers, because it
allows using adaptors that convert a TCP stream to a stream of messages,
and potentially allows more efficient message handling.
2019-09-25 14:59:47 -07:00
Henry de Valence 0b1acc50c3 Make a new protocol module with message submodule.
This allows us to organize all of the Bitcoin-Zcash specific parts of
the protocol into a subtree.
2019-09-25 14:59:47 -07:00
Henry de Valence c8a3d47b56 Use tracing::instrument and monitor for messages. 2019-09-23 22:17:12 -04:00
Henry de Valence 15ca12a2f5 Add a `connect` command for testing.
With `./src/zcashd -debug=net -logips=1`:
```
2019-09-19 15:24:38 Added connection to 127.0.0.1:35932 peer=1
2019-09-19 15:24:38 connection from 127.0.0.1:35932 accepted
2019-09-19 15:24:38 socket closed
2019-09-19 15:24:38 disconnecting peer=1
```

With `RUST_LOG="trace"`, `cargo run connect`:
```
Sep 19 08:24:24.530  INFO zebrad::commands::connect: version=Version { version: Version(170007), services: Services(1), timestamp: 2019-09-19T15:24:24.530059300Z, address_recv: (Services(1), V4(127.0.0.1:8233)), address_from: (Services(1), V4(127.0.0.1:9000)), nonce: Nonce(1), user_agent: "Zebra Connect", start_height: BlockHeight(0), relay: false }
Sep 19 08:24:24.530 TRACE Task::run: tokio_executor::threadpool::task: state=Running
Sep 19 08:24:24.530 DEBUG Task::run: tokio_net::driver::reactor: adding I/O source token=0
Sep 19 08:24:24.530  INFO zebrad::commands::connect: version_bytes="24e9276476657273696f6e000000000063000000cb30ab03179802000100000000000000a89d835d00000000010000000000000000000000000000000000ffff7f0000012029010000000000000000000000000000000000ffff7f000001232801000000000000000d5a6562726120436f6e6e6563740000000000"
Sep 19 08:24:24.530 TRACE Task::run: log: registering with poller
```
2019-09-22 17:27:08 -04:00
Henry de Valence df7801d623 Temporarily change hyper to git version.
This avoids some crate selection conflicts, but makes some futures
extension traits fall out of order?  This seems to be an issue with
`pin-project` resolved in the git branch of `hyper` (but not yet
released).
2019-09-22 17:27:08 -04:00
Henry de Valence 976a81e7b9 Use failure::Error in zebra_network::message.
This gives backtraces and more ergonomic errors, at the cost of possible
allocations (which we do here anyways).
2019-09-22 17:06:07 -04:00
Henry de Valence 9fe8f22a84 Add verack, ping, pong serialization. 2019-09-22 17:06:07 -04:00
Henry de Valence 3b51056857 Change Message serialization to async send/recv.
Because we want to be able to read messages from async sources (like a
tcp socket), we need to have at least async header parsing logic, so
that we can correctly determine how many bytes to await to parse each
message, so it makes sense for the entire message parsing functions
to be async.

Because we perform message serialization into async readers and writers
in the context of sending messages over the network, code using these
functions is more clear with these names.
2019-09-22 17:06:07 -04:00
Henry de Valence fa4ba442eb Add a MIN_VERSION constant to zebra_network.
When we perform a handshake with a remote peer, we need to encode the
version messages with a particular network version before we find out
what the remote peer's version preference is.  So in addition to having
a CURRENT_VERSION constant (which represents our preference), we need to
have a MIN_VERSION during the handshake (and later to determine whether
we'll talk to the peer at all).
2019-09-22 17:06:07 -04:00
Henry de Valence 0cb439301a Add a USER_AGENT constant to zebra_network. 2019-09-22 17:06:07 -04:00
Henry de Valence 252dce1bad Use rand::thread_rng to impl Default for Nonce. 2019-09-22 17:06:07 -04:00
Henry de Valence a64a051276 Clean tracing_subscriber deprecation warnings. 2019-09-20 16:02:55 -04:00
Henry de Valence b3e094bc40 Clean parsing via ReadZcashExt read-array helpers.
This adds convenience methods to `ReadZcashExt` that read 4 and 12 byte
fixed size arrays from the `Reader`, making the actual parsing code more
legible.

Closes #10.
2019-09-19 12:53:16 -04:00