-
Notifications
You must be signed in to change notification settings - Fork 152
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
OrderTxsForEvaluationV3 added #1518
Conversation
4967433
to
6677943
Compare
Codecov Report
@@ Coverage Diff @@
## main #1518 +/- ##
===========================================
- Coverage 84.65% 26.88% -57.78%
===========================================
Files 262 276 +14
Lines 9240 18116 +8876
===========================================
- Hits 7822 4870 -2952
- Misses 1418 12856 +11438
- Partials 0 390 +390
|
23d5c21
to
bf0004b
Compare
Just some benchmark result
Performance improvement seems to be about 30%. |
ce5916b
to
8160415
Compare
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@@ -590,6 +592,43 @@ ActionContext CreateActionContext(IAccountStateDelta prevStates, int randomSeed) | |||
.SelectMany(group => group.OrderBy(tx => tx.Nonce)); | |||
} | |||
|
|||
[Pure] | |||
private static IEnumerable<Transaction<T>> OrderTxsForEvaluationV3( |
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.
We don't have OrderTxsForEvaluationV3
test here. Could you add some tests for this method?
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.
Actually, OrderTxsForEvaluation()
in ActionEvaluatorTest.cs
covers all cases. 🙃
f9feecf
to
2d1c363
Compare
Bumped |
7a66323
to
8dba46d
Compare
8dba46d
to
ba463ab
Compare
ff4dd90
to
a25fd2a
Compare
a25fd2a
to
fa8fc96
Compare
8af5067
to
d8d370f
Compare
Tests integrated Changelog Typo Clarity Remove changelog
More optimization Edge cases
Missing empty line Internal class
7a739fb
to
f62487e
Compare
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
Related to #1326.
Closes #1322.
Closes #1323.
This tries to readdress the issues mentioned in #1322 and #1323. While working on this PR, initial attempt was made to implement Fisher-Yates shuffling, but it turns out this is no trivial task.
First, some context on why Fisher-Yates is not used in this PR. The goal is to use
PreEvaluationHash
of aBlock<T>
to deterministically pseudo-randomly shuffle transactions by signer addresses. What Fisher-Yates algorithm provides is an unbiased sampling, but this requires higher entropy than that ofPreEvaluationHash
can provide by itself.1 Proper implementation would require increasing entropy by extendingPreEvaluationHash
with each transaction's signature, not signer address, on each step of selection required for Fisher-Yates. As my own implementation got more and more elaborate, I became concerned about possible performance degradation, so decided to take another route.Implementation in this PR tries to achieve at least the following.
n
signers, the probability of any signer to be selected as first is1/n
.a
andb
, the probability ofa
being selected beforeb
is1/2
.Keep in mind, these conditions are not sufficient enough to give us unbiased permutation samplings of
n
signers, which is a potential security hole, however minor it may be. As two "consecutive" signers in the original ordering is highly likely to be executed consecutively, although not necessarily in order. This can be somewhat mitigated easily with some additional computation, but cannot be completely normalized while using onlyPreEvaluationHash
as the random seed.1: For unbiased sampling of permutations of
n
elements, minimum required entropy islog2(n!)
, meaning approximately524
randomly generatedbit
s are required for shuffling100
elements.