-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Neo Core Fix]Fix https://github.com/neo-project/neo/issues/2862 #3364
Conversation
@superboyiii can you help to test it? I will fix the test if this pr is truly working. @dusmart can you take a look? |
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.
Not a solution to me.
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.
Why are all these markdown
file in with the source? Should be in docs
folder in the root of the repo.
I know what you mean, but we don't have a doc folder. |
I need more specific reason. |
clean empty lines
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.
Partially review at Jim8y#1
/// </summary> | ||
private bool IsHighPriorityTransaction(Transaction tx) | ||
{ | ||
// High priority: fee > 3x average |
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.
committee address?
|
||
// Fields for network load estimation | ||
private readonly Queue<ulong> _recentBlockTimes = new(); | ||
private const int BlockTimeWindowSize = 20; // Consider last 20 blocks |
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.
Move to config
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 reviewed the PR, @Jim8y.
I see some hope in it right now.
This is currently not in milestone for 3.8.0, however, I will try to take a look more carefully soon.
var memoryPoolUtilization = (double)_memoryPool.Count / _system.Settings.MemoryPoolMaxTransactions; | ||
var networkLoad = EstimateNetworkLoad(block); | ||
|
||
_maxTransactionsPerSecond = CalculateOptimalTps(memoryPoolUtilization, networkLoad, 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.
_optimalMaxTransactionsPerSecond instead of _maxTransactionsPerSecond
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.
no difference to the code.
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.
nomenclature is bad like this, maxTransactionPerSecond
for something that is variable does not looks good to me.
/// Estimates current network load | ||
/// </summary> | ||
/// <returns>An integer between 0 and 100 representing the estimated network load</returns> | ||
private int EstimateNetworkLoad(Block? 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.
move to double as well and base %, already divided by 100.
The only use of it is aligned with memPool Use
var load = 0; | ||
|
||
// 1. Memory pool utilization (30% weight) | ||
var memPoolUtilization = (double)_memoryPool.Count / _system.Settings.MemoryPoolMaxTransactions; |
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.
get this value from previous line before calling the method, it is called just once as it is right now
src/Neo/Ledger/SmartThrottler.cs
Outdated
{ | ||
var avgBlockTime = _recentBlockTimes.Average(t => (double)t); | ||
var blockTimeRatio = avgBlockTime / _system.Settings.MillisecondsPerBlock; | ||
load += (int)(Math.Min(blockTimeRatio, 2) * 30); // Cap at 60 points |
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 am not sure.
avgBlockTime should usually not be lower than " _system.Settings.MillisecondsPerBlock".
So, usually blockTimeRatio is close to "1".
So, there is an average load from 30 - 60
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.
its either 0 or 30 actually.
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.
How?
(int)(Math.Min(blockTimeRatio, 2) * 30);
BlockTimeRatio will never/RARELY be less than 1.
So the range is 30 - 60 in this formula
{ | ||
var load = 0; | ||
|
||
// 1. Memory pool utilization (30% weight) |
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.
These weights does not look like %, they are more than 100
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.
how could it be more than 100?
var memPoolUtilization = (double)_memoryPool.Count / _system.Settings.MemoryPoolMaxTransactions * 100;
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 in the thread below
src/Neo/Ledger/SmartThrottler.cs
Outdated
load += (int)(Math.Min(txGrowthRate, 1) * 40); | ||
} | ||
|
||
return Math.Min(load, 100); // Ensure load doesn't exceed 100 |
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 is bad for any weight metric, insert some cut after weighting.
This part of the code needs enhanced.
If we decide move on with this solution I can later test and analyze.
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.
Updated, now maximum load is 100.
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.
how could it be more than 100?
The same reason you have this Math.Min(load, 100);
here
src/Neo/Ledger/SmartThrottler.cs
Outdated
if (_recentBlockTimes.Count > 0) | ||
{ | ||
var avgBlockTime = _recentBlockTimes.Average(t => (double)t); | ||
load += (avgBlockTime < _system.Settings.MillisecondsPerBlock?1:0) * 30; // Cap at 30 points |
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 is bad formula as well, @Jim8y.
load += (avgBlockTime < _system.Settings.MillisecondsPerBlock?1:0) * 30; // Cap at 30 points
is a degree function in control theory.
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.
Previous formula was surely better, you just need to adjust the weights.
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.
could not understand, maybe you can provide one for me.
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.
Not a solution to me.
I need more specific reason.
I agree with Roman, and I don't quite like the idea of restricting the node in that way. I also agree with the #2862 (comment), it seems that this problem should be resolved on a consensus level rather than by restricting TPS at mempool level.
It's great to have a feasible solution here. My concern is that will this smart throttler can not defend us from other DoS vectors. A possible scene maybe the leader CN chooses a low priority tx somehow, then the other CNs may not get that low priority tx during a heavy network load. Then the consensus could not be reached. I've got to say. This is not the issue introduced by this PR. It's there already. It would be better if this or some new PRs could prevent the above scene. |
@AnnaShaleva I dont care about how you agree with roman, i am sorry to say this anna, you and roman are in the same community and ofcourse you are with him all the time. What i care is what is your solution, you can always say this is not a perfect solution, I accept that, but where is your solution? leaving the network unprotected for months even years just waiting for a You are such a great reviewer and core contributer, I will always carefully consider your suggestions. As long as its not some |
replaced with #3631 |
Closes #2862
Description
There is an issue in the memorypool where attacker can dos the node by sending tons of transactions with ascending transaction fees.
Fixes # #2862
Type of change
How Has This Been Tested?
Test Configuration:
Checklist: