-
Notifications
You must be signed in to change notification settings - Fork 975
Description
While studying the existing fundchannel in preparation for fully implementing #1936 , I noticed that the current fundchannel does this:
connectto peer.txpreparea "dry-run" fundchannel using a dummy funding address.- Extract the funding output amount in the returned transaction --- presumably this is how we determine the actual amount when given
all.
- Extract the funding output amount in the returned transaction --- presumably this is how we determine the actual amount when given
fundchannel_startto peer using the extracted amount, receiving a target funding addresstxdiscardthe previous "dry-run" transaction.txprepare, this time with the now-filled-in funding address.fundchannel_completewith the transaction ID.txsendthe transaction.
What I want to point is that in theory, it would be possible for a sufficiently heavily-used server to have some other withdraw, fundchannel, or txprepare execute between the txdiscard of the dry-run transaction and the subsequent txprepare as a multithreaded race condition.
As locking of the RPC is not implemented (and would be dangerous as well --- consider that a plugin can easily deadlock itself with an incorrect lock behavior), we might instead want to have an atomic operation that combines a txdiscard with a txprepare that uses the exact same inputs and outputs, just redirects the address of an output.
So let me propose:
txmodifypayee txid modifications
Where modifications is an array containing objects with fields:
{
'outnum' : 0,
'address': "3LXPWUpTGKmeatx6NpyQ8A8TZr2GCXkK4u"
}
The address would have to take up the same amount of space as the current address at that outnum.
The command succeeds or fails "atomically". If it succeeds, then the old txid is no longer passable to txdiscard or txsend. If it fails, then the old txid can still be passed to txdiscard or txsend.
Thoughts @niftynei @cdecker @rustyrussell ?