2020-09-23 22:36:56 +00:00
|
|
|
package verifreg
|
|
|
|
|
|
|
|
import (
|
2022-06-14 15:00:51 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-09-23 22:36:56 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2023-11-14 00:06:11 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg"
|
|
|
|
|
2020-09-24 00:01:40 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
2020-09-23 22:36:56 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
|
|
|
)
|
|
|
|
|
2021-01-19 00:06:16 +00:00
|
|
|
// taking this as a function instead of asking the caller to call it helps reduce some of the error
|
|
|
|
// checking boilerplate.
|
|
|
|
//
|
|
|
|
// "go made me do it"
|
|
|
|
type rootFunc func() (adt.Map, error)
|
|
|
|
|
2021-01-16 04:12:31 +00:00
|
|
|
// Assumes that the bitwidth for v3 HAMTs is the DefaultHamtBitwidth
|
2021-01-19 00:06:16 +00:00
|
|
|
func getDataCap(store adt.Store, ver actors.Version, root rootFunc, addr address.Address) (bool, abi.StoragePower, error) {
|
2020-09-23 22:36:56 +00:00
|
|
|
if addr.Protocol() != address.ID {
|
|
|
|
return false, big.Zero(), xerrors.Errorf("can only look up ID addresses")
|
|
|
|
}
|
2021-01-19 00:06:16 +00:00
|
|
|
vh, err := root()
|
2020-09-23 22:36:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, big.Zero(), xerrors.Errorf("loading verifreg: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var dcap abi.StoragePower
|
|
|
|
if found, err := vh.Get(abi.AddrKey(addr), &dcap); err != nil {
|
|
|
|
return false, big.Zero(), xerrors.Errorf("looking up addr: %w", err)
|
|
|
|
} else if !found {
|
|
|
|
return false, big.Zero(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, dcap, nil
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:12:31 +00:00
|
|
|
// Assumes that the bitwidth for v3 HAMTs is the DefaultHamtBitwidth
|
2021-01-19 00:06:16 +00:00
|
|
|
func forEachCap(store adt.Store, ver actors.Version, root rootFunc, cb func(addr address.Address, dcap abi.StoragePower) error) error {
|
|
|
|
vh, err := root()
|
2020-09-23 22:36:56 +00:00
|
|
|
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))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return cb(a, dcap)
|
|
|
|
})
|
|
|
|
}
|
2022-02-23 02:25:30 +00:00
|
|
|
|
|
|
|
func getRemoveDataCapProposalID(store adt.Store, ver actors.Version, root rootFunc, verifier address.Address, client address.Address) (bool, uint64, error) {
|
|
|
|
if verifier.Protocol() != address.ID {
|
|
|
|
return false, 0, xerrors.Errorf("can only look up ID addresses")
|
|
|
|
}
|
|
|
|
if client.Protocol() != address.ID {
|
|
|
|
return false, 0, xerrors.Errorf("can only look up ID addresses")
|
|
|
|
}
|
|
|
|
vh, err := root()
|
|
|
|
if err != nil {
|
|
|
|
return false, 0, xerrors.Errorf("loading verifreg: %w", err)
|
|
|
|
}
|
2022-02-23 17:02:26 +00:00
|
|
|
if vh == nil {
|
|
|
|
return false, 0, xerrors.Errorf("remove data cap proposal hamt not found. you are probably using an incompatible version of actors")
|
|
|
|
}
|
2022-02-23 02:25:30 +00:00
|
|
|
|
|
|
|
var id verifreg.RmDcProposalID
|
|
|
|
if found, err := vh.Get(abi.NewAddrPairKey(verifier, client), &id); err != nil {
|
|
|
|
return false, 0, xerrors.Errorf("looking up addr pair: %w", err)
|
|
|
|
} else if !found {
|
|
|
|
return false, 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, id.ProposalID, nil
|
|
|
|
}
|