-
Notifications
You must be signed in to change notification settings - Fork 479
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
Heuristic tx censorship detection #7259
Heuristic tx censorship detection #7259
Conversation
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.
Good first try and place to polish it a bit!
src/Nethermind/Nethermind.Blockchain/Blocks/PotentialCensorshipCache.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Blocks/PotentialCensorshipCache.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Blocks/PotentialCensorshipCache.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Blocks/PotentialCensorshipCache.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Blocks/PotentialCensorshipCache.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Blocks/PotentialCensorshipCache.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Blockchain/Blocks/PotentialCensorshipCache.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.TxPool/Collections/TxGasPriceSortedCollection.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.TxPool/Collections/TxGasPriceSortedCollection.cs
Outdated
Show resolved
Hide resolved
…m/Arindam2407/nethermind into heuristic_tx_censorship_detection
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.
Love the simplifications!
Few minor things to polish.
Next steps:
- Write tests for CensorshipDetector class - either unit or proper integration using BlockchainTests or descendant class.
- Test in real world.
- Consider implementing different censorship detection strategies.
- Run it on mainnet - @kamilchodola can you help with that?
src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.Setup.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Merge.Plugin/Handlers/GetPayloadV3Handler.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Merge.Plugin/Data/GetPayloadV3Result.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
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.
In the way you wrote it - it will be working, but you overcomplicated it. You are taking snapshot of the whole pool, then selecting lowest nonce from each bucket, then reading accounts and looking for next-nonce-to-be-executed and then iterating for the biggest gas price (which post-1559 is equal to maxPriorityFeePerGas
).
Instead, you can simplify it and do a snapshot of lowest-nonce-per-sender only and then just look for the tx with biggest gasBottleneck.
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
One more potential issue - there are 2 ways of paying tx fee. New way, post London fork, you are paying So what I will recommend here is to prepare Then you only need to find tx in mempool with biggest gasBottleneck - gas bottleneck has inside current base fee + priority fee |
And one more thing - blob transactions. There is a separate market with blob date fee and a hard limit of max 6 blob txs per block. We probably don't need to check censorship in the context of blob transactions. But we can miss some censorship attempts because of it. Example: Our most expensive tx in the pool is 1559-type tx with My recommendation - exclude blob-type txs when setting |
…m/Arindam2407/nethermind into heuristic_tx_censorship_detection
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.
Good changes, but still a bit to improve.
Also it would be great to add some unit tests - tests will help you to catch potential mistakes/inconsistences in implementation and we will be protected from broking it by accident in the future
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
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.
LGTM
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/CensorshipDetectorConfig.cs
Show resolved
Hide resolved
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
…hipThreshold to config
…ithub.com/NethermindEth/nethermind into heuristic_tx_censorship_detection
{ | ||
long bestSuggestedNumber = _blockTree.FindBestSuggestedHeader()?.Number ?? 0; | ||
long headNumberOrZero = _blockTree.Head?.Number ?? 0; | ||
return bestSuggestedNumber > headNumberOrZero + 8; |
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 probably shouldn't even do 8
threshold, as here we should only check tx pool if we are processing current head block, right?
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.
Right, my bad
[ConfigItem(DefaultValue = "false", | ||
Description = "Enabling censorship detection feature")] | ||
bool Enabled { get; set; } |
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.
Shouldn't we enable it by default? Or do we plan to start slowly?
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 don't knw why I disabled it by default. It should be enabled ofc
src/Nethermind/Nethermind.Consensus/Processing/CensorshipDetector/CensorshipDetector.cs
Outdated
Show resolved
Hide resolved
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.
Looks good, let's just add a metric for potentially censored blocks
Actually more useful will be not block number, but number of blocks. Maybe let's have both? |
Co-authored-by: lukasz.rozmej <lukasz.rozmej@gmail.com> Co-authored-by: Marcin Sobczak <marcindsobczak@gmail.com>
Co-authored-by: lukasz.rozmej <lukasz.rozmej@gmail.com> Co-authored-by: Marcin Sobczak <marcindsobczak@gmail.com>
Changes
Censorship Detection Using Heuristics
Types of changes
What types of changes does your code introduce?
Requires testing
If yes, did you write tests?