Skip to content

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Sword-Smith
Copy link
Member

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.

@Sword-Smith Sword-Smith marked this pull request as draft March 13, 2025 19:42
@Sword-Smith
Copy link
Member Author

Sword-Smith commented Mar 13, 2025

Feel free to comment on design. Marked as draft because this new parameter is completely untested. Needs tests!

@Sword-Smith Sword-Smith requested review from aszepieniec and removed request for aszepieniec and jan-ferdinand March 13, 2025 19:42
Copy link
Contributor

@aszepieniec aszepieniec left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check if tx conforms to mempool policy.
// Check if tx conforms to mempool policy wrt # inputs

@Sword-Smith Sword-Smith force-pushed the thv/allow-restricting-num-inputs branch 2 times, most recently from feac0b3 to 1f3d5eb Compare March 14, 2025 13:08
@@ -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>,
Copy link
Member

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.
@Sword-Smith Sword-Smith force-pushed the thv/allow-restricting-num-inputs branch from 1f3d5eb to e38c78b Compare March 14, 2025 15:49
}

None
(0..self.len() - 1).find_map(|i| most_dense_pair_skip_first_n(self, i))
Copy link
Member Author

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.

Copy link
Member Author

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.
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 this pull request may close these issues.

3 participants