mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 14:17:56 +01:00
batch: update to allow for read-only calls
In this commit, we update the batch schedular so that it has the ability to do read-only calls. It will do a best effort attempt at keeping a transaction in read-only mode and then if any requests get added to a batch that require a read-write tx, then the entire batch's tx will be upgraded to use a read-write tx.
This commit is contained in:
@@ -26,7 +26,16 @@ func (t *BoltBatcher[Q]) ExecTx(_ context.Context, opts sqldb.TxOptions,
|
||||
txBody func(Q) error, reset func()) error {
|
||||
|
||||
if opts.ReadOnly() {
|
||||
return fmt.Errorf("read-only transactions not supported")
|
||||
return kvdb.View(t.db, func(tx kvdb.RTx) error {
|
||||
q, ok := any(tx).(Q)
|
||||
if !ok {
|
||||
return fmt.Errorf("unable to cast tx(%T) "+
|
||||
"into the type expected by the "+
|
||||
"BoltBatcher(%T)", tx, t)
|
||||
}
|
||||
|
||||
return txBody(q)
|
||||
}, reset)
|
||||
}
|
||||
|
||||
return kvdb.Update(t.db, func(tx kvdb.RwTx) error {
|
||||
|
||||
Reference in New Issue
Block a user