multi: add reset closure to kvdb.View
This commit adds a reset() closure to the kvdb.View function which will be called before each retry (including the first) of the view transaction. The reset() closure can be used to reset external state (eg slices or maps) where the view closure puts intermediate results.
This commit is contained in:
47 files changed
+340
-82
No files matched your search
+12
-4
@@ -152,10 +152,12 @@ func (b *breachArbiter) start() error {
|
||||
brarLog.Tracef("Starting breach arbiter")
|
||||
|
||||
// Load all retributions currently persisted in the retribution store.
|
||||
breachRetInfos := make(map[wire.OutPoint]retributionInfo)
|
||||
var breachRetInfos map[wire.OutPoint]retributionInfo
|
||||
if err := b.cfg.Store.ForAll(func(ret *retributionInfo) error {
|
||||
breachRetInfos[ret.chanPoint] = *ret
|
||||
return nil
|
||||
}, func() {
|
||||
breachRetInfos = make(map[wire.OutPoint]retributionInfo)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1223,7 +1225,7 @@ type RetributionStore interface {
|
||||
// ForAll iterates over the existing on-disk contents and applies a
|
||||
// chosen, read-only callback to each. This method should ensure that it
|
||||
// immediately propagate any errors generated by the callback.
|
||||
ForAll(cb func(*retributionInfo) error) error
|
||||
ForAll(cb func(*retributionInfo) error, reset func()) error
|
||||
}
|
||||
|
||||
// retributionStore handles persistence of retribution states to disk and is
|
||||
@@ -1312,6 +1314,8 @@ func (rs *retributionStore) GetFinalizedTxn(
|
||||
finalTxBytes = justiceBkt.Get(chanBuf.Bytes())
|
||||
|
||||
return nil
|
||||
}, func() {
|
||||
finalTxBytes = nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1349,6 +1353,8 @@ func (rs *retributionStore) IsBreached(chanPoint *wire.OutPoint) (bool, error) {
|
||||
}
|
||||
|
||||
return nil
|
||||
}, func() {
|
||||
found = false
|
||||
})
|
||||
|
||||
return found, err
|
||||
@@ -1395,7 +1401,9 @@ func (rs *retributionStore) Remove(chanPoint *wire.OutPoint) error {
|
||||
|
||||
// ForAll iterates through all stored retributions and executes the passed
|
||||
// callback function on each retribution.
|
||||
func (rs *retributionStore) ForAll(cb func(*retributionInfo) error) error {
|
||||
func (rs *retributionStore) ForAll(cb func(*retributionInfo) error,
|
||||
reset func()) error {
|
||||
|
||||
return kvdb.View(rs.db, func(tx kvdb.RTx) error {
|
||||
// If the bucket does not exist, then there are no pending
|
||||
// retributions.
|
||||
@@ -1416,7 +1424,7 @@ func (rs *retributionStore) ForAll(cb func(*retributionInfo) error) error {
|
||||
|
||||
return cb(ret)
|
||||
})
|
||||
})
|
||||
}, reset)
|
||||
}
|
||||
|
||||
// Encode serializes the retribution into the passed byte stream.
|
||||
|
||||
Reference in new issue
Block a user