While studying the existing fundchannel in preparation for fully implementing #1936 , I noticed that the current fundchannel does this:
connect to peer.
txprepare a "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.
fundchannel_start to peer using the extracted amount, receiving a target funding address
txdiscard the previous "dry-run" transaction.
txprepare, this time with the now-filled-in funding address.
fundchannel_complete with the transaction ID.
txsend the 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 ?
While studying the existing
fundchannelin preparation for fully implementing #1936 , I noticed that the currentfundchanneldoes this:connectto peer.txpreparea "dry-run" fundchannel using a dummy funding address.all.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, ortxprepareexecute between thetxdiscardof the dry-run transaction and the subsequenttxprepareas 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
txdiscardwith atxpreparethat uses the exact same inputs and outputs, just redirects the address of an output.So let me propose:
Where
modificationsis an array containing objects with fields:The
addresswould have to take up the same amount of space as the current address at thatoutnum.The command succeeds or fails "atomically". If it succeeds, then the old txid is no longer passable to
txdiscardortxsend. If it fails, then the old txid can still be passed totxdiscardortxsend.Thoughts @niftynei @cdecker @rustyrussell ?