htlcswitch+channeldb: single tx for removing fwdpkgs
This commit changes RemoveFwdPkg to RemoveFwdPkgs so that a single tx is used instead of N where N is the number of fwd pkgs to remove.
This commit is contained in:
parent
e4764a67cc
commit
62e19185f1
@ -2409,16 +2409,24 @@ func (c *OpenChannel) SetFwdFilter(height uint64, fwdFilter *PkgFilter) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveFwdPkg atomically removes a forwarding package specified by the remote
|
// RemoveFwdPkgs atomically removes forwarding packages specified by the remote
|
||||||
// commitment height.
|
// commitment heights. If one of the intermediate RemovePkg calls fails, then the
|
||||||
|
// later packages won't be removed.
|
||||||
//
|
//
|
||||||
// NOTE: This method should only be called on packages marked FwdStateCompleted.
|
// NOTE: This method should only be called on packages marked FwdStateCompleted.
|
||||||
func (c *OpenChannel) RemoveFwdPkg(height uint64) error {
|
func (c *OpenChannel) RemoveFwdPkgs(heights ...uint64) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
return kvdb.Update(c.Db, func(tx kvdb.RwTx) error {
|
return kvdb.Update(c.Db, func(tx kvdb.RwTx) error {
|
||||||
return c.Packager.RemovePkg(tx, height)
|
for _, height := range heights {
|
||||||
|
err := c.Packager.RemovePkg(tx, height)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -776,7 +776,7 @@ func (l *channelLink) resolveFwdPkg(fwdPkg *channeldb.FwdPkg) error {
|
|||||||
l.log.Debugf("removing completed fwd pkg for height=%d",
|
l.log.Debugf("removing completed fwd pkg for height=%d",
|
||||||
fwdPkg.Height)
|
fwdPkg.Height)
|
||||||
|
|
||||||
err := l.channel.RemoveFwdPkg(fwdPkg.Height)
|
err := l.channel.RemoveFwdPkgs(fwdPkg.Height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.log.Errorf("unable to remove fwd pkg for height=%d: "+
|
l.log.Errorf("unable to remove fwd pkg for height=%d: "+
|
||||||
"%v", fwdPkg.Height, err)
|
"%v", fwdPkg.Height, err)
|
||||||
@ -859,7 +859,7 @@ func (l *channelLink) fwdPkgGarbager() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.channel.RemoveFwdPkg(fwdPkg.Height)
|
err = l.channel.RemoveFwdPkgs(fwdPkg.Height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.log.Warnf("unable to remove fwd pkg "+
|
l.log.Warnf("unable to remove fwd pkg "+
|
||||||
"for height=%d: %v",
|
"for height=%d: %v",
|
||||||
|
@ -4850,9 +4850,9 @@ func (lc *LightningChannel) SetFwdFilter(height uint64,
|
|||||||
return lc.channelState.SetFwdFilter(height, fwdFilter)
|
return lc.channelState.SetFwdFilter(height, fwdFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveFwdPkg permanently deletes the forwarding package at the given height.
|
// RemoveFwdPkgs permanently deletes the forwarding package at the given heights.
|
||||||
func (lc *LightningChannel) RemoveFwdPkg(height uint64) error {
|
func (lc *LightningChannel) RemoveFwdPkgs(heights ...uint64) error {
|
||||||
return lc.channelState.RemoveFwdPkg(height)
|
return lc.channelState.RemoveFwdPkgs(heights...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NextRevocationKey returns the commitment point for the _next_ commitment
|
// NextRevocationKey returns the commitment point for the _next_ commitment
|
||||||
|
Loading…
Reference in New Issue
Block a user