Skip to content

Commit d46552f

Browse files
committed
graph/db+sqldb: implement AddEdgeProof
And run `TestAddEdgeProof` against the SQL backends.
1 parent 5d926b3 commit d46552f

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

graph/db/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ func TestAddEdgeProof(t *testing.T) {
11281128
t.Parallel()
11291129
ctx := context.Background()
11301130

1131-
graph := MakeTestGraph(t)
1131+
graph := MakeTestGraphNew(t)
11321132

11331133
// Add an edge with no proof.
11341134
node1 := createTestVertex(t)

graph/db/sql_store.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type SQLQueries interface {
9191
Channel queries.
9292
*/
9393
CreateChannel(ctx context.Context, arg sqlc.CreateChannelParams) (int64, error)
94+
AddV1ChannelProof(ctx context.Context, arg sqlc.AddV1ChannelProofParams) (sql.Result, error)
9495
GetChannelBySCID(ctx context.Context, arg sqlc.GetChannelBySCIDParams) (sqlc.Channel, error)
9596
GetChannelByOutpoint(ctx context.Context, outpoint string) (sqlc.GetChannelByOutpointRow, error)
9697
GetChannelsBySCIDRange(ctx context.Context, arg sqlc.GetChannelsBySCIDRangeParams) ([]sqlc.GetChannelsBySCIDRangeRow, error)
@@ -2575,6 +2576,54 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
25752576
return removedChans, nil
25762577
}
25772578

2579+
// AddEdgeProof sets the proof of an existing edge in the graph database.
2580+
//
2581+
// NOTE: part of the V1Store interface.
2582+
func (s *SQLStore) AddEdgeProof(scid lnwire.ShortChannelID,
2583+
proof *models.ChannelAuthProof) error {
2584+
2585+
var (
2586+
ctx = context.TODO()
2587+
scidBytes = channelIDToBytes(scid.ToUint64())
2588+
)
2589+
2590+
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
2591+
res, err := db.AddV1ChannelProof(
2592+
ctx, sqlc.AddV1ChannelProofParams{
2593+
Scid: scidBytes[:],
2594+
Node1Signature: proof.NodeSig1Bytes,
2595+
Node2Signature: proof.NodeSig2Bytes,
2596+
Bitcoin1Signature: proof.BitcoinSig1Bytes,
2597+
Bitcoin2Signature: proof.BitcoinSig2Bytes,
2598+
},
2599+
)
2600+
if err != nil {
2601+
return fmt.Errorf("unable to add edge proof: %w", err)
2602+
}
2603+
2604+
n, err := res.RowsAffected()
2605+
if err != nil {
2606+
return err
2607+
}
2608+
2609+
if n == 0 {
2610+
return fmt.Errorf("no rows affected when adding edge "+
2611+
"proof for SCID %v", scid)
2612+
} else if n > 1 {
2613+
return fmt.Errorf("multiple rows affected when adding "+
2614+
"edge proof for SCID %v: %d rows affected",
2615+
scid, n)
2616+
}
2617+
2618+
return nil
2619+
}, sqldb.NoOpReset)
2620+
if err != nil {
2621+
return fmt.Errorf("unable to add edge proof: %w", err)
2622+
}
2623+
2624+
return nil
2625+
}
2626+
25782627
// forEachNodeDirectedChannel iterates through all channels of a given
25792628
// node, executing the passed callback on the directed edge representing the
25802629
// channel and its incoming policy. If the node is not found, no error is

sqldb/sqlc/graph.sql.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/queries/graph.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,15 @@ INSERT INTO channels (
208208
)
209209
RETURNING id;
210210

211+
-- name: AddV1ChannelProof :execresult
212+
UPDATE channels
213+
SET node_1_signature = $2,
214+
node_2_signature = $3,
215+
bitcoin_1_signature = $4,
216+
bitcoin_2_signature = $5
217+
WHERE scid = $1
218+
AND version = 1;
219+
211220
-- name: GetChannelsBySCIDRange :many
212221
SELECT sqlc.embed(c),
213222
n1.pub_key AS node1_pub_key,

0 commit comments

Comments
 (0)