Skip to content
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

Implement BNB Selection #1

Closed
rajarshimaitra opened this issue Feb 28, 2024 · 3 comments
Closed

Implement BNB Selection #1

rajarshimaitra opened this issue Feb 28, 2024 · 3 comments
Labels
good first issue Good for newcomers
Milestone

Comments

@rajarshimaitra
Copy link
Contributor

rajarshimaitra commented Feb 28, 2024

Implement the BNB Coin selection algorithm and add tests via suitable test vectors.

BNB tries to select inputs in such a way that no change outputs are required.
So the total value of the selected outputs should not exceed the target + dust value

You are expected to follow the thesis of Mark Erhard, Algorithm 10 closely.
Here the author tries to explain the concepts by visualizing a tree but in reality we are not going to create the tree
in our program but rather walk through the imaginary tree using recursion.

The user level public function

pub fn select_coin_bnb(
    inputs: Vec<OutputGroup>,
    options: CoinSelectionOpt,
) -> Result<SelectionOutput, SelectionError>

should follow Algorithm 9.

The private function

fn bnb(
    inputs_in_desc_value: &Vec<(usize, OutputGroup)>,
    selected_inputs: &[usize],
    effective_value: u64,
    depth: usize,
    bnp_tries: u32,
    options: &CoinSelectionOpt,
) -> Vec<usize>

should follow Algorithm 10.
NOTE: mutation of variables should not happen rather those state changes should be passed on correctly in the recursive calls.

In order to do BNP we need to find the exact match so the effective value of a target is optimal rather than
recomputing fee at every step.
So implement the private function fn effective_value(output: &OutputGroup, option: &CoinSelectionOpt) -> u64 first.

For practical purposes we are not going to explore all possible subsets and we want the algorithm to finish faster.
So bnp_tries are decremented for every recursion call and if it reaches 0, terminate the search.

Read the code of generating subsets for understanding, how to manipulate selections using Vec.

Read the implementation of SRD on how to calculate fee and waste.

@i-am-yuvi
Copy link

I'll give it a try!!

aruokhai pushed a commit to aruokhai/rust-coinselect that referenced this issue Jul 29, 2024
Pulling all Changes to the Forked Main Repo
@delcin-raj delcin-raj added this to the v0.1.0 milestone Aug 18, 2024
@delcin-raj delcin-raj closed this as completed by moving to review in coinselection v0.1.0 task list Aug 18, 2024
@delcin-raj delcin-raj reopened this Aug 18, 2024
@delcin-raj delcin-raj closed this as completed by moving to review in coinselection v0.1.0 task list Aug 18, 2024
@delcin-raj delcin-raj reopened this Aug 18, 2024
@i-am-yuvi
Copy link

is this still open?? @delcin-raj ?

@NeoZ666
Copy link
Contributor

NeoZ666 commented Aug 30, 2024

#29

@delcin-raj delcin-raj closed this as completed by moving to review in coinselection v0.1.0 task list Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
Status: review
Development

No branches or pull requests

4 participants