Coin "selection/use" order for outgoing transactions

#1

I’m in the process of working up a web tool to help you calculate the coinage contained within an address, but to do so, I need to understand a bit more about how the protocol selects coins to use in outgoing transactions. Here’s an example address, with a couple of incoming transactions that all occurred within a five day window early in the month:

[table]
[tr][td]Date & Time[/td]
[td]Amount (PPC)[/td]
[td]Coin Age[/td][/tr]
[tr]
[td]Jan. 01 2014 @ 00:01[/td]
[td] 200[/td]
[td] 0[/td]
[/tr]
[tr]
[td]Jan. 02 2014 @ 00:01[/td]
[td] 100[/td]
[td] 0[/td]
[/tr]
[tr]
[td]Jan. 05 2014 @ 00:01[/td]
[td] 50[/td]
[td] 0[/td]
[/tr]
[/table]

Now, nothing happens until Jan. 15, 2014 @ 00:01 (14 days later), when a payment is made from the address for 75 PPC. Prior to transaction, the address’s coin age (presumably) looks like this:

[table]
[tr][td]Date & Time[/td]
[td]Amount (PPC)[/td]
[td]Coin Age[/td][/tr][tr]
[td]Jan. 01 2014 @ 00:01[/td]
[td] 200[/td]
[td] 2800[/td]
[/tr]
[tr]
[td]Jan. 02 2014 @ 00:01[/td]
[td] 100[/td]
[td] 1400[/td]
[/tr]
[tr]
[td]Jan. 05 2014 @ 00:01[/td]
[td] 50[/td]
[td] 450[/td]
[/tr]
[/table]

When the payment for 75 PPC goes out, from which of the previous input transactions is the coin age destroyed? First in, first out; last in, first out?

If it is taken out for the first transaction, you would lose a total of 1050 coin days ([font=courier]14 days * 75[/font]), but if it came out of the most recent transactions, you would only lose 800 coin days ([font=courier]( 9 days * 50 ) + ( 14 days * 25 )[/font]). As you can see, it is better for the holder to take the coins out of the most recent transactions, vs. the first ones into the address, but before I made the assumption that this is how it worked, I wanted to check with the Community.

#2

I think the smallest input transaction will be used. I recently transfered some coins out of my wallet. The amount, about ~27PPC, was chosen such that it matched (with transaction fee) exactly the amount in a address that was created as the change back in Sept, plus 4PPC of small recent input transactions. It would have cost me ~2600 coindays.
What happened was that two inputs (~11 and ~14 PPCs) received back in May were used, with some of the small inputs. The two inputs were the oldest inputs in the wallet. The transaction also leaves a small change of something like ~0.07PPC, much to my dislike, after destroying 5000+ coindays. >:(

#3

Well, that’s certainly a wrinkle in coming up with a model :slight_smile:

Conceptually, what you described makes sense (at least, mechanically, not so much rationally), with my limited knowledge of how transactions and “change” work.

#4

U can specify which address u send coins from sendfromaccount I think is the command, this is how u get round sending ur coins with most coinage
Fuzzybear

Sent from my HTC Desire using Tapatalk 2

#5

[quote=“FuzzyBear, post:4, topic:1399”]U can specify which address u send coins from sendfromaccount I think is the command, this is how u get round sending ur coins with most coinage
Fuzzybear

Sent from my HTC Desire using Tapatalk 2[/quote]

For the [font=courier]sendfrom[/font] function, the command is structured as:

sendfrom <fromaccount> <toppcoinaddress> <amount> [minconf=1] [comment] [comment-to]

So, if I’m understanding how to use the daemon correctly, I’d set up a couple of “storage” addresses, where each account in this case is just the label of the address, right? I’d also have a “transitional” account, where I’d spend from.

When I need to pay for something, I’d use the daemon to manually initiate a payment (to example address “P111Test123abc”) from the “transitional” address, like:

[font=courier]./ppcoind sendfrom “Transitional” P111Test123abc 20.5 “Test payment for helping me out”[/font]

That still doesn’t give me the option to pick and choose which coins to use, but it would be helpful for making sure I’m only transacting using the addresses that I want to impact. Definitely a step up than the “blind” transfer from one of your wallet addresses that the UI currently does (though, I suppose that there is a method to how it selects which address to send from).

Thanks for the tip, FuzzyBear – I like learning more about how to use the daemon, as I’ve found that it’s been very beneficial to expanding my knowledge of how the protocol works by understanding these base-level commands.

#6

I think the “account” in the command line is just another name of “address”. At least that is what I got from the output of the listaccounts command.

#7

Right, it’s just the label, but maybe it would work with the address itself, too. I’ll have to give it a try.

#8

i thought u have to assign a address to an account… i have not done this myself … or was ages ago when i was playing with it, but might be able to have a look when i get home… need to not kill my coin age days :stuck_out_tongue:

Fuzzybear

#9

Here’s an old comment from MUTO that asks a similar question about how the coins are selected. It sounds like it has never really been answered. I’m wondering if the answer might be found in some of the Bitcoin technical documents, as I imagine that the mechanics of the selection of coins to be included in a transaction is shared between Bitcoin and Peercoin’s codebases.

#10

You might also want to understand what Sunny said about avartar mode. It sounded like the avartar mode would allow all wallet operations to be limited to one address/account in the wallet, the purpose mainly being that others can’t associate your different addresses by analysing the output. Currently you could do this by exporting the private key of the address to a clean wallet, which is not convenient.

Note that the avartar mode perhaps isn’t totally relevant with what you want, which is controling which input transactions to be used in an output, as POS calculation is based on transactions, not addresses, apparently. An address can have many input transactions. So understanding the avartar mode is good to learn how PPC wallet looks at accounts/addresses.