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