feat: api: new verified registry methods to get all allocations and claims (#11631)

* new verireg methods

* update changelog and add itest

* update itest and cli

* update new method's support till v9

* remove gateway APIs

* fix cli internal var names
This commit is contained in:
LexLuthr 2024-02-22 22:37:47 +04:00 committed by Phi-rjan
parent 1347bfb64e
commit 3f9b6837c9
34 changed files with 906 additions and 75 deletions

View File

@ -47,9 +47,42 @@ Replace the `CodeCid` field in the message trace (added in 1.23.4) with an `Invo
"Subcalls": [],
}
```
This means the trace now contains an accurate "snapshot" of the actor at the time of the call, information that may not be present in the final state-tree (e.g., due to reverts). This will hopefully improve the performance and accuracy of indexing services.
### Lotus API
2 new methods have benn added to the Lotus API called `GetAllAllocations` and `GetAllClaims` which lists all the available allocations and claims available in the actor state.
### Lotus CLI
The `filplus` commands used for listing allocations and claims have been updated. If no argument is provided to the either command, they will list out all the allocations and claims in the verified registry actor.
The output list columns have been modified to `AllocationID` and `ClaimID` instead of ID.
```shell
lotus filplus list-allocations --help
NAME:
lotus filplus list-allocations - List allocations available in verified registry actor or made by a client if specified
USAGE:
lotus filplus list-allocations [command options] clientAddress
OPTIONS:
--expired list only expired allocations (default: false)
--json output results in json format (default: false)
--help, -h show help
lotus filplus list-claims --help
NAME:
lotus filplus list-claims - List claims available in verified registry actor or made by provider if specified
USAGE:
lotus filplus list-claims [command options] providerAddress
OPTIONS:
--expired list only expired claims (default: false)
--help, -h show help
```
# v1.25.2 / 2024-01-11
This is an optional but **highly recommended feature release** of Lotus, as it includes fixes for synchronizations issues that users have experienced. The feature release also introduces `Lotus-Provider` in its alpha testing phase, as well as the ability to call external PC2-binaries during the sealing process.

View File

@ -559,10 +559,14 @@ type FullNode interface {
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
// StateGetAllocations returns the all the allocations for a given client.
StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) //perm:read
// StateGetAllAllocations returns the all the allocations available in verified registry actor.
StateGetAllAllocations(ctx context.Context, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) //perm:read
// StateGetClaim returns the claim for a given address and claim ID.
StateGetClaim(ctx context.Context, providerAddr address.Address, claimId verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) //perm:read
// StateGetClaims returns the all the claims for a given provider.
StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) //perm:read
// StateGetAllClaims returns the all the claims available in verified registry actor.
StateGetAllClaims(ctx context.Context, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) //perm:read
// StateComputeDataCID computes DataCID from a set of on-chain deals
StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) //perm:read
// StateLookupID retrieves the ID address of the given address

View File

@ -3188,6 +3188,36 @@ func (mr *MockFullNodeMockRecorder) StateGetActor(arg0, arg1, arg2 interface{})
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetActor", reflect.TypeOf((*MockFullNode)(nil).StateGetActor), arg0, arg1, arg2)
}
// StateGetAllAllocations mocks base method.
func (m *MockFullNode) StateGetAllAllocations(arg0 context.Context, arg1 types.TipSetKey) (map[verifreg.AllocationId]verifreg.Allocation, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StateGetAllAllocations", arg0, arg1)
ret0, _ := ret[0].(map[verifreg.AllocationId]verifreg.Allocation)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetAllAllocations indicates an expected call of StateGetAllAllocations.
func (mr *MockFullNodeMockRecorder) StateGetAllAllocations(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetAllAllocations", reflect.TypeOf((*MockFullNode)(nil).StateGetAllAllocations), arg0, arg1)
}
// StateGetAllClaims mocks base method.
func (m *MockFullNode) StateGetAllClaims(arg0 context.Context, arg1 types.TipSetKey) (map[verifreg.ClaimId]verifreg.Claim, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StateGetAllClaims", arg0, arg1)
ret0, _ := ret[0].(map[verifreg.ClaimId]verifreg.Claim)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetAllClaims indicates an expected call of StateGetAllClaims.
func (mr *MockFullNodeMockRecorder) StateGetAllClaims(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetAllClaims", reflect.TypeOf((*MockFullNode)(nil).StateGetAllClaims), arg0, arg1)
}
// StateGetAllocation mocks base method.
func (m *MockFullNode) StateGetAllocation(arg0 context.Context, arg1 address.Address, arg2 verifreg.AllocationId, arg3 types.TipSetKey) (*verifreg.Allocation, error) {
m.ctrl.T.Helper()

View File

@ -485,6 +485,10 @@ type FullNodeMethods struct {
StateGetActor func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*types.Actor, error) `perm:"read"`
StateGetAllAllocations func(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) `perm:"read"`
StateGetAllClaims func(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) `perm:"read"`
StateGetAllocation func(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) `perm:"read"`
StateGetAllocationForPendingDeal func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) `perm:"read"`
@ -3405,6 +3409,28 @@ func (s *FullNodeStub) StateGetActor(p0 context.Context, p1 address.Address, p2
return nil, ErrNotSupported
}
func (s *FullNodeStruct) StateGetAllAllocations(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) {
if s.Internal.StateGetAllAllocations == nil {
return *new(map[verifregtypes.AllocationId]verifregtypes.Allocation), ErrNotSupported
}
return s.Internal.StateGetAllAllocations(p0, p1)
}
func (s *FullNodeStub) StateGetAllAllocations(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) {
return *new(map[verifregtypes.AllocationId]verifregtypes.Allocation), ErrNotSupported
}
func (s *FullNodeStruct) StateGetAllClaims(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) {
if s.Internal.StateGetAllClaims == nil {
return *new(map[verifregtypes.ClaimId]verifregtypes.Claim), ErrNotSupported
}
return s.Internal.StateGetAllClaims(p0, p1)
}
func (s *FullNodeStub) StateGetAllClaims(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) {
return *new(map[verifregtypes.ClaimId]verifregtypes.Claim), ErrNotSupported
}
func (s *FullNodeStruct) StateGetAllocation(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) {
if s.Internal.StateGetAllocation == nil {
return nil, ErrNotSupported

View File

@ -537,10 +537,14 @@ type FullNode interface {
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
// StateGetAllocations returns the all the allocations for a given client.
StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) //perm:read
// StateGetAllAllocations returns the all the allocations available in verified registry actor.
StateGetAllAllocations(ctx context.Context, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) //perm:read
// StateGetClaim returns the claim for a given address and claim ID.
StateGetClaim(ctx context.Context, providerAddr address.Address, claimId verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) //perm:read
// StateGetClaims returns the all the claims for a given provider.
StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) //perm:read
// StateGetAllClaims returns the all the claims available in verified registry actor.
StateGetAllClaims(ctx context.Context, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) //perm:read
// StateLookupID retrieves the ID address of the given address
StateLookupID(context.Context, address.Address, types.TipSetKey) (address.Address, error) //perm:read
// StateAccountKey returns the public key address of the given ID address

View File

@ -280,6 +280,10 @@ type FullNodeMethods struct {
StateGetActor func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*types.Actor, error) `perm:"read"`
StateGetAllAllocations func(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) `perm:"read"`
StateGetAllClaims func(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) `perm:"read"`
StateGetAllocation func(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) `perm:"read"`
StateGetAllocationForPendingDeal func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) `perm:"read"`
@ -1837,6 +1841,28 @@ func (s *FullNodeStub) StateGetActor(p0 context.Context, p1 address.Address, p2
return nil, ErrNotSupported
}
func (s *FullNodeStruct) StateGetAllAllocations(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) {
if s.Internal.StateGetAllAllocations == nil {
return *new(map[verifregtypes.AllocationId]verifregtypes.Allocation), ErrNotSupported
}
return s.Internal.StateGetAllAllocations(p0, p1)
}
func (s *FullNodeStub) StateGetAllAllocations(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) {
return *new(map[verifregtypes.AllocationId]verifregtypes.Allocation), ErrNotSupported
}
func (s *FullNodeStruct) StateGetAllClaims(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) {
if s.Internal.StateGetAllClaims == nil {
return *new(map[verifregtypes.ClaimId]verifregtypes.Claim), ErrNotSupported
}
return s.Internal.StateGetAllClaims(p0, p1)
}
func (s *FullNodeStub) StateGetAllClaims(p0 context.Context, p1 types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) {
return *new(map[verifregtypes.ClaimId]verifregtypes.Claim), ErrNotSupported
}
func (s *FullNodeStruct) StateGetAllocation(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) {
if s.Internal.StateGetAllocation == nil {
return nil, ErrNotSupported

View File

@ -2338,6 +2338,36 @@ func (mr *MockFullNodeMockRecorder) StateGetActor(arg0, arg1, arg2 interface{})
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetActor", reflect.TypeOf((*MockFullNode)(nil).StateGetActor), arg0, arg1, arg2)
}
// StateGetAllAllocations mocks base method.
func (m *MockFullNode) StateGetAllAllocations(arg0 context.Context, arg1 types.TipSetKey) (map[verifreg.AllocationId]verifreg.Allocation, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StateGetAllAllocations", arg0, arg1)
ret0, _ := ret[0].(map[verifreg.AllocationId]verifreg.Allocation)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetAllAllocations indicates an expected call of StateGetAllAllocations.
func (mr *MockFullNodeMockRecorder) StateGetAllAllocations(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetAllAllocations", reflect.TypeOf((*MockFullNode)(nil).StateGetAllAllocations), arg0, arg1)
}
// StateGetAllClaims mocks base method.
func (m *MockFullNode) StateGetAllClaims(arg0 context.Context, arg1 types.TipSetKey) (map[verifreg.ClaimId]verifreg.Claim, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StateGetAllClaims", arg0, arg1)
ret0, _ := ret[0].(map[verifreg.ClaimId]verifreg.Claim)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetAllClaims indicates an expected call of StateGetAllClaims.
func (mr *MockFullNodeMockRecorder) StateGetAllClaims(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetAllClaims", reflect.TypeOf((*MockFullNode)(nil).StateGetAllClaims), arg0, arg1)
}
// StateGetAllocation mocks base method.
func (m *MockFullNode) StateGetAllocation(arg0 context.Context, arg1 address.Address, arg2 verifreg.AllocationId, arg3 types.TipSetKey) (*verifreg.Allocation, error) {
m.ctrl.T.Helper()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -81,8 +81,10 @@ type State interface {
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
GetAllocation(clientIdAddr address.Address, allocationId AllocationId) (*Allocation, bool, error)
GetAllocations(clientIdAddr address.Address) (map[AllocationId]Allocation, error)
GetAllAllocations() (map[AllocationId]Allocation, error)
GetClaim(providerIdAddr address.Address, claimId ClaimId) (*Claim, bool, error)
GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, error)
GetAllClaims() (map[ClaimId]Claim, error)
GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error)
GetState() interface{}
}

View File

@ -145,6 +145,21 @@ func (s *state{{.v}}) GetAllocations(clientIdAddr address.Address) (map[Allocati
{{end}}
}
func (s *state{{.v}}) GetAllAllocations() (map[AllocationId]Allocation, error) {
{{if (le .v 8)}}
return nil, xerrors.Errorf("unsupported in actors v{{.v}}")
{{else}}
v{{.v}}Map, err := s.State.GetAllAllocations(s.store)
retMap := make(map[AllocationId]Allocation, len(v{{.v}}Map))
for k, v := range v{{.v}}Map {
retMap[AllocationId(k)] = Allocation(v)
}
return retMap, err
{{end}}
}
func (s *state{{.v}}) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
{{if (le .v 8)}}
return nil, false, xerrors.Errorf("unsupported in actors v{{.v}}")
@ -170,6 +185,22 @@ func (s *state{{.v}}) GetClaims(providerIdAddr address.Address) (map[ClaimId]Cla
{{end}}
}
func (s *state{{.v}}) GetAllClaims() (map[ClaimId]Claim, error) {
{{if (le .v 8)}}
return nil, xerrors.Errorf("unsupported in actors v{{.v}}")
{{else}}
v{{.v}}Map, err := s.State.GetAllClaims(s.store)
retMap := make(map[ClaimId]Claim, len(v{{.v}}Map))
for k, v := range v{{.v}}Map {
retMap[ClaimId(k)] = Claim(v)
}
return retMap, err
{{end}}
}
func (s *state{{.v}}) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
{{if (le .v 8)}}
return nil, xerrors.Errorf("unsupported in actors v{{.v}}")

View File

@ -106,6 +106,12 @@ func (s *state0) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state0) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v0")
}
func (s *state0) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v0")
@ -118,6 +124,12 @@ func (s *state0) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state0) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v0")
}
func (s *state0) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v0")

View File

@ -114,6 +114,19 @@ func (s *state10) GetAllocations(clientIdAddr address.Address) (map[AllocationId
}
func (s *state10) GetAllAllocations() (map[AllocationId]Allocation, error) {
v10Map, err := s.State.GetAllAllocations(s.store)
retMap := make(map[AllocationId]Allocation, len(v10Map))
for k, v := range v10Map {
retMap[AllocationId(k)] = Allocation(v)
}
return retMap, err
}
func (s *state10) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
claim, ok, err := s.FindClaim(s.store, providerIdAddr, verifreg10.ClaimId(claimId))
@ -134,6 +147,19 @@ func (s *state10) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim,
}
func (s *state10) GetAllClaims() (map[ClaimId]Claim, error) {
v10Map, err := s.State.GetAllClaims(s.store)
retMap := make(map[ClaimId]Claim, len(v10Map))
for k, v := range v10Map {
retMap[ClaimId(k)] = Claim(v)
}
return retMap, err
}
func (s *state10) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
v10Map, err := s.LoadClaimsToMap(s.store, providerIdAddr)

View File

@ -114,6 +114,19 @@ func (s *state11) GetAllocations(clientIdAddr address.Address) (map[AllocationId
}
func (s *state11) GetAllAllocations() (map[AllocationId]Allocation, error) {
v11Map, err := s.State.GetAllAllocations(s.store)
retMap := make(map[AllocationId]Allocation, len(v11Map))
for k, v := range v11Map {
retMap[AllocationId(k)] = Allocation(v)
}
return retMap, err
}
func (s *state11) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
claim, ok, err := s.FindClaim(s.store, providerIdAddr, verifreg11.ClaimId(claimId))
@ -134,6 +147,19 @@ func (s *state11) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim,
}
func (s *state11) GetAllClaims() (map[ClaimId]Claim, error) {
v11Map, err := s.State.GetAllClaims(s.store)
retMap := make(map[ClaimId]Claim, len(v11Map))
for k, v := range v11Map {
retMap[ClaimId(k)] = Claim(v)
}
return retMap, err
}
func (s *state11) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
v11Map, err := s.LoadClaimsToMap(s.store, providerIdAddr)

View File

@ -114,6 +114,19 @@ func (s *state12) GetAllocations(clientIdAddr address.Address) (map[AllocationId
}
func (s *state12) GetAllAllocations() (map[AllocationId]Allocation, error) {
v12Map, err := s.State.GetAllAllocations(s.store)
retMap := make(map[AllocationId]Allocation, len(v12Map))
for k, v := range v12Map {
retMap[AllocationId(k)] = Allocation(v)
}
return retMap, err
}
func (s *state12) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
claim, ok, err := s.FindClaim(s.store, providerIdAddr, verifreg12.ClaimId(claimId))
@ -134,6 +147,19 @@ func (s *state12) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim,
}
func (s *state12) GetAllClaims() (map[ClaimId]Claim, error) {
v12Map, err := s.State.GetAllClaims(s.store)
retMap := make(map[ClaimId]Claim, len(v12Map))
for k, v := range v12Map {
retMap[ClaimId(k)] = Claim(v)
}
return retMap, err
}
func (s *state12) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
v12Map, err := s.LoadClaimsToMap(s.store, providerIdAddr)

View File

@ -114,6 +114,19 @@ func (s *state13) GetAllocations(clientIdAddr address.Address) (map[AllocationId
}
func (s *state13) GetAllAllocations() (map[AllocationId]Allocation, error) {
v13Map, err := s.State.GetAllAllocations(s.store)
retMap := make(map[AllocationId]Allocation, len(v13Map))
for k, v := range v13Map {
retMap[AllocationId(k)] = Allocation(v)
}
return retMap, err
}
func (s *state13) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
claim, ok, err := s.FindClaim(s.store, providerIdAddr, verifreg13.ClaimId(claimId))
@ -134,6 +147,19 @@ func (s *state13) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim,
}
func (s *state13) GetAllClaims() (map[ClaimId]Claim, error) {
v13Map, err := s.State.GetAllClaims(s.store)
retMap := make(map[ClaimId]Claim, len(v13Map))
for k, v := range v13Map {
retMap[ClaimId(k)] = Claim(v)
}
return retMap, err
}
func (s *state13) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
v13Map, err := s.LoadClaimsToMap(s.store, providerIdAddr)

View File

@ -106,6 +106,12 @@ func (s *state2) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state2) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v2")
}
func (s *state2) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v2")
@ -118,6 +124,12 @@ func (s *state2) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state2) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v2")
}
func (s *state2) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v2")

View File

@ -107,6 +107,12 @@ func (s *state3) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state3) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v3")
}
func (s *state3) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v3")
@ -119,6 +125,12 @@ func (s *state3) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state3) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v3")
}
func (s *state3) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v3")

View File

@ -107,6 +107,12 @@ func (s *state4) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state4) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v4")
}
func (s *state4) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v4")
@ -119,6 +125,12 @@ func (s *state4) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state4) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v4")
}
func (s *state4) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v4")

View File

@ -107,6 +107,12 @@ func (s *state5) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state5) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v5")
}
func (s *state5) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v5")
@ -119,6 +125,12 @@ func (s *state5) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state5) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v5")
}
func (s *state5) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v5")

View File

@ -107,6 +107,12 @@ func (s *state6) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state6) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v6")
}
func (s *state6) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v6")
@ -119,6 +125,12 @@ func (s *state6) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state6) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v6")
}
func (s *state6) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v6")

View File

@ -106,6 +106,12 @@ func (s *state7) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state7) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v7")
}
func (s *state7) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v7")
@ -118,6 +124,12 @@ func (s *state7) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state7) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v7")
}
func (s *state7) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v7")

View File

@ -106,6 +106,12 @@ func (s *state8) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state8) GetAllAllocations() (map[AllocationId]Allocation, error) {
return nil, xerrors.Errorf("unsupported in actors v8")
}
func (s *state8) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v8")
@ -118,6 +124,12 @@ func (s *state8) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state8) GetAllClaims() (map[ClaimId]Claim, error) {
return nil, xerrors.Errorf("unsupported in actors v8")
}
func (s *state8) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
return nil, xerrors.Errorf("unsupported in actors v8")

View File

@ -113,6 +113,19 @@ func (s *state9) GetAllocations(clientIdAddr address.Address) (map[AllocationId]
}
func (s *state9) GetAllAllocations() (map[AllocationId]Allocation, error) {
v9Map, err := s.State.GetAllAllocations(s.store)
retMap := make(map[AllocationId]Allocation, len(v9Map))
for k, v := range v9Map {
retMap[AllocationId(k)] = Allocation(v)
}
return retMap, err
}
func (s *state9) GetClaim(providerIdAddr address.Address, claimId verifreg9.ClaimId) (*Claim, bool, error) {
claim, ok, err := s.FindClaim(s.store, providerIdAddr, verifreg9.ClaimId(claimId))
@ -133,6 +146,19 @@ func (s *state9) GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, e
}
func (s *state9) GetAllClaims() (map[ClaimId]Claim, error) {
v9Map, err := s.State.GetAllClaims(s.store)
retMap := make(map[ClaimId]Claim, len(v9Map))
for k, v := range v9Map {
retMap[ClaimId(k)] = Claim(v)
}
return retMap, err
}
func (s *state9) GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error) {
v9Map, err := s.LoadClaimsToMap(s.store, providerIdAddr)

View File

@ -147,8 +147,10 @@ type State interface {
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
GetAllocation(clientIdAddr address.Address, allocationId AllocationId) (*Allocation, bool, error)
GetAllocations(clientIdAddr address.Address) (map[AllocationId]Allocation, error)
GetAllAllocations() (map[AllocationId]Allocation, error)
GetClaim(providerIdAddr address.Address, claimId ClaimId) (*Claim, bool, error)
GetClaims(providerIdAddr address.Address) (map[ClaimId]Claim, error)
GetAllClaims() (map[ClaimId]Claim, error)
GetClaimIdsBySector(providerIdAddr address.Address) (map[abi.SectorNumber][]ClaimId, error)
GetState() interface{}
}

View File

@ -7,6 +7,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/urfave/cli/v2"
@ -233,16 +234,21 @@ var filplusListClientsCmd = &cli.Command{
var filplusListAllocationsCmd = &cli.Command{
Name: "list-allocations",
Usage: "List allocations made by client",
Usage: "List allocations available in verified registry actor or made by a client if specified",
ArgsUsage: "clientAddress",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "expired",
Usage: "list only expired allocations",
},
&cli.BoolFlag{
Name: "json",
Usage: "output results in json format",
Value: false,
},
},
Action: func(cctx *cli.Context) error {
if cctx.NArg() != 1 {
if cctx.NArg() > 1 {
return IncorrectNumArgs(cctx)
}
@ -253,14 +259,76 @@ var filplusListAllocationsCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
clientAddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
writeOut := func(tsHeight abi.ChainEpoch, allocations map[verifreg.AllocationId]verifreg.Allocation, json, expired bool) error {
// Map Keys. Corresponds to the standard tablewriter output
allocationID := "AllocationID"
client := "Client"
provider := "Miner"
pieceCid := "PieceCid"
pieceSize := "PieceSize"
tMin := "TermMin"
tMax := "TermMax"
expr := "Expiration"
clientIdAddr, err := api.StateLookupID(ctx, clientAddr, types.EmptyTSK)
if err != nil {
return err
// One-to-one mapping between tablewriter keys and JSON keys
tableKeysToJsonKeys := map[string]string{
allocationID: strings.ToLower(allocationID),
client: strings.ToLower(client),
provider: strings.ToLower(provider),
pieceCid: strings.ToLower(pieceCid),
pieceSize: strings.ToLower(pieceSize),
tMin: strings.ToLower(tMin),
tMax: strings.ToLower(tMax),
expr: strings.ToLower(expr),
}
var allocs []map[string]interface{}
for key, val := range allocations {
if tsHeight > val.Expiration || !expired {
alloc := map[string]interface{}{
allocationID: key,
client: val.Client,
provider: val.Provider,
pieceCid: val.Data,
pieceSize: val.Size,
tMin: val.TermMin,
tMax: val.TermMax,
expr: val.Expiration,
}
allocs = append(allocs, alloc)
}
}
if json {
// get a new list of allocations with json keys instead of tablewriter keys
var jsonAllocs []map[string]interface{}
for _, alloc := range allocs {
jsonAlloc := make(map[string]interface{})
for k, v := range alloc {
jsonAlloc[tableKeysToJsonKeys[k]] = v
}
jsonAllocs = append(jsonAllocs, jsonAlloc)
}
// then return this!
return PrintJson(jsonAllocs)
}
// Init the tablewriter's columns
tw := tablewriter.New(
tablewriter.Col(allocationID),
tablewriter.Col(client),
tablewriter.Col(provider),
tablewriter.Col(pieceCid),
tablewriter.Col(pieceSize),
tablewriter.Col(tMin),
tablewriter.Col(tMax),
tablewriter.NewLineCol(expr))
// populate it with content
for _, alloc := range allocs {
tw.Write(alloc)
}
// return the corresponding string
return tw.Flush(os.Stdout)
}
store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(api)))
@ -280,41 +348,38 @@ var filplusListAllocationsCmd = &cli.Command{
return err
}
allocationsMap, err := verifregState.GetAllocations(clientIdAddr)
if cctx.NArg() == 1 {
clientAddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
clientIdAddr, err := api.StateLookupID(ctx, clientAddr, types.EmptyTSK)
if err != nil {
return err
}
allocationsMap, err := verifregState.GetAllocations(clientIdAddr)
if err != nil {
return err
}
return writeOut(ts.Height(), allocationsMap, cctx.Bool("json"), cctx.Bool("expired"))
}
allocationsMap, err := verifregState.GetAllAllocations()
if err != nil {
return err
}
tw := tablewriter.New(
tablewriter.Col("ID"),
tablewriter.Col("Provider"),
tablewriter.Col("Data"),
tablewriter.Col("Size"),
tablewriter.Col("TermMin"),
tablewriter.Col("TermMax"),
tablewriter.Col("Expiration"),
)
return writeOut(ts.Height(), allocationsMap, cctx.Bool("json"), cctx.Bool("expired"))
for allocationId, allocation := range allocationsMap {
if ts.Height() > allocation.Expiration || !cctx.IsSet("expired") {
tw.Write(map[string]interface{}{
"ID": allocationId,
"Provider": allocation.Provider,
"Data": allocation.Data,
"Size": allocation.Size,
"TermMin": allocation.TermMin,
"TermMax": allocation.TermMax,
"Expiration": allocation.Expiration,
})
}
}
return tw.Flush(os.Stdout)
},
}
var filplusListClaimsCmd = &cli.Command{
Name: "list-claims",
Usage: "List claims made by provider",
Usage: "List claims available in verified registry actor or made by provider if specified",
ArgsUsage: "providerAddress",
Flags: []cli.Flag{
&cli.BoolFlag{
@ -323,7 +388,7 @@ var filplusListClaimsCmd = &cli.Command{
},
},
Action: func(cctx *cli.Context) error {
if cctx.NArg() != 1 {
if cctx.NArg() > 1 {
return IncorrectNumArgs(cctx)
}
@ -334,14 +399,81 @@ var filplusListClaimsCmd = &cli.Command{
defer closer()
ctx := ReqContext(cctx)
providerAddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
writeOut := func(tsHeight abi.ChainEpoch, claims map[verifreg.ClaimId]verifreg.Claim, json, expired bool) error {
// Map Keys. Corresponds to the standard tablewriter output
claimID := "ClaimID"
provider := "Provider"
client := "Client"
data := "Data"
size := "Size"
tMin := "TermMin"
tMax := "TermMax"
tStart := "TermStart"
sector := "Sector"
providerIdAddr, err := api.StateLookupID(ctx, providerAddr, types.EmptyTSK)
if err != nil {
return err
// One-to-one mapping between tablewriter keys and JSON keys
tableKeysToJsonKeys := map[string]string{
claimID: strings.ToLower(claimID),
provider: strings.ToLower(provider),
client: strings.ToLower(client),
data: strings.ToLower(data),
size: strings.ToLower(size),
tMin: strings.ToLower(tMin),
tMax: strings.ToLower(tMax),
tStart: strings.ToLower(tStart),
sector: strings.ToLower(sector),
}
var claimList []map[string]interface{}
for key, val := range claims {
if tsHeight > val.TermMax || !expired {
claim := map[string]interface{}{
claimID: key,
provider: val.Provider,
client: val.Client,
data: val.Data,
size: val.Size,
tMin: val.TermMin,
tMax: val.TermMax,
tStart: val.TermStart,
sector: val.Sector,
}
claimList = append(claimList, claim)
}
}
if json {
// get a new list of claims with json keys instead of tablewriter keys
var jsonClaims []map[string]interface{}
for _, claim := range claimList {
jsonClaim := make(map[string]interface{})
for k, v := range claim {
jsonClaim[tableKeysToJsonKeys[k]] = v
}
jsonClaims = append(jsonClaims, jsonClaim)
}
// then return this!
return PrintJson(jsonClaims)
}
// Init the tablewriter's columns
tw := tablewriter.New(
tablewriter.Col(claimID),
tablewriter.Col(client),
tablewriter.Col(provider),
tablewriter.Col(data),
tablewriter.Col(size),
tablewriter.Col(tMin),
tablewriter.Col(tMax),
tablewriter.Col(tStart),
tablewriter.NewLineCol(sector))
// populate it with content
for _, alloc := range claimList {
tw.Write(alloc)
}
// return the corresponding string
return tw.Flush(os.Stdout)
}
store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(api)))
@ -361,39 +493,32 @@ var filplusListClaimsCmd = &cli.Command{
return err
}
claimsMap, err := verifregState.GetClaims(providerIdAddr)
if cctx.NArg() == 1 {
providerAddr, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
providerIdAddr, err := api.StateLookupID(ctx, providerAddr, types.EmptyTSK)
if err != nil {
return err
}
claimsMap, err := verifregState.GetClaims(providerIdAddr)
if err != nil {
return err
}
return writeOut(ts.Height(), claimsMap, cctx.Bool("json"), cctx.Bool("expired"))
}
claimsMap, err := verifregState.GetAllClaims()
if err != nil {
return err
}
tw := tablewriter.New(
tablewriter.Col("ID"),
tablewriter.Col("Provider"),
tablewriter.Col("Client"),
tablewriter.Col("Data"),
tablewriter.Col("Size"),
tablewriter.Col("TermMin"),
tablewriter.Col("TermMax"),
tablewriter.Col("TermStart"),
tablewriter.Col("Sector"),
)
return writeOut(ts.Height(), claimsMap, cctx.Bool("json"), cctx.Bool("expired"))
for claimId, claim := range claimsMap {
if ts.Height() > claim.TermMax || !cctx.IsSet("expired") {
tw.Write(map[string]interface{}{
"ID": claimId,
"Provider": claim.Provider,
"Client": claim.Client,
"Data": claim.Data,
"Size": claim.Size,
"TermMin": claim.TermMin,
"TermMax": claim.TermMax,
"TermStart": claim.TermStart,
"Sector": claim.Sector,
})
}
}
return tw.Flush(os.Stdout)
},
}

View File

@ -2,6 +2,8 @@ package cli
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/fatih/color"
@ -37,3 +39,13 @@ func parseTipSet(ctx context.Context, api v0api.FullNode, vals []string) (*types
return types.NewTipSet(headers)
}
func PrintJson(obj interface{}) error {
resJson, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return fmt.Errorf("marshalling json: %w", err)
}
fmt.Println(string(resJson))
return nil
}

View File

@ -170,6 +170,8 @@
* [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds)
* [StateDecodeParams](#StateDecodeParams)
* [StateGetActor](#StateGetActor)
* [StateGetAllAllocations](#StateGetAllAllocations)
* [StateGetAllClaims](#StateGetAllClaims)
* [StateGetAllocation](#StateGetAllocation)
* [StateGetAllocationForPendingDeal](#StateGetAllocationForPendingDeal)
* [StateGetAllocations](#StateGetAllocations)
@ -5313,6 +5315,50 @@ Response:
}
```
### StateGetAllAllocations
StateGetAllAllocations returns the all the allocations available in verified registry actor.
Perms: read
Inputs:
```json
[
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response: `{}`
### StateGetAllClaims
StateGetAllClaims returns the all the claims available in verified registry actor.
Perms: read
Inputs:
```json
[
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response: `{}`
### StateGetAllocation
StateGetAllocation returns the allocation for a given address and allocation ID.

View File

@ -230,6 +230,8 @@
* [StateDecodeParams](#StateDecodeParams)
* [StateEncodeParams](#StateEncodeParams)
* [StateGetActor](#StateGetActor)
* [StateGetAllAllocations](#StateGetAllAllocations)
* [StateGetAllClaims](#StateGetAllClaims)
* [StateGetAllocation](#StateGetAllocation)
* [StateGetAllocationForPendingDeal](#StateGetAllocationForPendingDeal)
* [StateGetAllocationIdForPendingDeal](#StateGetAllocationIdForPendingDeal)
@ -6892,6 +6894,50 @@ Response:
}
```
### StateGetAllAllocations
StateGetAllAllocations returns the all the allocations available in verified registry actor.
Perms: read
Inputs:
```json
[
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response: `{}`
### StateGetAllClaims
StateGetAllClaims returns the all the claims available in verified registry actor.
Perms: read
Inputs:
```json
[
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response: `{}`
### StateGetAllocation
StateGetAllocation returns the allocation for a given address and allocation ID.

View File

@ -1188,8 +1188,8 @@ COMMANDS:
check-client-datacap check verified client remaining bytes
check-notary-datacap check a notary's remaining bytes
sign-remove-data-cap-proposal allows a notary to sign a Remove Data Cap Proposal
list-allocations List allocations made by client
list-claims List claims made by provider
list-allocations List allocations available in verified registry actor or made by a client if specified
list-claims List claims available in verified registry actor or made by provider if specified
remove-expired-allocations remove expired allocations (if no allocations are specified all eligible allocations are removed)
remove-expired-claims remove expired claims (if no claims are specified all eligible claims are removed)
help, h Shows a list of commands or help for one command
@ -1275,20 +1275,21 @@ OPTIONS:
### lotus filplus list-allocations
```
NAME:
lotus filplus list-allocations - List allocations made by client
lotus filplus list-allocations - List allocations available in verified registry actor or made by a client if specified
USAGE:
lotus filplus list-allocations [command options] clientAddress
OPTIONS:
--expired list only expired allocations (default: false)
--json output results in json format (default: false)
--help, -h show help
```
### lotus filplus list-claims
```
NAME:
lotus filplus list-claims - List claims made by provider
lotus filplus list-claims - List claims available in verified registry actor or made by provider if specified
USAGE:
lotus filplus list-claims [command options] providerAddress

View File

@ -503,3 +503,152 @@ func makeVerifier(ctx context.Context, t *testing.T, api *impl.FullNodeAPI, root
require.NoError(t, err)
require.Equal(t, allowance, *verifierAllowance)
}
func TestVerifiedListAllAllocationsAndClaims(t *testing.T) {
blockTime := 100 * time.Millisecond
rootKey, err := key.GenerateKey(types.KTSecp256k1)
require.NoError(t, err)
verifier1Key, err := key.GenerateKey(types.KTSecp256k1)
require.NoError(t, err)
verifiedClientKey, err := key.GenerateKey(types.KTBLS)
require.NoError(t, err)
bal, err := types.ParseFIL("100fil")
require.NoError(t, err)
node, miner, ens := kit.EnsembleMinimal(t, kit.MockProofs(),
kit.RootVerifier(rootKey, abi.NewTokenAmount(bal.Int64())),
kit.Account(verifier1Key, abi.NewTokenAmount(bal.Int64())),
kit.Account(verifiedClientKey, abi.NewTokenAmount(bal.Int64())),
)
ens.InterconnectAll().BeginMining(blockTime)
api := node.FullNode.(*impl.FullNodeAPI)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// get VRH
vrh, err := api.StateVerifiedRegistryRootKey(ctx, types.TipSetKey{})
fmt.Println(vrh.String())
require.NoError(t, err)
// import the root key.
rootAddr, err := api.WalletImport(ctx, &rootKey.KeyInfo)
require.NoError(t, err)
// import the verifiers' keys.
verifier1Addr, err := api.WalletImport(ctx, &verifier1Key.KeyInfo)
require.NoError(t, err)
// import the verified client's key.
verifiedClientAddr, err := api.WalletImport(ctx, &verifiedClientKey.KeyInfo)
require.NoError(t, err)
// resolve all keys
// make the 2 verifiers
makeVerifier(ctx, t, api, rootAddr, verifier1Addr)
// assign datacap to a client
initialDatacap := big.NewInt(20000)
params, err := actors.SerializeParams(&verifregst.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: initialDatacap})
require.NoError(t, err)
msg := &types.Message{
From: verifier1Addr,
To: verifreg.Address,
Method: verifreg.Methods.AddVerifiedClient,
Params: params,
Value: big.Zero(),
}
sm, err := api.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err)
res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.EqualValues(t, 0, res.Receipt.ExitCode)
// check datacap balance
dcap, err := api.StateVerifiedClientStatus(ctx, verifiedClientAddr, types.EmptyTSK)
require.NoError(t, err)
require.Equal(t, *dcap, initialDatacap)
minerId, err := address.IDFromAddress(miner.ActorAddr)
require.NoError(t, err)
allocationRequest1 := verifregst.AllocationRequest{
Provider: abi.ActorID(minerId),
Data: cid.MustParse("baga6ea4seaaqa"),
Size: abi.PaddedPieceSize(initialDatacap.Uint64() / 2),
TermMin: verifregst.MinimumVerifiedAllocationTerm,
TermMax: verifregst.MinimumVerifiedAllocationTerm,
Expiration: verifregst.MaximumVerifiedAllocationExpiration,
}
allocationRequest2 := verifregst.AllocationRequest{
Provider: abi.ActorID(minerId),
Data: cid.MustParse("baga6ea4seaaqc"),
Size: abi.PaddedPieceSize(initialDatacap.Uint64() / 2),
TermMin: verifregst.MinimumVerifiedAllocationTerm,
TermMax: verifregst.MinimumVerifiedAllocationTerm,
Expiration: verifregst.MaximumVerifiedAllocationExpiration,
}
allocationRequests := verifregst.AllocationRequests{
Allocations: []verifregst.AllocationRequest{allocationRequest1, allocationRequest2},
}
receiverParams, err := actors.SerializeParams(&allocationRequests)
require.NoError(t, err)
transferParams, err := actors.SerializeParams(&datacap2.TransferParams{
To: builtin.VerifiedRegistryActorAddr,
Amount: big.Mul(initialDatacap, builtin.TokenPrecision),
OperatorData: receiverParams,
})
require.NoError(t, err)
msg = &types.Message{
To: builtin.DatacapActorAddr,
From: verifiedClientAddr,
Method: datacap.Methods.TransferExported,
Params: transferParams,
Value: big.Zero(),
}
sm, err = api.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err)
res, err = api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.EqualValues(t, 0, res.Receipt.ExitCode)
allocations, err := api.StateGetAllAllocations(ctx, types.EmptyTSK)
require.NoError(t, err)
require.Equal(t, 2, len(allocations))
var pcids []string
for _, a := range allocations {
clientIdAddr, err := api.StateLookupID(ctx, verifiedClientAddr, types.EmptyTSK)
require.NoError(t, err)
clientId, err := address.IDFromAddress(clientIdAddr)
require.NoError(t, err)
require.Equal(t, abi.ActorID(clientId), a.Client)
require.Equal(t, abi.ActorID(minerId), a.Provider)
require.Equal(t, abi.PaddedPieceSize(10000), a.Size)
pcids = append(pcids, a.Data.String())
}
require.ElementsMatch(t, []string{"baga6ea4seaaqa", "baga6ea4seaaqc"}, pcids)
// TODO: Add claims check to this test once https://github.com/filecoin-project/lotus/pull/11618 lands
}

View File

@ -866,6 +866,25 @@ func (a *StateAPI) StateGetAllocations(ctx context.Context, clientAddr address.A
return allocations, nil
}
func (a *StateAPI) StateGetAllAllocations(ctx context.Context, tsk types.TipSetKey) (map[verifreg.AllocationId]verifreg.Allocation, error) {
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("loading verifreg state: %w", err)
}
allocations, err := st.GetAllAllocations()
if err != nil {
return nil, xerrors.Errorf("getting all allocations: %w", err)
}
return allocations, nil
}
func (a *StateAPI) StateGetClaim(ctx context.Context, providerAddr address.Address, claimId verifreg.ClaimId, tsk types.TipSetKey) (*verifreg.Claim, error) {
idAddr, err := a.StateLookupID(ctx, providerAddr, tsk)
if err != nil {
@ -917,6 +936,25 @@ func (a *StateAPI) StateGetClaims(ctx context.Context, providerAddr address.Addr
return claims, nil
}
func (a *StateAPI) StateGetAllClaims(ctx context.Context, tsk types.TipSetKey) (map[verifreg.ClaimId]verifreg.Claim, error) {
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("loading verifreg state: %w", err)
}
claims, err := st.GetAllClaims()
if err != nil {
return nil, xerrors.Errorf("getting all claims: %w", err)
}
return claims, nil
}
func (a *StateAPI) StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
nv, err := a.StateNetworkVersion(ctx, tsk)
if err != nil {