-
Notifications
You must be signed in to change notification settings - Fork 70
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
Second (control) mempool implementation #885
Conversation
viquezclaudio
commented
Jun 14, 2022
- Introduced a second mempool, used for control transactions
- When blocks are produced, first we try to include control txns
- If there is space left, we include regular txns
- This means that control txns have a higher priority over reg txns.
Codecov Report
@@ Coverage Diff @@
## albatross #885 +/- ##
=============================================
+ Coverage 64.16% 64.26% +0.10%
=============================================
Files 357 359 +2
Lines 42028 42264 +236
=============================================
+ Hits 26968 27163 +195
- Misses 15060 15101 +41
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
314cdb8
to
2abf491
Compare
2abf491
to
5eb0e38
Compare
@sisou any more comments? |
c10ba04
to
34ed994
Compare
ef1e197
to
bafa796
Compare
bafa796
to
20a0980
Compare
20a0980
to
df8fd9d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #929 to some smaller refactoring and to move some code pieces to their own files. Feel free to look through it and cherry pick if necessary.
Other than that I have little to add to what @sisou already provided. I do agree that control transactions should always come first, as there is no reason to do it the other way around and it does not introduce any complexity as far as I can tell.
mempool/src/executor.rs
Outdated
filter, | ||
network, | ||
network_id: Arc::new(blockchain.read().network_id), | ||
verification_tasks: Arc::new(AtomicU32::new(0)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More of a question than an actual comment:
So each mempool has their ow transaction verification task limit. That doubles the amount of verification tasks from what it was previously. Is that intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we never really hit that limit under normal operation, should I set it to half of it, so we maintain the same total amount of verification tasks as before?
mempool/src/mempool.rs
Outdated
pub const DEFAULT_SIZE_LIMIT: usize = 12_000_000; | ||
|
||
/// Default total size limit of control transactions in the mempool (bytes) | ||
pub const DEFAULT_CONTROL_SIZE_LIMIT: usize = 6_000_000; | ||
|
||
/// Creates a new mempool | ||
pub fn new(blockchain: Arc<RwLock<Blockchain>>, config: MempoolConfig) -> Self { | ||
let state = MempoolState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a MempoolState::new(size_limit: usize) -> MempoolState { ... }
/// Returns a vector with accepted control transactions from the mempool. | ||
/// | ||
/// Returns the highest fee per byte up to max_bytes transactions and removes them from the mempool | ||
pub fn get_control_transactions_for_block( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the logic for the expired transactions into the MempoolState
. I did not do it for get_transactions_for_block
because I am unsure wether or not more fine grained control over the byte size in particular is required.
However I believe even then a function like:
impl MempoolState {
pub fn get_transactions_for_block(&self, max_bytes: (usize, usize)) -> Vec<Transactions>) {
...
}
}
might be the way to go here. One thing in particular that I see is that for both the regular and the control transactions a self.state.upgradable_read()
and a subsequent upgrade of the lock are required. Moving the logic to the MempoolState
would remove that. The code is also pretty much identical, aside from which field to access. Abstracting what transactions shall be retrieved might also be a good idea.
If that is not desirable, I probably would still move both these functions in the more lightweight MempoolState
and just call them from here after taking the lock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we move to the pub fn get_transactions_for_block(&self, max_bytes: (usize, usize))
format, how would you specify what we are currently doing? i.e.: we know how much available bytes we have in the block, and we want to fill the block with control txns and if there is space left, fill the remaining with regular txns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still agree about the other benefits, the code its pretty much identical and it would be a good idea to move it to the MempoolState
df6114a
to
77e1b99
Compare
77e1b99
to
e4f9a72
Compare
- Introduced a second mempool, used for control transactions - When blocks are produced, first we try to include control txns - If there is space left, we include regular txns - This means that control txns have a higher priority over reg txns.
Create a new config parameter to limit the amount of transactions that can be kept in the control mempool
* Move some structs to their own modules All logic remains unchanged, this commit only moves code around. * Only use a single MempoolExecutor by using generic Topic * Add private fn start_executor and reuse where applicable * Move expired_transactions function to MempoolState
- Small warning/compilation fixes - Return control txns first, regular txns second - Share the max number of verif tasks among multiple executors - create constructor for mempool state
e4f9a72
to
f75c6fd
Compare