diff --git a/chain/actors/builtin/datacap/state.go.template b/chain/actors/builtin/datacap/state.go.template index f5b993bfb..297f9f79f 100644 --- a/chain/actors/builtin/datacap/state.go.template +++ b/chain/actors/builtin/datacap/state.go.template @@ -49,7 +49,7 @@ func (s *state{{.v}}) GetState() interface{} { } func (s *state{{.v}}) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version{{.v}}, s.verifiedClients, cb) + return forEachClient(s.store, actors.Version{{.v}}, s.verifiedClients, cb) } func (s *state{{.v}}) verifiedClients() (adt.Map, error) { diff --git a/chain/actors/builtin/datacap/util.go b/chain/actors/builtin/datacap/util.go index da8e07a84..e1442055a 100644 --- a/chain/actors/builtin/datacap/util.go +++ b/chain/actors/builtin/datacap/util.go @@ -1,6 +1,7 @@ package datacap import ( + "github.com/multiformats/go-varint" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -37,17 +38,23 @@ func getDataCap(store adt.Store, ver actors.Version, root rootFunc, addr address return true, big.Div(dcap, verifreg.DataCapGranularity), nil } -func forEachCap(store adt.Store, ver actors.Version, root rootFunc, cb func(addr address.Address, dcap abi.StoragePower) error) error { +func forEachClient(store adt.Store, ver actors.Version, root rootFunc, cb func(addr address.Address, dcap abi.StoragePower) error) error { vh, err := root() if err != nil { return xerrors.Errorf("loading verified clients: %w", err) } var dcap abi.StoragePower return vh.ForEach(&dcap, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) + id, n, err := varint.FromUvarint([]byte(key)) + if n != len([]byte(key)) { + return xerrors.Errorf("could not get varint from address string") + } if err != nil { return err } + + a, err := address.NewIDAddress(id) + return cb(a, big.Div(dcap, verifreg.DataCapGranularity)) }) } diff --git a/chain/actors/builtin/datacap/v9.go b/chain/actors/builtin/datacap/v9.go index 9e03a4779..a6e4bbcd6 100644 --- a/chain/actors/builtin/datacap/v9.go +++ b/chain/actors/builtin/datacap/v9.go @@ -49,7 +49,7 @@ func (s *state9) GetState() interface{} { } func (s *state9) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version9, s.verifiedClients, cb) + return forEachClient(s.store, actors.Version9, s.verifiedClients, cb) } func (s *state9) verifiedClients() (adt.Map, error) { diff --git a/cmd/lotus-shed/migrations.go b/cmd/lotus-shed/migrations.go index a3157703d..ae5ce266c 100644 --- a/cmd/lotus-shed/migrations.go +++ b/cmd/lotus-shed/migrations.go @@ -163,7 +163,7 @@ func checkStateInvariants(ctx context.Context, oldStateRoot cid.Cid, newStateRoo if !ok { return xerrors.Errorf("datacap for address: %s not found in datacap state", addr) } - if dcap != oldDcap { + if !dcap.Equals(oldDcap) { return xerrors.Errorf("datacap for address: %s do not match. verifreg: %d, datacap: %d", addr, oldDcap, dcap) } }