2021-10-25 16:41:23 -07:00
|
|
|
//! Errors that can occur when interacting with the mempool.
|
|
|
|
//!
|
|
|
|
//! Most of the mempool errors are related to manipulating transactions in the
|
|
|
|
//! mempool.
|
2021-08-25 11:39:27 -07:00
|
|
|
|
|
|
|
use thiserror::Error;
|
|
|
|
|
Send crawled transaction IDs to downloader (#2801)
* Rename type parameter to be more explicit
Replace the single letter with a proper name.
* Remove imports for `Request` and `Response`
The type names will conflict with the ones for the mempool service.
* Attach `Mempool` service to the `Crawler`
Add a field to the `Crawler` type to store a way to access the `Mempool`
service.
* Forward crawled transactions to downloader
The crawled transactions are now sent to the transaction downloader and
verifier, to be included in the mempool.
* Derive `Eq` and `PartialEq` for `mempool::Request`
Make it simpler to use the `MockService::expect_request` method.
* Test if crawled transactions are downloaded
Create some dummy crawled transactions, and let the crawler discover
them. Then check if they are forwarded to the mempool to be downloaded
and verified.
* Don't send empty transaction ID list to downloader
Ignore response from peers that don't provide any crawled transactions.
* Log errors when forwarding crawled transaction IDs
Calling the Mempool service should not fail, so if an error happens it
should be visible. However, errors when downloading individual
transactions can happen from time to time, so there's no need for them
to be very visible.
* Document existing `mempool::Crawler` test
Provide some depth as to what the test expect from the crawler's
behavior.
* Refactor to create `setup_crawler` helper function
Make it easier to reuse the common test setup code.
* Simplify code to expect requests
Now that `zebra_network::Request` implement `Eq`, the call can be
simplified into `expect_request`.
* Refactor to create `respond_with_transaction_ids`
A helper function that checks for a network crawl request and responds
with the given list of crawled transaction IDs.
* Refactor to create `crawler_iterator` helper
A function to intercept and respond to the fanned-out requests sent
during a single crawl iteration.
* Refactor to create `respond_to_queue_request`
Reduce the repeated code necessary to intercept and reply to a request
for queuing transactions to be downloaded.
* Add `respond_to_queue_request_with_error` helper
Intercepts a mempool request to queue transactions to be downloaded, and
responds with an error, simulating an internal problem in the mempool
service implementation.
* Derive `Arbitrary` for `NetworkUpgrade`
This is required for deriving `Arbitrary` for some error types.
* Derive `Arbitrary` for `TransactionError`
Allow random transaction errors to be generated for property tests.
* Derive `Arbitrary` for `MempoolError`
Allow random Mempool errors to be generated for property tests.
* Test if errors don't stop the mempool crawler
The crawler should be robust enough to continue operating even if the
mempool service fails to download transactions or even fails to handle
requests to enqueue transactions.
* Reduce the log level for download errors
They should happen regularly, so there's no need to have them with a
high visibility level.
Co-authored-by: teor <teor@riseup.net>
* Stop crawler if service stops
If `Mempool::poll_ready` returns an error, it's because the mempool
service has stopped and can't handle any requests, so the crawler should
stop as well.
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Conrado Gouvea <conrado@zfnd.org>
2021-10-04 17:55:42 -07:00
|
|
|
#[cfg(any(test, feature = "proptest-impl"))]
|
|
|
|
use proptest_derive::Arbitrary;
|
|
|
|
|
2021-10-07 12:58:42 -07:00
|
|
|
use super::storage::{
|
|
|
|
ExactTipRejectionError, SameEffectsChainRejectionError, SameEffectsTipRejectionError,
|
|
|
|
};
|
2021-10-06 18:20:38 -07:00
|
|
|
|
2021-10-25 16:41:23 -07:00
|
|
|
/// Mempool errors.
|
2021-10-06 18:20:38 -07:00
|
|
|
#[derive(Error, Clone, Debug, PartialEq, Eq)]
|
Send crawled transaction IDs to downloader (#2801)
* Rename type parameter to be more explicit
Replace the single letter with a proper name.
* Remove imports for `Request` and `Response`
The type names will conflict with the ones for the mempool service.
* Attach `Mempool` service to the `Crawler`
Add a field to the `Crawler` type to store a way to access the `Mempool`
service.
* Forward crawled transactions to downloader
The crawled transactions are now sent to the transaction downloader and
verifier, to be included in the mempool.
* Derive `Eq` and `PartialEq` for `mempool::Request`
Make it simpler to use the `MockService::expect_request` method.
* Test if crawled transactions are downloaded
Create some dummy crawled transactions, and let the crawler discover
them. Then check if they are forwarded to the mempool to be downloaded
and verified.
* Don't send empty transaction ID list to downloader
Ignore response from peers that don't provide any crawled transactions.
* Log errors when forwarding crawled transaction IDs
Calling the Mempool service should not fail, so if an error happens it
should be visible. However, errors when downloading individual
transactions can happen from time to time, so there's no need for them
to be very visible.
* Document existing `mempool::Crawler` test
Provide some depth as to what the test expect from the crawler's
behavior.
* Refactor to create `setup_crawler` helper function
Make it easier to reuse the common test setup code.
* Simplify code to expect requests
Now that `zebra_network::Request` implement `Eq`, the call can be
simplified into `expect_request`.
* Refactor to create `respond_with_transaction_ids`
A helper function that checks for a network crawl request and responds
with the given list of crawled transaction IDs.
* Refactor to create `crawler_iterator` helper
A function to intercept and respond to the fanned-out requests sent
during a single crawl iteration.
* Refactor to create `respond_to_queue_request`
Reduce the repeated code necessary to intercept and reply to a request
for queuing transactions to be downloaded.
* Add `respond_to_queue_request_with_error` helper
Intercepts a mempool request to queue transactions to be downloaded, and
responds with an error, simulating an internal problem in the mempool
service implementation.
* Derive `Arbitrary` for `NetworkUpgrade`
This is required for deriving `Arbitrary` for some error types.
* Derive `Arbitrary` for `TransactionError`
Allow random transaction errors to be generated for property tests.
* Derive `Arbitrary` for `MempoolError`
Allow random Mempool errors to be generated for property tests.
* Test if errors don't stop the mempool crawler
The crawler should be robust enough to continue operating even if the
mempool service fails to download transactions or even fails to handle
requests to enqueue transactions.
* Reduce the log level for download errors
They should happen regularly, so there's no need to have them with a
high visibility level.
Co-authored-by: teor <teor@riseup.net>
* Stop crawler if service stops
If `Mempool::poll_ready` returns an error, it's because the mempool
service has stopped and can't handle any requests, so the crawler should
stop as well.
Co-authored-by: teor <teor@riseup.net>
Co-authored-by: Conrado Gouvea <conrado@zfnd.org>
2021-10-04 17:55:42 -07:00
|
|
|
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
|
2021-08-25 11:39:27 -07:00
|
|
|
pub enum MempoolError {
|
2021-10-25 16:41:23 -07:00
|
|
|
/// Transaction rejected based on its authorizing data (scripts, proofs,
|
|
|
|
/// signatures). The rejection is valid for the current chain tip.
|
|
|
|
///
|
|
|
|
/// See [`ExactTipRejectionError`] for more details.
|
|
|
|
///
|
|
|
|
/// Note that the mempool caches this error. See [`super::storage::Storage`]
|
|
|
|
/// for more details.
|
2021-10-28 13:09:05 -07:00
|
|
|
#[error("the transaction will be rejected from the mempool until the next chain tip block")]
|
2021-10-07 12:58:42 -07:00
|
|
|
StorageExactTip(#[from] ExactTipRejectionError),
|
2021-10-07 08:04:23 -07:00
|
|
|
|
2021-10-25 16:41:23 -07:00
|
|
|
/// Transaction rejected based on its effects (spends, outputs, transaction
|
|
|
|
/// header). The rejection is valid for the current chain tip.
|
|
|
|
///
|
|
|
|
/// See [`SameEffectsTipRejectionError`] for more details.
|
|
|
|
///
|
|
|
|
/// Note that the mempool caches this error. See [`super::storage::Storage`]
|
|
|
|
/// for more details.
|
2021-10-28 13:09:05 -07:00
|
|
|
#[error("any transaction with the same effects will be rejected from the mempool until the next chain tip block")]
|
2021-10-07 12:58:42 -07:00
|
|
|
StorageEffectsTip(#[from] SameEffectsTipRejectionError),
|
|
|
|
|
2021-10-25 16:41:23 -07:00
|
|
|
/// Transaction rejected based on its effects (spends, outputs, transaction
|
|
|
|
/// header). The rejection is valid while the current chain continues to
|
|
|
|
/// grow.
|
|
|
|
///
|
|
|
|
/// See [`SameEffectsChainRejectionError`] for more details.
|
|
|
|
///
|
|
|
|
/// Note that the mempool caches this error. See [`super::storage::Storage`]
|
|
|
|
/// for more details.
|
2021-10-28 13:09:05 -07:00
|
|
|
#[error("any transaction with the same effects will be rejected from the mempool until a chain reset")]
|
2021-10-07 12:58:42 -07:00
|
|
|
StorageEffectsChain(#[from] SameEffectsChainRejectionError),
|
2021-10-06 18:20:38 -07:00
|
|
|
|
2021-10-25 16:41:23 -07:00
|
|
|
/// Transaction rejected because the mempool already contains another
|
|
|
|
/// transaction with the same hash.
|
2021-08-25 11:39:27 -07:00
|
|
|
#[error("transaction already exists in mempool")]
|
|
|
|
InMempool,
|
|
|
|
|
2021-09-13 13:28:07 -07:00
|
|
|
/// The transaction hash is already queued, so this request was ignored.
|
|
|
|
///
|
|
|
|
/// Another peer has already gossiped the same hash to us, or the mempool crawler has fetched it.
|
|
|
|
#[error("transaction dropped because it is already queued for download")]
|
|
|
|
AlreadyQueued,
|
|
|
|
|
|
|
|
/// The queue is at capacity, so this request was ignored.
|
|
|
|
///
|
|
|
|
/// The mempool crawler should discover this transaction later.
|
|
|
|
/// If it is mined into a block, it will be downloaded by the syncer, or the inbound block downloader.
|
|
|
|
///
|
|
|
|
/// The queue's capacity is [`super::downloads::MAX_INBOUND_CONCURRENCY`].
|
|
|
|
#[error("transaction dropped because the queue is full")]
|
|
|
|
FullQueue,
|
2021-09-27 18:03:08 -07:00
|
|
|
|
2021-10-25 16:41:23 -07:00
|
|
|
/// The mempool is not enabled yet.
|
|
|
|
///
|
|
|
|
/// Zebra enables the mempool when it is at the chain tip.
|
2021-09-28 16:06:40 -07:00
|
|
|
#[error("mempool is disabled since synchronization is behind the chain tip")]
|
|
|
|
Disabled,
|
2021-08-25 11:39:27 -07:00
|
|
|
}
|