Skip to content

Commit

Permalink
Merge pull request #3971 from filecoin-project/init-remove
Browse files Browse the repository at this point in the history
add init.State#Remove() for testing.
  • Loading branch information
magik6k committed Sep 23, 2020
2 parents c46e157 + f1ab1af commit b28b8b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions chain/actors/builtin/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ type State interface {
NetworkName() (dtypes.NetworkName, error)

ForEachActor(func(id abi.ActorID, address address.Address) error) error

// Remove exists to support tooling that manipulates state for testing.
// It should not be used in production code, as init actor entries are
// immutable.
Remove(addrs ...address.Address) error
}
19 changes: 19 additions & 0 deletions chain/actors/builtin/init/v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"

Expand Down Expand Up @@ -46,3 +47,21 @@ func (s *state0) ForEachActor(cb func(id abi.ActorID, address address.Address) e
func (s *state0) NetworkName() (dtypes.NetworkName, error) {
return dtypes.NetworkName(s.State.NetworkName), nil
}

func (s *state0) Remove(addrs ...address.Address) (err error) {
m, err := adt0.AsMap(s.store, s.State.AddressMap)
if err != nil {
return err
}
for _, addr := range addrs {
if err = m.Delete(abi.AddrKey(addr)); err != nil {
return xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err)
}
}
amr, err := m.Root()
if err != nil {
return xerrors.Errorf("failed to get address map root: %w", err)
}
s.State.AddressMap = amr
return nil
}

0 comments on commit b28b8b9

Please sign in to comment.