Commit Graph

760 Commits

Author SHA1 Message Date
Alfredo Garcia 5b3c6e4c6c
Port bash checkpoint scripts to zebra-checkpoints single rust binary (#740)
* make zebra-checkpoints
* fix LOOKAHEAD_LIMIT scope
* add a default cli path
* change doc usage text
* add tracing
* move MAX_CHECKPOINT_HEIGHT_GAP to zebra-consensus
* do byte_reverse_hex in a map
2020-07-25 17:53:00 +10:00
Henry de Valence b59cfc49b7 sync: create requests sequentially to respect backpressure.
This seems like a better design on principle but also appears to give a much
nicer sawtooth pattern of queued blocks in the checkpointer and a much smoother
pattern of block requests.
2020-07-24 18:36:00 -04:00
Henry de Valence 4aa00ad216 Align crate versions and user-agent with NU numbers.
We had a brief discussion on discord and it seemed like we had consensus on the
following versioning policy:

* zebrad: match major version to NU version, so we will start by releasing
  zebrad 3.0.0;

* zebra-* libraries: start by matching zebrad's version, then increment major
  versions of each library as we need to make breaking changes (potentially
  faster than the zebrad version, always respecting semver but making no
  guarantees about the longevity of major releases).

This commit sets all of the crate versions to 3.0.0-alpha.0 -- the -alpha.0
marks it as a prerelease not subject to perfect adherence to compatibility
guarantees.
2020-07-24 11:46:37 -07:00
dependabot[bot] f7c59c99b5 build(deps): bump tracing-subscriber from 0.2.8 to 0.2.9
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.8 to 0.2.9.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.8...tracing-subscriber-0.2.9)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-24 14:31:44 -04:00
teor 2acfcf3a90
Make the CheckpointVerifier handle partial restarts (#736)
Also put generic bounds on the BlockVerifier struct,
so we get better compilation errors.
2020-07-24 11:47:48 +10:00
teor 77a1fefa1e
Download genesis (#731)
* feature: Add more CheckpointVerifier tracing

* fix: Download the genesis block
2020-07-23 10:56:52 -07:00
Jane Lusby c1a1493159
use dirs crate for default location of state and config (#714)
* use dirs crate for default location of state and config
* panic if a path isn't specified for zebra-state
2020-07-23 21:12:20 +10:00
teor c95c825707 fix: Lookup the genesis hash based on the network 2020-07-23 03:46:24 -04:00
Henry de Valence 4a98b8fa0d Add basic metrics to the syncer. 2020-07-22 21:59:00 -07:00
Henry de Valence c2c2a28e8b Improve tracing output in chain verifier 2020-07-22 21:59:00 -07:00
Jane Lusby 7d4e717182
Add block locator request to state layer (#712)
* Add block locator request to state layer

* pass genesis in request

* Update zebrad/src/commands/start/sync.rs

* fix errors
2020-07-22 18:01:31 -07:00
Henry de Valence 49aa41544d sync: try to ignore spurious inv messages.
Closes #697.

per  https://github.com/ZcashFoundation/zebra/issues/697#issuecomment-662742971

The response to a getblocks message is an inv message with the hashes of the
following blocks. However, inv messages are also sent unsolicited to gossip new
blocks across the network. Normally, this wouldn't be a problem, because for
every other request we filter only for the messages that are relevant to us.
But because the response to a getblocks message is an inv, the network layer
doesn't (and can't) distinguish between the response inv and the unsolicited
inv.

But there is a mitigation we can do. In our sync algorithm we have two phases:
(1) "ObtainTips" to get a set of tips to chase down, (2) repeatedly call
"ExtendTips" to extend those as far as possible. The unsolicited inv messages
have length 1, but when extending tips we expect to get more than one hash. So
we could reject responses in ExtendTips that have length 1 in order to ignore
these messages. This way we automatically ignore gossip messages during initial
block sync (while we're extending a tip) but we don't ignore length-1 responses
while trying to obtain tips (while querying the network for new tips).
2020-07-22 17:55:52 -07:00
teor 9b97ebbd61 feature: Choose checkpoints based on the config 2020-07-23 10:26:25 +10:00
teor 3d721a96a5 feature: Add the state config to the config file 2020-07-23 10:26:25 +10:00
teor 89ac2793d6 feature: Use ChainVerifier in the sync service 2020-07-23 10:26:25 +10:00
Jane Lusby a722cf33f7 enable new tracing instrumentation in tokio 2020-07-22 14:39:54 -04:00
Henry de Valence 928b0beb5d sync: unindent fetch task 2020-07-21 20:16:23 -07:00
Henry de Valence b722818e02 sync: remove redundant tracing specifier
Co-authored-by: Jane Lusby <jlusby42@gmail.com>
2020-07-21 20:16:23 -07:00
Henry de Valence 1047d2f690 sync: add backpressure to syncer
Closes #617.
Closes #698.

The remaining work on the syncer is alluded to in a new comment:

1. Correctly constructing a block locator object
2. Detecting when we've stopped making progress syncing and restarting obtain_tips.
2020-07-21 20:16:23 -07:00
Alfredo Garcia db2eb80b3e
Create consensus utils and move byte_reverse_hex function to it (#705)
* move byte_reverse_hex function
2020-07-22 12:29:14 +10:00
teor e5bb96715f fix: Reduce sync error logs to info or warn
Network issues are very common.
2020-07-21 10:13:03 -07:00
teor a0dbe85acd fix: Rewrite the config usage comment 2020-07-21 12:58:55 -04:00
dependabot[bot] 2208a6a22d build(deps): bump tracing-subscriber from 0.2.7 to 0.2.8
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.7 to 0.2.8.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.7...tracing-subscriber-0.2.8)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-21 12:01:40 -04:00
Alfredo Garcia fe2a468417
add favicon to generated docs (#681) 2020-07-17 16:45:29 -07:00
teor 71de6de701 fix: Only enable tokio components for servers
Only enable the tokio and tracing components for server commands.
2020-07-17 10:12:51 +10:00
teor 49a3a7d6d1 fix: Only launch network endpoints for server commands
Fixes #669.
2020-07-16 10:40:03 -07:00
teor 851afad01f
fix: Resist CheckpointVerifier memory DoS attacks (#635)
* fix: Resist CheckpointVerifier memory DoS attacks

Allow a maximum of 2 queued blocks at each height, as a tradeoff between
efficient bad block rejection, and memory usage.

Closes #628.

* fix: Make max queued blocks at height equal to fanout

* fix: Just allocate all the capacity upfront

* fix: Use with_capacity(1) and reserve_exact(1)
2020-07-15 13:27:10 -07:00
teor 78459afe97 fix: Stop revhex on EOF 2020-07-15 19:19:02 +10:00
teor 12b9fa8ae2
Let zebrad revhex read from stdin (#648)
* Log at warn level for commands that use stdout
* Let zebrad revhex read from stdin

Most unix tools support reading from stdin, so they can be used in
pipelines.

Part of #564.
2020-07-15 16:16:07 +10:00
dependabot[bot] c3fcac8a5c Bump hyper from 0.13.6 to 0.13.7
Bumps [hyper](https://github.com/hyperium/hyper) from 0.13.6 to 0.13.7.
- [Release notes](https://github.com/hyperium/hyper/releases)
- [Changelog](https://github.com/hyperium/hyper/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/hyper/compare/v0.13.6...v0.13.7)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-14 10:40:53 -07:00
teor e1bb95603c
Put zebrad/Cargo.toml in a nicer order (#650) 2020-07-14 10:17:05 -07:00
teor 8b5ec155f0
Consensus refactor (#629)
* Flatten consensus::verify::* to consensus::*
* Move consensus::*::tests into their own files
* Move CheckpointList into its own file
* Move Progress and Target into a types module

QueuedBlock and QueuedBlockList can stay in checkpoint.rs, because
they are tightly coupled to CheckpointVerifier.
2020-07-10 16:51:01 +10:00
Henry de Valence ff4e722cd7 sync: touch up tracing output. 2020-07-09 11:15:06 -07:00
Dimitris Apostolou ba81d7d4c0 Fix typos 2020-07-07 11:13:49 -07:00
dependabot[bot] a1d02c2606 Bump tracing-subscriber from 0.2.6 to 0.2.7
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.6 to 0.2.7.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber-0.2.6...tracing-subscriber-0.2.7)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-02 06:47:04 -04:00
Jane Lusby 51f6ce86ff
Implement retry policy for syncer (#551) 2020-07-01 13:35:01 -07:00
Jane Lusby 7245d91fe9
fix block downloading to be parallelized and commited via the verifier (#540) 2020-06-30 09:42:09 -07:00
Henry de Valence 21bf913b48 Revert "correctly trim and download tips (#531)"
This reverts commit e102bd5e34.
2020-06-24 12:24:37 -07:00
Jane Lusby e102bd5e34
correctly trim and download tips (#531)
* also download tips and filter tips

* dispatch all block downloads together

* tweek to match henry's changes

* switch to more intuitive match

Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-06-24 15:19:34 -04:00
Alfredo Garcia 67718898c5
add usage help to generated config (#527) 2020-06-23 11:56:00 -07:00
Henry de Valence a453edd91c Put type definitions back at the bottom of the file. 2020-06-23 10:16:27 -07:00
Henry de Valence 18eb212d8e Set the new tips to be the last, not first, hash. 2020-06-23 10:16:27 -07:00
Henry de Valence 70241d3cad Fix broken git dependencies.
Pinning hashes means these won't break again in the future; they can always be updated.
2020-06-22 20:23:02 -07:00
Jane Lusby 1c42b66a4f
Implement sync component for start subcommand (#506) 2020-06-22 19:24:53 -07:00
Jane Lusby 246e7cd2a9
Start testing out new version of `eyre` and `color-eyre` in zebra (#526)
* port to new version of eyre without generics

* correctly setup color_eyre hooks

Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-06-22 15:36:23 -07:00
dependabot[bot] f301de41fa Bump tracing-subscriber from 0.2.5 to 0.2.6
Bumps [tracing-subscriber](https://github.com/tokio-rs/tracing) from 0.2.5 to 0.2.6.
- [Release notes](https://github.com/tokio-rs/tracing/releases)
- [Commits](https://github.com/tokio-rs/tracing/compare/tracing-subscriber/-0.2.5...tracing-subscriber-0.2.6)

Signed-off-by: dependabot[bot] <support@github.com>
2020-06-22 12:01:47 -04:00
Deirdre Connolly 05316dee21 Listen on 0.0.0.0, not 127.0.0.1
Turns out when your node faces the internet directly, it has to listen
to those addresses directly.
2020-06-19 03:46:09 -04:00
Henry de Valence 6cc1627a5d zebrad: apply serde(default) to config sections
Each subsection has to have `serde(default)` to get the behaviour we want
(delete all fields except the ones that have been changed); otherwise, we can
delete only entire sections.
2020-06-18 17:43:36 -04:00
Henry de Valence 4b8f07ebb2 zebrad: Add reference to config docs. 2020-06-18 17:43:36 -04:00
Alfredo Garcia b8f174ee3a change config module to generate 2020-06-18 12:44:02 -07:00
Jane Lusby 7f8a336b69 switch to on_disk state service for start cmd 2020-06-17 23:30:50 -07:00
Jane Lusby df18ac72c5 fix sharedpeererror to propagate tracing context 2020-06-17 14:38:26 -07:00
Jane Lusby 06fd3b2503 be more explicit with pattern in drain_requests 2020-06-16 12:04:45 -07:00
Jane Lusby b0ecd019b6 apply comments from code review 2020-06-16 12:04:45 -07:00
Jane Lusby d09c339dc5 little more cleaning 2020-06-16 12:04:45 -07:00
Jane Lusby 528fd2b5b1 add an outline of the structure of the node 2020-06-16 12:04:45 -07:00
Jane Lusby fc96a41b18 copy connect command into start command 2020-06-16 12:04:45 -07:00
Jane Lusby df656a8bf0
Reorganize `connect` subcommand for readibility (#450) 2020-06-12 09:20:58 -07:00
Jane Lusby 431f194c0f
propagate errors out of zebra_network::init (#435)
Prior to this change, the service returned by `zebra_network::init` would spawn background tasks that could silently fail, causing unexpected errors in the zebra_network service.

This change modifies the `PeerSet` that backs `zebra_network::init` to store all of the `JoinHandle`s for each background task it depends on. The `PeerSet` then checks this set of futures to see if any of them have exited with an error or a panic, and if they have it returns the error as part of `poll_ready`.
2020-06-09 12:24:28 -07:00
Deirdre Connolly 42cc55b0bb Remove testing tokio task
That fires 'GetPeers' requests at our running 'zebra seed'.
2020-06-08 19:26:23 -04:00
Deirdre Connolly 43b77b080e Fix 'dos' feature for seed command, and Buffer the seed service 2020-06-08 19:26:23 -04:00
Deirdre Connolly 8f5e7c268b Request::Peers not GetPeers 2020-06-08 19:26:23 -04:00
Jane Lusby 9bcda0f9c7 Wrap Blocks in Arc throughout codebase 2020-06-05 00:36:55 -04:00
Jane Lusby 18b4dbc16c
fix tracing configuration issues (#432) 2020-06-04 19:34:06 -07:00
dependabot-preview[bot] 07b7c711fb Bump color-eyre from 0.3.2 to 0.3.4
Bumps [color-eyre](https://github.com/yaahc/color-eyre) from 0.3.2 to 0.3.4.
- [Release notes](https://github.com/yaahc/color-eyre/releases)
- [Commits](https://github.com/yaahc/color-eyre/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-02 22:55:02 -04:00
Jane Lusby e9af80b875
Add initial version of zebra-state (#414)
* rename zebra-storage to zebra-state

* Setup initial skeleton for zebra-state

* add test

* Apply suggestions from code review

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

* move shared test vectors to a common crate

Co-authored-by: Jane Lusby <jane@zfnd.org>
Co-authored-by: Henry de Valence <hdevalence@hdevalence.ca>
2020-06-02 16:16:17 -07:00
dependabot-preview[bot] 8e7d91b4a3 Bump eyre from 0.4.2 to 0.4.3
Bumps [eyre](https://github.com/yaahc/eyre) from 0.4.2 to 0.4.3.
- [Release notes](https://github.com/yaahc/eyre/releases)
- [Commits](https://github.com/yaahc/eyre/commits)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-06-02 18:48:50 -04:00
dependabot-preview[bot] a62b93d47c Bump hyper from 0.13.5 to 0.13.6
Bumps [hyper](https://github.com/hyperium/hyper) from 0.13.5 to 0.13.6.
- [Release notes](https://github.com/hyperium/hyper/releases)
- [Changelog](https://github.com/hyperium/hyper/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/hyper/compare/v0.13.5...v0.13.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-30 00:29:05 -04:00
Jane Lusby da72c5a86a
switch from abscissa::Context to color-eyre (#409)
Co-authored-by: Jane Lusby <jane@zfnd.org>
2020-05-28 23:01:24 -04:00
Jane Lusby 8c178c3ee4
fix panic in seed subcommand (#401)
Co-authored-by: Jane Lusby <jane@zfnd.org>

Prior to this change, the seed subcommand would consistently encounter a panic in one of the background tasks, but would continue running after the panic. This is indicative of two bugs. 

First, zebrad was not configured to treat panics as non recoverable and instead defaulted to the tokio defaults, which are to catch panics in tasks and return them via the join handle if available, or to print them if the join handle has been discarded. This is likely a poor fit for zebrad as an application, we do not need to maximize uptime or minimize the extent of an outage should one of our tasks / services start encountering panics. Ignoring a panic increases our risk of observing invalid state, causing all sorts of wild and bad bugs. To deal with this we've switched the default panic behavior from `unwind` to `abort`. This makes panics fail immediately and take down the entire application, regardless of where they occur, which is consistent with our treatment of misbehaving connections.

The second bug is the panic itself. This was triggered by a duplicate entry in the initial_peers set. To fix this we've switched the storage for the peers from a `Vec` to a `HashSet`, which has similar properties but guarantees uniqueness of its keys.
2020-05-27 17:40:12 -07:00
Jane Lusby b6b35364f3 cleanup warnings throughout codebase 2020-05-27 15:42:29 -04:00
dependabot-preview[bot] 46cb7c02f2 Bump once_cell from 1.3.1 to 1.4.0
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.3.1 to 1.4.0.
- [Release notes](https://github.com/matklad/once_cell/releases)
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.3.1...v1.4.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-05-13 22:28:18 -04:00
dependabot-preview[bot] 83ee4c2ca3 Bump hyper from 0.13.4 to 0.13.5
Bumps [hyper](https://github.com/hyperium/hyper) from 0.13.4 to 0.13.5.
- [Release notes](https://github.com/hyperium/hyper/releases)
- [Changelog](https://github.com/hyperium/hyper/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/hyper/compare/v0.13.4...v0.13.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-04-18 08:43:40 +00:00
dependabot-preview[bot] 6867449ff4 Bump hyper from 0.13.3 to 0.13.4
Bumps [hyper](https://github.com/hyperium/hyper) from 0.13.3 to 0.13.4.
- [Release notes](https://github.com/hyperium/hyper/releases)
- [Changelog](https://github.com/hyperium/hyper/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/hyper/compare/v0.13.3...v0.13.4)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-20 21:05:17 -04:00
Henry de Valence dd8ba287bf Correct block version parsing. 2020-03-18 21:34:02 -04:00
dependabot-preview[bot] cf0348b4f5 Bump hyper from 0.13.2 to 0.13.3
Bumps [hyper](https://github.com/hyperium/hyper) from 0.13.2 to 0.13.3.
- [Release notes](https://github.com/hyperium/hyper/releases)
- [Changelog](https://github.com/hyperium/hyper/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/hyper/compare/v0.13.2...v0.13.3)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-03 20:16:27 -05:00
Henry de Valence 81500dfe11 Add Zebra logotype. 2020-02-26 21:25:35 -08:00
Henry de Valence cd6deea7e1 Clarify that it's the ZF discord and that it's engineering-focused. 2020-02-26 21:25:35 -08:00
Henry de Valence ff3efd504c Add Zebra logo to all workspace crates.
Also add html_root_url attributes.
2020-02-26 21:25:35 -08:00
Henry de Valence f98cda40f9 Remove unused import. 2020-02-21 06:48:25 -05:00
Henry de Valence 9c357eaf1e Use retries for FindBlocks requests. 2020-02-21 06:48:25 -05:00
Henry de Valence b951f13f06 Add a `revhex` utility command to reverse endianness.
This makes it easier to translate block hashes output by our debug logs into
the format used by other tools.
2020-02-21 06:48:25 -05:00
Henry de Valence afa2c2347f fmt 2020-02-21 06:48:25 -05:00
Henry de Valence 8bff6ada6c Prevent a crash serializing configs. 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 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 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 3c9b5612f3 Update zebrad docs and README. 2020-02-12 12:50:55 -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 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 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 f04f4f0b98 Apply clippy fixes 2020-02-05 12:42:32 -08:00
dependabot-preview[bot] dd24dbece3 Bump hyper from 0.13.1 to 0.13.2
Bumps [hyper](https://github.com/hyperium/hyper) from 0.13.1 to 0.13.2.
- [Release notes](https://github.com/hyperium/hyper/releases)
- [Changelog](https://github.com/hyperium/hyper/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/hyper/compare/v0.13.1...v0.13.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-29 17:25:34 -05:00
Deirdre Connolly 08012f058a cargo fmt 2020-01-28 03:48:23 -05:00
dependabot-preview[bot] dbe7427f58 Bump once_cell from 1.3.0 to 1.3.1
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.3.0 to 1.3.1.
- [Release notes](https://github.com/matklad/once_cell/releases)
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.3.0...v1.3.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-01-18 23:26:25 -05:00
Henry de Valence e492cf067e Disable version string test. 2020-01-15 12:06:31 -08:00
Henry de Valence 4fcb550aa6 Fix a deadlock in TokioComponent.
The components are accessed by a lock on application state.  When some command
calls block_on to enter an async context, it obtained a write lock on the
entire application state.  This meant that if the application state were
accessed later in an async context, a deadlock would occur.  Instead the
TokioComponent holds an Option<Runtime> now, so that before calling block_on,
the caller can .take() the runtime and release the lock.  Since we only ever
enter an async context once, it's not a problem that the component is then
missing its runtime, as once we are inside of a task we can access the runtime.
2020-01-15 12:06:31 -08:00
Henry de Valence ab3db201ee Change TracingEndpoint to forward to the Abscissa Tracing component. 2020-01-15 12:06:31 -08:00
Tony Arcieri 45eb81a204 Upgrade to Abscissa v0.5 2020-01-15 12:06:31 -08:00
Henry de Valence d3e954cd4a Remove vestigial tower git dep 2020-01-15 14:23:01 -05:00
dependabot-preview[bot] 3c77c6f685 Bump hyper from 0.13.0 to 0.13.1
Bumps [hyper](https://github.com/hyperium/hyper) from 0.13.0 to 0.13.1.
- [Release notes](https://github.com/hyperium/hyper/releases)
- [Changelog](https://github.com/hyperium/hyper/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/hyper/compare/v0.13.0...v0.13.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-12-17 17:11:28 -05:00
Henry de Valence 2965187b91 Upgrade tokio, futures, hyper to released versions. 2019-12-13 17:42:15 -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
Henry de Valence 6d79352fb6 Remove nightly toolchain pin since async/await is stable. 2019-11-16 00:11:14 -05:00
Henry de Valence 3b02b40758 Simplify tracing output. 2019-11-13 18:43:18 -05:00
Henry de Valence ec4f6bd9ea Allow using the connect stub to test address messages. 2019-11-13 18:43:18 -05:00
Henry de Valence 9a0bffecb8 Sanitize outbound address responses.
This aims to prevent a remote peer from inspecting timings of all messages
received by this node.
2019-11-13 18:43:18 -05:00
Deirdre Connolly e5aa02bbd4 Remove special wait, unneeded for seed
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-11-12 22:39:47 -05:00
Deirdre Connolly bdba52936e Unwrap address_book in call(), which relies on poll_ready giving a positive response first, otherwise panic
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-11-12 22:39:47 -05:00
Deirdre Connolly fb19febe26 Remove config override, not needed 2019-11-12 22:39:47 -05:00
Deirdre Connolly 4923e0d783 Update tracing invocation to be better manipulated
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-11-12 22:39:47 -05:00
Deirdre Connolly 73d777fe65 Update `Ok(None)` case logging. 2019-11-12 22:39:47 -05:00
Deirdre Connolly 0f20ff59c7 Clean up SeedService.poll_ready with a 'ref mut'
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-11-12 22:39:47 -05:00
Deirdre Connolly 9d8e32d05f Update `seed` subcommand description
Co-Authored-By: Henry de Valence <hdevalence@hdevalence.ca>
2019-11-12 22:39:47 -05:00
Deirdre Connolly fe2a1ec1ea Remove autogenerated Abscissa doc comments 2019-11-12 22:39:47 -05:00
Deirdre Connolly a2292d94a0 Clean up some logging and comments on seed service 2019-11-12 22:39:47 -05:00
Deirdre Connolly d6ab549fd5 Yay, SeedService makes a remote 'connect' happy 2019-11-12 22:39:47 -05:00
Deirdre Connolly 4d3ab201e6 seed command seems to be functional
Moved SeedService out of the command closure Command currently spawns
a tokio task to DOS the seed service with `Request::GetPeers` every
second.

Pertains to #54
2019-11-12 22:39:47 -05:00
Deirdre Connolly fee75b5da8 Add SeedService
This may need some cleaning up, but this is the first iteration to appease the compiler.
2019-11-12 22:39:47 -05:00
Deirdre Connolly 0ac1b663fe Keep sets of initial peers as Strings in config file 2019-11-12 22:39:47 -05:00
Deirdre Connolly b5bbef5c47 Default init seed nodes based on network choice
And more flushed out but incomplete
2019-11-12 22:39:47 -05:00
Henry de Valence f588f5d368 Remove connect loop 2019-10-26 19:54:17 -04:00
Henry de Valence 027bdc8465 Rework initial crawler logic.
This splits out the connection handling code into a try_connect closure, which
could be refactored into a Service of its own.

On creation, when we are likely to have very few peers, launch many concurrent
connections to the first few candidates in the initial candidate set, before
continuing to grow the peer set according to demand signals.
2019-10-22 19:06:08 -07:00
Henry de Valence 2f3292759f Add an explicit tracing span to each address book.
Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2019-10-22 19:06:08 -07:00
Henry de Valence b1832ce593 Initial work to add a crawl-and-dial task.
This responds to peerset demand by connecting to additional peers.

Co-authored-by: Deirdre Connolly <deirdre@zfnd.org>
2019-10-22 19:06:08 -07:00
Henry de Valence fe9cef261d Allow draining AddressBook entries oldest-first. 2019-10-21 14:40:03 -04:00
Henry de Valence 39d38a8647 Rewrite AddressBook to use a BTreeSet.
The previous implementation failed when timestamps were duplicated between
peers, because there was not a 1-1 relationship between timestamps and peers.
2019-10-21 14:40:03 -04:00
Henry de Valence 5e9ac87f57 Collect into an AddressBook in connect. 2019-10-21 14:40:03 -04:00
Henry de Valence 0bfd57def2 Add iteration functions to `AddressBook`.
The disconnected_peers() function allows us to prevent duplicate
connections without maintaining shared state between the peerset and the
dial-additional-peers task.
2019-10-21 14:40:03 -04:00
Henry de Valence b03a83fa86 Simplify TimestampCollector.
Previously, the TimestampCollector was intended to own the address book
data, so it was intended to be cloneable and hold shared state among all
of its handles.  This is now modeled more directly by an
`Arc<Mutex<AddressBook>>`, so the only functionality left in the
`TimestampCollector` is setting up the inital worker, which is better
called `spawn` than `new`.

This also fixes a problem introduced in the previous commit where the
`TimestampCollector` was dropped, causing the worker task to shut down
early.
2019-10-21 14:40:03 -04:00
Henry de Valence 53be838d51 Extract `TimestampData` to `AddressBook`.
This allows us to hide the `TimestampCollector` and to expose only the
address book data required by the inbound request service.  It also lets
us have a common data structure (the `AddressBook`) for collecting peer
information that can be used to manage information that other peers
report to us.
2019-10-21 14:40:03 -04:00
Henry de Valence 9ec1e01c8f Add a config command. 2019-10-18 21:00:01 -04:00
Henry de Valence f0bb2bff77 Do not export zebra-network internals.
Until we finish outbound peer dialing, this still contains
one module that re-exports the `PeerConnector`.
2019-10-18 16:11:01 -07:00
Henry de Valence 7c35e7e6c0 Delete the listen stub command. 2019-10-18 16:11:01 -07:00
Henry de Valence 5847b490da Move PeerSet setup logic into a peer_set::init() 2019-10-18 16:11:01 -07:00
Henry de Valence 17b93523bd Restore PeerSet code in connect stub.
This was commented out because making the PeerConnector take a TcpStream
meant that the PeerConnector futures couldn't be constructed in the same
way as before, but now that the PeerConnector is Buffer'able, we can
just clone a buffered copy.
2019-10-17 09:34:18 -07:00
Henry de Valence ff27334e81 Make PeerConnector tower::Buffer'able 2019-10-17 09:34:18 -07:00
Henry de Valence 8a1aa71736 Modify PeerConnector to also handle inbound conns.
Because the Bitcoin handshake is symmetric, we can reuse the same logic
for both incoming and outgoing connections.
2019-10-17 09:34:18 -07:00
Henry de Valence fc872ea03f Remove async-await feature of futures. 2019-10-15 14:49:11 -04:00
Henry de Valence ae1a164ff8
Beginning of peerset implementation. (#62)
* Don't expose submodules of zebra_network::peer.

* PeerSet, PeerDiscover stubs.

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

* Initial work on PeerSet.

This is adapted from the MIT-licensed tower-balance implementation.

* Use PeerSet in the connect stub.
2019-10-10 18:15:24 -07:00
Henry de Valence 8a3b4f48fc Move all git dependencies to published crates. (#58)
The earlier issues with version resolution incompatibilities are now
resolved, and all the upstream changes we made to tracing are released.
2019-10-09 00:10:01 -04:00
Henry de Valence fb2b502eb9 Add a `Config` struct to zebra-network.
This struct is pulled into the main abscissa config as a subsection.
2019-10-08 23:34:16 -04:00
Henry de Valence 92dc7a5ea1
Fix authorship, license information. (#55)
* Fix authorship, license information.

I *thought* I had done a sed pass over the Cargo defaults when doing
repository initialization, but I guess I missed it or something.
Anyways, fixed now.
2019-10-08 09:25:59 -07: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
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 9f43d0987b nit: suppress async_await nightly warning. 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
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 a64a051276 Clean tracing_subscriber deprecation warnings. 2019-09-20 16:02:55 -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 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
Henry de Valence ec363d2d41 Create workspace skeleton based on design.md 2019-08-29 14:46:54 -07:00