Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear mempool storage if the syncer starts syncing large numbers of blocks again #2723

Closed
Tracked by #2309
teor2345 opened this issue Sep 2, 2021 · 2 comments · Fixed by #2815
Closed
Tracked by #2309

Clear mempool storage if the syncer starts syncing large numbers of blocks again #2723

teor2345 opened this issue Sep 2, 2021 · 2 comments · Fixed by #2815
Assignees

Comments

@teor2345
Copy link
Contributor

teor2345 commented Sep 2, 2021

Motivation

If large numbers of blocks get synced, Zebra needs to clear the mempool storage and reject list, because:

  • previously verified transactions might have become invalid
  • previously invalid transactions might have become valid

Design

Tasks can check if they are behind the tip using SyncStatus::is_close_to_tip:

/// Check if the synchronization is likely close to the chain tip.
pub fn is_close_to_tip(&self) -> bool {

Tasks can await tip jumps using ChainTipChange::tip_change and TipAction::Reset:

pub async fn tip_change(&mut self) -> Result<TipAction, watch::error::RecvError> {

@teor2345 teor2345 mentioned this issue Sep 2, 2021
59 tasks
@mpguerra mpguerra added this to the 2021 Sprint 18 milestone Sep 6, 2021
@jvff jvff self-assigned this Sep 7, 2021
@mpguerra
Copy link
Contributor

dconnolly added a commit that referenced this issue Sep 15, 2021
* Pass sync_status to mempool

* Update zebrad/src/components/mempool.rs

Co-authored-by: Deirdre Connolly <[email protected]>

* Remove enabled flag for now; will be handled in #2723

Co-authored-by: Deirdre Connolly <[email protected]>
@jvff jvff modified the milestones: 2021 Sprint 18, 2021 Sprint 19 Sep 20, 2021
@teor2345
Copy link
Contributor Author

@jvff I think PRs #2773 and #2764 might have already closed this ticket:

Here's the code that clears the mempool if the syncer reports large numbers of blocks:

if is_close_to_tip {
let tx_downloads = Box::pin(TxDownloads::new(
Timeout::new(self.outbound.clone(), TRANSACTION_DOWNLOAD_TIMEOUT),
Timeout::new(self.tx_verifier.clone(), TRANSACTION_VERIFY_TIMEOUT),
self.state.clone(),
));
self.active_state = ActiveState::Enabled {
storage: Default::default(),
tx_downloads,
};
} else {
self.active_state = ActiveState::Disabled
}

And we also clear if the state commits more than one block at the same time:

if let Some(tip_action) = self.chain_tip_change.last_tip_change() {
match tip_action {
// Clear the mempool if there has been a chain tip reset.
TipAction::Reset { .. } => {
storage.clear();
}

@mpguerra mpguerra linked a pull request Oct 1, 2021 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants