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
b24f53f4a1
Add From impls for InventoryHash
2020-02-04 17:48:36 -08:00
Deirdre Connolly
6d3d4c4f64
s/GetData/NotFound/ in read_notfound
2020-02-04 18:04:53 -05:00
Deirdre Connolly
1ca55846eb
Little test to exercise sha256dWriter::flush()
2020-02-04 18:04:53 -05:00
Deirdre Connolly
beb72080cb
Delete out of date comment on incomplete Message variants
2020-01-30 13:39:13 -05:00
Deirdre Connolly
53a7af82a0
Add back a missing quotemark
...
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2020-01-28 03:48:23 -05:00
Deirdre Connolly
71d5571e39
Add roundtrip proptest for LockTime serialization/deserialization
...
Relates to #150
2020-01-28 03:48:23 -05:00
Deirdre Connolly
c2411f4315
Add a little proptest around Magic's Debug impl
2020-01-28 03:48:23 -05:00
Deirdre Connolly
9709b54c57
Fix proptest-regressions locations after reorganizations of files
2020-01-28 03:48:23 -05:00
Henry de Valence
92ddf0542f
Provide impl Zcash[De]Serialize for Vec<T: Zcash[De]Serialize>.
...
This replaces the read_list function and makes the code significantly cleaner.
The only downside is that it loses exact preallocation, but this is probably not a big deal.
2019-12-31 02:46:39 -05:00
Henry de Valence
2965187b91
Upgrade tokio, futures, hyper to released versions.
2019-12-13 17:42:15 -05:00
Deirdre Connolly
d559a3fa52
Return an error result if the filterload msg size is out of bounds
2019-12-05 13:48:42 -05:00
Deirdre Connolly
cbd95dfc1f
Pass body_len to read_filterload instead of calculating it ourself
...
This lets us still be generic over the reader trait and we aren't recomputing again.
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-12-05 13:48:42 -05:00
Deirdre Connolly
3fbfffeb44
Remove superfluous zcash_(de)serialize impls
2019-12-05 13:48:42 -05:00
Deirdre Connolly
9a0c2198aa
Parse out exact/max possible lengths for filterload filters
...
Add some unit tests that make sure we obey max values.
2019-12-05 13:48:42 -05:00
Deirdre Connolly
78f0b8aab0
Remove NODE_BLOOM service bit
...
We do not support bloom filters.
2019-12-05 13:48:42 -05:00
Deirdre Connolly
3c26092b01
Read max of 520 bytes for data fields when parsing filteradd messages
2019-12-05 13:48:42 -05:00
Deirdre Connolly
1b8b4d0fac
Encode and decode Filter* messages
...
Also remove stubs related to MerkleBlock and the catchall case for unknown types since we
are finally matching all variants of the Message enum.
2019-12-05 13:48:42 -05:00
Deirdre Connolly
72def27b78
Add FilterLoad, FilterAdd, FilterClear message variants
...
Also remove MerkleBlock stub, we are no longer supporting it (zcashd doesn't either).
2019-12-05 13:48:42 -05:00
Deirdre Connolly
f5aa5f3794
Add Tweak and Filter types
2019-12-05 13:48:42 -05:00
Henry de Valence
6db852fab2
Refactor protocol into internal, external modules.
...
This commit just moves things around and patches import paths.
2019-11-27 05:06:01 -05:00
Deirdre Connolly
8a9a5ba29b
Revert "Add some simple proptests using the Arbitray trait on Requests and Responses, gated to test only"
...
This reverts commit 5a123acf561c3f17bc2647e7ff3fbfcf98ce1f8d.
2019-11-26 19:35:49 -05:00
Deirdre Connolly
6f52fc7773
Add 'Other' opcode matching when parsing Reject messages
2019-11-26 19:35:49 -05:00
Deirdre Connolly
dd042cf4d8
Add some simple proptests using the Arbitray trait on Requests and Responses, gated to test only
2019-11-26 19:35:49 -05:00
Deirdre Connolly
6168cb51d7
Prefixed currently unused error variable with underscore
2019-11-26 19:35:49 -05:00
Deirdre Connolly
efd37300b9
Impl From trait for Responses from generic Error impls
...
Also include new Response::Error variant.
2019-11-26 19:35:49 -05:00
Deirdre Connolly
9cdef4acf0
Implement From trait for generic Error impls
...
Also add 'Other' RejectCode variant.
2019-11-26 19:35:49 -05:00
Deirdre Connolly
bae9347f6e
Rustfmt
2019-11-26 19:35:49 -05:00
Deirdre Connolly
ed77aaacd9
Read and write Reject messages
...
Also change field type to as it's unclear if it actually has
to match the set of enum variants we care about.
2019-11-26 19:35:49 -05:00
Deirdre Connolly
189d89a7fc
Handle 'mempool' messages as 'GetMempool' requests
...
With a 'Transactions' response that gets turned into an 'Inv(Vec<InventoryHash::Tx>)' message.
We don't yet handle a response from our peer for a 'mempool', which will have to be
a more generic 'Inv' type because we might receive transaction hashes we don't know about yet.
Pertains to #26
2019-11-18 15:55:25 -05:00
Deirdre Connolly
98079c9d77
Support Mempool message
...
This does not yet push requests into services that actually respond with transaction
hashes in our node's mempool, which doesn't exist yet.
Pertains to #26
2019-11-18 15:55:25 -05:00
Deirdre Connolly
61a07c67ef
Inside tokio::spawn, loop over Iterator stream and send ClientRequest
...
msgs on the channel instead
Related to #49
2019-10-21 15:55:18 -04:00
Deirdre Connolly
adffc4239d
Partially complete heartbeats to peer
2019-10-21 15:55:18 -04:00
Henry de Valence
ad43a61fb4
Ensure that all types appearing in public types are exported.
2019-10-18 16:11:01 -07:00
Henry de Valence
1f0a7e5e73
Remove Codec::builder doctest.
...
Doctests can only test public API, so now that the Codec is private, we can't
have a doctest. Since this test was only a code example (no behaviour test),
there's no value in replacing it with a unit test.
2019-10-18 16:11:01 -07:00
Henry de Valence
0a56830eab
Ascii-fy the command string in message header trace
2019-10-17 13:22:33 -04:00
Henry de Valence
db7ac53f3b
Add a Mutex<HashSet<Nonce>> to detect self-conns.
2019-10-17 09:34:18 -07:00
Henry de Valence
31651cf87c
Fix copy-paste bug in Codec
...
Co-authored-by: George Tankersley <george@zfnd.org>
2019-10-17 09:34:18 -07:00
Deirdre Connolly
0db69addec
Add custom Debug impl for DecodeState
...
Relates to #63
2019-10-17 09:33:10 -07:00
Deirdre Connolly
051dc2f039
Implement custom Debug for Magic types
...
Related to #63
2019-10-17 09:33:10 -07:00
Henry de Valence
f6e62b0f5e
Remove failure from zebra-chain, zebra-network.
...
Failure uses a distinct Fail trait rather than the standard library's
Error trait, which causes a lot of interoperability problems with tower
and other Error-using crates. Since failure was created, the standard
library's Error trait was improved, and its conveniences are now
available without the custom Fail trait using `thiserror` (for easy
error derives) and `anyhow` (for a better boxed Error).
2019-10-16 13:16:52 -04:00
Deirdre Connolly
dc18e8f24c
Remove .expect()s for block and transaction, they might fail for writer reasons
2019-10-09 22:25:37 -04:00
Deirdre Connolly
4ec7590b42
Add placeholders for remaining messages in write_body
2019-10-09 22:25:37 -04:00
Deirdre Connolly
d8986098c6
Add write_body implementations for GetData, NotFound, and a placeholder for Reject
2019-10-09 22:25:37 -04:00
Deirdre Connolly
483d6584f9
Add Block msg reader and writers, and Tx msg writer
2019-10-09 22:25:37 -04:00
Deirdre Connolly
8dc9181610
Fill out write_body for GetBlocks, GetHeaders, Headers messages
2019-10-09 22:25:37 -04:00
Deirdre Connolly
a0302a5507
Implement read_getaddr
2019-10-09 22:25:37 -04:00
Deirdre Connolly
cfbe8dfdbf
Add comments about the 500 blocks /2000 headers max numbers are speculative based on Bitcoin docs
2019-10-09 22:25:37 -04:00
Deirdre Connolly
5acdaa6d2f
Remove some defunct XXXs
2019-10-09 22:25:37 -04: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
Deirdre Connolly
eed69063f6
Add read_list to ReadZcashExt
2019-10-09 22:25:37 -04:00
Deirdre Connolly
d470dd9709
Parse messages
2019-10-09 22:25:37 -04:00
Deirdre Connolly
b991c413cd
Parse GetBlock messages
2019-10-09 22:25:37 -04:00
Deirdre Connolly
7632d5b8cc
Abstract the common case of a message with a Vec<InventoryHash>
2019-10-09 22:25:37 -04:00
Deirdre Connolly
9699ef2fa1
Codec::read_tx()
2019-10-09 22:25:37 -04:00
Deirdre Connolly
565dc92afe
Support a response message
2019-10-09 22:25:37 -04:00
Henry de Valence
ed608f7231
Initial tower-based peer implementation. ( #17 )
...
Add a tower-based peer implementation.
Tower provides middleware for request-response oriented protocols, while Bitcoin/Zcash just send messages which could be interpreted either as requests or responses, depending on context. To bridge this mismatch we define our own internal request/response protocol, and implement a per-peer event loop that scans incoming messages and interprets them either as requests from the remote peer to our node, or as responses to requests we made previously. This is performed by the `PeerService` task, and a corresponding `PeerClient: tower::Service` can send it requests. These tasks are themselves created by a `PeerConnector: tower::Service` which dials a remote peer and performs a handshake.
2019-10-07 15:36:16 -07:00
Henry de Valence
f5dca597dd
Replace PeerServices(u64) with a bitflags struct.
...
This gives considerably better ergonomics.
2019-10-01 01:07:56 -04:00
Henry de Valence
9603a29399
Rename `Services` to `PeerServices`.
...
This field is called `services` in Bitcoin and Zcash, but because we use
that word internally for other purposes, calling it `PeerServices`
disambiguates the meaning to "the services advertised by the peer",
rather than, e.g., a `tower::Service`.
2019-10-01 01:07:56 -04: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
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
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
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
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
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
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