Merge pull request #3218 from Roasbeef/fee-estimate-fee-dust

lnwallet/btcwallet: use relay fee not tx fee rate for dust check
This commit is contained in:
Olaoluwa Osuntokun 2019-06-19 01:13:18 -07:00 committed by GitHub
commit 507ebea222
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 8 deletions

2
go.mod

@ -8,7 +8,7 @@ require (
github.com/btcsuite/btcd v0.0.0-20190614013741-962a206e94e9
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
github.com/btcsuite/btcwallet v0.0.0-20190614043544-a335c566148c
github.com/btcsuite/btcwallet v0.0.0-20190619005538-de02d6fdfb23
github.com/btcsuite/fastsha256 v0.0.0-20160815193821-637e65642941
github.com/coreos/bbolt v1.3.2
github.com/davecgh/go-spew v1.1.1

4
go.sum

@ -39,8 +39,8 @@ github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+q
github.com/btcsuite/btcwallet v0.0.0-20180904010540-284e2e0e696e33d5be388f7f3d9a26db703e0c06/go.mod h1:/d7QHZsfUAruXuBhyPITqoYOmJ+nq35qPsJjz/aSpCg=
github.com/btcsuite/btcwallet v0.0.0-20190313032608-acf3b04b0273/go.mod h1:mkOYY8/psBiL5E+Wb0V7M0o+N7NXi2SZJz6+RKkncIc=
github.com/btcsuite/btcwallet v0.0.0-20190319010515-89ab2044f962/go.mod h1:qMi4jGpAO6YRsd81RYDG7o5pBIGqN9faCioJdagLu64=
github.com/btcsuite/btcwallet v0.0.0-20190614043544-a335c566148c h1:9fQATx2+LheGbExN2jYuPJXNkvve5/9n/1EaUhzsZf0=
github.com/btcsuite/btcwallet v0.0.0-20190614043544-a335c566148c/go.mod h1:GlcKHrCBxtujd/6coLUvczN68EkaBezgyN+JnEGVDUY=
github.com/btcsuite/btcwallet v0.0.0-20190619005538-de02d6fdfb23 h1:tja9kILSaG27Z/kiR91dxmMk3T5+qplNLOxWT8iShKg=
github.com/btcsuite/btcwallet v0.0.0-20190619005538-de02d6fdfb23/go.mod h1:GlcKHrCBxtujd/6coLUvczN68EkaBezgyN+JnEGVDUY=
github.com/btcsuite/fastsha256 v0.0.0-20160815193821-637e65642941 h1:kij1x2aL7VE6gtx8KMIt8PGPgI5GV9LgtHFG5KaEMPY=
github.com/btcsuite/fastsha256 v0.0.0-20160815193821-637e65642941/go.mod h1:QcFA8DZHtuIAdYKCq/BzELOaznRsCvwf4zTPmaYwaig=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=

@ -330,7 +330,14 @@ func (b *BtcWallet) CreateSimpleTx(outputs []*wire.TxOut,
return nil, lnwallet.ErrNoOutputs
}
for _, output := range outputs {
err := txrules.CheckOutput(output, feeSatPerKB)
// When checking an output for things like dusty-ness, we'll
// use the default mempool relay fee rather than the target
// effective fee rate to ensure accuracy. Otherwise, we may
// mistakenly mark small-ish, but not quite dust output as
// dust.
err := txrules.CheckOutput(
output, txrules.DefaultRelayFeePerKb,
)
if err != nil {
return nil, err
}

@ -2246,7 +2246,7 @@ func testCreateSimpleTx(r *rpctest.Harness, w *lnwallet.LightningWallet,
},
{
outVals: []int64{1e3},
outVals: []int64{200},
feeRate: 2500,
valid: false, // Dust output.
},
@ -2279,7 +2279,7 @@ func testCreateSimpleTx(r *rpctest.Harness, w *lnwallet.LightningWallet,
},
}
for _, test := range testCases {
for i, test := range testCases {
feeRate := test.feeRate
// Grab some fresh addresses from the miner that we will send
@ -2308,10 +2308,15 @@ func testCreateSimpleTx(r *rpctest.Harness, w *lnwallet.LightningWallet,
createTx, createErr := w.CreateSimpleTx(
outputs, feeRate, true,
)
if test.valid == (createErr != nil) {
switch {
case test.valid && createErr != nil:
fmt.Println(spew.Sdump(createTx.Tx))
t.Fatalf("got unexpected error when creating tx: %v",
createErr)
case !test.valid && createErr == nil:
t.Fatalf("test #%v should have failed on tx "+
"creation", i)
}
// Also send to these outputs. This should result in a tx
@ -2319,9 +2324,13 @@ func testCreateSimpleTx(r *rpctest.Harness, w *lnwallet.LightningWallet,
// only difference is that the dry run tx is not signed, and
// that the change output position might be different.
tx, sendErr := w.SendOutputs(outputs, feeRate)
if test.valid == (sendErr != nil) {
switch {
case test.valid && sendErr != nil:
t.Fatalf("got unexpected error when sending tx: %v",
sendErr)
case !test.valid && sendErr == nil:
t.Fatalf("test #%v should fail for tx sending", i)
}
// We expected either both to not fail, or both to fail with