graph/db+sqldb: implement AddEdgeProof
And run `TestAddEdgeProof` against the SQL backends.
This commit is contained in:
5 files changed
+88
-1
No files matched your search
@@ -1128,7 +1128,7 @@ func TestAddEdgeProof(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
graph := MakeTestGraph(t)
|
graph := MakeTestGraphNew(t)
|
||||||
|
|
||||||
// Add an edge with no proof.
|
// Add an edge with no proof.
|
||||||
node1 := createTestVertex(t)
|
node1 := createTestVertex(t)
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ type SQLQueries interface {
|
|||||||
Channel queries.
|
Channel queries.
|
||||||
*/
|
*/
|
||||||
CreateChannel(ctx context.Context, arg sqlc.CreateChannelParams) (int64, error)
|
CreateChannel(ctx context.Context, arg sqlc.CreateChannelParams) (int64, error)
|
||||||
|
AddV1ChannelProof(ctx context.Context, arg sqlc.AddV1ChannelProofParams) (sql.Result, error)
|
||||||
GetChannelBySCID(ctx context.Context, arg sqlc.GetChannelBySCIDParams) (sqlc.Channel, error)
|
GetChannelBySCID(ctx context.Context, arg sqlc.GetChannelBySCIDParams) (sqlc.Channel, error)
|
||||||
GetChannelByOutpoint(ctx context.Context, outpoint string) (sqlc.GetChannelByOutpointRow, error)
|
GetChannelByOutpoint(ctx context.Context, outpoint string) (sqlc.GetChannelByOutpointRow, error)
|
||||||
GetChannelsBySCIDRange(ctx context.Context, arg sqlc.GetChannelsBySCIDRangeParams) ([]sqlc.GetChannelsBySCIDRangeRow, error)
|
GetChannelsBySCIDRange(ctx context.Context, arg sqlc.GetChannelsBySCIDRangeParams) ([]sqlc.GetChannelsBySCIDRangeRow, error)
|
||||||
@@ -2575,6 +2576,54 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
|
|||||||
return removedChans, nil
|
return removedChans, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddEdgeProof sets the proof of an existing edge in the graph database.
|
||||||
|
//
|
||||||
|
// NOTE: part of the V1Store interface.
|
||||||
|
func (s *SQLStore) AddEdgeProof(scid lnwire.ShortChannelID,
|
||||||
|
proof *models.ChannelAuthProof) error {
|
||||||
|
|
||||||
|
var (
|
||||||
|
ctx = context.TODO()
|
||||||
|
scidBytes = channelIDToBytes(scid.ToUint64())
|
||||||
|
)
|
||||||
|
|
||||||
|
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
||||||
|
res, err := db.AddV1ChannelProof(
|
||||||
|
ctx, sqlc.AddV1ChannelProofParams{
|
||||||
|
Scid: scidBytes[:],
|
||||||
|
Node1Signature: proof.NodeSig1Bytes,
|
||||||
|
Node2Signature: proof.NodeSig2Bytes,
|
||||||
|
Bitcoin1Signature: proof.BitcoinSig1Bytes,
|
||||||
|
Bitcoin2Signature: proof.BitcoinSig2Bytes,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to add edge proof: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := res.RowsAffected()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if n == 0 {
|
||||||
|
return fmt.Errorf("no rows affected when adding edge "+
|
||||||
|
"proof for SCID %v", scid)
|
||||||
|
} else if n > 1 {
|
||||||
|
return fmt.Errorf("multiple rows affected when adding "+
|
||||||
|
"edge proof for SCID %v: %d rows affected",
|
||||||
|
scid, n)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, sqldb.NoOpReset)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to add edge proof: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// forEachNodeDirectedChannel iterates through all channels of a given
|
// forEachNodeDirectedChannel iterates through all channels of a given
|
||||||
// node, executing the passed callback on the directed edge representing the
|
// node, executing the passed callback on the directed edge representing the
|
||||||
// channel and its incoming policy. If the node is not found, no error is
|
// channel and its incoming policy. If the node is not found, no error is
|
||||||
|
|||||||
@@ -26,6 +26,34 @@ func (q *Queries) AddSourceNode(ctx context.Context, nodeID int64) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addV1ChannelProof = `-- name: AddV1ChannelProof :execresult
|
||||||
|
UPDATE channels
|
||||||
|
SET node_1_signature = $2,
|
||||||
|
node_2_signature = $3,
|
||||||
|
bitcoin_1_signature = $4,
|
||||||
|
bitcoin_2_signature = $5
|
||||||
|
WHERE scid = $1
|
||||||
|
AND version = 1
|
||||||
|
`
|
||||||
|
|
||||||
|
type AddV1ChannelProofParams struct {
|
||||||
|
Scid []byte
|
||||||
|
Node1Signature []byte
|
||||||
|
Node2Signature []byte
|
||||||
|
Bitcoin1Signature []byte
|
||||||
|
Bitcoin2Signature []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) AddV1ChannelProof(ctx context.Context, arg AddV1ChannelProofParams) (sql.Result, error) {
|
||||||
|
return q.db.ExecContext(ctx, addV1ChannelProof,
|
||||||
|
arg.Scid,
|
||||||
|
arg.Node1Signature,
|
||||||
|
arg.Node2Signature,
|
||||||
|
arg.Bitcoin1Signature,
|
||||||
|
arg.Bitcoin2Signature,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const countZombieChannels = `-- name: CountZombieChannels :one
|
const countZombieChannels = `-- name: CountZombieChannels :one
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM zombie_channels
|
FROM zombie_channels
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
type Querier interface {
|
type Querier interface {
|
||||||
AddSourceNode(ctx context.Context, nodeID int64) error
|
AddSourceNode(ctx context.Context, nodeID int64) error
|
||||||
|
AddV1ChannelProof(ctx context.Context, arg AddV1ChannelProofParams) (sql.Result, error)
|
||||||
ClearKVInvoiceHashIndex(ctx context.Context) error
|
ClearKVInvoiceHashIndex(ctx context.Context) error
|
||||||
CountZombieChannels(ctx context.Context, version int16) (int64, error)
|
CountZombieChannels(ctx context.Context, version int16) (int64, error)
|
||||||
CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error)
|
CreateChannel(ctx context.Context, arg CreateChannelParams) (int64, error)
|
||||||
|
|||||||
@@ -208,6 +208,15 @@ INSERT INTO channels (
|
|||||||
)
|
)
|
||||||
RETURNING id;
|
RETURNING id;
|
||||||
|
|
||||||
|
-- name: AddV1ChannelProof :execresult
|
||||||
|
UPDATE channels
|
||||||
|
SET node_1_signature = $2,
|
||||||
|
node_2_signature = $3,
|
||||||
|
bitcoin_1_signature = $4,
|
||||||
|
bitcoin_2_signature = $5
|
||||||
|
WHERE scid = $1
|
||||||
|
AND version = 1;
|
||||||
|
|
||||||
-- name: GetChannelsBySCIDRange :many
|
-- name: GetChannelsBySCIDRange :many
|
||||||
SELECT sqlc.embed(c),
|
SELECT sqlc.embed(c),
|
||||||
n1.pub_key AS node1_pub_key,
|
n1.pub_key AS node1_pub_key,
|
||||||
|
|||||||
Reference in new issue
Block a user