polish(statetree): accept a context in statetree diff for timeouts
- this operation can take a while, this changes gives users the option to abort if it takes "too long".
This commit is contained in:
parent
6a5b94ca3b
commit
d02a2a2cfa
@ -547,7 +547,7 @@ func (st *StateTree) Version() types.StateTreeVersion {
|
||||
return st.version
|
||||
}
|
||||
|
||||
func Diff(oldTree, newTree *StateTree) (map[string]types.Actor, error) {
|
||||
func Diff(ctx context.Context, oldTree, newTree *StateTree) (map[string]types.Actor, error) {
|
||||
out := map[string]types.Actor{}
|
||||
|
||||
var (
|
||||
@ -555,6 +555,10 @@ func Diff(oldTree, newTree *StateTree) (map[string]types.Actor, error) {
|
||||
buf = bytes.NewReader(nil)
|
||||
)
|
||||
if err := newTree.root.ForEach(&ncval, func(k string) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
var act types.Actor
|
||||
|
||||
addr, err := address.NewFromBytes([]byte(k))
|
||||
@ -582,6 +586,7 @@ func Diff(oldTree, newTree *StateTree) (map[string]types.Actor, error) {
|
||||
out[addr.String()] = act
|
||||
|
||||
return nil
|
||||
}
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -705,7 +705,7 @@ func (a *StateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid.
|
||||
return nil, xerrors.Errorf("failed to load new state tree: %w", err)
|
||||
}
|
||||
|
||||
return state.Diff(oldTree, newTree)
|
||||
return state.Diff(ctx, oldTree, newTree)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MinerSectors, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user