[Neo Core Fix]Fix https://github.com/neo-project/neo/issues/2862#3364
[Neo Core Fix]Fix https://github.com/neo-project/neo/issues/2862#3364Jim8y wants to merge 11 commits intoneo-project:masterfrom
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? |
roman-khimov
left a comment
There was a problem hiding this comment.
Not a solution to me.
cschuchardt88
left a comment
There was a problem hiding this comment.
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
| /// </summary> | ||
| private bool IsHighPriorityTransaction(Transaction tx) | ||
| { | ||
| // High priority: fee > 3x average |
|
|
||
| // Fields for network load estimation | ||
| private readonly Queue<ulong> _recentBlockTimes = new(); | ||
| private const int BlockTimeWindowSize = 20; // Consider last 20 blocks |
| var memoryPoolUtilization = (double)_memoryPool.Count / _system.Settings.MemoryPoolMaxTransactions; | ||
| var networkLoad = EstimateNetworkLoad(block); | ||
|
|
||
| _maxTransactionsPerSecond = CalculateOptimalTps(memoryPoolUtilization, networkLoad, block); |
There was a problem hiding this comment.
_optimalMaxTransactionsPerSecond instead of _maxTransactionsPerSecond
There was a problem hiding this comment.
no difference to the code.
There was a problem hiding this comment.
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.
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.
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.
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.
its either 0 or 30 actually.
There was a problem hiding this comment.
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.
These weights does not look like %, they are more than 100
There was a problem hiding this comment.
how could it be more than 100?
var memPoolUtilization = (double)_memoryPool.Count / _system.Settings.MemoryPoolMaxTransactions * 100;
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.
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.
Updated, now maximum load is 100.
There was a problem hiding this comment.
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.
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.
Previous formula was surely better, you just need to adjust the weights.
There was a problem hiding this comment.
could not understand, maybe you can provide one for me.
AnnaShaleva
left a comment
There was a problem hiding this comment.
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: