Add api for getting allocation

This commit is contained in:
Geoff Stuart 2022-10-03 02:51:30 -03:00
parent de95667a6a
commit f55dc46a32
43 changed files with 739 additions and 12 deletions

View File

@ -20,6 +20,7 @@ import (
"github.com/filecoin-project/go-state-types/builtin/v8/paych"
"github.com/filecoin-project/go-state-types/builtin/v9/market"
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline"
abinetwork "github.com/filecoin-project/go-state-types/network"
@ -527,6 +528,10 @@ type FullNode interface {
StateMarketDeals(context.Context, types.TipSetKey) (map[string]*MarketDeal, error) //perm:read
// StateMarketStorageDeal returns information about the indicated deal
StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*MarketDeal, error) //perm:read
// StateGetDealAllocation returns the allocation ID for a given deal ID.
StateGetDealAllocation(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
// StateGetAllocation returns the allocation ID for a given address and allocation ID.
StateGetAllocation(ctx context.Context, addr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, 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

@ -139,7 +139,9 @@ func init() {
addExample(&apiSelExample)
addExample(network.ReachabilityPublic)
addExample(build.TestNetworkVersion)
addExample(verifreg.AllocationId(0))
allocationId := verifreg.AllocationId(0)
addExample(allocationId)
addExample(&allocationId)
addExample(map[string]int{"name": 42})
addExample(map[string]time.Time{"name": time.Unix(1615243938, 0).UTC()})
addExample(&types.ExecutionTrace{

View File

@ -28,6 +28,7 @@ import (
big "github.com/filecoin-project/go-state-types/big"
paych "github.com/filecoin-project/go-state-types/builtin/v8/paych"
miner "github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifreg "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
crypto "github.com/filecoin-project/go-state-types/crypto"
dline "github.com/filecoin-project/go-state-types/dline"
network "github.com/filecoin-project/go-state-types/network"
@ -2467,6 +2468,21 @@ func (mr *MockFullNodeMockRecorder) StateGetActor(arg0, arg1, arg2 interface{})
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetActor", reflect.TypeOf((*MockFullNode)(nil).StateGetActor), arg0, arg1, arg2)
}
// 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()
ret := m.ctrl.Call(m, "StateGetAllocation", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].(*verifreg.Allocation)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetAllocation indicates an expected call of StateGetAllocation.
func (mr *MockFullNodeMockRecorder) StateGetAllocation(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetAllocation", reflect.TypeOf((*MockFullNode)(nil).StateGetAllocation), arg0, arg1, arg2, arg3)
}
// StateGetBeaconEntry mocks base method.
func (m *MockFullNode) StateGetBeaconEntry(arg0 context.Context, arg1 abi.ChainEpoch) (*types.BeaconEntry, error) {
m.ctrl.T.Helper()
@ -2482,6 +2498,21 @@ func (mr *MockFullNodeMockRecorder) StateGetBeaconEntry(arg0, arg1 interface{})
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetBeaconEntry", reflect.TypeOf((*MockFullNode)(nil).StateGetBeaconEntry), arg0, arg1)
}
// StateGetDealAllocation mocks base method.
func (m *MockFullNode) StateGetDealAllocation(arg0 context.Context, arg1 abi.DealID, arg2 types.TipSetKey) (*verifreg.Allocation, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StateGetDealAllocation", arg0, arg1, arg2)
ret0, _ := ret[0].(*verifreg.Allocation)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetDealAllocation indicates an expected call of StateGetDealAllocation.
func (mr *MockFullNodeMockRecorder) StateGetDealAllocation(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetDealAllocation", reflect.TypeOf((*MockFullNode)(nil).StateGetDealAllocation), arg0, arg1, arg2)
}
// StateGetNetworkParams mocks base method.
func (m *MockFullNode) StateGetNetworkParams(arg0 context.Context) (*api.NetworkParams, error) {
m.ctrl.T.Helper()

View File

@ -26,6 +26,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v8/paych"
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline"
abinetwork "github.com/filecoin-project/go-state-types/network"
@ -365,8 +366,12 @@ type FullNodeStruct struct {
StateGetActor func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*types.Actor, error) `perm:"read"`
StateGetAllocation func(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) `perm:"read"`
StateGetBeaconEntry func(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) `perm:"read"`
StateGetDealAllocation func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) `perm:"read"`
StateGetNetworkParams func(p0 context.Context) (*NetworkParams, error) `perm:"read"`
StateGetRandomnessFromBeacon func(p0 context.Context, p1 crypto.DomainSeparationTag, p2 abi.ChainEpoch, p3 []byte, p4 types.TipSetKey) (abi.Randomness, error) `perm:"read"`
@ -2592,6 +2597,17 @@ func (s *FullNodeStub) StateGetActor(p0 context.Context, p1 address.Address, p2
return nil, 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
}
return s.Internal.StateGetAllocation(p0, p1, p2, p3)
}
func (s *FullNodeStub) StateGetAllocation(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) {
return nil, ErrNotSupported
}
func (s *FullNodeStruct) StateGetBeaconEntry(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) {
if s.Internal.StateGetBeaconEntry == nil {
return nil, ErrNotSupported
@ -2603,6 +2619,17 @@ func (s *FullNodeStub) StateGetBeaconEntry(p0 context.Context, p1 abi.ChainEpoch
return nil, ErrNotSupported
}
func (s *FullNodeStruct) StateGetDealAllocation(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) {
if s.Internal.StateGetDealAllocation == nil {
return nil, ErrNotSupported
}
return s.Internal.StateGetDealAllocation(p0, p1, p2)
}
func (s *FullNodeStub) StateGetDealAllocation(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) {
return nil, ErrNotSupported
}
func (s *FullNodeStruct) StateGetNetworkParams(p0 context.Context) (*NetworkParams, error) {
if s.Internal.StateGetNetworkParams == nil {
return nil, ErrNotSupported

View File

@ -16,6 +16,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v8/paych"
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline"
abinetwork "github.com/filecoin-project/go-state-types/network"
@ -531,6 +532,10 @@ type FullNode interface {
StateMarketDeals(context.Context, types.TipSetKey) (map[string]*api.MarketDeal, error) //perm:read
// StateMarketStorageDeal returns information about the indicated deal
StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*api.MarketDeal, error) //perm:read
// StateGetDealAllocation returns the allocation ID for a given deal ID.
StateGetDealAllocation(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error)
// StateGetAllocation returns the allocation ID for a given address and allocation ID.
StateGetAllocation(ctx context.Context, addr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, 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

@ -18,6 +18,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v8/paych"
"github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline"
abinetwork "github.com/filecoin-project/go-state-types/network"
@ -277,6 +278,10 @@ type FullNodeStruct struct {
StateGetActor func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*types.Actor, error) `perm:"read"`
StateGetAllocation func(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) `perm:"read"`
StateGetDealAllocation func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) ``
StateGetNetworkParams func(p0 context.Context) (*api.NetworkParams, error) `perm:"read"`
StateGetRandomnessFromBeacon func(p0 context.Context, p1 crypto.DomainSeparationTag, p2 abi.ChainEpoch, p3 []byte, p4 types.TipSetKey) (abi.Randomness, error) `perm:"read"`
@ -1793,6 +1798,28 @@ func (s *FullNodeStub) StateGetActor(p0 context.Context, p1 address.Address, p2
return nil, 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
}
return s.Internal.StateGetAllocation(p0, p1, p2, p3)
}
func (s *FullNodeStub) StateGetAllocation(p0 context.Context, p1 address.Address, p2 verifregtypes.AllocationId, p3 types.TipSetKey) (*verifregtypes.Allocation, error) {
return nil, ErrNotSupported
}
func (s *FullNodeStruct) StateGetDealAllocation(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) {
if s.Internal.StateGetDealAllocation == nil {
return nil, ErrNotSupported
}
return s.Internal.StateGetDealAllocation(p0, p1, p2)
}
func (s *FullNodeStub) StateGetDealAllocation(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*verifregtypes.Allocation, error) {
return nil, ErrNotSupported
}
func (s *FullNodeStruct) StateGetNetworkParams(p0 context.Context) (*api.NetworkParams, error) {
if s.Internal.StateGetNetworkParams == nil {
return nil, ErrNotSupported

View File

@ -28,6 +28,7 @@ import (
big "github.com/filecoin-project/go-state-types/big"
paych "github.com/filecoin-project/go-state-types/builtin/v8/paych"
miner "github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifreg "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
crypto "github.com/filecoin-project/go-state-types/crypto"
dline "github.com/filecoin-project/go-state-types/dline"
network "github.com/filecoin-project/go-state-types/network"
@ -2322,6 +2323,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)
}
// 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()
ret := m.ctrl.Call(m, "StateGetAllocation", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].(*verifreg.Allocation)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetAllocation indicates an expected call of StateGetAllocation.
func (mr *MockFullNodeMockRecorder) StateGetAllocation(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetAllocation", reflect.TypeOf((*MockFullNode)(nil).StateGetAllocation), arg0, arg1, arg2, arg3)
}
// StateGetDealAllocation mocks base method.
func (m *MockFullNode) StateGetDealAllocation(arg0 context.Context, arg1 abi.DealID, arg2 types.TipSetKey) (*verifreg.Allocation, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "StateGetDealAllocation", arg0, arg1, arg2)
ret0, _ := ret[0].(*verifreg.Allocation)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// StateGetDealAllocation indicates an expected call of StateGetDealAllocation.
func (mr *MockFullNodeMockRecorder) StateGetDealAllocation(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetDealAllocation", reflect.TypeOf((*MockFullNode)(nil).StateGetDealAllocation), arg0, arg1, arg2)
}
// StateGetNetworkParams mocks base method.
func (m *MockFullNode) StateGetNetworkParams(arg0 context.Context) (*api.NetworkParams, error) {
m.ctrl.T.Helper()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,12 +1,12 @@
package datacap
import (
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
@ -34,7 +34,7 @@ func getDataCap(store adt.Store, ver actors.Version, root rootFunc, addr address
return false, big.Zero(), nil
}
return true, big.Div(dcap, verifreg9.DataCapGranularity), nil
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 {
@ -48,6 +48,6 @@ func forEachCap(store adt.Store, ver actors.Version, root rootFunc, cb func(addr
if err != nil {
return err
}
return cb(a, big.Div(dcap, verifreg9.DataCapGranularity))
return cb(a, big.Div(dcap, verifreg.DataCapGranularity))
})
}

View File

@ -14,6 +14,7 @@ import (
cbg "github.com/whyrusleeping/cbor-gen"
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
{{range .versions}}
{{if (le . 7)}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
@ -85,6 +86,7 @@ type State interface {
) (weight, verifiedWeight abi.DealWeight, err error)
NextID() (abi.DealID, error)
GetState() interface{}
GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error)
}
type BalanceTable interface {

View File

@ -12,6 +12,7 @@ import (
"github.com/filecoin-project/go-state-types/big"
builtintypes "github.com/filecoin-project/go-state-types/builtin"
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/network"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
@ -126,6 +127,7 @@ type State interface {
) (weight, verifiedWeight abi.DealWeight, err error)
NextID() (abi.DealID, error)
GetState() interface{}
GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error)
}
type BalanceTable interface {

View File

@ -16,6 +16,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
{{if (le .v 7)}}
market{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/market"
@ -25,6 +26,9 @@ import (
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt"
{{end}}
{{if (ge .v 9)}}
"github.com/filecoin-project/go-state-types/builtin"
{{end}}
)
var _ State = (*state{{.v}})(nil)
@ -361,3 +365,24 @@ func (r *publishStorageDealsReturn{{.v}}) IsDealValid(index uint64) (bool, int,
func (r *publishStorageDealsReturn{{.v}}) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state{{.v}}) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
{{if (le .v 8)}}
return 0, xerrors.Errorf("unsupported before actors v9")
{{else}}
allocations, err := adt9.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth)
if err != nil {
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
}
var allocationId cbg.CborInt
found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId)
if err != nil {
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
}
if !found {
return 0, xerrors.Errorf("failed to find allocation id for %d", dealId)
}
return verifregtypes.AllocationId(allocationId), nil
{{end}}
}

View File

@ -9,6 +9,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
@ -300,3 +301,9 @@ func (r *publishStorageDealsReturn0) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn0) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state0) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -9,6 +9,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
@ -300,3 +301,9 @@ func (r *publishStorageDealsReturn2) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn2) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state2) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -9,6 +9,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market"
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
@ -295,3 +296,9 @@ func (r *publishStorageDealsReturn3) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn3) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state3) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -9,6 +9,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
@ -295,3 +296,9 @@ func (r *publishStorageDealsReturn4) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn4) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state4) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -9,6 +9,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market"
adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt"
@ -295,3 +296,9 @@ func (r *publishStorageDealsReturn5) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn5) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state5) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/go-bitfield"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
market6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/market"
adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt"
@ -313,3 +314,9 @@ func (r *publishStorageDealsReturn6) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn6) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state6) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/go-bitfield"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
@ -313,3 +314,9 @@ func (r *publishStorageDealsReturn7) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn7) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state7) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -14,6 +14,7 @@ import (
market8 "github.com/filecoin-project/go-state-types/builtin/v8/market"
adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt"
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"
@ -330,3 +331,9 @@ func (r *publishStorageDealsReturn8) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn8) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state8) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
return 0, xerrors.Errorf("unsupported before actors v9")
}

View File

@ -11,9 +11,11 @@ import (
"github.com/filecoin-project/go-bitfield"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
market9 "github.com/filecoin-project/go-state-types/builtin/v9/market"
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
adt9 "github.com/filecoin-project/go-state-types/builtin/v9/util/adt"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/types"
@ -325,3 +327,22 @@ func (r *publishStorageDealsReturn9) IsDealValid(index uint64) (bool, int, error
func (r *publishStorageDealsReturn9) DealIDs() ([]abi.DealID, error) {
return r.IDs, nil
}
func (s *state9) GetAllocationId(dealId abi.DealID) (verifregtypes.AllocationId, error) {
allocations, err := adt9.AsMap(s.store, s.PendingDealAllocationIds, builtin.DefaultHamtBitwidth)
if err != nil {
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
}
var allocationId cbg.CborInt
found, err := allocations.Get(abi.UIntKey(uint64(dealId)), &allocationId)
if err != nil {
return 0, xerrors.Errorf("failed to load allocation id for %d: %w", dealId, err)
}
if !found {
return 0, xerrors.Errorf("failed to find allocation id for %d", dealId)
}
return verifregtypes.AllocationId(allocationId), nil
}

View File

@ -18,6 +18,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
)
var (
@ -72,5 +73,6 @@ type State interface {
RemoveDataCapProposalID(verifier address.Address, client address.Address) (bool, uint64, error)
ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
GetAllocation(addr address.Address, allocationId verifregtypes.AllocationId) (*verifregtypes.Allocation, bool, error)
GetState() interface{}
}

View File

@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"golang.org/x/xerrors"
{{if (le .v 7)}}
{{if (ge .v 3)}}
@ -21,7 +22,8 @@ import (
{{end}}
{{if (ge .v 9)}}
"github.com/filecoin-project/go-state-types/big"
"golang.org/x/xerrors"
{{else}}
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
{{end}}
)
@ -112,4 +114,12 @@ func (s *state{{.v}}) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state{{.v}}) GetState() interface{} {
return &s.State
}
func (s *state{{.v}}) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
{{if (le .v 8)}}
return nil, false, xerrors.Errorf("unsupported in actors v{{.v}}")
{{else}}
return s.FindAllocation(s.store, addr, allocationId)
{{end}}
}

View File

@ -2,9 +2,11 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
@ -87,3 +89,9 @@ func (s *state0) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state0) GetState() interface{} {
return &s.State
}
func (s *state0) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v0")
}

View File

@ -2,9 +2,11 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg"
adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
@ -87,3 +89,9 @@ func (s *state2) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state2) GetState() interface{} {
return &s.State
}
func (s *state2) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v2")
}

View File

@ -2,9 +2,11 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
verifreg3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/verifreg"
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
@ -88,3 +90,9 @@ func (s *state3) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state3) GetState() interface{} {
return &s.State
}
func (s *state3) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v3")
}

View File

@ -2,9 +2,11 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg"
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
@ -88,3 +90,9 @@ func (s *state4) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state4) GetState() interface{} {
return &s.State
}
func (s *state4) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v4")
}

View File

@ -2,9 +2,11 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
verifreg5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg"
adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt"
@ -88,3 +90,9 @@ func (s *state5) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state5) GetState() interface{} {
return &s.State
}
func (s *state5) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v5")
}

View File

@ -2,9 +2,11 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
verifreg6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/verifreg"
adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt"
@ -88,3 +90,9 @@ func (s *state6) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state6) GetState() interface{} {
return &s.State
}
func (s *state6) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v6")
}

View File

@ -2,9 +2,11 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin"
verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg"
adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt"
@ -87,3 +89,9 @@ func (s *state7) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state7) GetState() interface{} {
return &s.State
}
func (s *state7) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v7")
}

View File

@ -2,12 +2,14 @@ package verifreg
import (
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
builtin8 "github.com/filecoin-project/go-state-types/builtin"
adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt"
verifreg8 "github.com/filecoin-project/go-state-types/builtin/v8/verifreg"
verifreg9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
@ -87,3 +89,9 @@ func (s *state8) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state8) GetState() interface{} {
return &s.State
}
func (s *state8) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return nil, false, xerrors.Errorf("unsupported in actors v8")
}

View File

@ -89,3 +89,9 @@ func (s *state9) removeDataCapProposalIDs() (adt.Map, error) {
func (s *state9) GetState() interface{} {
return &s.State
}
func (s *state9) GetAllocation(addr address.Address, allocationId verifreg9.AllocationId) (*verifreg9.Allocation, bool, error) {
return s.FindAllocation(s.store, addr, allocationId)
}

View File

@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
actorstypes "github.com/filecoin-project/go-state-types/actors"
builtin9 "github.com/filecoin-project/go-state-types/builtin"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/cbor"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
@ -114,5 +115,6 @@ type State interface {
RemoveDataCapProposalID(verifier address.Address, client address.Address) (bool, uint64, error)
ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
GetAllocation(addr address.Address, allocationId verifregtypes.AllocationId) (*verifregtypes.Allocation, bool, error)
GetState() interface{}
}

View File

@ -21,6 +21,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/paych"
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
"github.com/filecoin-project/lotus/chain/beacon"
"github.com/filecoin-project/lotus/chain/rand"
"github.com/filecoin-project/lotus/chain/types"
@ -516,6 +517,24 @@ func (sm *StateManager) GetMarketState(ctx context.Context, ts *types.TipSet) (m
return actState, nil
}
func (sm *StateManager) GetVerifregState(ctx context.Context, ts *types.TipSet) (verifreg.State, error) {
st, err := sm.ParentState(ts)
if err != nil {
return nil, err
}
act, err := st.GetActor(verifreg.Address)
if err != nil {
return nil, err
}
actState, err := verifreg.Load(sm.cs.ActorStore(ctx), act)
if err != nil {
return nil, err
}
return actState, nil
}
func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address, ts *types.TipSet) (api.MarketBalance, error) {
mstate, err := sm.GetMarketState(ctx, ts)
if err != nil {

View File

@ -168,6 +168,8 @@
* [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds)
* [StateDecodeParams](#StateDecodeParams)
* [StateGetActor](#StateGetActor)
* [StateGetAllocation](#StateGetAllocation)
* [StateGetDealAllocation](#StateGetDealAllocation)
* [StateGetNetworkParams](#StateGetNetworkParams)
* [StateGetRandomnessFromBeacon](#StateGetRandomnessFromBeacon)
* [StateGetRandomnessFromTickets](#StateGetRandomnessFromTickets)
@ -5242,6 +5244,79 @@ Response:
}
```
### StateGetAllocation
StateGetAllocation returns the allocation ID for a given address and allocation ID.
Perms: read
Inputs:
```json
[
"f01234",
0,
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response:
```json
{
"Client": 1000,
"Provider": 1000,
"Data": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"Size": 1032,
"TermMin": 10101,
"TermMax": 10101,
"Expiration": 10101
}
```
### StateGetDealAllocation
StateGetDealAllocation returns the allocation ID for a given deal ID.
Perms:
Inputs:
```json
[
5432,
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response:
```json
{
"Client": 1000,
"Provider": 1000,
"Data": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"Size": 1032,
"TermMin": 10101,
"TermMax": 10101,
"Expiration": 10101
}
```
### StateGetNetworkParams
StateGetNetworkParams return current network params

View File

@ -178,7 +178,9 @@
* [StateDecodeParams](#StateDecodeParams)
* [StateEncodeParams](#StateEncodeParams)
* [StateGetActor](#StateGetActor)
* [StateGetAllocation](#StateGetAllocation)
* [StateGetBeaconEntry](#StateGetBeaconEntry)
* [StateGetDealAllocation](#StateGetDealAllocation)
* [StateGetNetworkParams](#StateGetNetworkParams)
* [StateGetRandomnessFromBeacon](#StateGetRandomnessFromBeacon)
* [StateGetRandomnessFromTickets](#StateGetRandomnessFromTickets)
@ -5725,6 +5727,43 @@ Response:
}
```
### StateGetAllocation
StateGetAllocation returns the allocation ID for a given address and allocation ID.
Perms: read
Inputs:
```json
[
"f01234",
0,
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response:
```json
{
"Client": 1000,
"Provider": 1000,
"Data": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"Size": 1032,
"TermMin": 10101,
"TermMax": 10101,
"Expiration": 10101
}
```
### StateGetBeaconEntry
StateGetBeaconEntry returns the beacon entry for the given filecoin epoch. If
the entry has not yet been produced, the call will block until the entry
@ -5748,6 +5787,42 @@ Response:
}
```
### StateGetDealAllocation
StateGetDealAllocation returns the allocation ID for a given deal ID.
Perms: read
Inputs:
```json
[
5432,
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```
Response:
```json
{
"Client": 1000,
"Provider": 1000,
"Data": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"Size": 1032,
"TermMin": 10101,
"TermMax": 10101,
"Expiration": 10101
}
```
### StateGetNetworkParams
StateGetNetworkParams return current network params

2
go.mod
View File

@ -42,7 +42,7 @@ require (
github.com/filecoin-project/go-legs v0.4.4
github.com/filecoin-project/go-padreader v0.0.1
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.1.13-0.20221004152844-60ff2344a55e
github.com/filecoin-project/go-state-types v0.1.13-0.20221004175601-1427aec8869f
github.com/filecoin-project/go-statemachine v1.0.2
github.com/filecoin-project/go-statestore v0.2.0
github.com/filecoin-project/go-storedcounter v0.1.0

6
go.sum
View File

@ -343,10 +343,8 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
github.com/filecoin-project/go-state-types v0.1.12 h1:KsC820XAwhhlcS7Fu6Yq7Bim53NbVe+4rWKS+81h+LM=
github.com/filecoin-project/go-state-types v0.1.12/go.mod h1:n/kujdC9JphvYTrmaD1+vJpvDPy/DwzckoMzP0nBKWI=
github.com/filecoin-project/go-state-types v0.1.13-0.20221004152844-60ff2344a55e h1:vmBYH93NV8Q8CCPvg8ZjFrBEabtv3y42e38E0zMA5xM=
github.com/filecoin-project/go-state-types v0.1.13-0.20221004152844-60ff2344a55e/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
github.com/filecoin-project/go-state-types v0.1.13-0.20221004175601-1427aec8869f h1:UKVkUqu7aMXr07HpBqCvC1J8R0lTFX7rK6+92XUs10g=
github.com/filecoin-project/go-state-types v0.1.13-0.20221004175601-1427aec8869f/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=

View File

@ -2,7 +2,9 @@
package itests
import (
"bytes"
"context"
"fmt"
"path/filepath"
"testing"
"time"
@ -13,9 +15,22 @@ import (
commp "github.com/filecoin-project/go-fil-commp-hashhash"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/exitcode"
"github.com/filecoin-project/lotus/api"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet/key"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/filecoin-project/lotus/node/impl"
)
func TestOfflineDealFlow(t *testing.T) {
@ -81,7 +96,7 @@ func TestOfflineDealFlow(t *testing.T) {
// Create a CAR file from the raw file
carFileDir := t.TempDir()
carFilePath := filepath.Join(carFileDir, "out.car")
err = client.ClientGenCar(ctx, api.FileRef{Path: inFile}, carFilePath)
err = client.ClientGenCar(ctx, lapi.FileRef{Path: inFile}, carFilePath)
require.NoError(t, err)
// Import the CAR file on the miner - this is the equivalent to
@ -105,3 +120,178 @@ func TestOfflineDealFlow(t *testing.T) {
t.Run("fastretrieval", func(t *testing.T) { runTest(t, true, 0) })
t.Run("fastretrieval", func(t *testing.T) { runTest(t, true, 1024) })
}
func TestGetAllocationFromDealId(t *testing.T) {
ctx := context.Background()
rootKey, err := key.GenerateKey(types.KTSecp256k1)
require.NoError(t, err)
verifierKey, 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(verifierKey, abi.NewTokenAmount(bal.Int64())), // assign some balance to the verifier so they can send an AddClient message.
kit.Account(verifiedClientKey, abi.NewTokenAmount(bal.Int64())),
)
ens.InterconnectAll().BeginMining(250 * time.Millisecond)
api := node.FullNode.(*impl.FullNodeAPI)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// get VRH
//stm: @CHAIN_STATE_VERIFIED_REGISTRY_ROOT_KEY_001
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 verifier's key.
verifierAddr, err := api.WalletImport(ctx, &verifierKey.KeyInfo)
require.NoError(t, err)
// import the verified client's key.
verifiedClientAddr, err := api.WalletImport(ctx, &verifiedClientKey.KeyInfo)
require.NoError(t, err)
params, err := actors.SerializeParams(&verifregtypes.AddVerifierParams{Address: verifierAddr, Allowance: big.NewInt(100000000000)})
require.NoError(t, err)
msg := &types.Message{
From: rootAddr,
To: verifreg.Address,
Method: verifreg.Methods.AddVerifier,
Params: params,
Value: big.Zero(),
}
sm, err := api.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err, "AddVerifier failed")
//stm: @CHAIN_STATE_WAIT_MSG_001
res, err := api.StateWaitMsg(ctx, sm.Cid(), 1, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.EqualValues(t, 0, res.Receipt.ExitCode)
// assign datacap to a client
datacap := big.NewInt(10000)
params, err = actors.SerializeParams(&verifregtypes.AddVerifiedClientParams{Address: verifiedClientAddr, Allowance: datacap})
require.NoError(t, err)
msg = &types.Message{
From: verifierAddr,
To: verifreg.Address,
Method: verifreg.Methods.AddVerifiedClient,
Params: params,
Value: big.Zero(),
}
sm, err = api.MpoolPushMessage(ctx, msg, nil)
require.NoError(t, err)
//stm: @CHAIN_STATE_WAIT_MSG_001
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
//stm: @CHAIN_STATE_VERIFIED_CLIENT_STATUS_001
dcap, err := api.StateVerifiedClientStatus(ctx, verifiedClientAddr, types.EmptyTSK)
require.NoError(t, err)
if !dcap.Equals(datacap) {
t.Fatal("")
}
// Create a random file and import on the client.
importedFile, _ := node.CreateImportFile(ctx, 1, 200)
// Get the piece size and commP
rootCid := importedFile.Root
pieceInfo, err := node.ClientDealPieceCID(ctx, rootCid)
require.NoError(t, err)
t.Log("FILE CID:", rootCid)
label, err := markettypes.NewLabelFromString("")
require.NoError(t, err)
dealProposal := markettypes.DealProposal{
PieceCID: pieceInfo.PieceCID,
PieceSize: pieceInfo.PieceSize,
Client: verifiedClientAddr,
Provider: miner.ActorAddr,
Label: label,
StartEpoch: abi.ChainEpoch(1000_000),
EndEpoch: abi.ChainEpoch(2000_000),
StoragePricePerEpoch: big.Zero(),
ProviderCollateral: big.Zero(),
ClientCollateral: big.Zero(),
VerifiedDeal: true,
}
serializedProposal := new(bytes.Buffer)
err = dealProposal.MarshalCBOR(serializedProposal)
require.NoError(t, err)
sig, err := api.WalletSign(ctx, verifiedClientAddr, serializedProposal.Bytes())
publishDealParams := markettypes.PublishStorageDealsParams{
Deals: []markettypes.ClientDealProposal{{
Proposal: dealProposal,
ClientSignature: crypto.Signature{
Type: crypto.SigTypeBLS,
Data: sig.Data,
},
}},
}
serializedParams := new(bytes.Buffer)
require.NoError(t, publishDealParams.MarshalCBOR(serializedParams))
m, err := node.MpoolPushMessage(ctx, &types.Message{
To: builtin.StorageMarketActorAddr,
From: miner.OwnerKey.Address,
Value: types.FromFil(0),
Method: builtin.MethodsMarket.PublishStorageDeals,
Params: serializedParams.Bytes(),
}, nil)
require.NoError(t, err)
r, err := node.StateWaitMsg(ctx, m.Cid(), 2, lapi.LookbackNoLimit, true)
require.NoError(t, err)
require.Equal(t, exitcode.Ok, r.Receipt.ExitCode)
ret, err := market.DecodePublishStorageDealsReturn(r.Receipt.Return, build.TestNetworkVersion)
require.NoError(t, err)
valid, _, err := ret.IsDealValid(0)
require.NoError(t, err)
require.True(t, valid)
dealIds, err := ret.DealIDs()
require.NoError(t, err)
dealInfo, err := api.StateMarketStorageDeal(ctx, dealIds[0], types.EmptyTSK)
require.NoError(t, err)
require.Equal(t, verifregtypes.AllocationId(0), dealInfo.State.VerifiedClaim) // Allocation in State should not be set yet, because it's in the allocation map
allocation, err := api.StateGetDealAllocation(ctx, dealIds[0], types.EmptyTSK)
require.NoError(t, err)
require.Equal(t, dealProposal.PieceCID, allocation.Data)
// Just another way of getting the allocation if we don't have the deal ID
allocation, err = api.StateGetAllocation(ctx, verifiedClientAddr, 3, types.EmptyTSK)
require.NoError(t, err)
require.Equal(t, dealProposal.PieceCID, allocation.Data)
}

View File

@ -19,6 +19,7 @@ import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/filecoin-project/go-state-types/big"
minertypes "github.com/filecoin-project/go-state-types/builtin/v9/miner"
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/dline"
@ -770,6 +771,57 @@ func (m *StateModule) StateMarketStorageDeal(ctx context.Context, dealId abi.Dea
return stmgr.GetStorageDeal(ctx, m.StateManager, dealId, ts)
}
func (a *StateAPI) StateGetDealAllocation(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*verifregtypes.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.GetMarketState(ctx, ts)
if err != nil {
return nil, err
}
allocationId, err := st.GetAllocationId(dealId)
if err != nil {
return nil, err
}
dealState, err := a.StateMarketStorageDeal(ctx, dealId, tsk)
if err != nil {
return nil, err
}
return a.StateGetAllocation(ctx, dealState.Proposal.Client, allocationId, tsk)
}
func (a *StateAPI) StateGetAllocation(ctx context.Context, addr address.Address, allocationId verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) {
idAddr, err := a.StateLookupID(ctx, addr, tsk)
if err != nil {
return nil, err
}
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, err
}
allocation, found, err := st.GetAllocation(idAddr, allocationId)
if err != nil {
return nil, err
}
if !found {
return nil, nil
}
return allocation, 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 {