Spending unconfirmed coins

When I send 1 grin from an output of 10 grin, my wallet does not allow me to spend from my 9 grin change until it is 10 blocks old.

This is a wallet imposed limitation to guide me away from risk right? And a wallet could give me the option to spend my change after 0 or 1 blocks?

Affirmative, could be bypassed in theory.

2 Likes

The default is indeed 10, I think this can be changed when sending. There’s a minimum_confirmations flag when using send command from grin-wallet.

3 Likes

And anyone know if it’s possible to do this in 0 blocks? Spend from an output and spend from the change in the same block? Not whether current wallets support it, but in theory. I think sender can inform the recipient of an input that they haven’t seen on the chain yet right so should be possible?

If i understand correctly your case you have:
Tx1 (sending 1 grin):
Inputs: utxo1(10)
Outputs: utxo2(1), utxo3(9)
Kernels: kernel1

Tx2 (sending 2 grin):
Inputs: utxo3(9)
Outputs: utxo4(2), utxo5(7)
Kernels: kernel2

Now you could merge these 2 transactions into a single one:
Tx3:
Inputs: utxo1(10)
Outputs: utxo2(1), utxo4(2), utxo5(7)
Kernels: kernel1, kernel2

Now one could just broadcast this merged transaction in theory.

2 Likes

If I recall correctly, cut-through is performed in the mempool. If the mempool validation check that the input is either an output in the utxo set or in an output in the mempool, then it can just add the 2nd tx and do the cut-through to get the aggregate transaction. So yes, I think it should be possible in theory and there’s a chance we’re doing this today already.

2 Likes

I am not sure if this helps but we have something which is called late-lock :

  1. Lets check wallet help ./grin-wallet -r https://grinnode.live send --help

-l, --late-lock EXPERIMENTAL - Do not lock the coins immediately, instead only lock them during finalization.

I did never use this feature but there is also:

-c, --min_conf <minimum_confirmations> Minimum number of confirmations required for an output to be spendable
[default: 10]

And you can always create manually more outputs manually to have them ready to spend when needed. We did a proof of concept here: GitHub - Grinnode-live/grin-multi-wallet-scripts

It would require some changes to fit the current syntax of the grin-wallet any PR are welcome.

2 Likes

It is an interesting idea, since you could obfuscate the transaction graph by directly spending received outputs in the same block only visible to someone who monitors and stores the mempool. The first time I heard about cut-through I though that was its exact purpose.