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
+13
-4
@@ -431,11 +431,13 @@ func (frs *failingRetributionStore) Remove(key *wire.OutPoint) error {
|
||||
return frs.rs.Remove(key)
|
||||
}
|
||||
|
||||
func (frs *failingRetributionStore) ForAll(cb func(*retributionInfo) error) error {
|
||||
func (frs *failingRetributionStore) ForAll(cb func(*retributionInfo) error,
|
||||
reset func()) error {
|
||||
|
||||
frs.mu.Lock()
|
||||
defer frs.mu.Unlock()
|
||||
|
||||
return frs.rs.ForAll(cb)
|
||||
return frs.rs.ForAll(cb, reset)
|
||||
}
|
||||
|
||||
// Parse the pubkeys in the breached outputs.
|
||||
@@ -592,10 +594,13 @@ func (rs *mockRetributionStore) Remove(key *wire.OutPoint) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rs *mockRetributionStore) ForAll(cb func(*retributionInfo) error) error {
|
||||
func (rs *mockRetributionStore) ForAll(cb func(*retributionInfo) error,
|
||||
reset func()) error {
|
||||
|
||||
rs.mu.Lock()
|
||||
defer rs.mu.Unlock()
|
||||
|
||||
reset()
|
||||
for _, retInfo := range rs.state {
|
||||
if err := cb(copyRetInfo(retInfo)); err != nil {
|
||||
return err
|
||||
@@ -717,6 +722,8 @@ func countRetributions(t *testing.T, rs RetributionStore) int {
|
||||
err := rs.ForAll(func(_ *retributionInfo) error {
|
||||
count++
|
||||
return nil
|
||||
}, func() {
|
||||
count = 0
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unable to list retributions in db: %v", err)
|
||||
@@ -919,7 +926,7 @@ restartCheck:
|
||||
// Construct a set of all channel points presented by the store. Entries
|
||||
// are only be added to the set if their corresponding retribution
|
||||
// information matches the test vector.
|
||||
var foundSet = make(map[wire.OutPoint]struct{})
|
||||
var foundSet map[wire.OutPoint]struct{}
|
||||
|
||||
// Iterate through the stored retributions, checking to see if we have
|
||||
// an equivalent retribution in the test vector. This will return an
|
||||
@@ -948,6 +955,8 @@ restartCheck:
|
||||
}
|
||||
|
||||
return nil
|
||||
}, func() {
|
||||
foundSet = make(map[wire.OutPoint]struct{})
|
||||
}); err != nil {
|
||||
t.Fatalf("failed to iterate over persistent retributions: %v",
|
||||
err)
|
||||
|
||||
Reference in new issue
Block a user