-
Notifications
You must be signed in to change notification settings - Fork 5
Algo/coin grinder #75
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
Open
yancyribbens
wants to merge
12
commits into
p2pderivatives:master
Choose a base branch
from
yancyribbens:algo/coin-grinder
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Algo/coin grinder #75
yancyribbens
wants to merge
12
commits into
p2pderivatives:master
from
yancyribbens:algo/coin-grinder
Conversation
This file contains 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
This is a preparatory step. Preferably, the effective_value function from rust-bitcoin would be used, however in an upcoming commit, the library transitions to use weight instead of satisfaction_weight. Therefore, while the rust-bitcoin upstream effective_value uses satisfaction_weight, a local version of effective_value using weight is added.
Simplify by using a trait method which requires only argument instead of three.
Core uses just weight in coin-grinder, and it's complicated to maintain using both satisfaction_weight and weight. Therefore, switch to just weight units for all algorithms. As a consequence, two tests in SRD needed to be revised. Now that Weight is used instead, if no Weight is defined in the test, the default Weight is zero since 160 is no longer added as the base_weight. This means that the default weight for all UTXOs in the tests is now zero where in previously the default was 160 if not otherwise defined.
Simplify code base by using an upstream method instead of creating a local method that does the same thing.
Provide a DFS-based selection algorithm which optimizes for transaction weight and creates a change output.
If the currently selected input does not contribute to a valid solution, and the next input to be evaluated is of the same construction (same value and weight), then skip (do not evaluate). Therefore, this optimization significantly improves performance when a candidate input set contains many identical inputs. See also: bitcoin/bitcoin@451be19
It can be estimated that if we continue adding inputs that no better solution than the current best solution will be forthcoming. The estimation is done as follows: Calculate the number of inputs needed to reach the remaining target. The input set is sorted by descending value, so we know that every following input will be less than the current input. Therefore, to determine the number of inputs needed to reach the target, we use a lower bound by estimating that every following input will be the same value as the current input. Then, multiply the lower bound input count by the best possible weight (tail weight) and check if the result could be better than the known best weight so far. If the resulting estimation is higher (worse), then decide what fashion of backtrack is next. Check the value of the last selected value (tail). If it's greater than any remaining values then move it to the exclusion branch (shift) since a better combination is might be possible. Otherwise cut entire sub-tree since the tail was the best possibility for this sub-tree. See also: bitcoin/bitcoin@13161ec
A UTXO pool that contains multiple values that when added together produce an overflow. Instead of panic, return None in order to safely handle such cases.
b740740
to
6921b39
Compare
Return None during computation so that the result can be handled instead of panicking.
28b4e92
to
2ba2fb0
Compare
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.
Add Coin Grinder, A Rust DFS-based selection algorithm which optimizes for transaction
weight and creates a change output.
This is a Rust implementation of the C++ version bitcoin/bitcoin#27877
I plan to follow up and add fuzz tests, property tests and benchmarks before a release. While i've made a best attempt to guard against possible overflows by using checked arithmetic, I suspect more will be uncovered once fuzz tests are added. Every instance of checked arithmetic slows the performance, therefore I've left places unchecked for now that are not obvious.