mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-04 18:01:57 +01:00
channeldb+routing: move adding shell nodes into db txn of AddChannelEdge
In this commit, we fix a slight race condition that can occur when we go to add a shell node for a node announcement, but then right afterwards, a new block arrives that causes us to prune an unconnected node. To ensure this doesn't happen, we now add shell nodes within the same db transaction as AddChannelEdge. This ensures that the state is fully consistent and shell nodes will be added atomically along with the new channel edge. As a result of this change, we no longer need to add shell nodes within the ChannelRouter, as the database will take care of this operation as it should.
This commit is contained in:
@@ -956,34 +956,6 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
||||
"chan_id=%v", msg.ChannelID)
|
||||
}
|
||||
|
||||
// Query the database for the existence of the two nodes in this
|
||||
// channel. If not found, add a partial node to the database,
|
||||
// containing only the node keys.
|
||||
_, exists, _ = r.cfg.Graph.HasLightningNode(msg.NodeKey1Bytes)
|
||||
if !exists {
|
||||
node1 := &channeldb.LightningNode{
|
||||
PubKeyBytes: msg.NodeKey1Bytes,
|
||||
HaveNodeAnnouncement: false,
|
||||
}
|
||||
err := r.cfg.Graph.AddLightningNode(node1)
|
||||
if err != nil {
|
||||
return errors.Errorf("unable to add node %v to"+
|
||||
" the graph: %v", node1.PubKeyBytes, err)
|
||||
}
|
||||
}
|
||||
_, exists, _ = r.cfg.Graph.HasLightningNode(msg.NodeKey2Bytes)
|
||||
if !exists {
|
||||
node2 := &channeldb.LightningNode{
|
||||
PubKeyBytes: msg.NodeKey2Bytes,
|
||||
HaveNodeAnnouncement: false,
|
||||
}
|
||||
err := r.cfg.Graph.AddLightningNode(node2)
|
||||
if err != nil {
|
||||
return errors.Errorf("unable to add node %v to"+
|
||||
" the graph: %v", node2.PubKeyBytes, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Before we can add the channel to the channel graph, we need
|
||||
// to obtain the full funding outpoint that's encoded within
|
||||
// the channel ID.
|
||||
|
||||
Reference in New Issue
Block a user