review fixes

This commit is contained in:
Geoff Stuart 2022-10-07 00:25:00 -04:00
parent c6eb7b69e6
commit a629bcab8d
4 changed files with 12 additions and 5 deletions

View File

@ -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) {

View File

@ -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))
})
}

View File

@ -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) {

View File

@ -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)
}
}