-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
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 { |
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.
sort_by_key method could be used here.
Implementing a trait for a type is for re-usability across the code base.
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.
- Implemented the sorting using sort_by_key
- 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 { |
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.
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
…uding feerate and weight calculation
src/lib.rs
Outdated
fn partial_cmp(&self, other:&Self) -> Option<Ordering>{ | ||
Some(self.cmp(other)) | ||
} | ||
} |
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.
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
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.
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.
Merged with main according to updates
…uding feerate and weight calculation
This reverts commit 663e2bf.
* 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
…cubator#11) This reverts commit 663e2bf.
* 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
* 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>
* 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
…cubator#11) This reverts commit 663e2bf.
* 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>
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.