Description
An idea, is to ensure as much as possible that channel funding transactions have a "change" output that is controlled by the built-in onchain wallet.
Then, if the funding transaction takes a long time to confirm on mainnet (due to the well-known congestion problems there), it would be possible to accelerate the channel funding transaction by creating a child transaction from the "change" output. This child transaction would have a larger-than-usual feerate (CPFP) to encourage mining of the channel funding transaction, and pay out to yet another address of the built-in onchain wallet. In addition, the child transaction would be marked RBF so that further increases of the fee can be done.
Using CPFP to speed up the channel funding transaction has the advantage that it requires no change to the Lightning BOLT protocol. Using RBF on the channel funding transaction directly requires that the both ends of the channel sign new versions of the commitment transaction.
While not a priority, I suspect this feature would be necessary before we can practically deploy to mainnet.
At the JSON-RPC level, I imagine:
# open the channel but do not wait to confirm
tx=$(lightning-cli fundchannelasync $node $satoshis)
sleep 1h
# Not yet confirmed even after one hour...?
if [$(lightning-cli fundchannelconfirmed $tx) = False]; then
# If we accelerate, how much more will we spend?
moresatoshis=$(lightning-cli fundchannelaccelerateestimate $tx)
# so expensive! can we afford it?
if [$moresatoshis < $satoshithreshhold]; then
# fine, pay more to speed it up.
lightning-cli fundchannelaccelerate $tx
fi
fi
Further calls to fundchannelaccelerate will be possible and will RBF the child transaction instead.
The fundchannelaccelerate command will silently fail without an error if the specified channel is already confirmed at least once.
Implementation-wise, we would need a new table for pending channel funding transactions. Entries in this table will be removed when the peer enters CHANNELD_NORMAL
.
CREATE TABLE funding_tx
( id INTEGER PRIMARY KEY REFERENCES channel(id) ON DELETE CASCADE
, funding_tx_change_outnum INTEGER
, cpfp_feerate INTEGER
);
When initially created only the funding_tx_change_outnum
column has a non-null value. The first fundchannelaccelerate will fill in cpfp_feerate
, with future calls bumping the feerate and recreating the CPFP acceleration transaction. fundchannelaccelerateestimate will compute a fee based on whether cpfp_feerate
exists or not and assuming a simple 1-input 1-output RBF transaction. Care point is when the change output runs out: this will cause acceleration to fail as there is no longer any change to pay with.
Since lightningd will now scan UTXOs that appear onchain we should not use addfunds
especially since the child transaction is RBF.