channeldb: add SchedulerOp arg to graph update methods

This commit is contained in:
Johan T. Halseth 2021-01-27 13:35:32 +01:00
parent e3b529939e
commit b5d6d7b4fd
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -458,12 +458,20 @@ func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
// channel update. // channel update.
// //
// TODO(roasbeef): also need sig of announcement // TODO(roasbeef): also need sig of announcement
func (c *ChannelGraph) AddLightningNode(node *LightningNode) error { func (c *ChannelGraph) AddLightningNode(node *LightningNode,
return c.nodeScheduler.Execute(&batch.Request{ op ...batch.SchedulerOption) error {
r := &batch.Request{
Update: func(tx kvdb.RwTx) error { Update: func(tx kvdb.RwTx) error {
return addLightningNode(tx, node) return addLightningNode(tx, node)
}, },
}) }
for _, f := range op {
f(r)
}
return c.nodeScheduler.Execute(r)
} }
func addLightningNode(tx kvdb.RwTx, node *LightningNode) error { func addLightningNode(tx kvdb.RwTx, node *LightningNode) error {
@ -588,9 +596,11 @@ func (c *ChannelGraph) deleteLightningNode(nodes kvdb.RwBucket,
// involved in creation of the channel, and the set of features that the channel // involved in creation of the channel, and the set of features that the channel
// supports. The chanPoint and chanID are used to uniquely identify the edge // supports. The chanPoint and chanID are used to uniquely identify the edge
// globally within the database. // globally within the database.
func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo) error { func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo,
op ...batch.SchedulerOption) error {
var alreadyExists bool var alreadyExists bool
return c.chanScheduler.Execute(&batch.Request{ r := &batch.Request{
Reset: func() { Reset: func() {
alreadyExists = false alreadyExists = false
}, },
@ -618,7 +628,13 @@ func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo) error {
return nil return nil
} }
}, },
}) }
for _, f := range op {
f(r)
}
return c.chanScheduler.Execute(r)
} }
// addChannelEdge is the private form of AddChannelEdge that allows callers to // addChannelEdge is the private form of AddChannelEdge that allows callers to
@ -1994,12 +2010,15 @@ func delChannelEdge(edges, edgeIndex, chanIndex, zombieIndex,
// updated, otherwise it's the second node's information. The node ordering is // updated, otherwise it's the second node's information. The node ordering is
// determined by the lexicographical ordering of the identity public keys of the // determined by the lexicographical ordering of the identity public keys of the
// nodes on either side of the channel. // nodes on either side of the channel.
func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error { func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy,
op ...batch.SchedulerOption) error {
var ( var (
isUpdate1 bool isUpdate1 bool
edgeNotFound bool edgeNotFound bool
) )
return c.chanScheduler.Execute(&batch.Request{
r := &batch.Request{
Reset: func() { Reset: func() {
isUpdate1 = false isUpdate1 = false
edgeNotFound = false edgeNotFound = false
@ -2028,7 +2047,13 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error {
return nil return nil
} }
}, },
}) }
for _, f := range op {
f(r)
}
return c.chanScheduler.Execute(r)
} }
func (c *ChannelGraph) updateEdgeCache(e *ChannelEdgePolicy, isUpdate1 bool) { func (c *ChannelGraph) updateEdgeCache(e *ChannelEdgePolicy, isUpdate1 bool) {