Open bedeho opened 7 years ago
I agree with the need to hide the paymentchannel details from the application layer, and the second approach to your proposed solution is arguably better than the first.
Although there is additional complexity introduced by having a UTXO manager, it does eliminate the construction of the transaction at the application layer, and any need to make calls into the wallet from the plugin to sign/fund a transaction.
The start_download will need to provide the serialized transaction in the callback so the application can broadcast it? Or if it's available in the "DownloadStarted" event payload, the application can get the transaction from there I suppose.
The details of payment channels can creep up again when pre-allocating the utxos however: when selecting the total funds required to make a utxo set which will be captured by the financier it needs to account for the fee that is based on the estimated size of the contract Tx.
Another approach is possible, by not having to pre-allocate utxos. Add a new plugin function
plugin.prepare_contract(PeerToStartDownloadInformationMap, function callback(contracTx, feeRate){
})
which submits a new plugin request "PrepareContract" that will create a partial contract transaction (containing commitment outputs, no inputs, no change output).
The application can then fund and sign the contract with a given feeRate, and make a subsequent call to plugin.start_downloading, passing in the signed transaction and the same peerToStartDownloadInformationMap.
This solves the need to know details about how to construct the transaction in javascript, but still has to be aware of the fact that a contract needs to be prepared.
GOAL: minimize buying complexity for user of javascript developer, and perhaps also extension-cpp
extension-cpp
joystream-node-cpp
start_downloading
such that
contractTx
joystream-node-npm
user/utility code
extension-cpp
joystream-node-cpp
plugin.start_downloading
signer(tx, min_fee_rate)
param,
where tx
is an unsigned transaction, and fee_rate
is the minimum fee rate on the signed transaction.tx
, using modified peers map, and the paychan contract builder.min_fee_rate
, by using the peers map.start_downloading
passes that on to user, e.g. due to insufficient funds.joystream-node-npm
extension-cpp
joystream-node-cpp
joystream-node-npm
Background
This proposal is a deep fix to the issue of having the user construct the contract transaction in javascript. We have been discussing moving this into the addon, or the wrapper, to hide some of it from the end user, but at the deepest level, there is a redundancy which this proposal tries to look at the lowest level where it exists.
When trying to start downloading, using the
extension::request::StartDownloading
, the user of the extension has the following pieces of non-trivial informationprotocol_session::PeerToStartDownloadInformationMap<libtorrent::tcp::endpoint> peerToStartDownloadInformationMap
: what peers to use, and corresponding setup informationCoin::Transaction contractTx
: a fully signed contract transactionImportantly, the extension knows everything it needs to know to construct
contractTx
on it own, it only requires some means of financing it.Problem
Requiring user to construct
contractTx
leaks lots of details about the payment channel into user code, which both makes it more complicated, to manage, test and change. It really should be avoidable to have the user to this redundant work, and instead give the extension the minimal amount of information.Solutions
Replace
contractTx
in theextension::request::StartDownloading
request withwhich is called by the extension to construct the final contract transaction.
Two approaches
There are two approaches to implementing a
Financier
instance.have it make a direct call with whatever manages the UTXO set in the application, for example a wallet or UTXO manager. This introduces the potentially difficult problem of synchronizing the libtorrent thread with user thread(s).
preallocate the UTXO set, and capture it in the
Financier
, and use it to sign when called.The second option is better, as it avoids any need for synchronization, however, the ability to do so requires a sufficiently flexible signing infrastructure in the application.
Example: joystream-node-cpp
The first approach would require synchronizing with the nodejs thread, which is possible, but non-trivial.
The second approach would require altering the
start_download
binding in the addon to take some sort of utxo representation. This representation could be converted into anCoin::UnspentOutputSet
instance, and capture this inside theFinancier
. This will require fixing the representation to a predetermined set of UTXO types, e.g. only p2sh, or p2pkh. So a user of the js wrapper would do something like