Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions autopilot/prefattach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
return nil, nil, err
}
edgePolicy := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(),
Expand All @@ -528,6 +529,7 @@ func (d *testDBGraph) addRandChannel(node1, node2 *btcec.PublicKey,
return nil, nil, err
}
edgePolicy = &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
ChannelID: chanID.ToUint64(),
LastUpdate: time.Now(),
Expand Down
19 changes: 6 additions & 13 deletions discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3415,19 +3415,12 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
// different alias. This might mean that SigBytes is incorrect as it
// signs a different SCID than the database SCID, but since there will
// only be a difference if AuthProof == nil, this is fine.
update := &models.ChannelEdgePolicy{
SigBytes: upd.Signature.ToSignatureBytes(),
ChannelID: chanInfo.ChannelID,
LastUpdate: timestamp,
MessageFlags: upd.MessageFlags,
ChannelFlags: upd.ChannelFlags,
TimeLockDelta: upd.TimeLockDelta,
MinHTLC: upd.HtlcMinimumMsat,
MaxHTLC: upd.HtlcMaximumMsat,
FeeBaseMSat: lnwire.MilliSatoshi(upd.BaseFee),
FeeProportionalMillionths: lnwire.MilliSatoshi(upd.FeeRate),
InboundFee: upd.InboundFee.ValOpt(),
ExtraOpaqueData: upd.ExtraOpaqueData,
update, err := models.ChanEdgePolicyFromWire(
chanInfo.ChannelID, upd,
)
if err != nil {
nMsg.err <- err
return nil, false
}

if err := d.cfg.Graph.UpdateEdge(ctx, update, ops...); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion docs/release-notes/release-notes-0.21.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@
* Prepare the graph DB for handling gossip V2
nodes and channels [1](https://github.com/lightningnetwork/lnd/pull/10339)
[2](https://github.com/lightningnetwork/lnd/pull/10379)
[3](https://github.com/lightningnetwork/lnd/pull/10380).
[3](https://github.com/lightningnetwork/lnd/pull/10380)
[4](https://github.com/lightningnetwork/lnd/pull/10542).

## Code Health

Expand Down
37 changes: 16 additions & 21 deletions graph/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,19 +952,12 @@ func (b *Builder) ApplyChannelUpdate(msg *lnwire.ChannelUpdate1) bool {
return false
}

update := &models.ChannelEdgePolicy{
SigBytes: msg.Signature.ToSignatureBytes(),
ChannelID: msg.ShortChannelID.ToUint64(),
LastUpdate: time.Unix(int64(msg.Timestamp), 0),
MessageFlags: msg.MessageFlags,
ChannelFlags: msg.ChannelFlags,
TimeLockDelta: msg.TimeLockDelta,
MinHTLC: msg.HtlcMinimumMsat,
MaxHTLC: msg.HtlcMaximumMsat,
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
InboundFee: msg.InboundFee.ValOpt(),
ExtraOpaqueData: msg.ExtraOpaqueData,
update, err := models.ChanEdgePolicyFromWire(
msg.ShortChannelID.ToUint64(), msg,
)
if err != nil {
log.Errorf("Unable to parse channel update: %v", err)
return false
}

err = b.UpdateEdge(ctx, update)
Expand Down Expand Up @@ -1050,8 +1043,8 @@ func (b *Builder) addEdge(ctx context.Context, edge *models.ChannelEdgeInfo,

// Prior to processing the announcement we first check if we
// already know of this channel, if so, then we can exit early.
_, _, exists, isZombie, err := b.cfg.Graph.HasChannelEdge(
edge.ChannelID,
exists, isZombie, err := b.cfg.Graph.HasChannelEdge(
edge.Version, edge.ChannelID,
)
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
return fmt.Errorf("unable to check for edge existence: %w",
Expand Down Expand Up @@ -1152,7 +1145,7 @@ func (b *Builder) updateEdge(ctx context.Context,
defer b.channelEdgeMtx.Unlock(policy.ChannelID)

edge1Timestamp, edge2Timestamp, exists, isZombie, err :=
b.cfg.Graph.HasChannelEdge(policy.ChannelID)
b.cfg.Graph.HasV1ChannelEdge(policy.ChannelID)
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
return fmt.Errorf("unable to check for edge existence: %w", err)
}
Expand Down Expand Up @@ -1283,7 +1276,7 @@ func (b *Builder) ForAllOutgoingChannels(ctx context.Context,
reset func()) error {

return b.cfg.Graph.ForEachNodeChannel(
ctx, b.cfg.SelfNode,
ctx, lnwire.GossipVersion1, b.cfg.SelfNode,
func(c *models.ChannelEdgeInfo, e *models.ChannelEdgePolicy,
_ *models.ChannelEdgePolicy) error {

Expand Down Expand Up @@ -1338,8 +1331,8 @@ func (b *Builder) IsPublicNode(node route.Vertex) (bool, error) {
//
// NOTE: This method is part of the ChannelGraphSource interface.
func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
_, _, exists, isZombie, _ := b.cfg.Graph.HasChannelEdge(
chanID.ToUint64(),
exists, isZombie, _ := b.cfg.Graph.HasChannelEdge(
lnwire.GossipVersion1, chanID.ToUint64(),
)

return exists || isZombie
Expand All @@ -1350,7 +1343,9 @@ func (b *Builder) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
//
// NOTE: This method is part of the ChannelGraphSource interface.
func (b *Builder) IsZombieEdge(chanID lnwire.ShortChannelID) (bool, error) {
_, _, _, isZombie, err := b.cfg.Graph.HasChannelEdge(chanID.ToUint64())
_, isZombie, err := b.cfg.Graph.HasChannelEdge(
lnwire.GossipVersion1, chanID.ToUint64(),
)

return isZombie, err
}
Expand All @@ -1363,7 +1358,7 @@ func (b *Builder) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
timestamp time.Time, flags lnwire.ChanUpdateChanFlags) bool {

edge1Timestamp, edge2Timestamp, exists, isZombie, err :=
b.cfg.Graph.HasChannelEdge(chanID.ToUint64())
b.cfg.Graph.HasV1ChannelEdge(chanID.ToUint64())
if err != nil {
log.Debugf("Check stale edge policy got error: %v", err)
return false
Expand Down
30 changes: 19 additions & 11 deletions graph/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
require.NoError(t, err)

edgePolicy := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
ChannelID: edge.ChannelID,
LastUpdate: testTime,
Expand Down Expand Up @@ -318,7 +319,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
}

// Check that the fundingTxs are in the graph db.
_, _, has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
if err != nil {
t.Fatalf("error looking for edge: %v", chanID1)
}
Expand All @@ -329,7 +330,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
t.Fatal("edge was marked as zombie")
}

_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
if err != nil {
t.Fatalf("error looking for edge: %v", chanID2)
}
Expand Down Expand Up @@ -386,7 +387,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
// The channel with chanID2 should not be in the database anymore,
// since it is not confirmed on the longest chain. chanID1 should
// still be.
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
require.NoError(t, err)

if !has {
Expand All @@ -396,7 +397,7 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
t.Fatal("edge was marked as zombie")
}

_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
if err != nil {
t.Fatalf("error looking for edge: %v", chanID2)
}
Expand Down Expand Up @@ -526,7 +527,7 @@ func TestDisconnectedBlocks(t *testing.T) {
}

// Check that the fundingTxs are in the graph db.
_, _, has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
has, isZombie, err := ctx.graph.HasChannelEdge(chanID1)
if err != nil {
t.Fatalf("error looking for edge: %v", chanID1)
}
Expand All @@ -537,7 +538,7 @@ func TestDisconnectedBlocks(t *testing.T) {
t.Fatal("edge was marked as zombie")
}

_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
if err != nil {
t.Fatalf("error looking for edge: %v", chanID2)
}
Expand Down Expand Up @@ -579,7 +580,7 @@ func TestDisconnectedBlocks(t *testing.T) {

// chanID2 should not be in the database anymore, since it is not
// confirmed on the longest chain. chanID1 should still be.
_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
has, isZombie, err = ctx.graph.HasChannelEdge(chanID1)
if err != nil {
t.Fatalf("error looking for edge: %v", chanID1)
}
Expand All @@ -590,7 +591,7 @@ func TestDisconnectedBlocks(t *testing.T) {
t.Fatal("edge was marked as zombie")
}

_, _, has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
has, isZombie, err = ctx.graph.HasChannelEdge(chanID2)
if err != nil {
t.Fatalf("error looking for edge: %v", chanID2)
}
Expand Down Expand Up @@ -664,7 +665,7 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) {
}

// The router should now be aware of the channel we created above.
_, _, hasChan, isZombie, err := ctx.graph.HasChannelEdge(
hasChan, isZombie, err := ctx.graph.HasChannelEdge(
chanID1.ToUint64(),
)
if err != nil {
Expand Down Expand Up @@ -746,7 +747,7 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) {

// At this point, the channel that was pruned should no longer be known
// by the router.
_, _, hasChan, isZombie, err = ctx.graph.HasChannelEdge(
hasChan, isZombie, err = ctx.graph.HasChannelEdge(
chanID1.ToUint64(),
)
if err != nil {
Expand Down Expand Up @@ -1219,6 +1220,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {

// We'll also add two edge policies, one for each direction.
edgePolicy := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
ChannelID: edge.ChannelID,
LastUpdate: updateTimeStamp,
Expand All @@ -1233,6 +1235,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {
}

edgePolicy = &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
ChannelID: edge.ChannelID,
LastUpdate: updateTimeStamp,
Expand Down Expand Up @@ -1557,6 +1560,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
}

edgePolicy := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
MessageFlags: lnwire.ChanUpdateMsgFlags(
edge.MessageFlags,
Expand Down Expand Up @@ -1715,7 +1719,7 @@ func assertChannelsPruned(t *testing.T, graph *graphdb.VersionedGraph,

for _, channel := range channels {
_, shouldPrune := pruned[channel.ChannelID]
_, _, exists, isZombie, err := graph.HasChannelEdge(
exists, isZombie, err := graph.HasChannelEdge(
channel.ChannelID,
)
if err != nil {
Expand Down Expand Up @@ -1939,7 +1943,9 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
channelFlags |= lnwire.ChanUpdateDisabled
}

//nolint:ll
edgePolicy := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
MessageFlags: msgFlags,
ChannelFlags: channelFlags,
Expand Down Expand Up @@ -1970,7 +1976,9 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
}
channelFlags |= lnwire.ChanUpdateDirection

//nolint:ll
edgePolicy := &models.ChannelEdgePolicy{
Version: lnwire.GossipVersion1,
SigBytes: testSig.Serialize(),
MessageFlags: msgFlags,
ChannelFlags: channelFlags,
Expand Down
Loading
Loading