rpc: re-write GetNetworkInfo implementation to use single db transaction

This commit re-writes the GetNetworkInfo implenetaiton to use a single
database transaction. We’re now able to do this due to the recent
change in the API for the ChannelGraph struct and it’s related objects.
The recent change allows the passed callback to accept a db
transaction, with this, the callback is now able to issue another
traversal routine _within_ the prior one.
This commit is contained in:
Olaoluwa Osuntokun
2017-04-14 13:17:51 -07:00
parent 79807022a5
commit 7ac50b060e
2 changed files with 55 additions and 44 deletions

View File

@@ -11,6 +11,7 @@ import (
"sync/atomic"
"time"
"github.com/boltdb/bolt"
"github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/brontide"
"github.com/lightningnetwork/lnd/chainntnfs"
@@ -340,8 +341,9 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
if err != nil {
return nil, err
}
err = sourceNode.ForEachChannel(nil, func(_ *channeldb.ChannelEdgeInfo,
policy *channeldb.ChannelEdgePolicy) error {
err = sourceNode.ForEachChannel(nil, func(_ *bolt.Tx,
_ *channeldb.ChannelEdgeInfo, policy *channeldb.ChannelEdgePolicy) error {
pubStr := string(policy.Node.PubKey.SerializeCompressed())
// Add addresses from channel graph/NodeAnnouncements to the