mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-12 04:57:18 +02:00
graph/db+sqldb: implement FetchChannelEdgesByOutpoint/SCID
And run `TestEdgeInsertionDeletion` against our SQL backends.
This commit is contained in:
@ -263,6 +263,138 @@ func (q *Queries) GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAn
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getChannelByOutpointWithPolicies = `-- name: GetChannelByOutpointWithPolicies :one
|
||||
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_pubkey,
|
||||
n2.pub_key AS node2_pubkey,
|
||||
|
||||
-- Node 1 policy
|
||||
cp1.id AS policy_1_id,
|
||||
cp1.node_id AS policy_1_node_id,
|
||||
cp1.version AS policy_1_version,
|
||||
cp1.timelock AS policy_1_timelock,
|
||||
cp1.fee_ppm AS policy_1_fee_ppm,
|
||||
cp1.base_fee_msat AS policy_1_base_fee_msat,
|
||||
cp1.min_htlc_msat AS policy_1_min_htlc_msat,
|
||||
cp1.max_htlc_msat AS policy_1_max_htlc_msat,
|
||||
cp1.last_update AS policy_1_last_update,
|
||||
cp1.disabled AS policy_1_disabled,
|
||||
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
||||
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
||||
cp1.signature AS policy_1_signature,
|
||||
|
||||
-- Node 2 policy
|
||||
cp2.id AS policy_2_id,
|
||||
cp2.node_id AS policy_2_node_id,
|
||||
cp2.version AS policy_2_version,
|
||||
cp2.timelock AS policy_2_timelock,
|
||||
cp2.fee_ppm AS policy_2_fee_ppm,
|
||||
cp2.base_fee_msat AS policy_2_base_fee_msat,
|
||||
cp2.min_htlc_msat AS policy_2_min_htlc_msat,
|
||||
cp2.max_htlc_msat AS policy_2_max_htlc_msat,
|
||||
cp2.last_update AS policy_2_last_update,
|
||||
cp2.disabled AS policy_2_disabled,
|
||||
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
||||
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
||||
cp2.signature AS policy_2_signature
|
||||
FROM channels c
|
||||
JOIN nodes n1 ON c.node_id_1 = n1.id
|
||||
JOIN nodes n2 ON c.node_id_2 = n2.id
|
||||
LEFT JOIN channel_policies cp1
|
||||
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
||||
LEFT JOIN channel_policies cp2
|
||||
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
||||
WHERE c.outpoint = $1 AND c.version = $2
|
||||
`
|
||||
|
||||
type GetChannelByOutpointWithPoliciesParams struct {
|
||||
Outpoint string
|
||||
Version int16
|
||||
}
|
||||
|
||||
type GetChannelByOutpointWithPoliciesRow struct {
|
||||
Channel Channel
|
||||
Node1Pubkey []byte
|
||||
Node2Pubkey []byte
|
||||
Policy1ID sql.NullInt64
|
||||
Policy1NodeID sql.NullInt64
|
||||
Policy1Version sql.NullInt16
|
||||
Policy1Timelock sql.NullInt32
|
||||
Policy1FeePpm sql.NullInt64
|
||||
Policy1BaseFeeMsat sql.NullInt64
|
||||
Policy1MinHtlcMsat sql.NullInt64
|
||||
Policy1MaxHtlcMsat sql.NullInt64
|
||||
Policy1LastUpdate sql.NullInt64
|
||||
Policy1Disabled sql.NullBool
|
||||
Policy1InboundBaseFeeMsat sql.NullInt64
|
||||
Policy1InboundFeeRateMilliMsat sql.NullInt64
|
||||
Policy1Signature []byte
|
||||
Policy2ID sql.NullInt64
|
||||
Policy2NodeID sql.NullInt64
|
||||
Policy2Version sql.NullInt16
|
||||
Policy2Timelock sql.NullInt32
|
||||
Policy2FeePpm sql.NullInt64
|
||||
Policy2BaseFeeMsat sql.NullInt64
|
||||
Policy2MinHtlcMsat sql.NullInt64
|
||||
Policy2MaxHtlcMsat sql.NullInt64
|
||||
Policy2LastUpdate sql.NullInt64
|
||||
Policy2Disabled sql.NullBool
|
||||
Policy2InboundBaseFeeMsat sql.NullInt64
|
||||
Policy2InboundFeeRateMilliMsat sql.NullInt64
|
||||
Policy2Signature []byte
|
||||
}
|
||||
|
||||
func (q *Queries) GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, getChannelByOutpointWithPolicies, arg.Outpoint, arg.Version)
|
||||
var i GetChannelByOutpointWithPoliciesRow
|
||||
err := row.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,
|
||||
&i.Policy1ID,
|
||||
&i.Policy1NodeID,
|
||||
&i.Policy1Version,
|
||||
&i.Policy1Timelock,
|
||||
&i.Policy1FeePpm,
|
||||
&i.Policy1BaseFeeMsat,
|
||||
&i.Policy1MinHtlcMsat,
|
||||
&i.Policy1MaxHtlcMsat,
|
||||
&i.Policy1LastUpdate,
|
||||
&i.Policy1Disabled,
|
||||
&i.Policy1InboundBaseFeeMsat,
|
||||
&i.Policy1InboundFeeRateMilliMsat,
|
||||
&i.Policy1Signature,
|
||||
&i.Policy2ID,
|
||||
&i.Policy2NodeID,
|
||||
&i.Policy2Version,
|
||||
&i.Policy2Timelock,
|
||||
&i.Policy2FeePpm,
|
||||
&i.Policy2BaseFeeMsat,
|
||||
&i.Policy2MinHtlcMsat,
|
||||
&i.Policy2MaxHtlcMsat,
|
||||
&i.Policy2LastUpdate,
|
||||
&i.Policy2Disabled,
|
||||
&i.Policy2InboundBaseFeeMsat,
|
||||
&i.Policy2InboundFeeRateMilliMsat,
|
||||
&i.Policy2Signature,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getChannelBySCID = `-- name: GetChannelBySCID :one
|
||||
SELECT id, version, scid, node_id_1, node_id_2, outpoint, capacity, bitcoin_key_1, bitcoin_key_2, node_1_signature, node_2_signature, bitcoin_1_signature, bitcoin_2_signature FROM channels
|
||||
WHERE scid = $1 AND version = $2
|
||||
@ -1211,6 +1343,27 @@ func (q *Queries) InsertNodeFeature(ctx context.Context, arg InsertNodeFeaturePa
|
||||
return err
|
||||
}
|
||||
|
||||
const isZombieChannel = `-- name: IsZombieChannel :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM zombie_channels
|
||||
WHERE scid = $1
|
||||
AND version = $2
|
||||
) AS is_zombie
|
||||
`
|
||||
|
||||
type IsZombieChannelParams struct {
|
||||
Scid []byte
|
||||
Version int16
|
||||
}
|
||||
|
||||
func (q *Queries) IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error) {
|
||||
row := q.db.QueryRowContext(ctx, isZombieChannel, arg.Scid, arg.Version)
|
||||
var is_zombie bool
|
||||
err := row.Scan(&is_zombie)
|
||||
return is_zombie, err
|
||||
}
|
||||
|
||||
const listChannelsByNodeID = `-- name: ListChannelsByNodeID :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_pubkey,
|
||||
|
Reference in New Issue
Block a user