sweep: log sweep tx id and full list of inputs
To facilitate debugging.
This commit is contained in:
parent
8b7bde7200
commit
b3afa0c9ed
@ -138,10 +138,6 @@ func createSweepTx(inputs []input.Input, outputPkScript []byte,
|
|||||||
|
|
||||||
txFee := feePerKw.FeeForWeight(txWeight)
|
txFee := feePerKw.FeeForWeight(txWeight)
|
||||||
|
|
||||||
log.Infof("Creating sweep transaction for %v inputs (%s) "+
|
|
||||||
"using %v sat/kw, tx_fee=%v", len(inputs),
|
|
||||||
inputTypeSummary(inputs), int64(feePerKw), txFee)
|
|
||||||
|
|
||||||
// Sum up the total value contained in the inputs.
|
// Sum up the total value contained in the inputs.
|
||||||
var totalSum btcutil.Amount
|
var totalSum btcutil.Amount
|
||||||
for _, o := range inputs {
|
for _, o := range inputs {
|
||||||
@ -211,6 +207,10 @@ func createSweepTx(inputs []input.Input, outputPkScript []byte,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("Creating sweep transaction %v for %v inputs (%s) "+
|
||||||
|
"using %v sat/kw, tx_fee=%v", sweepTx.TxHash(), len(inputs),
|
||||||
|
inputTypeSummary(inputs), int64(feePerKw), txFee)
|
||||||
|
|
||||||
return sweepTx, nil
|
return sweepTx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,27 +254,19 @@ func getWeightEstimate(inputs []input.Input) ([]input.Input, int64) {
|
|||||||
// inputSummary returns a string containing a human readable summary about the
|
// inputSummary returns a string containing a human readable summary about the
|
||||||
// witness types of a list of inputs.
|
// witness types of a list of inputs.
|
||||||
func inputTypeSummary(inputs []input.Input) string {
|
func inputTypeSummary(inputs []input.Input) string {
|
||||||
// Count each input by the string representation of its witness type.
|
// Sort inputs by witness type.
|
||||||
// We also keep track of the keys so we can later sort by them to get
|
sortedInputs := make([]input.Input, len(inputs))
|
||||||
// a stable output.
|
copy(sortedInputs, inputs)
|
||||||
counts := make(map[string]uint32)
|
sort.Slice(sortedInputs, func(i, j int) bool {
|
||||||
keys := make([]string, 0, len(inputs))
|
return sortedInputs[i].WitnessType().String() <
|
||||||
for _, i := range inputs {
|
sortedInputs[j].WitnessType().String()
|
||||||
key := i.WitnessType().String()
|
})
|
||||||
_, ok := counts[key]
|
|
||||||
if !ok {
|
|
||||||
counts[key] = 0
|
|
||||||
keys = append(keys, key)
|
|
||||||
}
|
|
||||||
counts[key]++
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
|
|
||||||
// Return a nice string representation of the counts by comma joining a
|
|
||||||
// slice.
|
|
||||||
var parts []string
|
var parts []string
|
||||||
for _, witnessType := range keys {
|
for _, i := range sortedInputs {
|
||||||
part := fmt.Sprintf("%d %s", counts[witnessType], witnessType)
|
part := fmt.Sprintf("%v (%v)",
|
||||||
|
*i.OutPoint(), i.WitnessType())
|
||||||
|
|
||||||
parts = append(parts, part)
|
parts = append(parts, part)
|
||||||
}
|
}
|
||||||
return strings.Join(parts, ", ")
|
return strings.Join(parts, ", ")
|
||||||
|
@ -3,6 +3,7 @@ package sweep
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
)
|
)
|
||||||
@ -15,9 +16,10 @@ var (
|
|||||||
input.WitnessKeyHash,
|
input.WitnessKeyHash,
|
||||||
}
|
}
|
||||||
expectedWeight = int64(1462)
|
expectedWeight = int64(1462)
|
||||||
expectedSummary = "1 CommitmentTimeLock, 1 " +
|
expectedSummary = "0000000000000000000000000000000000000000000000000000000000000000:10 (CommitmentTimeLock), " +
|
||||||
"HtlcAcceptedSuccessSecondLevel, 1 HtlcOfferedRemoteTimeout, " +
|
"0000000000000000000000000000000000000000000000000000000000000001:11 (HtlcAcceptedSuccessSecondLevel), " +
|
||||||
"1 WitnessKeyHash"
|
"0000000000000000000000000000000000000000000000000000000000000002:12 (HtlcOfferedRemoteTimeout), " +
|
||||||
|
"0000000000000000000000000000000000000000000000000000000000000003:13 (WitnessKeyHash)"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestWeightEstimate tests that the estimated weight and number of CSVs/CLTVs
|
// TestWeightEstimate tests that the estimated weight and number of CSVs/CLTVs
|
||||||
@ -27,9 +29,12 @@ func TestWeightEstimate(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
var inputs []input.Input
|
var inputs []input.Input
|
||||||
for _, witnessType := range witnessTypes {
|
for i, witnessType := range witnessTypes {
|
||||||
inputs = append(inputs, input.NewBaseInput(
|
inputs = append(inputs, input.NewBaseInput(
|
||||||
&wire.OutPoint{}, witnessType,
|
&wire.OutPoint{
|
||||||
|
Hash: chainhash.Hash{byte(i)},
|
||||||
|
Index: uint32(i) + 10,
|
||||||
|
}, witnessType,
|
||||||
&input.SignDescriptor{}, 0,
|
&input.SignDescriptor{}, 0,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user