Merge pull request #9525 from ellemouton/graph10
graph: Restrict interface to update channel proof instead of entire channel
This commit is contained in:
3 files changed
+16
-28
No files matched your search
+1
-8
@@ -1441,14 +1441,7 @@ func (b *Builder) ForAllOutgoingChannels(cb func(*models.ChannelEdgeInfo,
|
||||
func (b *Builder) AddProof(chanID lnwire.ShortChannelID,
|
||||
proof *models.ChannelAuthProof) error {
|
||||
|
||||
info, _, _, err := b.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
info.AuthProof = proof
|
||||
|
||||
return b.cfg.Graph.UpdateChannelEdge(info)
|
||||
return b.cfg.Graph.AddEdgeProof(chanID, proof)
|
||||
}
|
||||
|
||||
// IsStaleNode returns true if the graph source has a node announcement for the
|
||||
|
||||
+11
-14
@@ -1317,19 +1317,17 @@ func (c *ChannelGraph) HasChannelEdge(
|
||||
return upd1Time, upd2Time, exists, isZombie, nil
|
||||
}
|
||||
|
||||
// UpdateChannelEdge retrieves and update edge of the graph database. Method
|
||||
// only reserved for updating an edge info after its already been created.
|
||||
// In order to maintain this constraints, we return an error in the scenario
|
||||
// that an edge info hasn't yet been created yet, but someone attempts to update
|
||||
// it.
|
||||
func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
|
||||
// AddEdgeProof sets the proof of an existing edge in the graph database.
|
||||
func (c *ChannelGraph) AddEdgeProof(chanID lnwire.ShortChannelID,
|
||||
proof *models.ChannelAuthProof) error {
|
||||
|
||||
// Construct the channel's primary key which is the 8-byte channel ID.
|
||||
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 {
|
||||
edges := tx.ReadWriteBucket(edgeBucket)
|
||||
if edge == nil {
|
||||
if edges == nil {
|
||||
return ErrEdgeNotFound
|
||||
}
|
||||
|
||||
@@ -1338,15 +1336,14 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
|
||||
return ErrEdgeNotFound
|
||||
}
|
||||
|
||||
if edgeInfo := edgeIndex.Get(chanKey[:]); edgeInfo == nil {
|
||||
return ErrEdgeNotFound
|
||||
edge, err := fetchChanEdgeInfo(edgeIndex, chanKey[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.graphCache != nil {
|
||||
c.graphCache.UpdateChannel(edge)
|
||||
}
|
||||
edge.AuthProof = proof
|
||||
|
||||
return putChanEdgeInfo(edgeIndex, edge, chanKey)
|
||||
return putChanEdgeInfo(edgeIndex, &edge, chanKey)
|
||||
}, func() {})
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -259,12 +259,10 @@ type DB interface {
|
||||
*models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy) error) error
|
||||
|
||||
// UpdateChannelEdge retrieves and update edge of the graph database.
|
||||
// Method only reserved for updating an edge info after its already been
|
||||
// created. In order to maintain this constraints, we return an error in
|
||||
// the scenario that an edge info hasn't yet been created yet, but
|
||||
// someone attempts to update it.
|
||||
UpdateChannelEdge(edge *models.ChannelEdgeInfo) error
|
||||
// AddEdgeProof sets the proof of an existing edge in the graph
|
||||
// database.
|
||||
AddEdgeProof(chanID lnwire.ShortChannelID,
|
||||
proof *models.ChannelAuthProof) error
|
||||
|
||||
// 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
|
||||
|
||||
Reference in new issue
Block a user