sweep: pass dustLimit to CreateSweepTx
This commit is contained in:
parent
3d209059c1
commit
aa8fa9d0cf
|
@ -1254,7 +1254,8 @@ func (r *rpcServer) SendCoins(ctx context.Context,
|
||||||
// single transaction. This will be generated in a concurrent
|
// single transaction. This will be generated in a concurrent
|
||||||
// safe manner, so no need to worry about locking.
|
// safe manner, so no need to worry about locking.
|
||||||
sweepTxPkg, err := sweep.CraftSweepAllTx(
|
sweepTxPkg, err := sweep.CraftSweepAllTx(
|
||||||
feePerKw, uint32(bestHeight), targetAddr, wallet,
|
feePerKw, lnwallet.DefaultDustLimit(),
|
||||||
|
uint32(bestHeight), targetAddr, wallet,
|
||||||
wallet.WalletController, wallet.WalletController,
|
wallet.WalletController, wallet.WalletController,
|
||||||
r.server.cc.FeeEstimator, r.server.cc.Signer,
|
r.server.cc.FeeEstimator, r.server.cc.Signer,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1165,7 +1165,7 @@ func (s *UtxoSweeper) sweep(inputs inputSet, feeRate chainfee.SatPerKWeight,
|
||||||
// Create sweep tx.
|
// Create sweep tx.
|
||||||
tx, err := createSweepTx(
|
tx, err := createSweepTx(
|
||||||
inputs, s.currentOutputScript, uint32(currentHeight), feeRate,
|
inputs, s.currentOutputScript, uint32(currentHeight), feeRate,
|
||||||
s.cfg.Signer,
|
dustLimit(s.relayFeeRate), s.cfg.Signer,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("create sweep tx: %v", err)
|
return fmt.Errorf("create sweep tx: %v", err)
|
||||||
|
@ -1455,7 +1455,8 @@ func (s *UtxoSweeper) CreateSweepTx(inputs []input.Input, feePref FeePreference,
|
||||||
}
|
}
|
||||||
|
|
||||||
return createSweepTx(
|
return createSweepTx(
|
||||||
inputs, pkScript, currentBlockHeight, feePerKw, s.cfg.Signer,
|
inputs, pkScript, currentBlockHeight, feePerKw,
|
||||||
|
dustLimit(s.relayFeeRate), s.cfg.Signer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,14 +83,18 @@ type txInputSet struct {
|
||||||
wallet Wallet
|
wallet Wallet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func dustLimit(relayFee chainfee.SatPerKWeight) btcutil.Amount {
|
||||||
|
return txrules.GetDustThreshold(
|
||||||
|
input.P2WPKHSize,
|
||||||
|
btcutil.Amount(relayFee.FeePerKVByte()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// newTxInputSet constructs a new, empty input set.
|
// newTxInputSet constructs a new, empty input set.
|
||||||
func newTxInputSet(wallet Wallet, feePerKW,
|
func newTxInputSet(wallet Wallet, feePerKW,
|
||||||
relayFee chainfee.SatPerKWeight, maxInputs int) *txInputSet {
|
relayFee chainfee.SatPerKWeight, maxInputs int) *txInputSet {
|
||||||
|
|
||||||
dustLimit := txrules.GetDustThreshold(
|
dustLimit := dustLimit(relayFee)
|
||||||
input.P2WPKHSize,
|
|
||||||
btcutil.Amount(relayFee.FeePerKVByte()),
|
|
||||||
)
|
|
||||||
|
|
||||||
state := txInputSetState{
|
state := txInputSetState{
|
||||||
weightEstimate: newWeightEstimator(feePerKW),
|
weightEstimate: newWeightEstimator(feePerKW),
|
||||||
|
|
|
@ -132,7 +132,7 @@ func generateInputPartitionings(sweepableInputs []txInput,
|
||||||
// createSweepTx builds a signed tx spending the inputs to a the output script.
|
// createSweepTx builds a signed tx spending the inputs to a the output script.
|
||||||
func createSweepTx(inputs []input.Input, outputPkScript []byte,
|
func createSweepTx(inputs []input.Input, outputPkScript []byte,
|
||||||
currentBlockHeight uint32, feePerKw chainfee.SatPerKWeight,
|
currentBlockHeight uint32, feePerKw chainfee.SatPerKWeight,
|
||||||
signer input.Signer) (*wire.MsgTx, error) {
|
dustLimit btcutil.Amount, signer input.Signer) (*wire.MsgTx, error) {
|
||||||
|
|
||||||
inputs, estimator := getWeightEstimate(inputs, feePerKw)
|
inputs, estimator := getWeightEstimate(inputs, feePerKw)
|
||||||
|
|
||||||
|
@ -169,14 +169,16 @@ func createSweepTx(inputs []input.Input, outputPkScript []byte,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sweep as much possible, after subtracting txn fees.
|
// Sweep as much possible, after subtracting txn fees.
|
||||||
sweepAmt := int64(totalSum - txFee)
|
sweepAmt := totalSum - txFee
|
||||||
|
|
||||||
// The txn will sweep the amount after fees to the pkscript generated
|
// The txn will sweep the amount after fees to the pkscript generated
|
||||||
// above.
|
// above.
|
||||||
sweepTx.AddTxOut(&wire.TxOut{
|
if sweepAmt >= dustLimit {
|
||||||
PkScript: outputPkScript,
|
sweepTx.AddTxOut(&wire.TxOut{
|
||||||
Value: sweepAmt,
|
PkScript: outputPkScript,
|
||||||
})
|
Value: int64(sweepAmt),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// We'll default to using the current block height as locktime, if none
|
// We'll default to using the current block height as locktime, if none
|
||||||
// of the inputs commits to a different locktime.
|
// of the inputs commits to a different locktime.
|
||||||
|
|
|
@ -153,10 +153,10 @@ type WalletSweepPackage struct {
|
||||||
// by the delivery address. The sweep transaction will be crafted with the
|
// by the delivery address. The sweep transaction will be crafted with the
|
||||||
// target fee rate, and will use the utxoSource and outpointLocker as sources
|
// target fee rate, and will use the utxoSource and outpointLocker as sources
|
||||||
// for wallet funds.
|
// for wallet funds.
|
||||||
func CraftSweepAllTx(feeRate chainfee.SatPerKWeight, blockHeight uint32,
|
func CraftSweepAllTx(feeRate chainfee.SatPerKWeight, dustLimit btcutil.Amount,
|
||||||
deliveryAddr btcutil.Address, coinSelectLocker CoinSelectionLocker,
|
blockHeight uint32, deliveryAddr btcutil.Address,
|
||||||
utxoSource UtxoSource, outpointLocker OutpointLocker,
|
coinSelectLocker CoinSelectionLocker, utxoSource UtxoSource,
|
||||||
feeEstimator chainfee.Estimator,
|
outpointLocker OutpointLocker, feeEstimator chainfee.Estimator,
|
||||||
signer input.Signer) (*WalletSweepPackage, error) {
|
signer input.Signer) (*WalletSweepPackage, error) {
|
||||||
|
|
||||||
// TODO(roasbeef): turn off ATPL as well when available?
|
// TODO(roasbeef): turn off ATPL as well when available?
|
||||||
|
@ -273,7 +273,8 @@ func CraftSweepAllTx(feeRate chainfee.SatPerKWeight, blockHeight uint32,
|
||||||
// Finally, we'll ask the sweeper to craft a sweep transaction which
|
// Finally, we'll ask the sweeper to craft a sweep transaction which
|
||||||
// respects our fee preference and targets all the UTXOs of the wallet.
|
// respects our fee preference and targets all the UTXOs of the wallet.
|
||||||
sweepTx, err := createSweepTx(
|
sweepTx, err := createSweepTx(
|
||||||
inputsToSweep, deliveryPkScript, blockHeight, feeRate, signer,
|
inputsToSweep, deliveryPkScript, blockHeight, feeRate,
|
||||||
|
dustLimit, signer,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
unlockOutputs()
|
unlockOutputs()
|
||||||
|
|
|
@ -288,7 +288,7 @@ func TestCraftSweepAllTxCoinSelectFail(t *testing.T) {
|
||||||
utxoLocker := newMockOutpointLocker()
|
utxoLocker := newMockOutpointLocker()
|
||||||
|
|
||||||
_, err := CraftSweepAllTx(
|
_, err := CraftSweepAllTx(
|
||||||
0, 100, nil, coinSelectLocker, utxoSource, utxoLocker, nil, nil,
|
0, 100, 10, nil, coinSelectLocker, utxoSource, utxoLocker, nil, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Since we instructed the coin select locker to fail above, we should
|
// Since we instructed the coin select locker to fail above, we should
|
||||||
|
@ -313,7 +313,7 @@ func TestCraftSweepAllTxUnknownWitnessType(t *testing.T) {
|
||||||
utxoLocker := newMockOutpointLocker()
|
utxoLocker := newMockOutpointLocker()
|
||||||
|
|
||||||
_, err := CraftSweepAllTx(
|
_, err := CraftSweepAllTx(
|
||||||
0, 100, nil, coinSelectLocker, utxoSource, utxoLocker, nil, nil,
|
0, 100, 10, nil, coinSelectLocker, utxoSource, utxoLocker, nil, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Since passed in a p2wsh output, which is unknown, we should fail to
|
// Since passed in a p2wsh output, which is unknown, we should fail to
|
||||||
|
@ -347,7 +347,7 @@ func TestCraftSweepAllTx(t *testing.T) {
|
||||||
utxoLocker := newMockOutpointLocker()
|
utxoLocker := newMockOutpointLocker()
|
||||||
|
|
||||||
sweepPkg, err := CraftSweepAllTx(
|
sweepPkg, err := CraftSweepAllTx(
|
||||||
0, 100, deliveryAddr, coinSelectLocker, utxoSource, utxoLocker,
|
0, 100, 10, deliveryAddr, coinSelectLocker, utxoSource, utxoLocker,
|
||||||
feeEstimator, signer,
|
feeEstimator, signer,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user