mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-08 14:31:53 +02:00
sqldb+graph/db: impl DisconnectBlockAtHeight
Which lets us run `TestDisconnectBlockAtHeight` and `TestStressTestChannelGraphAPI` against our SQL backends.
This commit is contained in:
@ -200,6 +200,22 @@ func (q *Queries) DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeaturePa
|
||||
return err
|
||||
}
|
||||
|
||||
const deletePruneLogEntriesInRange = `-- name: DeletePruneLogEntriesInRange :exec
|
||||
DELETE FROM prune_log
|
||||
WHERE block_height >= $1
|
||||
AND block_height <= $2
|
||||
`
|
||||
|
||||
type DeletePruneLogEntriesInRangeParams struct {
|
||||
StartHeight int64
|
||||
EndHeight int64
|
||||
}
|
||||
|
||||
func (q *Queries) DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error {
|
||||
_, err := q.db.ExecContext(ctx, deletePruneLogEntriesInRange, arg.StartHeight, arg.EndHeight)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteZombieChannel = `-- name: DeleteZombieChannel :execresult
|
||||
DELETE FROM zombie_channels
|
||||
WHERE scid = $1
|
||||
@ -943,6 +959,67 @@ func (q *Queries) GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg Ge
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getChannelsBySCIDRange = `-- name: GetChannelsBySCIDRange :many
|
||||
SELECT c.id, c.version, c.scid, c.node_id_1, c.node_id_2, c.outpoint, c.capacity, c.bitcoin_key_1, c.bitcoin_key_2, c.node_1_signature, c.node_2_signature, c.bitcoin_1_signature, c.bitcoin_2_signature,
|
||||
n1.pub_key AS node1_pub_key,
|
||||
n2.pub_key AS node2_pub_key
|
||||
FROM channels c
|
||||
JOIN nodes n1 ON c.node_id_1 = n1.id
|
||||
JOIN nodes n2 ON c.node_id_2 = n2.id
|
||||
WHERE scid >= $1
|
||||
AND scid < $2
|
||||
`
|
||||
|
||||
type GetChannelsBySCIDRangeParams struct {
|
||||
StartScid []byte
|
||||
EndScid []byte
|
||||
}
|
||||
|
||||
type GetChannelsBySCIDRangeRow struct {
|
||||
Channel Channel
|
||||
Node1PubKey []byte
|
||||
Node2PubKey []byte
|
||||
}
|
||||
|
||||
func (q *Queries) GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getChannelsBySCIDRange, arg.StartScid, arg.EndScid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetChannelsBySCIDRangeRow
|
||||
for rows.Next() {
|
||||
var i GetChannelsBySCIDRangeRow
|
||||
if err := rows.Scan(
|
||||
&i.Channel.ID,
|
||||
&i.Channel.Version,
|
||||
&i.Channel.Scid,
|
||||
&i.Channel.NodeID1,
|
||||
&i.Channel.NodeID2,
|
||||
&i.Channel.Outpoint,
|
||||
&i.Channel.Capacity,
|
||||
&i.Channel.BitcoinKey1,
|
||||
&i.Channel.BitcoinKey2,
|
||||
&i.Channel.Node1Signature,
|
||||
&i.Channel.Node2Signature,
|
||||
&i.Channel.Bitcoin1Signature,
|
||||
&i.Channel.Bitcoin2Signature,
|
||||
&i.Node1PubKey,
|
||||
&i.Node2PubKey,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getExtraNodeTypes = `-- name: GetExtraNodeTypes :many
|
||||
SELECT node_id, type, value
|
||||
FROM node_extra_types
|
||||
|
@ -25,6 +25,7 @@ type Querier interface {
|
||||
DeleteNodeAddresses(ctx context.Context, nodeID int64) error
|
||||
DeleteNodeByPubKey(ctx context.Context, arg DeleteNodeByPubKeyParams) (sql.Result, error)
|
||||
DeleteNodeFeature(ctx context.Context, arg DeleteNodeFeatureParams) error
|
||||
DeletePruneLogEntriesInRange(ctx context.Context, arg DeletePruneLogEntriesInRangeParams) error
|
||||
DeleteZombieChannel(ctx context.Context, arg DeleteZombieChannelParams) (sql.Result, error)
|
||||
FetchAMPSubInvoiceHTLCs(ctx context.Context, arg FetchAMPSubInvoiceHTLCsParams) ([]FetchAMPSubInvoiceHTLCsRow, error)
|
||||
FetchAMPSubInvoices(ctx context.Context, arg FetchAMPSubInvoicesParams) ([]AmpSubInvoice, error)
|
||||
@ -40,6 +41,7 @@ type Querier interface {
|
||||
GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error)
|
||||
GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error)
|
||||
GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error)
|
||||
GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error)
|
||||
GetDatabaseVersion(ctx context.Context) (int32, error)
|
||||
GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error)
|
||||
// This method may return more than one invoice if filter using multiple fields
|
||||
|
@ -208,6 +208,16 @@ INSERT INTO channels (
|
||||
)
|
||||
RETURNING id;
|
||||
|
||||
-- name: GetChannelsBySCIDRange :many
|
||||
SELECT sqlc.embed(c),
|
||||
n1.pub_key AS node1_pub_key,
|
||||
n2.pub_key AS node2_pub_key
|
||||
FROM channels c
|
||||
JOIN nodes n1 ON c.node_id_1 = n1.id
|
||||
JOIN nodes n2 ON c.node_id_2 = n2.id
|
||||
WHERE scid >= @start_scid
|
||||
AND scid < @end_scid;
|
||||
|
||||
-- name: GetChannelBySCID :one
|
||||
SELECT * FROM channels
|
||||
WHERE scid = $1 AND version = $2;
|
||||
@ -685,3 +695,8 @@ SELECT block_height, block_hash
|
||||
FROM prune_log
|
||||
ORDER BY block_height DESC
|
||||
LIMIT 1;
|
||||
|
||||
-- name: DeletePruneLogEntriesInRange :exec
|
||||
DELETE FROM prune_log
|
||||
WHERE block_height >= @start_height
|
||||
AND block_height <= @end_height;
|
||||
|
Reference in New Issue
Block a user