From b2a7e42f449eb6b6651e56cd1eccc196b0b6b14e Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Sun, 16 Sep 2018 10:40:09 +0200 Subject: [PATCH] fundingmanager: commit to new states in stateStep This commit moves the saving of the new channelOpeningState to the stateStep method. --- fundingmanager.go | 70 ++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 0394ba43..29640c31 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -907,8 +907,22 @@ func (f *fundingManager) stateStep(channel *channeldb.OpenChannel, err) } + // As the fundingLocked message is now sent to the peer, the + // channel is moved to the next state of the state machine. It + // will be moved to the last state (actually deleted from the + // database) after the channel is finally announced. + err = f.saveChannelOpeningState( + &channel.FundingOutpoint, fundingLockedSent, + shortChanID, + ) + if err != nil { + return fmt.Errorf("error setting channel state to"+ + " fundingLockedSent: %v", err) + } + fndgLog.Debugf("Channel(%v) with ShortChanID %v: successfully "+ "sent FundingLocked", chanID, shortChanID) + return nil // fundingLocked was sent to peer, but the channel was not added to the @@ -920,6 +934,19 @@ func (f *fundingManager) stateStep(channel *channeldb.OpenChannel, "router graph: %v", err) } + // As the channel is now added to the ChannelRouter's topology, + // the channel is moved to the next state of the state machine. + // It will be moved to the last state (actually deleted from + // the database) after the channel is finally announced. + err = f.saveChannelOpeningState( + &channel.FundingOutpoint, addedToRouterGraph, + shortChanID, + ) + if err != nil { + return fmt.Errorf("error setting channel state to"+ + " addedToRouterGraph: %v", err) + } + fndgLog.Debugf("Channel(%v) with ShortChanID %v: successfully "+ "added to router graph", chanID, shortChanID) @@ -961,8 +988,20 @@ func (f *fundingManager) stateStep(channel *channeldb.OpenChannel, "announcement: %v", err) } + // We delete the channel opening state from our internal + // database as the opening process has succeeded. We can do + // this because we assume the AuthenticatedGossiper queues the + // announcement messages, and persists them in case of a daemon + // shutdown. + err = f.deleteChannelOpeningState(&channel.FundingOutpoint) + if err != nil { + return fmt.Errorf("error deleting channel state: %v", + err) + } + fndgLog.Debugf("Channel(%v) with ShortChanID %v: successfully "+ "announced", chanID, shortChanID) + return nil } @@ -2068,17 +2107,6 @@ func (f *fundingManager) sendFundingLocked(peer lnpeer.Peer, } } - // As the fundingLocked message is now sent to the peer, the channel is - // moved to the next state of the state machine. It will be moved to the - // last state (actually deleted from the database) after the channel is - // finally announced. - err = f.saveChannelOpeningState(&completeChan.FundingOutpoint, - fundingLockedSent, shortChanID) - if err != nil { - return fmt.Errorf("error setting channel state to"+ - " fundingLockedSent: %v", err) - } - return nil } @@ -2157,17 +2185,6 @@ func (f *fundingManager) addToRouterGraph(completeChan *channeldb.OpenChannel, return ErrFundingManagerShuttingDown } - // As the channel is now added to the ChannelRouter's topology, the - // channel is moved to the next state of the state machine. It will be - // moved to the last state (actually deleted from the database) after - // the channel is finally announced. - err = f.saveChannelOpeningState(&completeChan.FundingOutpoint, - addedToRouterGraph, shortChanID) - if err != nil { - return fmt.Errorf("error setting channel state to"+ - " addedToRouterGraph: %v", err) - } - return nil } @@ -2309,15 +2326,6 @@ func (f *fundingManager) annAfterSixConfs(completeChan *channeldb.OpenChannel, "announced", &fundingPoint, shortChanID) } - // We delete the channel opening state from our internal database - // as the opening process has succeeded. We can do this because we - // assume the AuthenticatedGossiper queues the announcement messages, - // and persists them in case of a daemon shutdown. - err := f.deleteChannelOpeningState(&completeChan.FundingOutpoint) - if err != nil { - return fmt.Errorf("error deleting channel state: %v", err) - } - return nil }