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

Randomly evict mempool transactions based on their eviction weights #2780

Closed
4 tasks done
Tracked by #2744 ...
teor2345 opened this issue Sep 21, 2021 · 3 comments · Fixed by #2889
Closed
4 tasks done
Tracked by #2744 ...

Randomly evict mempool transactions based on their eviction weights #2780

teor2345 opened this issue Sep 21, 2021 · 3 comments · Fixed by #2889
Assignees

Comments

@teor2345
Copy link
Contributor

teor2345 commented Sep 21, 2021

Motivation

ZIP-401 specifies weighted random mempool transaction evictions:
https://zips.z.cash/zip-0401#specification

This Ticket Depends On

match by txid not wtxid:

serialized transaction size in bytes:

transaction fee:

Consensus Rules

The mempool of a node holds a set of transactions.
Each transaction has a cost, which is an integer defined as:
max(serialized transaction size in bytes, 4000)

Each transaction also has an eviction weight, which is cost + low_fee_penalty,
where low_fee_penalty is 16000 if the transaction pays a fee less than the conventional fee, otherwise 0. The conventional fee is currently defined as 1000 zatoshis.

Each node also MUST hold a FIFO queue RecentlyEvicted of pairs (txid, time), where the time indicates when the transaction with the given txid was evicted. The txid (rather than the wtxid ...) is used even for version 5 transactions after activation of NU5.

On receiving a transaction:

  • If it is in RecentlyEvicted, the transaction MUST be dropped.
  • Calculate its cost. If the total cost of transactions in the mempool including this one would exceed mempooltxcostlimit, then the node MUST repeatedly call EvictTransaction (with the new transaction included as a candidate to evict) until the total cost does not exceed mempooltxcostlimit.

EvictTransaction MUST do the following:

  • Select a random transaction to evict, with probability in direct proportion to eviction weight.
  • Add the txid and the current time to RecentlyEvicted ...
  • Remove [the randomly selected transaction] from the mempool.

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

Design

rand::distributions::weighted::WeightedIndex is a weighted random implementation from a very popular crate.

It supports any collection type with continuous integer indexes. (Like Vec or VecDeque.)

@teor2345
Copy link
Contributor Author

@teor2345 teor2345 added this to the 2021 Sprint 20 milestone Sep 21, 2021
@teor2345
Copy link
Contributor Author

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.

@teor2345
Copy link
Contributor Author

teor2345 commented Oct 8, 2021

Partly unblocked by just using zero fees until #2779 gets merged.

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.

4 participants