Skip to content

Commit

Permalink
Merge pull request #4754 from oscarguindzberg/fee-estimation-fix
Browse files Browse the repository at this point in the history
Complete Segwit fee estimation
  • Loading branch information
ripcurlx committed Nov 6, 2020
2 parents ae47674 + 52f1d37 commit 325ba7f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public Coin getTxFeeBySize(Coin txFeePerByteFromFeeService, int sizeInBytes) {
// inputs and we would apply that fee for the other 2 txs as well. We still might
// overpay a bit for the payout tx.
public int getAverageTakerFeeTxSize(int txSize) {
return (txSize + 320) / 2;
return (txSize + 233) / 2;
}

/**
Expand Down
17 changes: 8 additions & 9 deletions core/src/main/java/bisq/core/offer/takeoffer/TakeOfferModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ public class TakeOfferModel implements Model {
private Coin securityDeposit;
private boolean useSavingsWallet;

// 260 kb is typical trade fee tx size with 1 input, but trade tx (deposit + payout)
// are larger so we adjust to 320.
private final int feeTxSize = 320;
// Use an average of a typical trade fee tx with 1 input, deposit tx and payout tx.
private final int feeTxSize = 192; // (175+233+169)/3
private Coin txFeePerByteFromFeeService;
@Getter
private Coin txFeeFromFeeService;
Expand Down Expand Up @@ -150,15 +149,15 @@ private void calculateTxFees() {
// payout tx with different fees might be an option but RBF is not supported yet
// in BitcoinJ and batched txs would add more complexity to the trade protocol.

// A typical trade fee tx has about 260 bytes (if one input). The trade txs has
// about 336-414 bytes. We use 320 as a average value.
// A typical trade fee tx has about 175 bytes (if one input). The trade txs has
// about 169-263 bytes. We use 192 as a average value.

// Fee calculations:
// Trade fee tx: 260 bytes (1 input)
// Deposit tx: 336 bytes (1 MS output+ OP_RETURN) - 414 bytes
// Trade fee tx: 175 bytes (1 input)
// Deposit tx: 233 bytes (1 MS output+ OP_RETURN) - 263 bytes
// (1 MS output + OP_RETURN + change in case of smaller trade amount)
// Payout tx: 371 bytes
// Disputed payout tx: 408 bytes
// Payout tx: 169 bytes
// Disputed payout tx: 139 bytes

txFeePerByteFromFeeService = getTxFeePerByte();
txFeeFromFeeService = offerUtil.getTxFeeBySize(txFeePerByteFromFeeService, feeTxSize);
Expand Down

0 comments on commit 325ba7f

Please sign in to comment.