improve code readability
This commit is contained in:
parent
5afc74d4f6
commit
f976637b14
|
@ -49,9 +49,18 @@ Defaults.FIAT_RATE_MAX_LOOK_BACK_TIME = 120; // In minutes
|
|||
|
||||
Defaults.HISTORY_LIMIT = 100;
|
||||
|
||||
// The maximum amount of an UTXO to be considered too big to be used in the tx before exploring smaller
|
||||
// alternatives (proportinal to tx amount).
|
||||
Defaults.UTXO_SELECTION_MAX_SINGLE_UTXO_FACTOR = 2;
|
||||
Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR = 5;
|
||||
Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR = 0.002;
|
||||
|
||||
// The minimum amount an UTXO need to contribute proportional to tx amount.
|
||||
Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR = 0.1;
|
||||
|
||||
// The maximum threshold to consider fees non-significant in relation to tx amount.
|
||||
Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR = 0.05;
|
||||
|
||||
// The maximum amount to pay for using small inputs instead of one big input
|
||||
// when fees are significant (proportional to how much we would pay for using that big input only).
|
||||
Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR = 5;
|
||||
|
||||
module.exports = Defaults;
|
||||
|
|
|
@ -1357,12 +1357,10 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
|
|||
log.debug('Tx size: ' + Utils.formatSize(txpSize) + ', Tx fee: ' + Utils.formatAmountInBtc(fee));
|
||||
|
||||
var feeVsAmountRatio = fee / txpAmount;
|
||||
var feeVsSingleInputFeeRatio = fee / (baseTxpFee + feePerInput);
|
||||
var amountVsUtxoRatio = netInputAmount / txpAmount;
|
||||
|
||||
log.debug('Tx amount/Fee: ' + Utils.formatRatio(feeVsAmountRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) + ')');
|
||||
log.debug('Single-input fee/Multi-input fee: ' + Utils.formatRatio(feeVsSingleInputFeeRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) + ')' + ' loses wrt single-input tx: ' + Utils.formatAmountInBtc((selected.length - 1) * feePerInput));
|
||||
log.debug('Tx amount/input amount:' + Utils.formatRatio(amountVsUtxoRatio) + ' (min: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) + ')');
|
||||
log.debug('Fee/Tx amount: ' + Utils.formatRatio(feeVsAmountRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) + ')');
|
||||
log.debug('Tx amount/Input amount:' + Utils.formatRatio(amountVsUtxoRatio) + ' (min: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) + ')');
|
||||
|
||||
if (txpSize / 1000. > Defaults.MAX_TX_SIZE_IN_KB) {
|
||||
log.debug('Breaking because tx size (' + Utils.formatSize(txpSize) + ') is too big (max: ' + Utils.formatSize(Defaults.MAX_TX_SIZE_IN_KB * 1000.) + ')');
|
||||
|
@ -1376,10 +1374,13 @@ WalletService.prototype._selectTxInputs = function(txp, utxosToExclude, cb) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if ((feeVsAmountRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR &&
|
||||
feeVsSingleInputFeeRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR)) {
|
||||
log.debug('Breaking because fee exceeded fee/amount ratio and fee is too expensive compared to single input tx');
|
||||
return false;
|
||||
if (feeVsAmountRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) {
|
||||
var feeVsSingleInputFeeRatio = fee / (baseTxpFee + feePerInput);
|
||||
log.debug('Fee/Single-input fee: ' + Utils.formatRatio(feeVsSingleInputFeeRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) + ')' + ' loses wrt single-input tx: ' + Utils.formatAmountInBtc((selected.length - 1) * feePerInput));
|
||||
if (feeVsSingleInputFeeRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) {
|
||||
log.debug('Breaking because fee is too significant compared to tx amount and it is too expensive compared to using single input');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue