logo
pub enum Request {
    Peers,
    BlocksByHash(HashSet<Hash>),
    TransactionsById(HashSet<UnminedTxId>),
    FindBlocks {
        known_blocks: Vec<Hash>,
        stop: Option<Hash>,
    },
    FindHeaders {
        known_blocks: Vec<Hash>,
        stop: Option<Hash>,
    },
    PushTransaction(UnminedTx),
    AdvertiseTransactionIds(HashSet<UnminedTxId>),
    AdvertiseBlock(Hash),
    MempoolTransactionIds,
    // some variants omitted
}
Expand description

A network request, represented in internal format.

The network layer aims to abstract away the details of the Bitcoin wire protocol into a clear request/response API. Each Request documents the possible Responses it can generate; it is fine (and recommended!) to match on the expected responses and treat the others as unreachable!(), since their return indicates a bug in the network code.

Cancellations

The peer set handles cancelled requests (i.e., requests where the future returned by Service::call is dropped before it resolves) on a best-effort basis. Requests are routed to a particular peer connection, and then translated into Zcash protocol messages and sent over the network. If a request is cancelled after it is submitted but before it is processed by a peer connection, no messages will be sent. Otherwise, if it is cancelled while waiting for a response, the peer connection resets its state and makes a best-effort attempt to ignore any messages responsive to the cancelled request, subject to limitations in the underlying Zcash protocol.

Variants

Peers

Requests additional peers from the server.

Response

Returns Response::Peers.

BlocksByHash(HashSet<Hash>)

Request block data by block hashes.

This uses a HashSet rather than a Vec for two reasons. First, it automatically deduplicates the requested blocks. Second, the internal protocol translator needs to maintain a HashSet anyways, in order to keep track of which requested blocks have been received and when the request is ready. Rather than force the internals to always convert into a HashSet, we require the caller to pass one, so that if the caller didn’t start with a Vec but with, e.g., an iterator, they can collect directly into a HashSet and save work.

If this requests a recently-advertised block, the peer set will make a best-effort attempt to route the request to a peer that advertised the block. This routing is only used for request sets of size 1. Otherwise, it is routed using the normal load-balancing strategy.

The list contains zero or more block hashes.

Returns

Returns Response::Blocks.

TransactionsById(HashSet<UnminedTxId>)

Request transactions by their unmined transaction ID.

v4 transactions use a legacy transaction ID, and v5 transactions use a witnessed transaction ID.

This uses a HashSet for the same reason as Request::BlocksByHash.

If this requests a recently-advertised transaction, the peer set will make a best-effort attempt to route the request to a peer that advertised the transaction. This routing is only used for request sets of size 1. Otherwise, it is routed using the normal load-balancing strategy.

The list contains zero or more unmined transaction IDs.

Returns

Returns Response::Transactions.

FindBlocks

Fields

known_blocks: Vec<Hash>

Hashes of known blocks, ordered from highest height to lowest height.

stop: Option<Hash>

Optionally, the last block hash to request.

Request block hashes of subsequent blocks in the chain, given hashes of known blocks.

The known blocks list contains zero or more block hashes.

Returns

Returns Response::BlockHashes.

Warning

This is implemented by sending a getblocks message. Bitcoin nodes respond to getblocks with an inv message containing a list of the subsequent blocks. However, Bitcoin nodes also send inv messages unsolicited in order to gossip new blocks to their peers. These gossip messages can race with the response to a getblocks request, and there is no way for the network layer to distinguish them. For this reason, the response may occasionally contain a single hash of a new chain tip rather than a list of hashes of subsequent blocks. We believe that unsolicited inv messages will always have exactly one block hash.

FindHeaders

Fields

known_blocks: Vec<Hash>

Hashes of known blocks, ordered from highest height to lowest height.

stop: Option<Hash>

Optionally, the last header to request.

Request headers of subsequent blocks in the chain, given hashes of known blocks.

The known blocks list contains zero or more block hashes.

Returns

Returns Response::BlockHeaders.

PushTransaction(UnminedTx)

Push an unmined transaction to a remote peer, without advertising it to them first.

This is implemented by sending an unsolicited tx message.

Returns

Returns Response::Nil.

AdvertiseTransactionIds(HashSet<UnminedTxId>)

Advertise a set of unmined transactions to all peers.

This is intended to be used in Zebra with a single transaction at a time (set of size 1), but multiple transactions are permitted because this is how we interpret advertisements from zcashd, which sometimes advertises multiple transactions at once.

This is implemented by sending an inv message containing the unmined transaction ID, allowing the remote peer to choose whether to download it. Remote peers who choose to download the transaction will generate a Request::TransactionsById against the “inbound” service passed to init.

v4 transactions use a legacy transaction ID, and v5 transactions use a witnessed transaction ID.

The list contains zero or more transaction IDs.

The peer set routes this request specially, sending it to half of the available peers.

Returns

Returns Response::Nil.

AdvertiseBlock(Hash)

Advertise a block to all peers.

This is implemented by sending an inv message containing the block hash, allowing the remote peer to choose whether to download it. Remote peers who choose to download the block will generate a Request::BlocksByHash against the “inbound” service passed to init.

The peer set routes this request specially, sending it to half of the available peers.

Returns

Returns Response::Nil.

MempoolTransactionIds

Request the contents of this node’s mempool.

Returns

Returns Response::TransactionIds.

Implementations

Returns the Zebra internal request type as a string.

Returns true if the request is for block or transaction inventory downloads.

Returns the block hash inventory downloads from the request, if any.

Returns the transaction ID inventory downloads from the request, if any.

Trait Implementations

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default. Read more

The type of Strategy used to generate values of type Self. Read more

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Responses given by the service.

Errors produced by the service.

The future response value.

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more

Process the request and return the response asynchronously. Read more

Responses given by the service.

Errors produced by the service.

The future response value.

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more

Process the request and return the response asynchronously. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Compare self to key and return true if they are equal.

Causes self to use its Binary implementation when Debug-formatted. Read more

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted. Read more

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Formats each item in a sequence. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Set the foreground color generically Read more

Set the background color generically. Read more

Change the foreground color to black

Change the background color to black

Change the foreground color to red

Change the background color to red

Change the foreground color to green

Change the background color to green

Change the foreground color to yellow

Change the background color to yellow

Change the foreground color to blue

Change the background color to blue

Change the foreground color to magenta

Change the background color to magenta

Change the foreground color to purple

Change the background color to purple

Change the foreground color to cyan

Change the background color to cyan

Change the foreground color to white

Change the background color to white

Change the foreground color to the terminal default

Change the background color to the terminal default

Change the foreground color to bright black

Change the background color to bright black

Change the foreground color to bright red

Change the background color to bright red

Change the foreground color to bright green

Change the background color to bright green

Change the foreground color to bright yellow

Change the background color to bright yellow

Change the foreground color to bright blue

Change the background color to bright blue

Change the foreground color to bright magenta

Change the background color to bright magenta

Change the foreground color to bright purple

Change the background color to bright purple

Change the foreground color to bright cyan

Change the background color to bright cyan

Change the foreground color to bright white

Change the background color to bright white

Make the text bold

Make the text dim

Make the text italicized

Make the text italicized

Make the text blink

Make the text blink (but fast!)

Swap the foreground and background colors

Hide the text

Cross out the text

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more

Set the foreground color to a specific RGB value.

Set the background color to a specific RGB value.

Sets the foreground color to an RGB value.

Sets the background color to an RGB value.

Apply a runtime-determined style

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Converts the type into a Result that can be sent as a response.

Should always be Self

Add a header to a Section and indent the body Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

Attempts to convert self into T using TryInto<T>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more