sweep: wrap weight estimator
Preparation for a cpfp-aware weight estimator. For cpfp, a regular weight estimator isn't sufficient, because it needs to take into account the weight of the parent transaction(s) as well.
This commit is contained in:
3 files changed
+61
-24
No files matched your search
@@ -0,0 +1,40 @@
|
||||
package sweep
|
||||
|
||||
import (
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
)
|
||||
|
||||
// weightEstimator wraps a standard weight estimator instance.
|
||||
type weightEstimator struct {
|
||||
estimator input.TxWeightEstimator
|
||||
}
|
||||
|
||||
// newWeightEstimator instantiates a new sweeper weight estimator.
|
||||
func newWeightEstimator() *weightEstimator {
|
||||
return &weightEstimator{}
|
||||
}
|
||||
|
||||
// clone returns a copy of this weight estimator.
|
||||
func (w *weightEstimator) clone() *weightEstimator {
|
||||
return &weightEstimator{
|
||||
estimator: w.estimator,
|
||||
}
|
||||
}
|
||||
|
||||
// add adds the weight of the given input to the weight estimate.
|
||||
func (w *weightEstimator) add(inp input.Input) error {
|
||||
wt := inp.WitnessType()
|
||||
|
||||
return wt.AddWeightEstimation(&w.estimator)
|
||||
}
|
||||
|
||||
// addP2WKHOutput updates the weight estimate to account for an additional
|
||||
// native P2WKH output.
|
||||
func (w *weightEstimator) addP2WKHOutput() {
|
||||
w.estimator.AddP2WKHOutput()
|
||||
}
|
||||
|
||||
// weight gets the estimated weight of the transaction.
|
||||
func (w *weightEstimator) weight() int {
|
||||
return w.estimator.Weight()
|
||||
}
|
||||
Reference in new issue
Block a user