Changed the note selection algorithm to try and reduce the notes used.#4748
Changed the note selection algorithm to try and reduce the notes used.#4748
Conversation
a2757ea to
bc4fd54
Compare
bbca0f0 to
a56ed68
Compare
Thanks for reviewing @grarco , understood. When rereading this PR, I realized that the fraction code could be replaced with a nested loop to achieve the same result. Please let me know if the latest commit (671d0b5) is problematic... Thanks! |
|
This seems important and time-sensitive. Would it make sense to merge this asap and cut a patch release? It just involves client changes, correct? |
Yes, this PR only involves client changes. However it depends upon namada-net/masp#100 being merged to |
dc7b4b3 to
ce65a04
Compare
ce65a04 to
86f29b4
Compare
86f29b4 to
e630f9e
Compare
|
replaced by #4763 |
Describe your changes
An attempt to optimize the MASP note selection algorithm in order to reduce the size of MASP transactions. Smaller transactions are desirable for reducing gas fees and ensuring that the hardware wallet is able to display transactions without erroring out. To this end, the following changes have been made:
Fractionstructure to facilitate comparing notes to potentially be used in a transactionThe major drawback of the new note selection algorithm is that it exchanges all unspent notes first before attempting to choose the most optimal notes. This makes it easier to handle situations where users want to spend NAM and this NAM has to be collected from the rewards because they don't have enough NAM notes. In this case the algorithm should select non-NAM notes that yield the largest NAM rewards after being exchanged.
Another drawback of the new algorithm is that it doesn't account for the space/bytes used by the conversions that accompany a note. Probably notes that require a lot of conversions should be less likely to be picked, i.e. they should have some sort of cost. This hasn't been investigated because it's not yet clear whether this will be a problem in practice. If it does become a problem, it might be possible to use a weighted version of the set cover approximation algorithm.
Perhaps the proposed algorithm is not the best, but hopefully it's now a bit easier to implement a more optimal note selection algorithm.
This PR depends upon namada-net/masp#100 for the dot product, supremum, and infimum operations used when manipulating note contributions.
Examples
What follows are printouts of the note selection algorithms' executions. The target amount is the minimum amount of value that we are trying to collect. Notes are first printed out in the order in which they are encountered. And then they are printed out in the order in which they are selected for the transaction. The ideal is to select the most effective notes first and the least effective ones last if they are still needed.
1) Before
1) After
2) Before
2) After
Checklist before merging
breaking::labelsnamada-docsreponamada-indexerornamada-masp-indexer, a corresponding PR is opened in that repo