mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-13 18:10:25 +02:00
watchtower: add DeleteCommittedUpdate DB method
Add a new DeleteCommittedUpdate method to the wtdb In preparation for an upcoming commit that will replay committed updates from one session to another.
This commit is contained in:
@@ -2073,6 +2073,42 @@ func (c *ClientDB) GetDBQueue(namespace []byte) Queue[*BackupID] {
|
||||
)
|
||||
}
|
||||
|
||||
// DeleteCommittedUpdate deletes the committed update with the given sequence
|
||||
// number from the given session.
|
||||
func (c *ClientDB) DeleteCommittedUpdate(id *SessionID, seqNum uint16) error {
|
||||
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||
sessions := tx.ReadWriteBucket(cSessionBkt)
|
||||
if sessions == nil {
|
||||
return ErrUninitializedDB
|
||||
}
|
||||
|
||||
sessionBkt := sessions.NestedReadWriteBucket(id[:])
|
||||
if sessionBkt == nil {
|
||||
return fmt.Errorf("session bucket %s not found",
|
||||
id.String())
|
||||
}
|
||||
|
||||
// If the commits sub-bucket doesn't exist, there can't possibly
|
||||
// be a corresponding update to remove.
|
||||
sessionCommits := sessionBkt.NestedReadWriteBucket(
|
||||
cSessionCommits,
|
||||
)
|
||||
if sessionCommits == nil {
|
||||
return ErrCommittedUpdateNotFound
|
||||
}
|
||||
|
||||
var seqNumBuf [2]byte
|
||||
byteOrder.PutUint16(seqNumBuf[:], seqNum)
|
||||
|
||||
if sessionCommits.Get(seqNumBuf[:]) == nil {
|
||||
return ErrCommittedUpdateNotFound
|
||||
}
|
||||
|
||||
// Remove the corresponding committed update.
|
||||
return sessionCommits.Delete(seqNumBuf[:])
|
||||
}, func() {})
|
||||
}
|
||||
|
||||
// putChannelToSessionMapping adds the given session ID to a channel's
|
||||
// cChanSessions bucket.
|
||||
func putChannelToSessionMapping(chanDetails kvdb.RwBucket,
|
||||
|
Reference in New Issue
Block a user