funding: defer initial forwarding policy deletion

This commit moves the deletion of the initial forwarding policy to the
end of `stateStep` to make sure the router has persisted it to disk
before the deletion.
This commit is contained in:
yyforyongyu 2023-08-22 07:04:37 +08:00
parent 38b106ccf3
commit d9e0464929
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868

View file

@ -1261,6 +1261,16 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
err)
}
// After the fee parameters have been stored in the
// announcement we can delete them from the database. For
// private channels we do not announce the channel policy to
// the network but still need to delete them from the database.
err = f.deleteInitialForwardingPolicy(chanID)
if err != nil {
log.Infof("Could not delete initial policy for chanId "+
"%x", chanID)
}
log.Debugf("Channel(%v) with ShortChanID %v: successfully "+
"announced", chanID, shortChanID)
@ -3286,15 +3296,6 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
return fmt.Errorf("unable to send node announcement "+
"to peer %x: %v", pubKey, err)
}
// For private channels we do not announce the channel policy
// to the network but still need to delete them from the
// database.
err = f.deleteInitialForwardingPolicy(chanID)
if err != nil {
log.Infof("Could not delete channel fees "+
"for chanId %x.", chanID)
}
} else {
// Otherwise, we'll wait until the funding transaction has
// reached 6 confirmations before announcing it.
@ -3978,14 +3979,6 @@ func (f *Manager) announceChannel(localIDKey, remoteIDKey *btcec.PublicKey,
return err
}
// After the fee parameters have been stored in the announcement
// we can delete them from the database.
err = f.deleteInitialForwardingPolicy(chanID)
if err != nil {
log.Infof("Could not delete channel fees for chanId %x.",
chanID)
}
// We only send the channel proof announcement and the node announcement
// because addToRouterGraph previously sent the ChannelAnnouncement and
// the ChannelUpdate announcement messages. The channel proof and node