Skip to content

Commit 31418e4

Browse files
authored
Merge pull request #9525 from ellemouton/graph10
graph: Restrict interface to update channel proof instead of entire channel
2 parents f9d29f9 + 9df8773 commit 31418e4

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

graph/builder.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,14 +1441,7 @@ func (b *Builder) ForAllOutgoingChannels(cb func(*models.ChannelEdgeInfo,
14411441
func (b *Builder) AddProof(chanID lnwire.ShortChannelID,
14421442
proof *models.ChannelAuthProof) error {
14431443

1444-
info, _, _, err := b.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
1445-
if err != nil {
1446-
return err
1447-
}
1448-
1449-
info.AuthProof = proof
1450-
1451-
return b.cfg.Graph.UpdateChannelEdge(info)
1444+
return b.cfg.Graph.AddEdgeProof(chanID, proof)
14521445
}
14531446

14541447
// IsStaleNode returns true if the graph source has a node announcement for the

graph/db/graph.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,19 +1317,17 @@ func (c *ChannelGraph) HasChannelEdge(
13171317
return upd1Time, upd2Time, exists, isZombie, nil
13181318
}
13191319

1320-
// UpdateChannelEdge retrieves and update edge of the graph database. Method
1321-
// only reserved for updating an edge info after its already been created.
1322-
// In order to maintain this constraints, we return an error in the scenario
1323-
// that an edge info hasn't yet been created yet, but someone attempts to update
1324-
// it.
1325-
func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
1320+
// AddEdgeProof sets the proof of an existing edge in the graph database.
1321+
func (c *ChannelGraph) AddEdgeProof(chanID lnwire.ShortChannelID,
1322+
proof *models.ChannelAuthProof) error {
1323+
13261324
// Construct the channel's primary key which is the 8-byte channel ID.
13271325
var chanKey [8]byte
1328-
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
1326+
binary.BigEndian.PutUint64(chanKey[:], chanID.ToUint64())
13291327

13301328
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
13311329
edges := tx.ReadWriteBucket(edgeBucket)
1332-
if edge == nil {
1330+
if edges == nil {
13331331
return ErrEdgeNotFound
13341332
}
13351333

@@ -1338,15 +1336,14 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
13381336
return ErrEdgeNotFound
13391337
}
13401338

1341-
if edgeInfo := edgeIndex.Get(chanKey[:]); edgeInfo == nil {
1342-
return ErrEdgeNotFound
1339+
edge, err := fetchChanEdgeInfo(edgeIndex, chanKey[:])
1340+
if err != nil {
1341+
return err
13431342
}
13441343

1345-
if c.graphCache != nil {
1346-
c.graphCache.UpdateChannel(edge)
1347-
}
1344+
edge.AuthProof = proof
13481345

1349-
return putChanEdgeInfo(edgeIndex, edge, chanKey)
1346+
return putChanEdgeInfo(edgeIndex, &edge, chanKey)
13501347
}, func() {})
13511348
}
13521349

graph/interfaces.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,10 @@ type DB interface {
259259
*models.ChannelEdgePolicy,
260260
*models.ChannelEdgePolicy) error) error
261261

262-
// UpdateChannelEdge retrieves and update edge of the graph database.
263-
// Method only reserved for updating an edge info after its already been
264-
// created. In order to maintain this constraints, we return an error in
265-
// the scenario that an edge info hasn't yet been created yet, but
266-
// someone attempts to update it.
267-
UpdateChannelEdge(edge *models.ChannelEdgeInfo) error
262+
// AddEdgeProof sets the proof of an existing edge in the graph
263+
// database.
264+
AddEdgeProof(chanID lnwire.ShortChannelID,
265+
proof *models.ChannelAuthProof) error
268266

269267
// IsPublicNode is a helper method that determines whether the node with
270268
// the given public key is seen as a public node in the graph from the

0 commit comments

Comments
 (0)