Skip to content

Commit f3a8fd8

Browse files
committed
graph+discovery: update graph/db gossip backlog interfaces to use iter.Seq2
This lets us emit a rich error if things fail when first creating the iterator, or if any of the yield attempts fail.
1 parent 0b3816a commit f3a8fd8

File tree

8 files changed

+239
-207
lines changed

8 files changed

+239
-207
lines changed

discovery/chan_series.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
114114
return func(yield func(lnwire.Message, error) bool) {
115115
// First, we'll query for all the set of channels that have an
116116
// update that falls within the specified horizon.
117-
chansInHorizon, err := c.graph.ChanUpdatesInHorizon(
117+
chansInHorizon := c.graph.ChanUpdatesInHorizon(
118118
startTime, endTime,
119119
)
120-
if err != nil {
121-
yield(nil, err)
122-
return
123-
}
124120

125-
for channel := range chansInHorizon {
121+
for channel, err := range chansInHorizon {
122+
if err != nil {
123+
yield(nil, err)
124+
return
125+
}
126126
// If the channel hasn't been fully advertised yet, or
127127
// is a private channel, then we'll skip it as we can't
128128
// construct a full authentication proof if one is
@@ -181,10 +181,14 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
181181
// Next, we'll send out all the node announcements that have an
182182
// update within the horizon as well. We send these second to
183183
// ensure that they follow any active channels they have.
184-
nodeAnnsInHorizon, err := c.graph.NodeUpdatesInHorizon(
184+
nodeAnnsInHorizon := c.graph.NodeUpdatesInHorizon(
185185
startTime, endTime, graphdb.WithIterPublicNodesOnly(),
186186
)
187-
for nodeAnn := range nodeAnnsInHorizon {
187+
for nodeAnn, err := range nodeAnnsInHorizon {
188+
if err != nil {
189+
yield(nil, err)
190+
return
191+
}
188192
nodeUpdate, err := nodeAnn.NodeAnnouncement(true)
189193
if err != nil {
190194
if !yield(nil, err) {

graph/builder.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,13 +593,14 @@ func (b *Builder) pruneZombieChans() error {
593593

594594
startTime := time.Unix(0, 0)
595595
endTime := time.Now().Add(-1 * chanExpiry)
596-
oldEdgesIter, err := b.cfg.Graph.ChanUpdatesInHorizon(startTime, endTime)
597-
if err != nil {
598-
return fmt.Errorf("unable to fetch expired channel updates "+
599-
"chans: %v", err)
600-
}
596+
oldEdgesIter := b.cfg.Graph.ChanUpdatesInHorizon(startTime, endTime)
597+
598+
for u, err := range oldEdgesIter {
599+
if err != nil {
600+
return fmt.Errorf("unable to fetch expired "+
601+
"channel updates chans: %v", err)
602+
}
601603

602-
for u := range oldEdgesIter {
603604
err = filterPruneChans(u.Info, u.Policy1, u.Policy2)
604605
if err != nil {
605606
return fmt.Errorf("error filtering channels to "+
@@ -619,7 +620,7 @@ func (b *Builder) pruneZombieChans() error {
619620
toPrune = append(toPrune, chanID)
620621
log.Tracef("Pruning zombie channel with ChannelID(%v)", chanID)
621622
}
622-
err = b.cfg.Graph.DeleteChannelEdges(
623+
err := b.cfg.Graph.DeleteChannelEdges(
623624
b.cfg.StrictZombiePruning, true, toPrune...,
624625
)
625626
if err != nil {

graph/db/benchmark_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/btcsuite/btcd/chaincfg"
1616
"github.com/btcsuite/btclog/v2"
1717
"github.com/lightningnetwork/lnd/batch"
18+
"github.com/lightningnetwork/lnd/fn/v2"
1819
"github.com/lightningnetwork/lnd/graph/db/models"
1920
"github.com/lightningnetwork/lnd/kvdb"
2021
"github.com/lightningnetwork/lnd/kvdb/postgres"
@@ -788,9 +789,10 @@ func BenchmarkGraphReadMethods(b *testing.B) {
788789
{
789790
name: "NodeUpdatesInHorizon",
790791
fn: func(b testing.TB, store V1Store) {
791-
_, err := store.NodeUpdatesInHorizon(
792+
iter := store.NodeUpdatesInHorizon(
792793
time.Unix(0, 0), time.Now(),
793794
)
795+
_, err := fn.CollectErr(iter)
794796
require.NoError(b, err)
795797
},
796798
},
@@ -836,9 +838,10 @@ func BenchmarkGraphReadMethods(b *testing.B) {
836838
{
837839
name: "ChanUpdatesInHorizon",
838840
fn: func(b testing.TB, store V1Store) {
839-
_, err := store.ChanUpdatesInHorizon(
841+
iter := store.ChanUpdatesInHorizon(
840842
time.Unix(0, 0), time.Now(),
841843
)
844+
_, err := fn.CollectErr(iter)
842845
require.NoError(b, err)
843846
},
844847
},

0 commit comments

Comments
 (0)