-
Notifications
You must be signed in to change notification settings - Fork 16
feat: Allow restriction of number of inputs per tx #503
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
base: master
Are you sure you want to change the base?
Conversation
Feel free to comment on design. Marked as draft because this new parameter is completely untested. Needs tests! |
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.
Basic structure looks good. I have some superficial comments. Before approving I would like to double-check against the list on the whiteboard and verify that the right logic is used in all of those cases.
@@ -346,13 +375,18 @@ impl Mempool { | |||
} | |||
} | |||
|
|||
let mut events = vec![]; | |||
// Check if tx conforms to mempool policy. |
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.
// Check if tx conforms to mempool policy. | |
// Check if tx conforms to mempool policy wrt # inputs |
feac0b3
to
1f3d5eb
Compare
src/models/state/mempool.rs
Outdated
@@ -152,6 +162,7 @@ impl Mempool { | |||
pub fn new( | |||
max_total_size: ByteSize, | |||
max_num_transactions: Option<usize>, | |||
max_num_inputs_per_tx: Option<usize>, |
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.
This interface is starting to get unwieldy. How about a builder instead? If you don't want to write one yourself, take a look at bon.
Allow the user to restrict the number of inputs per transaction to avoid having to deal with transactions that will likely never be mined, as they don't fit into a block. The current default limit is set quite low, to 28 inputs per transaction due to the big size of transaction inputs. This limit is intended to rise significantly in the future, but for now it should serve to prevent composers and transaction initiators from making transactions that cannot be mined. Both the wallet state and mempool state gets passed this value such that internally can enforce the correct policy.
Verify that the mempool respects the maximum number of inputs on a) insertion, b) returning a pair for proof-upgrading, and c) returning a list of transactions for inclusion in a block.
1f3d5eb
to
e38c78b
Compare
src/models/state/mempool.rs
Outdated
} | ||
|
||
None | ||
(0..self.len() - 1).find_map(|i| most_dense_pair_skip_first_n(self, i)) |
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 think the expression self.len() - 1
can overflow. Probably not good.
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.
Just shows that these getters need to be tested on an empty mempool. That would have caught this problem by producing a never-ending test case.
Add struct `MempoolSizePolicy` to contain policy for the maximum size of mempool, transactions in mempool, and transactions returned from mempool. All size restrictions on the mempool, max num transaction, max total size in memory, max number of inputs, are, with this commit, encapsulated in a struct. After the merger of hard-fork 1, #502, new rules for block validity wwill come into effetct: max num inputs/outputs/public announcements. Those rules can be enforced by the mempool by adding two new fields to this new struct.
Fix an overflow error that lead to a (practically) infinite loop.
Allow the user to restrict the number of inputs per transaction to avoid having to deal with transactions that will likely never be mined, as they don't fit into a block.
The current default limit is set quite low, to 28 inputs per transaction due to the big size of transaction inputs. This limit is intended to rise significantly in the future, but for now it should serve to prevent composers and transaction initiators from making transactions that cannot be mined.
Both the wallet state and mempool state gets passed this value such that they, internally, can enforce the correct policies.