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

FIFO selection algorithm #9

Merged
merged 12 commits into from
Mar 14, 2024
Merged

FIFO selection algorithm #9

merged 12 commits into from
Mar 14, 2024

Conversation

jkciw
Copy link
Contributor

@jkciw jkciw commented Mar 4, 2024

Added code to implement first in first out coin selection algorithm. I have used the value of the input as an identifier of selected coins. It is not the ideal solution as it is not an unique identifier. Maybe we should ask the user to include the 'txid' of the UTXO in OutputGroup.

@jkciw jkciw mentioned this pull request Mar 4, 2024
src/lib.rs Outdated
let mut totalvalue: u64 = 0;
let mut totalweight: u32 = 0;
let mut selectedinputs: Vec<u32> = Vec::new();
impl Ord for OutputGroup {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort_by_key method could be used here.
Implementing a trait for a type is for re-usability across the code base.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Implemented the sorting using sort_by_key
  2. Moved the impl Ord out of the FIFO function to below the struct definition

src/lib.rs Outdated
let mut sortedinputs = inputs.clone();
sortedinputs.sort_by(|a,b| a.creation_sequence.cmp(&b.creation_sequence));
for (index,input) in sortedinputs.iter().enumerate(){
if totalvalue >= options.target_value {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If and only if the total value of the inputs are greater than the target value + the estimated_fee, we can have a valid coin selection. Else appropriate error has to be returned

src/lib.rs Outdated
fn partial_cmp(&self, other:&Self) -> Option<Ordering>{
Some(self.cmp(other))
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These implementations are not required and they are not being used.
This is also not useful because you might want to select an utxo based on it's value etc.,
You can remove them

Copy link
Contributor Author

@jkciw jkciw Mar 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Removed custom order implementations altogether. sort_by_key does the job. Also added a basic test for FIFO. If the test is along the right line, I shall add more cases.

@delcin-raj delcin-raj merged commit 663e2bf into Bitshala-Incubator:main Mar 14, 2024
4 checks passed
delcin-raj added a commit that referenced this pull request Mar 14, 2024
delcin-raj added a commit that referenced this pull request Mar 14, 2024
jkciw added a commit to jkciw/rust-coinselect that referenced this pull request Apr 9, 2024
* Added FIFO

* Added changes to use value of the input as identifier for FIFO algorithm

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Added FIFO

Merged with main according to updates

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Performed fmt checks

* Addressed issues raised by clippy and checked fmt
jkciw pushed a commit to jkciw/rust-coinselect that referenced this pull request Apr 9, 2024
jkciw added a commit to jkciw/rust-coinselect that referenced this pull request Apr 10, 2024
* Added FIFO

* Added changes to use value of the input as identifier for FIFO algorithm

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Added FIFO

Merged with main according to updates

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Performed fmt checks

* Addressed issues raised by clippy and checked fmt
delcin-raj added a commit that referenced this pull request Apr 10, 2024
* Added FIFO

* Added changes to use value of the input as identifier for FIFO algorithm

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Defining SelectionOutput type and some Error Variants

* Changing the comments according to new types

* Added FIFO

Merged with main according to updates

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Performed fmt checks

* Addressed issues raised by clippy and checked fmt

* FIFO selection algorithm (#9)

* Added FIFO

* Added changes to use value of the input as identifier for FIFO algorithm

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Added FIFO

Merged with main according to updates

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Performed fmt checks

* Addressed issues raised by clippy and checked fmt

* Minor fmt edit

* Addressed issues causing test to fail

* Removed comments about using values/indexes in FIFO

* bnp function declaration (#13)

* bnp function declaration

* Clippy suggestion

* inputs type is changed to &[OutputGroup] (#14)

* inputs type is changed to &[OutputGroup]

Singalling the fact that selected_outputs should refer to indices of
the given inputs and that the order of the given inputs are not changed
with respect to the user.

* fmt fix

* Pulled changes from main and modified fifo accodingly

* Removed a redundant utility function. Substituted its function with the existing utility function

* Fmt fix

* removed redundat codes and replaced them with utility functions.

* Modified SelectionError msg to Insufficient funds

* Made changes w.r.t estimated_fees in accumulated_value conditionals.

* Removed unnecessary files committed earlier

* removed DS_Store and launch.json files

* signed commit

* Fresh commit after signing and rebasing

---------

Co-authored-by: delcin-raj <delcinraj@gmail.com>
Co-authored-by: Delcin Maria Koilraj <42584001+delcin-raj@users.noreply.github.com>
NeoZ666 pushed a commit to NeoZ666/rust-coinselect that referenced this pull request Sep 16, 2024
* Added FIFO

* Added changes to use value of the input as identifier for FIFO algorithm

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Added FIFO

Merged with main according to updates

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Performed fmt checks

* Addressed issues raised by clippy and checked fmt
NeoZ666 pushed a commit to NeoZ666/rust-coinselect that referenced this pull request Sep 16, 2024
NeoZ666 pushed a commit to NeoZ666/rust-coinselect that referenced this pull request Sep 16, 2024
* Added FIFO

* Added changes to use value of the input as identifier for FIFO algorithm

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Defining SelectionOutput type and some Error Variants

* Changing the comments according to new types

* Added FIFO

Merged with main according to updates

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Performed fmt checks

* Addressed issues raised by clippy and checked fmt

* FIFO selection algorithm (Bitshala-Incubator#9)

* Added FIFO

* Added changes to use value of the input as identifier for FIFO algorithm

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Added FIFO

Merged with main according to updates

* Added changes to use sort_by_key method and check for conditions including feerate and weight calculation

* Removed Partial Imp and added one test case for fifo

* Removed custom implementations of ordering

* Performed fmt checks

* Addressed issues raised by clippy and checked fmt

* Minor fmt edit

* Addressed issues causing test to fail

* Removed comments about using values/indexes in FIFO

* bnp function declaration (Bitshala-Incubator#13)

* bnp function declaration

* Clippy suggestion

* inputs type is changed to &[OutputGroup] (Bitshala-Incubator#14)

* inputs type is changed to &[OutputGroup]

Singalling the fact that selected_outputs should refer to indices of
the given inputs and that the order of the given inputs are not changed
with respect to the user.

* fmt fix

* Pulled changes from main and modified fifo accodingly

* Removed a redundant utility function. Substituted its function with the existing utility function

* Fmt fix

* removed redundat codes and replaced them with utility functions.

* Modified SelectionError msg to Insufficient funds

* Made changes w.r.t estimated_fees in accumulated_value conditionals.

* Removed unnecessary files committed earlier

* removed DS_Store and launch.json files

* signed commit

* Fresh commit after signing and rebasing

---------

Co-authored-by: delcin-raj <delcinraj@gmail.com>
Co-authored-by: Delcin Maria Koilraj <42584001+delcin-raj@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants