Commit Graph

81 Commits

Author SHA1 Message Date
Wilmer Paulino
c70858dc46
sweep: prevent default fee preference fallback
We want to make sure clients are aware of their own fee preferences,
rather than relying on defaults.
2019-06-11 15:06:35 -07:00
Wilmer Paulino
d75fac26bc
sweep: expose pending input sweeps within the UtxoSweeper 2019-06-05 12:10:32 -07:00
Wilmer Paulino
50a8f188a3
sweep: add lastFeeRate field to PendingInput
This will serve useful when exposing the pending inputs over RPC, since
we currently don't keep track of the last fee rate used for an input.
2019-06-05 12:10:31 -07:00
Wilmer Paulino
682aebdd53
sweep: broadcast sweep transactions in descending fee rate order
In this commit, we address another issue that arose with the
introduction of the fee rate buckets. We'll use an example to explain
the problem space:

Let's say we have inputs A, B, and C within the same fee rate bucket. If
A's fee rate is bumped to a higher bucket, then it's currently possible
for the lower fee rate bucket to be swept first, which would produce an
invalid RBF transaction since we're removing an input from the original
without providing a higher fee. By the time we get to the higher fee
rate bucket, we broadcast a valid RBF transaction _only_ sweeping input
A, which would evict the transaction sweeping inputs B and C from the
mempool.

To prevent this eviction, we can simply broadcast the higher fee rate
sweep transactions first, to ensure we have valid RBF transactions.
2019-05-24 15:30:39 -07:00
Wilmer Paulino
5172a5e255
multi: support arbitrary client fee preferences to UtxoSweeper
In this commit, we introduce support for arbitrary client fee
preferences when accepting input sweep requests. This is possible with
the addition of fee rate buckets. Fee rate buckets are buckets that
contain inputs with similar fee rates within a specific range, e.g.,
1-10 sat/vbyte, 11-20 sat/vbyte, etc. Having these buckets allows us to
batch and sweep inputs from different clients with similar fee rates
within a single transaction, allowing us to save on chain fees.

With this addition, we can now get rid of the UtxoSweeper's default fee
preference. As of this commit, any clients using the it to sweep inputs
specify the same fee preference to not change their behavior. Each of
these can be fine-tuned later on given their use cases.
2019-05-24 15:30:38 -07:00
Wilmer Paulino
138d9b68f0
lnwallet+sweep: add String method to FeePreference 2019-05-24 15:30:36 -07:00
Johan T. Halseth
10070ecab7
lnwallet: make BlockChainIO.GetUTXO take cancel chan
Use quit channels as cancel chan for call to GetUTXO.
2019-05-09 14:44:47 +02:00
Johan T. Halseth
beb5d14ed9
lnwallet/btcwallet: add compile time check for BlockChainIO interface 2019-05-09 14:44:41 +02:00
Joost Jager
9e012ecc93
multi: move Input interface and related code
This commit is a step to split the lnwallet package. It puts the Input
interface and implementations in a separate package along with all their
dependencies from lnwallet.
2019-01-31 13:25:33 +01:00
Olaoluwa Osuntokun
eda6ed224f
sweep: add unit tests for TestDetermineFeePerKw and CraftSweepAllTx
Along the way we also extend the mockFeeEstimator to be able to return a
fee rate for a specified confirmation target.
2019-01-09 15:55:28 -08:00
Olaoluwa Osuntokun
9c29e61826
sweep: add new CraftSweepAllTx method to fully withdrawal from a wallet
In this commit, we add a new function, CraftSweepAllTx. This function
allows callers to craft a transaction which sweeps ALL outputs from the
wallet to a single target address. It can either be used for UTXO
consolidation (at the cost of privacy by co-mingling inputs), or simply
to sweep all funds out of a wallet for various reasons.

In an attempt to ensure this method is loosely coupled and testable, for
all behavior structs, we create brand new interface to accept. This
ensures that we only rely on the minimal number of methods needed to
perform our duty.
2019-01-09 15:55:23 -08:00
Olaoluwa Osuntokun
4ad175c16d
sweep: update getInputWitnessSizeUpperBound to be aware of nested p2sh
In this commit, we update the `getInputWitnessSizeUpperBound` and all
its callers to be aware of nested p2sh witness inputs. We do so by
adding another bool which is true if the output is a nested p2sh output.
If so, then in order to properly estimate the total weight, the caller
needs to factor in the non-witness data of the additional sigScript data
push.
2019-01-09 15:55:22 -08:00
Olaoluwa Osuntokun
c18e166e03
lnwallet+sweep: extend the WitnessGenerator type to return an InputScript
In this commit, we extend the WitnessGenerator type to now return an
InputScript. This allows it to be more encompassing, as now callers can
expect a sigScript to be populated if the input being swept requires a
sigScript field.

Along the way, we've also renamed input.BuildWitness to
input.CraftInputScript.  We also take a step towards allowing the
sweeper to sweep transactions for n2pwkh outputs. We do so by modifying
the BuiltWitness method to instead return an InputScript. Additionally,
when populating inputs if a sigScript is present, it will now be
populated.
2019-01-09 15:55:19 -08:00
Olaoluwa Osuntokun
73c9c2ee15
sweep+cnct+nursery+rpc: extract DetermineFeePerKw to func, add FeePreference
In this commit, we extract the existing determineFeePerKw method on the
RPC server into a new file in the sweep package. Along the way, we
consolidate code by introducing a new FeePreference struct, which allows
the caller to express their fee preference either in blocks to
confirmation, or a direct fee rate. This move takes a small step to
father decoupling calls in the main RPC server.
2019-01-09 15:55:17 -08:00
Olaoluwa Osuntokun
77262ff699 sweep: rename Estimator to FeeEstimator 2019-01-09 15:55:01 -08:00
Joost Jager
347d1545de
utxonursery: use mocked sweeper in tests
This commit fixes a test flake caused by a race condition. Using the
real sweeper in the nursery test created too complex concurrent
behaviour to reliably assert on and made the tests difficult to
comprehend.
2018-12-19 14:14:53 +01:00
Joost Jager
eec2efdd6b
sweep: add sweeper test 2018-12-18 10:50:19 +01:00
Joost Jager
01e64afd56
sweep: add time-based sweeper
In this commit, the sweep package is extended from just tx generation to
an active sweeper that collects sweep inputs and autonomously proceeds
to publish the sweep tx after the batch window time interval has passed
without new inputs being added.
2018-12-18 10:50:17 +01:00
Joost Jager
1f0656559e
sweep: add sweeper store
This commit adds a store for the sweeper. The sweeper needs minimal
persistent data to be able to recognize its own sweeps.
2018-12-18 10:50:16 +01:00
Joost Jager
a2dcca2b08
sweep: add input partitionings generator
This commit adds a function that takes a set of inputs and splits them
in sensible sets to be used for generating transactions.
2018-12-18 10:50:14 +01:00
Joost Jager
067817f6d2
sweep: move tx generation to separate file 2018-12-18 10:50:13 +01:00
Joost Jager
e43e89514f
sweep+utxonursery+cnct+breacharbiter: add height hint to input
This commit is a preparation for the implementation of remote spend
detection. Remote spends may happen before we broadcast our own sweep
tx. This calls for accurate height hints.
2018-12-18 10:50:11 +01:00
Joost Jager
26cfc505ee
sweep: refactor weight estimation 2018-12-18 10:50:10 +01:00
Olaoluwa Osuntokun
fc21bf091a
multi: modify sweeper.CreateSweepTx to accept conf target, style changes
In this commit, we modify the newly introduced UtxoSweeper.CreateSweepTx
to accept the confirmation target as a param of the method rather than a
struct level variable. We do this as this allows each caller to decide
at sweep time, what the fee rate should be, rather than using a global
value that is meant to work in all scenarios. For example, anytime
we're sweeping an output with a CLTV lock that's has a dependant
transaction we need to sweep/cancel, we may require a higher fee rate
than a regular force close with a CSV output.
2018-10-18 18:08:27 -07:00
Conner Fromknecht
cae4f43c19
sweep/sweeper: ignore unknown witness types
This commit restores the sweep behavior of
filtering inputs with unknown witness types
from the final sweep transaction. Currently,
such inputs will be included without adding
anything to the weight estimate, possibly
creating a transaction with insufficient fees.
2018-10-17 16:21:06 -07:00
Joost Jager
95bf858ac3
sweep: refactor functions and unify tx info logging 2018-10-17 12:44:34 +02:00
Joost Jager
6977d59e35
cnct: reuse sweep tx logic for success resolver 2018-10-17 12:44:34 +02:00
Joost Jager
c1d845aa0d
cnct: reuse sweep tx logic for commit resolver
Removes duplicate sweep tx code from commit resolver
and delegates generation to UtxoSweeper in the sweep
package.
2018-10-17 12:44:34 +02:00
Joost Jager
7d69df77ed
sweep: create new Input interface
This commit introduces a common interface for sweep
inputs. It eliminates the type checking from UtxoSweeper.

Also the formerly present Amount() getter is removed. It was redundant
because this value is present in SignDesc().Output.Value as well.
2018-10-17 12:44:33 +02:00
Joost Jager
4dab405623
sweep: move sweep tx generation into sweep package
Sweep txes are currently generated in multiple locations. Moving
the sweep tx generation into a shared package will allow us to
reuse that logic.
2018-10-17 12:44:33 +02:00
Joost Jager
9fcc7ee390
utxonursery: move spendable output structs to sweep package
This commit moves the output structs to a new package as a
preparation for moving more logic into that package.
2018-10-17 12:44:33 +02:00