Skip to content

Commit

Permalink
Move Drop from mempool::ActiveState to mempool::Downloads, to avoid bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Dec 11, 2022
1 parent aa430e9 commit a7f820d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
8 changes: 0 additions & 8 deletions zebrad/src/components/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ impl Default for ActiveState {
}
}

impl Drop for ActiveState {
fn drop(&mut self) {
if let ActiveState::Enabled { tx_downloads, .. } = self {
tx_downloads.cancel_all();
}
}
}

impl ActiveState {
/// Returns the current state, leaving [`Self::Disabled`] in its place.
fn take(&mut self) -> Self {
Expand Down
8 changes: 5 additions & 3 deletions zebrad/src/components/mempool/downloads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub enum TransactionDownloadVerifyError {
#[derive(Debug)]
pub struct Downloads<ZN, ZV, ZS>
where
ZN: Service<zn::Request, Response = zn::Response, Error = BoxError> + Send + 'static,
ZN: Service<zn::Request, Response = zn::Response, Error = BoxError> + Send + Clone + 'static,
ZN::Future: Send,
ZV: Service<tx::Request, Response = tx::Response, Error = BoxError> + Send + Clone + 'static,
ZV::Future: Send,
Expand Down Expand Up @@ -467,14 +467,16 @@ where
#[pinned_drop]
impl<ZN, ZV, ZS> PinnedDrop for Downloads<ZN, ZV, ZS>
where
ZN: Service<zn::Request, Response = zn::Response, Error = BoxError> + Send + 'static,
ZN: Service<zn::Request, Response = zn::Response, Error = BoxError> + Send + Clone + 'static,
ZN::Future: Send,
ZV: Service<tx::Request, Response = tx::Response, Error = BoxError> + Send + Clone + 'static,
ZV::Future: Send,
ZS: Service<zs::Request, Response = zs::Response, Error = BoxError> + Send + Clone + 'static,
ZS::Future: Send,
{
fn drop(self: Pin<&mut Self>) {
fn drop(mut self: Pin<&mut Self>) {
self.cancel_all();

metrics::gauge!("mempool.currently.queued.transactions", 0 as f64);
}
}

0 comments on commit a7f820d

Please sign in to comment.