wtxmgr: filter out expired leases
Expired leases are kept in the database until the next cleaning round. This commit makes sure that expired leases look like they do not exist to outside callers.
This commit is contained in:
parent
6ab9b61557
commit
5b1e64abde
2 changed files with 20 additions and 0 deletions
|
@ -1240,6 +1240,12 @@ func (s *Store) ListLockedOutputs(ns walletdb.ReadBucket) ([]*LockedOutput,
|
||||||
var outputs []*LockedOutput
|
var outputs []*LockedOutput
|
||||||
err := forEachLockedOutput(
|
err := forEachLockedOutput(
|
||||||
ns, func(op wire.OutPoint, id LockID, expiration time.Time) {
|
ns, func(op wire.OutPoint, id LockID, expiration time.Time) {
|
||||||
|
// Skip expired leases. They will be cleaned up with the
|
||||||
|
// next call to DeleteExpiredLockedOutputs.
|
||||||
|
if !s.clock.Now().Before(expiration) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
outputs = append(outputs, &LockedOutput{
|
outputs = append(outputs, &LockedOutput{
|
||||||
Outpoint: op,
|
Outpoint: op,
|
||||||
LockID: id,
|
LockID: id,
|
||||||
|
|
|
@ -2780,6 +2780,16 @@ func TestOutputLocks(t *testing.T) {
|
||||||
// Let the output lock expired.
|
// Let the output lock expired.
|
||||||
s.clock.(*clock.TestClock).SetTime(expiry)
|
s.clock.(*clock.TestClock).SetTime(expiry)
|
||||||
|
|
||||||
|
// Lock should not longer be listed.
|
||||||
|
assertOutputLocksExist(t, s, ns)
|
||||||
|
|
||||||
|
// But the lock should still exist and active
|
||||||
|
// when time is turned back.
|
||||||
|
assertLocked(
|
||||||
|
t, ns, confirmedOutPoint, time.Time{},
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
// Delete all expired locked outputs. We should
|
// Delete all expired locked outputs. We should
|
||||||
// no longer see any locked outputs.
|
// no longer see any locked outputs.
|
||||||
err = s.DeleteExpiredLockedOutputs(ns)
|
err = s.DeleteExpiredLockedOutputs(ns)
|
||||||
|
@ -2788,6 +2798,10 @@ func TestOutputLocks(t *testing.T) {
|
||||||
"locked outputs: %v", err)
|
"locked outputs: %v", err)
|
||||||
}
|
}
|
||||||
assertOutputLocksExist(t, s, ns)
|
assertOutputLocksExist(t, s, ns)
|
||||||
|
assertLocked(
|
||||||
|
t, ns, confirmedOutPoint, time.Time{},
|
||||||
|
false,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue