mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-31 08:02:25 +02:00
channeldb: add method to wipe all forwarding packages
This commit adds a method, Wipe, to remove all forwarding packages on disk for a given channel.
This commit is contained in:
@@ -433,6 +433,9 @@ type FwdPackager interface {
|
||||
// RemovePkg deletes a forwarding package owned by this channel at
|
||||
// the provided remote `height`.
|
||||
RemovePkg(tx kvdb.RwTx, height uint64) error
|
||||
|
||||
// Wipe deletes all the forwarding packages owned by this channel.
|
||||
Wipe(tx kvdb.RwTx) error
|
||||
}
|
||||
|
||||
// ChannelPackager is used by a channel to manage the lifecycle of its forwarding
|
||||
@@ -944,6 +947,24 @@ func (p *ChannelPackager) RemovePkg(tx kvdb.RwTx, height uint64) error {
|
||||
return sourceBkt.DeleteNestedBucket(heightKey[:])
|
||||
}
|
||||
|
||||
// Wipe deletes all the channel's forwarding packages, if any.
|
||||
func (p *ChannelPackager) Wipe(tx kvdb.RwTx) error {
|
||||
// If the root bucket doesn't exist, there's no need to delete.
|
||||
fwdPkgBkt := tx.ReadWriteBucket(fwdPackagesKey)
|
||||
if fwdPkgBkt == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
sourceBytes := makeLogKey(p.source.ToUint64())
|
||||
|
||||
// If the nested bucket doesn't exist, there's no need to delete.
|
||||
if fwdPkgBkt.NestedReadWriteBucket(sourceBytes[:]) == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fwdPkgBkt.DeleteNestedBucket(sourceBytes[:])
|
||||
}
|
||||
|
||||
// uint16Key writes the provided 16-bit unsigned integer to a 2-byte slice.
|
||||
func uint16Key(i uint16) []byte {
|
||||
key := make([]byte, 2)
|
||||
|
Reference in New Issue
Block a user