Skip to content

multi: update ChanUpdatesInHorizon and NodeUpdatesInHorizon to return iterators (iter.Seq[T]) #10128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
24 changes: 3 additions & 21 deletions discovery/chan_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
if err != nil {
return nil, err
}
for _, channel := range chansInHorizon {
for channel := range chansInHorizon {
// If the channel hasn't been fully advertised yet, or is a
// private channel, then we'll skip it as we can't construct a
// full authentication proof if one is requested.
Expand Down Expand Up @@ -163,30 +163,12 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
// within the horizon as well. We send these second to ensure that they
// follow any active channels they have.
nodeAnnsInHorizon, err := c.graph.NodeUpdatesInHorizon(
startTime, endTime,
startTime, endTime, graphdb.WithIterPublicNodesOnly(),
)
if err != nil {
return nil, err
}
for _, nodeAnn := range nodeAnnsInHorizon {
nodeAnn := nodeAnn

// Ensure we only forward nodes that are publicly advertised to
// prevent leaking information about nodes.
isNodePublic, err := c.graph.IsPublicNode(nodeAnn.PubKeyBytes)
if err != nil {
log.Errorf("Unable to determine if node %x is "+
"advertised: %v", nodeAnn.PubKeyBytes, err)
continue
}

if !isNodePublic {
log.Tracef("Skipping forwarding announcement for "+
"node %x due to being unadvertised",
nodeAnn.PubKeyBytes)
continue
}

for nodeAnn := range nodeAnnsInHorizon {
nodeUpdate, err := nodeAnn.NodeAnnouncement(true)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion fn/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/lightningnetwork/lnd/fn/v2

go 1.19
go 1.23

require (
github.com/stretchr/testify v1.8.1
Expand Down
15 changes: 15 additions & 0 deletions fn/iter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package fn

import "iter"

// Collect drains all of the elements from the passed iterator, returning a
// slice of the contents.
func Collect[T any](seq iter.Seq[T]) []T {

var ret []T
for i := range seq {
ret = append(ret, i)
}

return ret
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ require (
// store have been included in a tagged sqldb version.
replace github.com/lightningnetwork/lnd/sqldb => ./sqldb

// Replace fn package to use local version with iterator Collect function.
replace github.com/lightningnetwork/lnd/fn/v2 => ./fn

// This replace is for https://github.com/advisories/GHSA-25xm-hr59-7c27
replace github.com/ulikunitz/xz => github.com/ulikunitz/xz v0.5.11

Expand Down
2 changes: 1 addition & 1 deletion graph/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func (b *Builder) pruneZombieChans() error {
"chans: %v", err)
}

for _, u := range oldEdges {
for u := range oldEdges {
err = filterPruneChans(u.Info, u.Policy1, u.Policy2)
if err != nil {
return fmt.Errorf("error filtering channels to "+
Expand Down
Loading