(mostly) Lock free transactions

When I was working on Grin-wallet contract prototype, I had to think about this a bit and would like to describe my current understanding. I think there are 2 actions every party does with respect to their inputs/output:

  1. First, it decides which inputs/outputs it will use and locks the inputs
  2. Second, it adds these to the slate

The 2. can always be done at the sign step. This means that we can do it such that the party at step2 never knows which inputs/outputs will be added by the initiator until they see the full transaction in the mempool. This is true even for the case of an early lock, because an early lock can select the inputs and lock them without adding them to slate (in grin-wallet, the inputs and outputs are added to the Context struct). At the moment, we add them to Context and Slate at the same time, but that’s not required and it would be better if we always “late add” inputs/outputs on the slate.

Let’s call this early-lock & late-add. I think this could be the default for every wallet because:

  1. If both parties contribute fees for their own inputs/outputs (as they should), then it’s impossible to make a wrong fee estimation because they locked the inputs and prepared the outputs before signing. This brings stability to transaction building and users should not be hitting fee estimation errors. Late-locking could fail on the first try and succeed a minute or two later because the wallet received new outputs that can work as inputs etc. We might want to minimize these cases and it’s best if we eliminate them completely.
  2. It hides input/output contribution of the initiator until the tx is in the mempool which means that the person at step2 can’t opt-out of a transaction because a specific input was used. This means the party at step2 can’t stop coinswap input contribution. In theory, they could RBF it once we start supporting this, but this comes at a cost.

The late-lock has its own benefits though, especially when the transaction takes a long time to make which allows us to reserve the inputs just in time.

It’s not clear to me which flow is more optimal for exchanges, it seems a bit tricky. An exchange could limit a user to 1 active withdrawal/deposit at a time meaning they can’t start another one until they either cancel or complete the ongoing one. Late-locking has some advantages, but it may result in wrong fee estimations and the exchange would need to handle these.

1 Like