batch: dont expose kvdb.RwTx in batch.SchedulerOptions

Currently, a few of the graph KVStore methods take the
`batch.SchedulerOptions` param. This is only used to set the LazyAdd
option. A SchedulerOption is a functional option that takes a
`batch.Request` which has bolt-specific fields in it. This commit
restructures things a bit such that the `batch.Request` type is no
longer part of the `batch.SchedulerOptions` - this will make it easier
to implement the graph store with a different DB backend.
This commit is contained in:
Elle Mouton committed 2025-05-22 14:14:40 +02:00
1 parent 5d7c6c4b60
commit 11b27f07da
3 files changed
+40 -23

No files matched your search

+6 -19
View File
@@ -848,18 +848,15 @@ func (c *KVStore) SetSourceNode(node *models.LightningNode) error {
//
// TODO(roasbeef): also need sig of announcement.
func (c *KVStore) AddLightningNode(node *models.LightningNode,
op ...batch.SchedulerOption) error {
opts ...batch.SchedulerOption) error {
r := &batch.Request{
Opts: batch.NewSchedulerOptions(opts...),
Update: func(tx kvdb.RwTx) error {
return addLightningNode(tx, node)
},
}
for _, f := range op {
f(r)
}
return c.nodeScheduler.Execute(r)
}
@@ -986,10 +983,11 @@ func (c *KVStore) deleteLightningNode(nodes kvdb.RwBucket,
// supports. The chanPoint and chanID are used to uniquely identify the edge
// globally within the database.
func (c *KVStore) AddChannelEdge(edge *models.ChannelEdgeInfo,
op ...batch.SchedulerOption) error {
opts ...batch.SchedulerOption) error {
var alreadyExists bool
r := &batch.Request{
Opts: batch.NewSchedulerOptions(opts...),
Reset: func() {
alreadyExists = false
},
@@ -1019,14 +1017,6 @@ func (c *KVStore) AddChannelEdge(edge *models.ChannelEdgeInfo,
},
}
for _, f := range op {
if f == nil {
return fmt.Errorf("nil scheduler option was used")
}
f(r)
}
return c.chanScheduler.Execute(r)
}
@@ -2696,7 +2686,7 @@ func makeZombiePubkeys(info *models.ChannelEdgeInfo,
// determined by the lexicographical ordering of the identity public keys of the
// nodes on either side of the channel.
func (c *KVStore) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
op ...batch.SchedulerOption) (route.Vertex, route.Vertex, error) {
opts ...batch.SchedulerOption) (route.Vertex, route.Vertex, error) {
var (
isUpdate1 bool
@@ -2705,6 +2695,7 @@ func (c *KVStore) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
)
r := &batch.Request{
Opts: batch.NewSchedulerOptions(opts...),
Reset: func() {
isUpdate1 = false
edgeNotFound = false
@@ -2738,10 +2729,6 @@ func (c *KVStore) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
},
}
for _, f := range op {
f(r)
}
err := c.chanScheduler.Execute(r)
return from, to, err