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

Make Mempool eviction compliant with ZIP-401 #2744

Closed
8 tasks done
Tracked by #2309
dconnolly opened this issue Sep 8, 2021 · 7 comments
Closed
8 tasks done
Tracked by #2309

Make Mempool eviction compliant with ZIP-401 #2744

dconnolly opened this issue Sep 8, 2021 · 7 comments
Labels
A-rust Area: Updates to Rust code Epic Zenhub Label. Denotes a theme of work under which related issues will be grouped

Comments

@dconnolly
Copy link
Contributor

dconnolly commented Sep 8, 2021

Motivation

ZIP-401 has some recommendations on how to mitigate DoS attacks on mempool implementations, including how many rejected tx's to track and for how long, and how to select a victim tx to evict from the mempool when out of space (we currently evict the oldest, they recommend a somewhat weighted random choice).

Specifications

https://zips.z.cash/zip-0401

Designs

Rejected set is recommended capped at 40K, we should check if everything we currently put in the rejected set maps to what ZIP-401 considers part of that 40K.

Sub-Tickets

@dconnolly dconnolly added C-enhancement Category: This is an improvement S-needs-triage Status: A bug report needs triage A-rust Area: Updates to Rust code P-Medium and removed C-enhancement Category: This is an improvement labels Sep 8, 2021
@dconnolly dconnolly added this to the 2021 Sprint 19 milestone Sep 8, 2021
@dconnolly dconnolly assigned dconnolly and unassigned dconnolly Sep 8, 2021
@mpguerra
Copy link
Contributor

@upbqdn
Copy link
Member

upbqdn commented Sep 19, 2021

ZIP-401 says:

There MUST be a configuration option mempoolevictionmemoryminutes, which SHOULD default to 60.

and

Nodes SHOULD remove transactions from RecentlyEvicted that were evicted more than mempoolevictionmemoryminutes minutes ago.

We were discussing that it might be a bit of a pain to deal with time in Zebra. Today I noticed Zebra actually deals with time already in order to implement the following from the protocol:

In addition, a full validator MUST NOT accept blocks with nTime more than two hours in the future according to its clock.

The implementation of that is here

pub fn time_is_valid_at(
and here
pub fn time_is_valid_at(

@teor2345
Copy link
Contributor

Rejected set is recommended capped at 40K, we should check if everything we currently put in the rejected set maps to what ZIP-401 considers part of that 40K.

I wouldn't worry about the exact contents of the rejected set - ZIP-401 is not consensus-critical, so there's no requirement for exact conformance.

But having a single rejected set will make the code much simpler, easier to test, and less likely to have security issues.

@teor2345
Copy link
Contributor

We were discussing that it might be a bit of a pain to deal with time in Zebra. Today I noticed Zebra actually deals with time already

There are actually 3 kinds of time here:

  • consensus time: the time in the block header, which is the same for all nodes
  • wall clock time: the local node's clock, which can be changed using NTP or by a sysadmin (used to check the block time)
  • monotonic time: the time elapsed on the local node, which can never go backwards (ZIP-401)

Picking the right kind of time is a tricky edge-case, which is why we try to avoid dealing with time as much as possible in Zebra.

@teor2345
Copy link
Contributor

This ticket's dependencies conflict with the NU5 block validation code freeze, so it needs to be done after NU5 testnet activation in sprint 19.

@mpguerra mpguerra added S-blocked Status: Blocked on other tasks Epic Zenhub Label. Denotes a theme of work under which related issues will be grouped and removed S-needs-triage Status: A bug report needs triage labels Oct 4, 2021
@mpguerra mpguerra removed this from the 2021 Sprint 20 milestone Oct 4, 2021
@mpguerra
Copy link
Contributor

mpguerra commented Oct 4, 2021

Changed to epic and removed from Sprint 20 since all relevant child issues are already in that sprint

@mpguerra mpguerra linked a pull request Oct 15, 2021 that will close this issue
3 tasks
@mpguerra mpguerra removed a link to a pull request Oct 18, 2021
3 tasks
@mpguerra
Copy link
Contributor

mpguerra commented Nov 1, 2021

We are done here 🎉

@mpguerra mpguerra closed this as completed Nov 1, 2021
@mpguerra mpguerra removed the S-blocked Status: Blocked on other tasks label Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code Epic Zenhub Label. Denotes a theme of work under which related issues will be grouped
Projects
None yet
Development

No branches or pull requests

4 participants