Skip to content

Commit 9df8773

Browse files
committed
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.
1 parent e58abbf commit 9df8773

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
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: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,15 +1297,13 @@ func (c *ChannelGraph) HasChannelEdge(
12971297
return upd1Time, upd2Time, exists, isZombie, nil
12981298
}
12991299

1300-
// UpdateChannelEdge retrieves and update edge of the graph database. Method
1301-
// only reserved for updating an edge info after its already been created.
1302-
// In order to maintain this constraints, we return an error in the scenario
1303-
// that an edge info hasn't yet been created yet, but someone attempts to update
1304-
// it.
1305-
func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
1300+
// AddEdgeProof sets the proof of an existing edge in the graph database.
1301+
func (c *ChannelGraph) AddEdgeProof(chanID lnwire.ShortChannelID,
1302+
proof *models.ChannelAuthProof) error {
1303+
13061304
// Construct the channel's primary key which is the 8-byte channel ID.
13071305
var chanKey [8]byte
1308-
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
1306+
binary.BigEndian.PutUint64(chanKey[:], chanID.ToUint64())
13091307

13101308
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
13111309
edges := tx.ReadWriteBucket(edgeBucket)
@@ -1318,15 +1316,14 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
13181316
return ErrEdgeNotFound
13191317
}
13201318

1321-
if edgeInfo := edgeIndex.Get(chanKey[:]); edgeInfo == nil {
1322-
return ErrEdgeNotFound
1319+
edge, err := fetchChanEdgeInfo(edgeIndex, chanKey[:])
1320+
if err != nil {
1321+
return err
13231322
}
13241323

1325-
if c.graphCache != nil {
1326-
c.graphCache.UpdateChannel(edge)
1327-
}
1324+
edge.AuthProof = proof
13281325

1329-
return putChanEdgeInfo(edgeIndex, edge, chanKey)
1326+
return putChanEdgeInfo(edgeIndex, &edge, chanKey)
13301327
}, func() {})
13311328
}
13321329

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)