Useless change transactions
While using Silkaj on GTest on a member account, I encountered a strange behavior. A lot of change transactions happened before my actual tx was sent. Each of these change txs gathered the necessary amount for the TX, .
To reproduce : send more than 40 UD from a member account. I have done it once, and you can observe on block 660862 : 2 change txs ; only the 1st one is used in the final tx.
Reason :
-
the result of tx/sources/ is ordered as so :
- UDs first
- TX after
-
the get_sources() function respects this order, and adds the pending transactions after.
Solution(s)
three solutions. What we want is that pending transactions should be considered first after a change transaction.
-
make money.get_sources add pending transaction at the beginning of the sources list. (not tested, just guessing)(needs few line change in the code)
-
make tx.get_list_input_for_transaction() reverse the list of inputs, in order to have pendings first.
-
call get_sources only once ; then write change txs and final tx we need ; then send it all to the node. (needs a lot of refactoring to the code)
- Solution 1 is easiest and for short-term. I plan to use it for #281 (closed). This means we use sources in this order : 1- pending, 2-UD, 3- TX on blockchain.
- I can use solution 2 as well if (for any reason) we don't want to change get_source() behavior. The source would be used as so : 1-pending, 2-TX on BC, 3- UD.
- Solution 3 is part of #172 (closed) : if we want to request sources only once, we will have to compute all txs before sending them.