multi: freeze graph SQL migration logic
Copy over all the code that the graph SQL migration needs to a separate folder. This will let us advance the main graph SQL CRUD code without worrying about changing the sql migration code. It will also let us change the SQL queries without changing the migration. In this commit, only the migration logic is "frozen" but in an upcoming commit, the sqlc queries & models will be frozen too.
This commit is contained in:
1 parent
07d0f0842c
commit
125325f625
17 files changed
+5136
-6
No files matched your search
@@ -0,0 +1,35 @@
|
||||
package models
|
||||
|
||||
// ChannelAuthProof is the authentication proof (the signature portion) for a
|
||||
// channel. Using the four signatures contained in the struct, and some
|
||||
// auxiliary knowledge (the funding script, node identities, and outpoint) nodes
|
||||
// on the network are able to validate the authenticity and existence of a
|
||||
// channel. Each of these signatures signs the following digest: chanID ||
|
||||
// nodeID1 || nodeID2 || bitcoinKey1|| bitcoinKey2 || 2-byte-feature-len ||
|
||||
// features.
|
||||
type ChannelAuthProof struct {
|
||||
// NodeSig1Bytes are the raw bytes of the first node signature encoded
|
||||
// in DER format.
|
||||
NodeSig1Bytes []byte
|
||||
|
||||
// NodeSig2Bytes are the raw bytes of the second node signature
|
||||
// encoded in DER format.
|
||||
NodeSig2Bytes []byte
|
||||
|
||||
// BitcoinSig1Bytes are the raw bytes of the first bitcoin signature
|
||||
// encoded in DER format.
|
||||
BitcoinSig1Bytes []byte
|
||||
|
||||
// BitcoinSig2Bytes are the raw bytes of the second bitcoin signature
|
||||
// encoded in DER format.
|
||||
BitcoinSig2Bytes []byte
|
||||
}
|
||||
|
||||
// IsEmpty check is the authentication proof is empty Proof is empty if at
|
||||
// least one of the signatures are equal to nil.
|
||||
func (c *ChannelAuthProof) IsEmpty() bool {
|
||||
return len(c.NodeSig1Bytes) == 0 ||
|
||||
len(c.NodeSig2Bytes) == 0 ||
|
||||
len(c.BitcoinSig1Bytes) == 0 ||
|
||||
len(c.BitcoinSig2Bytes) == 0
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/fn/v2"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// ChannelEdgeInfo represents a fully authenticated channel along with all its
|
||||
// unique attributes. Once an authenticated channel announcement has been
|
||||
// processed on the network, then an instance of ChannelEdgeInfo encapsulating
|
||||
// the channels attributes is stored. The other portions relevant to routing
|
||||
// policy of a channel are stored within a ChannelEdgePolicy for each direction
|
||||
// of the channel.
|
||||
type ChannelEdgeInfo struct {
|
||||
// ChannelID is the unique channel ID for the channel. The first 3
|
||||
// bytes are the block height, the next 3 the index within the block,
|
||||
// and the last 2 bytes are the output index for the channel.
|
||||
ChannelID uint64
|
||||
|
||||
// ChainHash is the hash that uniquely identifies the chain that this
|
||||
// channel was opened within.
|
||||
ChainHash chainhash.Hash
|
||||
|
||||
// NodeKey1Bytes is the raw public key of the first node.
|
||||
NodeKey1Bytes [33]byte
|
||||
|
||||
// NodeKey2Bytes is the raw public key of the first node.
|
||||
NodeKey2Bytes [33]byte
|
||||
|
||||
// BitcoinKey1Bytes is the raw public key of the first node.
|
||||
BitcoinKey1Bytes [33]byte
|
||||
|
||||
// BitcoinKey2Bytes is the raw public key of the first node.
|
||||
BitcoinKey2Bytes [33]byte
|
||||
|
||||
// Features is the list of protocol features supported by this channel
|
||||
// edge.
|
||||
Features *lnwire.FeatureVector
|
||||
|
||||
// AuthProof is the authentication proof for this channel. This proof
|
||||
// contains a set of signatures binding four identities, which attests
|
||||
// to the legitimacy of the advertised channel.
|
||||
AuthProof *ChannelAuthProof
|
||||
|
||||
// ChannelPoint is the funding outpoint of the channel. This can be
|
||||
// used to uniquely identify the channel within the channel graph.
|
||||
ChannelPoint wire.OutPoint
|
||||
|
||||
// Capacity is the total capacity of the channel, this is determined by
|
||||
// the value output in the outpoint that created this channel.
|
||||
Capacity btcutil.Amount
|
||||
|
||||
// FundingScript holds the script of the channel's funding transaction.
|
||||
//
|
||||
// NOTE: this is not currently persisted and so will not be present if
|
||||
// the edge object is loaded from the database.
|
||||
FundingScript fn.Option[[]byte]
|
||||
|
||||
// ExtraOpaqueData is the set of data that was appended to this
|
||||
// message, some of which we may not actually know how to iterate or
|
||||
// parse. By holding onto this data, we ensure that we're able to
|
||||
// properly validate the set of signatures that cover these new fields,
|
||||
// and ensure we're able to make upgrades to the network in a forwards
|
||||
// compatible manner.
|
||||
ExtraOpaqueData []byte
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lightningnetwork/lnd/fn/v2"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// ChannelEdgePolicy represents a *directed* edge within the channel graph. For
|
||||
// each channel in the database, there are two distinct edges: one for each
|
||||
// possible direction of travel along the channel. The edges themselves hold
|
||||
// information concerning fees, and minimum time-lock information which is
|
||||
// utilized during path finding.
|
||||
type ChannelEdgePolicy struct {
|
||||
// SigBytes is the raw bytes of the signature of the channel edge
|
||||
// policy. We'll only parse these if the caller needs to access the
|
||||
// signature for validation purposes. Do not set SigBytes directly, but
|
||||
// use SetSigBytes instead to make sure that the cache is invalidated.
|
||||
SigBytes []byte
|
||||
|
||||
// ChannelID is the unique channel ID for the channel. The first 3
|
||||
// bytes are the block height, the next 3 the index within the block,
|
||||
// and the last 2 bytes are the output index for the channel.
|
||||
ChannelID uint64
|
||||
|
||||
// LastUpdate is the last time an authenticated edge for this channel
|
||||
// was received.
|
||||
LastUpdate time.Time
|
||||
|
||||
// MessageFlags is a bitfield which indicates the presence of optional
|
||||
// fields (like max_htlc) in the policy.
|
||||
MessageFlags lnwire.ChanUpdateMsgFlags
|
||||
|
||||
// ChannelFlags is a bitfield which signals the capabilities of the
|
||||
// channel as well as the directed edge this update applies to.
|
||||
ChannelFlags lnwire.ChanUpdateChanFlags
|
||||
|
||||
// TimeLockDelta is the number of blocks this node will subtract from
|
||||
// the expiry of an incoming HTLC. This value expresses the time buffer
|
||||
// the node would like to HTLC exchanges.
|
||||
TimeLockDelta uint16
|
||||
|
||||
// MinHTLC is the smallest value HTLC this node will forward, expressed
|
||||
// in millisatoshi.
|
||||
MinHTLC lnwire.MilliSatoshi
|
||||
|
||||
// MaxHTLC is the largest value HTLC this node will forward, expressed
|
||||
// in millisatoshi.
|
||||
MaxHTLC lnwire.MilliSatoshi
|
||||
|
||||
// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
|
||||
// ANY HTLC, expressed in mSAT's.
|
||||
FeeBaseMSat lnwire.MilliSatoshi
|
||||
|
||||
// FeeProportionalMillionths is the rate that the node will charge for
|
||||
// HTLCs for each millionth of a satoshi forwarded.
|
||||
FeeProportionalMillionths lnwire.MilliSatoshi
|
||||
|
||||
// ToNode is the public key of the node that this directed edge leads
|
||||
// to. Using this pub key, the channel graph can further be traversed.
|
||||
ToNode [33]byte
|
||||
|
||||
// InboundFee is the fee that must be paid for incoming HTLCs.
|
||||
//
|
||||
// NOTE: for our kvdb implementation of the graph store, inbound fees
|
||||
// are still only persisted as part of extra opaque data and so this
|
||||
// field is not explicitly stored but is rather populated from the
|
||||
// ExtraOpaqueData field on deserialization. For our SQL implementation,
|
||||
// this field will be explicitly persisted in the database.
|
||||
InboundFee fn.Option[lnwire.Fee]
|
||||
|
||||
// ExtraOpaqueData is the set of data that was appended to this
|
||||
// message, some of which we may not actually know how to iterate or
|
||||
// parse. By holding onto this data, we ensure that we're able to
|
||||
// properly validate the set of signatures that cover these new fields,
|
||||
// and ensure we're able to make upgrades to the network in a forwards
|
||||
// compatible manner.
|
||||
ExtraOpaqueData lnwire.ExtraOpaqueData
|
||||
}
|
||||
|
||||
// IsDisabled determines whether the edge has the disabled bit set.
|
||||
func (c *ChannelEdgePolicy) IsDisabled() bool {
|
||||
return c.ChannelFlags.IsDisabled()
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/lightningnetwork/lnd/fn/v2"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
)
|
||||
|
||||
// Node represents an individual vertex/node within the channel graph.
|
||||
// A node is connected to other nodes by one or more channel edges emanating
|
||||
// from it. As the graph is directed, a node will also have an incoming edge
|
||||
// attached to it for each outgoing edge.
|
||||
type Node struct {
|
||||
// Version is the gossip version that this node was advertised on.
|
||||
Version lnwire.GossipVersion
|
||||
|
||||
// PubKeyBytes is the raw bytes of the public key of the target node.
|
||||
PubKeyBytes [33]byte
|
||||
pubKey *btcec.PublicKey
|
||||
|
||||
// LastUpdate is the last time the vertex information for this node has
|
||||
// been updated.
|
||||
LastUpdate time.Time
|
||||
|
||||
// Address is the TCP address this node is reachable over.
|
||||
Addresses []net.Addr
|
||||
|
||||
// Color is the selected color for the node.
|
||||
Color fn.Option[color.RGBA]
|
||||
|
||||
// Alias is a nick-name for the node. The alias can be used to confirm
|
||||
// a node's identity or to serve as a short ID for an address book.
|
||||
Alias fn.Option[string]
|
||||
|
||||
// AuthSigBytes is the raw signature under the advertised public key
|
||||
// which serves to authenticate the attributes announced by this node.
|
||||
AuthSigBytes []byte
|
||||
|
||||
// Features is the list of protocol features supported by this node.
|
||||
Features *lnwire.FeatureVector
|
||||
|
||||
// ExtraOpaqueData is the set of data that was appended to this
|
||||
// message, some of which we may not actually know how to iterate or
|
||||
// parse. By holding onto this data, we ensure that we're able to
|
||||
// properly validate the set of signatures that cover these new fields,
|
||||
// and ensure we're able to make upgrades to the network in a forwards
|
||||
// compatible manner.
|
||||
ExtraOpaqueData []byte
|
||||
}
|
||||
|
||||
// NodeV1Fields houses the fields that are specific to a version 1 node
|
||||
// announcement.
|
||||
type NodeV1Fields struct {
|
||||
// Address is the TCP address this node is reachable over.
|
||||
Addresses []net.Addr
|
||||
|
||||
// AuthSigBytes is the raw signature under the advertised public key
|
||||
// which serves to authenticate the attributes announced by this node.
|
||||
AuthSigBytes []byte
|
||||
|
||||
// Features is the list of protocol features supported by this node.
|
||||
Features *lnwire.RawFeatureVector
|
||||
|
||||
// Color is the selected color for the node.
|
||||
Color color.RGBA
|
||||
|
||||
// Alias is a nick-name for the node. The alias can be used to confirm
|
||||
// a node's identity or to serve as a short ID for an address book.
|
||||
Alias string
|
||||
|
||||
// LastUpdate is the last time the vertex information for this node has
|
||||
// been updated.
|
||||
LastUpdate time.Time
|
||||
|
||||
// ExtraOpaqueData is the set of data that was appended to this
|
||||
// message, some of which we may not actually know how to iterate or
|
||||
// parse. By holding onto this data, we ensure that we're able to
|
||||
// properly validate the set of signatures that cover these new fields,
|
||||
// and ensure we're able to make upgrades to the network in a forwards
|
||||
// compatible manner.
|
||||
ExtraOpaqueData []byte
|
||||
}
|
||||
|
||||
// NewV1Node creates a new version 1 node from the passed fields.
|
||||
func NewV1Node(pub route.Vertex, n *NodeV1Fields) *Node {
|
||||
return &Node{
|
||||
Version: lnwire.GossipVersion1,
|
||||
PubKeyBytes: pub,
|
||||
Addresses: n.Addresses,
|
||||
AuthSigBytes: n.AuthSigBytes,
|
||||
Features: lnwire.NewFeatureVector(
|
||||
n.Features, lnwire.Features,
|
||||
),
|
||||
Color: fn.Some(n.Color),
|
||||
Alias: fn.Some(n.Alias),
|
||||
LastUpdate: n.LastUpdate,
|
||||
ExtraOpaqueData: n.ExtraOpaqueData,
|
||||
}
|
||||
}
|
||||
|
||||
// NewV1ShellNode creates a new shell version 1 node.
|
||||
func NewV1ShellNode(pubKey route.Vertex) *Node {
|
||||
return NewShellNode(lnwire.GossipVersion1, pubKey)
|
||||
}
|
||||
|
||||
// NewShellNode creates a new shell node with the given gossip version and
|
||||
// public key.
|
||||
func NewShellNode(v lnwire.GossipVersion, pubKey route.Vertex) *Node {
|
||||
return &Node{
|
||||
Version: v,
|
||||
PubKeyBytes: pubKey,
|
||||
Features: lnwire.EmptyFeatureVector(),
|
||||
LastUpdate: time.Unix(0, 0),
|
||||
}
|
||||
}
|
||||
|
||||
// HaveAnnouncement returns true if we have received a node announcement for
|
||||
// this node. We determine this by checking if we have a signature for the
|
||||
// announcement.
|
||||
func (n *Node) HaveAnnouncement() bool {
|
||||
return len(n.AuthSigBytes) > 0
|
||||
}
|
||||
|
||||
// PubKey is the node's long-term identity public key. This key will be used to
|
||||
// authenticated any advertisements/updates sent by the node.
|
||||
//
|
||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||
// to fully deserialize the pubkey if absolutely necessary.
|
||||
func (n *Node) PubKey() (*btcec.PublicKey, error) {
|
||||
if n.pubKey != nil {
|
||||
return n.pubKey, nil
|
||||
}
|
||||
|
||||
key, err := btcec.ParsePubKey(n.PubKeyBytes[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
n.pubKey = key
|
||||
|
||||
return key, nil
|
||||
}
|
||||
Reference in new issue
Block a user