Merge pull request #9804 from ellemouton/removeChanGraphCacheMu
graph/db: remove ChannelGraph cacheMu
This commit is contained in:
1 file changed
-35
@@ -41,11 +41,6 @@ type ChannelGraph struct {
|
|||||||
started atomic.Bool
|
started atomic.Bool
|
||||||
stopped atomic.Bool
|
stopped atomic.Bool
|
||||||
|
|
||||||
// cacheMu guards any writes to the graphCache. It should be held
|
|
||||||
// across the DB write call and the graphCache update to make the
|
|
||||||
// two updates as atomic as possible.
|
|
||||||
cacheMu sync.Mutex
|
|
||||||
|
|
||||||
graphCache *GraphCache
|
graphCache *GraphCache
|
||||||
|
|
||||||
*KVStore
|
*KVStore
|
||||||
@@ -283,9 +278,6 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
|
|||||||
func (c *ChannelGraph) AddLightningNode(node *models.LightningNode,
|
func (c *ChannelGraph) AddLightningNode(node *models.LightningNode,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
err := c.KVStore.AddLightningNode(node, op...)
|
err := c.KVStore.AddLightningNode(node, op...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -309,9 +301,6 @@ func (c *ChannelGraph) AddLightningNode(node *models.LightningNode,
|
|||||||
// DeleteLightningNode starts a new database transaction to remove a vertex/node
|
// DeleteLightningNode starts a new database transaction to remove a vertex/node
|
||||||
// from the database according to the node's public key.
|
// from the database according to the node's public key.
|
||||||
func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error {
|
func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error {
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
err := c.KVStore.DeleteLightningNode(nodePub)
|
err := c.KVStore.DeleteLightningNode(nodePub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -333,9 +322,6 @@ func (c *ChannelGraph) DeleteLightningNode(nodePub route.Vertex) error {
|
|||||||
func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
|
func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
err := c.KVStore.AddChannelEdge(edge, op...)
|
err := c.KVStore.AddChannelEdge(edge, op...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -358,9 +344,6 @@ func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
|
|||||||
// If the cache is enabled, the edge will be added back to the graph cache if
|
// If the cache is enabled, the edge will be added back to the graph cache if
|
||||||
// we still have a record of this channel in the DB.
|
// we still have a record of this channel in the DB.
|
||||||
func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
|
func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
err := c.KVStore.MarkEdgeLive(chanID)
|
err := c.KVStore.MarkEdgeLive(chanID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -397,9 +380,6 @@ func (c *ChannelGraph) MarkEdgeLive(chanID uint64) error {
|
|||||||
func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
|
func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
|
||||||
chanIDs ...uint64) error {
|
chanIDs ...uint64) error {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
infos, err := c.KVStore.DeleteChannelEdges(
|
infos, err := c.KVStore.DeleteChannelEdges(
|
||||||
strictZombiePruning, markZombie, chanIDs...,
|
strictZombiePruning, markZombie, chanIDs...,
|
||||||
)
|
)
|
||||||
@@ -429,9 +409,6 @@ func (c *ChannelGraph) DeleteChannelEdges(strictZombiePruning, markZombie bool,
|
|||||||
func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
|
func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) (
|
||||||
[]*models.ChannelEdgeInfo, error) {
|
[]*models.ChannelEdgeInfo, error) {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
edges, err := c.KVStore.DisconnectBlockAtHeight(height)
|
edges, err := c.KVStore.DisconnectBlockAtHeight(height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -460,9 +437,6 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
|||||||
blockHash *chainhash.Hash, blockHeight uint32) (
|
blockHash *chainhash.Hash, blockHeight uint32) (
|
||||||
[]*models.ChannelEdgeInfo, error) {
|
[]*models.ChannelEdgeInfo, error) {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
edges, nodes, err := c.KVStore.PruneGraph(
|
edges, nodes, err := c.KVStore.PruneGraph(
|
||||||
spentOutputs, blockHash, blockHeight,
|
spentOutputs, blockHash, blockHeight,
|
||||||
)
|
)
|
||||||
@@ -508,9 +482,6 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
|||||||
// that we only maintain a graph of reachable nodes. In the event that a pruned
|
// that we only maintain a graph of reachable nodes. In the event that a pruned
|
||||||
// node gains more channels, it will be re-added back to the graph.
|
// node gains more channels, it will be re-added back to the graph.
|
||||||
func (c *ChannelGraph) PruneGraphNodes() error {
|
func (c *ChannelGraph) PruneGraphNodes() error {
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
nodes, err := c.KVStore.PruneGraphNodes()
|
nodes, err := c.KVStore.PruneGraphNodes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -583,9 +554,6 @@ func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
|
|||||||
func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
|
func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
|
||||||
pubKey1, pubKey2 [33]byte) error {
|
pubKey1, pubKey2 [33]byte) error {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
err := c.KVStore.MarkEdgeZombie(chanID, pubKey1, pubKey2)
|
err := c.KVStore.MarkEdgeZombie(chanID, pubKey1, pubKey2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -608,9 +576,6 @@ func (c *ChannelGraph) MarkEdgeZombie(chanID uint64,
|
|||||||
func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
|
func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
|
||||||
defer c.cacheMu.Unlock()
|
|
||||||
|
|
||||||
from, to, err := c.KVStore.UpdateEdgePolicy(edge, op...)
|
from, to, err := c.KVStore.UpdateEdgePolicy(edge, op...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in new issue
Block a user