-
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
Fix taskManager #2176
Fix taskManager #2176
Conversation
What is this? |
The last line will block nodes to relay transactions, even if the node is only one block behind. neo/src/neo/Network/P2P/TaskManager.cs Lines 93 to 99 in 095d7f7
|
src/neo/Network/P2P/TaskManager.cs
Outdated
@@ -95,7 +95,7 @@ private void OnNewTasks(InvPayload payload) | |||
if (!sessions.TryGetValue(Sender, out TaskSession session)) | |||
return; | |||
// Do not accept payload of type InventoryType.TX if not synced on best known HeaderHeight | |||
if (payload.Type == InventoryType.TX && Blockchain.Singleton.Height < sessions.Values.Max(p => p.LastBlockIndex)) | |||
if (payload.Type == InventoryType.TX && sessions.Values.Where(p => p.LastBlockIndex > Blockchain.Singleton.Height + 12).Count() > sessions.Count / 2) |
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.
if (payload.Type == InventoryType.TX && sessions.Values.Where(p => p.LastBlockIndex > Blockchain.Singleton.Height + 12).Count() > sessions.Count / 2) | |
if (payload.Type == InventoryType.TX && sessions.Values.Any(p => p.LastBlockIndex > Blockchain.Singleton.Height + 12)) |
What do you think?
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, it can be easily attacked.
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 think sessions.Count / 2
is too large.
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.
Adjusted to sessions.Count/3
.
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.
So as it is now with +12 it will accept more transactions? Also based on the number of peers it has?
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.
Before this, some seed nodes can't relay transactions to consensus nodes in preview4 testnet.
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.
What happens if I connect to you some nodes that never sync?
Current testnet has this issue that Preview3 nodes are influencing Preview4 nodes because they're higher in peers list which makes tx can't be relayed. |
@@ -95,7 +95,7 @@ private void OnNewTasks(InvPayload payload) | |||
if (!sessions.TryGetValue(Sender, out TaskSession session)) | |||
return; | |||
// Do not accept payload of type InventoryType.TX if not synced on best known HeaderHeight | |||
if (payload.Type == InventoryType.TX && Blockchain.Singleton.Height < sessions.Values.Max(p => p.LastBlockIndex)) | |||
if (payload.Type == InventoryType.TX && sessions.Values.Where(p => p.LastBlockIndex > Blockchain.Singleton.Height + 12).Count() > sessions.Count / 3) | |||
return; |
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 think that it's better to remove this lines, the mempool will work as expected, if it's filled, will be trimmed, so why we need to avoid this messages during sync based on untrusted information? Please check #2180
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.
That's the way neo-go currently works (IsInSync
logic mentioned earlier is only used to determine when we should start dbft). The only problem with this is that the node can try relaying invalid transactions which can be interpreted as suspicious behaviour by its peers. But these transactions should at the same time fall within MaxValidUntilBlockIncrement
range from current node's height which is not really likely to happen.
Let's move on? |
Already updated testnet with this fix, works well now. @erikzhang |
@erikzhang Merge? |
@erikzhang @shargon Merge? |
@Tommo-L I think maybe this is not the best solution. In NEO2, we sync the headers first, we can easily detect whether we are on the best known height. Now we sync the blocks directly, we can't do that. |
#1811 doesn't solve the problem. |
Can we make out a good solution before Preview5 release? If not, maybe we could merge this first, although not the best way but at least solve the issue. Otherwise we'll meet the same issue on Preview5 testnet. |
If a node is too far behind, every time a block is synchronized, the transaction in the memory pool will be re-verified. In fact, this part is not very time-consuming, because most of the verification time is spent on verifying the signature. In addition, we can optimize in the future. If multiple blocks are being synchronized, we can only use the last block(the highest height block) to verify transactions in the memory pool. |
This is uncertain, and we cannot rely on this assumption. Otherwise this will become a weakness. |
Maybe we can derive the "best" header from neo/src/neo/Ledger/Blockchain.cs Lines 301 to 307 in 8c72d54
|
We'll add header back. |
@@ -95,7 +95,7 @@ private void OnNewTasks(InvPayload payload) | |||
if (!sessions.TryGetValue(Sender, out TaskSession session)) | |||
return; | |||
// Do not accept payload of type InventoryType.TX if not synced on best known HeaderHeight | |||
if (payload.Type == InventoryType.TX && Blockchain.Singleton.Height < sessions.Values.Max(p => p.LastBlockIndex)) | |||
if (payload.Type == InventoryType.TX && sessions.Values.Where(p => p.LastBlockIndex > Blockchain.Singleton.Height + 12).Count() > sessions.Count / 3) |
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.
if (payload.Type == InventoryType.TX && !sessions.Values.Any(p => p.LastBlockIndex > Blockchain.Singleton.Height - 12 && p.LastBlockIndex < Blockchain.Singleton.Height + 12))
Will it be ok? I think one node must connect a correct
node.
No description provided.