mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
graph: update proof by ID
This commit restricts the graph CRUD interface such that one can only add a proof to a channel announcement and not update any other fields. This pattern is better suited for SQL land too.
This commit is contained in:
@@ -1441,14 +1441,7 @@ func (b *Builder) ForAllOutgoingChannels(cb func(*models.ChannelEdgeInfo,
|
|||||||
func (b *Builder) AddProof(chanID lnwire.ShortChannelID,
|
func (b *Builder) AddProof(chanID lnwire.ShortChannelID,
|
||||||
proof *models.ChannelAuthProof) error {
|
proof *models.ChannelAuthProof) error {
|
||||||
|
|
||||||
info, _, _, err := b.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
|
return b.cfg.Graph.AddEdgeProof(chanID, proof)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
info.AuthProof = proof
|
|
||||||
|
|
||||||
return b.cfg.Graph.UpdateChannelEdge(info)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsStaleNode returns true if the graph source has a node announcement for the
|
// IsStaleNode returns true if the graph source has a node announcement for the
|
||||||
|
@@ -1297,15 +1297,13 @@ func (c *ChannelGraph) HasChannelEdge(
|
|||||||
return upd1Time, upd2Time, exists, isZombie, nil
|
return upd1Time, upd2Time, exists, isZombie, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateChannelEdge retrieves and update edge of the graph database. Method
|
// AddEdgeProof sets the proof of an existing edge in the graph database.
|
||||||
// only reserved for updating an edge info after its already been created.
|
func (c *ChannelGraph) AddEdgeProof(chanID lnwire.ShortChannelID,
|
||||||
// In order to maintain this constraints, we return an error in the scenario
|
proof *models.ChannelAuthProof) error {
|
||||||
// that an edge info hasn't yet been created yet, but someone attempts to update
|
|
||||||
// it.
|
|
||||||
func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
|
|
||||||
// Construct the channel's primary key which is the 8-byte channel ID.
|
// Construct the channel's primary key which is the 8-byte channel ID.
|
||||||
var chanKey [8]byte
|
var chanKey [8]byte
|
||||||
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
binary.BigEndian.PutUint64(chanKey[:], chanID.ToUint64())
|
||||||
|
|
||||||
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||||
edges := tx.ReadWriteBucket(edgeBucket)
|
edges := tx.ReadWriteBucket(edgeBucket)
|
||||||
@@ -1318,15 +1316,14 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
|
|||||||
return ErrEdgeNotFound
|
return ErrEdgeNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
if edgeInfo := edgeIndex.Get(chanKey[:]); edgeInfo == nil {
|
edge, err := fetchChanEdgeInfo(edgeIndex, chanKey[:])
|
||||||
return ErrEdgeNotFound
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.graphCache != nil {
|
edge.AuthProof = proof
|
||||||
c.graphCache.UpdateChannel(edge)
|
|
||||||
}
|
|
||||||
|
|
||||||
return putChanEdgeInfo(edgeIndex, edge, chanKey)
|
return putChanEdgeInfo(edgeIndex, &edge, chanKey)
|
||||||
}, func() {})
|
}, func() {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -259,12 +259,10 @@ type DB interface {
|
|||||||
*models.ChannelEdgePolicy,
|
*models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error
|
*models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
// UpdateChannelEdge retrieves and update edge of the graph database.
|
// AddEdgeProof sets the proof of an existing edge in the graph
|
||||||
// Method only reserved for updating an edge info after its already been
|
// database.
|
||||||
// created. In order to maintain this constraints, we return an error in
|
AddEdgeProof(chanID lnwire.ShortChannelID,
|
||||||
// the scenario that an edge info hasn't yet been created yet, but
|
proof *models.ChannelAuthProof) error
|
||||||
// someone attempts to update it.
|
|
||||||
UpdateChannelEdge(edge *models.ChannelEdgeInfo) error
|
|
||||||
|
|
||||||
// IsPublicNode is a helper method that determines whether the node with
|
// IsPublicNode is a helper method that determines whether the node with
|
||||||
// the given public key is seen as a public node in the graph from the
|
// the given public key is seen as a public node in the graph from the
|
||||||
|
Reference in New Issue
Block a user