lnd icon indicating copy to clipboard operation
lnd copied to clipboard

`SendOuputs` fee estimation is incorrect

Open benthecarman opened this issue 3 years ago • 5 comments
trafficstars

Background

I am calling SendOuputs with satPerKw = 1000 and it creates a tx with a weight of 568 but fees of 932.

This seems like it only happens with taproot inputs

Your environment

  • version of lnd 0.15.1

Steps to reproduce

scala code of my test case:

    val sendAmt = Satoshis(10000)
    val feeRate = SatoshisPerKW.fromLong(1000)

    for {
      oldBalA <- lndA.walletBalance().map(_.balance)
      oldBalB <- lndB.walletBalance().map(_.balance)

      addr <- lndB.getNewAddress
      output = TransactionOutput(sendAmt, addr.scriptPubKey)

      tx <- lndA.sendOutputs(Vector(output), feeRate, spendUnconfirmed = false)
      _ <- lndA.publishTransaction(tx)
      _ <- bitcoind.getNewAddress.flatMap(bitcoind.generateToAddress(6, _))

      detailsOpt <- lndA.getTransaction(tx.txIdBE)
      _ = assert(detailsOpt.isDefined)
      details = detailsOpt.get

      newBalA <- lndA.walletBalance().map(_.balance)
      newBalB <- lndB.walletBalance().map(_.balance)
    } yield ...

Expected behaviour

correctly estimate fee

Actual behaviour

fee is off by a large margin

benthecarman avatar Aug 30 '22 23:08 benthecarman

Looks like this is the culprit: https://github.com/btcsuite/btcwallet/blob/5aafe47898507963ae099739e33ff5be9e5620c3/wallet/txauthor/author.go#L111-L125

We then end up using a default size for p2pkh, which is smaller than p2tr.

Roasbeef avatar Aug 31 '22 00:08 Roasbeef

looks like here as well: https://github.com/btcsuite/btcwallet/blob/6ab9b615576f4a86c31bcaef9eddee060b36da00/wallet/txsizes/size.go#L207

benthecarman avatar Aug 31 '22 00:08 benthecarman

I think fee estimation within the main daemon (so the sweeper, and funding inputs, etc) should be correct however.

Roasbeef avatar Aug 31 '22 00:08 Roasbeef

I think fee estimation within the main daemon (so the sweeper, and funding inputs, etc) should be correct however.

Yeah, I did a code sweep and searched for all occurrences of fee estimation. But it looks like I missed some code in btcwallet.

guggero avatar Aug 31 '22 07:08 guggero

Any blockers on this? I've had a fix for the underlying issue open for ~2 weeks now

https://github.com/btcsuite/btcwallet/pull/809

benthecarman avatar Sep 13 '22 19:09 benthecarman