Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What ?
This PR adds support for selecting the largest set of transactions / chunks based on their fees.
In this PR, I haven't included any usage of that algorithm, but rather just the algorithm itself ( + unit test )
Description
LargestSet takes a slice of dimensions and a dimensions limit, and find the
largest set of dimensions that would fit within the provided limit. The return
slice is the list of indices relative to the provided [dimensions] slice.
note that the solution of the largest set is not
deterministic ( by the nature of the problem, there could be multiple "correct"
and different results )
Algorithm ( high level )
to ensure fair comparison. This step normalizes the dimensions,
preventing larger dimensions from dominating the selection process.
magnitude is calculated. This metric is used to assess the
relative significance of each dimension.
their scaled magnitudes, adding them to the subset until the size
limit is reached. The greedy approach prioritizes the most significant
dimensions, maximizing the overall subset size.
Implementation notes:
small-scale dimensions, the function employs a scaling factor to
amplify values before normalization. This ensures accurate calculations
even when dealing with very small numbers.
for Euclidean distance, optimizing performance without sacrificing
accuracy for relative comparisons. This optimization avoids the
computationally expensive square root operation.
Motivation
The motivation behind this algorithm, in contrast to a FIFO ordering is the following -
Consider the following ( single dimension ) challenge:
This doesn't seems very meaningful as is, but imagine that you keep getting a stream of 3 transaction of weight 1 once every chunk/block ( high demand scenario ). Now, you would be generating the following:
Hence, the network would favor TPS over chunk/block saturation. Big transaction would get pushed down the road.