fix(statetree): make StateTree.ForEach take layers into account
This likely isn't used anywhere, but this _should_ take layers into account (and I kind of just assumed it did).
This commit is contained in:
parent
7dd58efb84
commit
8a215df46b
@ -504,6 +504,25 @@ func (st *StateTree) MutateActor(addr address.Address, f func(*types.Actor) erro
|
||||
}
|
||||
|
||||
func (st *StateTree) ForEach(f func(address.Address, *types.Actor) error) error {
|
||||
// Walk through layers, if any.
|
||||
seen := make(map[address.Address]struct{})
|
||||
for i := len(st.snaps.layers) - 1; i >= 0; i-- {
|
||||
for addr, op := range st.snaps.layers[i].actors {
|
||||
if _, ok := seen[addr]; ok {
|
||||
continue
|
||||
}
|
||||
seen[addr] = struct{}{}
|
||||
if op.Delete {
|
||||
continue
|
||||
}
|
||||
if err := f(addr, &op.Act); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Now walk through the saved actors.
|
||||
var act types.Actor
|
||||
return st.root.ForEach(&act, func(k string) error {
|
||||
act := act // copy
|
||||
@ -512,6 +531,12 @@ func (st *StateTree) ForEach(f func(address.Address, *types.Actor) error) error
|
||||
return xerrors.Errorf("invalid address (%x) found in state tree key: %w", []byte(k), err)
|
||||
}
|
||||
|
||||
// no need to record anything here, there are no duplicates in the actors HAMT
|
||||
// iself.
|
||||
if _, ok := seen[addr]; ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return f(addr, &act)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user