Conversation
ac47780 to
8af1a68
Compare
8af1a68 to
c917122
Compare
softsimon
approved these changes
Aug 26, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves on the method introduced in #5354 for detecting prioritized transactions in mined blocks.
Background
That naive algorithm assumed that transactions would only ever have their priority increased out-of-band, and so simply iterated over the set of transactions and marked anything positioned higher than expected as "prioritized".
However, if any transactions in the block had actually been deprioritized, this approach could produce (potentially very many) false positives.
For example, Ocean block 856119 includes several small inscriptions, which Ocean's default template deprioritizes by applying a datacarriercost penalty. The previous algorithm interpreted the large number of subsequent "normal" transactions as prioritized, since they had lower apparent fee rates than the later inscriptions:
Solution
The new algorithm implemented in this PR broadens the assumptions to allow for deprioritization, and efficiently figures out the most likely sets of prioritizations and deprioritizations to explain the composition of the block.
The precise details are a little complicated, but essentially the algorithm involves computing the Longest Increasing Subsequence of transactions in the block, which represents the most likely set of "normal" transactions without any out-of-band fee adjustments. Any other transactions falling outside of that set have probably been prioritized or penalized, depending whether they appear higher or lower than expected based on their simple in-band effective fee rates.
here, the dark blue transactions represent deprioritized inscriptions in the same Ocean block (see the "Other changes" section below)
Effects
In practice, the new algorithm produces exactly the same results as the old one for the 99%+ blocks constructed using default Bitcoin Core settings.
But for the occasional block constructed with, e.g,
datacarriercostpenalties, it very effectively mitigates the false positive issue.Other changes
The new algorithm is capable of efficiently detecting both prioritized and deprioritized transactions, and only requires the block summary data which is already available on the block page.
So this PR also runs the calculation in the frontend, and (where appropriate), identifies and highlights any deprioritized transactions in the block audit.
Once the algorithm is a bit more battle-tested, we can start saving those lists of deprioritized transactions to the block audits DB table so that the data is also available on the transaction page etc.
DB migration
Since only
fourfive blocks were affected by false positives from the previous algorithm, this PR adds a database migration to directly fix those specific audits in the DB (if present).