multi: optimize loggings around changes from blockbeat

This commit is contained in:
yyforyongyu committed 2024-12-20 17:54:08 +08:00
1 parent fecd5ac735
commit 4806b2fda7
9 files changed
+62 -38

No files matched your search

+4 -1
View File
@@ -1588,7 +1588,10 @@ func prepareSweepTx(inputs []input.Input, changePkScript lnwallet.AddrWithKey,
// Check if the lock time has reached
if lt > uint32(currentHeight) {
return 0, noChange, noLocktime, ErrLocktimeImmature
return 0, noChange, noLocktime,
fmt.Errorf("%w: current height is %v, "+
"locktime is %v", ErrLocktimeImmature,
currentHeight, lt)
}
// If another input commits to a different locktime, they
+24 -21
View File
@@ -229,7 +229,7 @@ func (p *SweeperInput) isMature(currentHeight uint32) (bool, uint32) {
locktime, _ := p.RequiredLockTime()
if currentHeight < locktime {
log.Debugf("Input %v has locktime=%v, current height is %v",
p.OutPoint(), locktime, currentHeight)
p, locktime, currentHeight)
return false, locktime
}
@@ -243,8 +243,7 @@ func (p *SweeperInput) isMature(currentHeight uint32) (bool, uint32) {
locktime = p.BlocksToMaturity() + p.HeightHint()
if currentHeight+1 < locktime {
log.Debugf("Input %v has CSV expiry=%v, current height is %v, "+
"skipped sweeping", p.OutPoint(), locktime,
currentHeight)
"skipped sweeping", p, locktime, currentHeight)
return false, locktime
}
@@ -255,6 +254,21 @@ func (p *SweeperInput) isMature(currentHeight uint32) (bool, uint32) {
// InputsMap is a type alias for a set of pending inputs.
type InputsMap = map[wire.OutPoint]*SweeperInput
// inputsMapToString returns a human readable interpretation of the pending
// inputs.
func inputsMapToString(inputs InputsMap) string {
if len(inputs) == 0 {
return ""
}
inps := make([]input.Input, 0, len(inputs))
for _, in := range inputs {
inps = append(inps, in)
}
return "\n" + inputTypeSummary(inps)
}
// pendingSweepsReq is an internal message we'll use to represent an external
// caller's intent to retrieve all of the pending inputs the UtxoSweeper is
// attempting to sweep.
@@ -700,17 +714,10 @@ func (s *UtxoSweeper) collector() {
inputs := s.updateSweeperInputs()
log.Debugf("Received new block: height=%v, attempt "+
"sweeping %d inputs:\n%s",
s.currentHeight, len(inputs),
"sweeping %d inputs:%s", s.currentHeight,
len(inputs),
lnutils.NewLogClosure(func() string {
inps := make(
[]input.Input, 0, len(inputs),
)
for _, in := range inputs {
inps = append(inps, in)
}
return inputTypeSummary(inps)
return inputsMapToString(inputs)
}))
// Attempt to sweep any pending inputs.
@@ -1244,10 +1251,10 @@ func (s *UtxoSweeper) handleNewInput(input *sweepInputMessage) error {
log.Tracef("input %v, state=%v, added to inputs", outpoint, pi.state)
log.Infof("Registered sweep request at block %d: out_point=%v, "+
"witness_type=%v, amount=%v, deadline=%d, params=(%v)",
s.currentHeight, pi.OutPoint(), pi.WitnessType(),
"witness_type=%v, amount=%v, deadline=%d, state=%v, "+
"params=(%v)", s.currentHeight, pi.OutPoint(), pi.WitnessType(),
btcutil.Amount(pi.SignDesc().Output.Value), pi.DeadlineHeight,
pi.params)
pi.state, pi.params)
// Start watching for spend of this input, either by us or the remote
// party.
@@ -1523,12 +1530,8 @@ func (s *UtxoSweeper) updateSweeperInputs() InputsMap {
// If the input has a locktime that's not yet reached, we will
// skip this input and wait for the locktime to be reached.
mature, locktime := input.isMature(uint32(s.currentHeight))
mature, _ := input.isMature(uint32(s.currentHeight))
if !mature {
log.Debugf("Skipping input %v due to locktime=%v not "+
"reached, current height is %v", op, locktime,
s.currentHeight)
continue
}
+2 -1
View File
@@ -315,5 +315,6 @@ func inputTypeSummary(inputs []input.Input) string {
part := fmt.Sprintf("%v (%v)", i.OutPoint(), i.WitnessType())
parts = append(parts, part)
}
return strings.Join(parts, ", ")
return strings.Join(parts, "\n")
}
+6 -4
View File
@@ -16,10 +16,12 @@ var (
input.HtlcOfferedRemoteTimeout,
input.WitnessKeyHash,
}
expectedWeight = int64(1460)
expectedSummary = "0000000000000000000000000000000000000000000000000000000000000000:10 (CommitmentTimeLock), " +
"0000000000000000000000000000000000000000000000000000000000000001:11 (HtlcAcceptedSuccessSecondLevel), " +
"0000000000000000000000000000000000000000000000000000000000000002:12 (HtlcOfferedRemoteTimeout), " +
expectedWeight = int64(1460)
//nolint:ll
expectedSummary = "0000000000000000000000000000000000000000000000000000000000000000:10 (CommitmentTimeLock)\n" +
"0000000000000000000000000000000000000000000000000000000000000001:11 (HtlcAcceptedSuccessSecondLevel)\n" +
"0000000000000000000000000000000000000000000000000000000000000002:12 (HtlcOfferedRemoteTimeout)\n" +
"0000000000000000000000000000000000000000000000000000000000000003:13 (WitnessKeyHash)"
)