From 4e003ff112e11b8c362fc38ee483d927c7b4a633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E9=A1=B5=E7=B4=A0=E4=B9=A6?= <2931107265@qq.com> Date: Tue, 23 Aug 2022 16:06:18 +0800 Subject: [PATCH 1/2] feat: expand state apis --- app/submodule/chain/miner_api.go | 182 +++++++++++++++++- pkg/vm/dispatch/loader.go | 12 +- pkg/vm/register/default.go | 22 +++ venus-devtool/api-gen/example.go | 5 + venus-devtool/api-gen/proxy.go | 4 + venus-shared/api/chain/v1/chain.go | 9 +- venus-shared/api/chain/v1/method.md | 175 +++++++++++++++++ .../api/chain/v1/mock/mock_fullnode.go | 91 +++++++++ venus-shared/api/chain/v1/proxy_gen.go | 25 +++ venus-shared/types/api_types.go | 22 +++ 10 files changed, 543 insertions(+), 4 deletions(-) diff --git a/app/submodule/chain/miner_api.go b/app/submodule/chain/miner_api.go index 0f82313a36..89600f9fbe 100644 --- a/app/submodule/chain/miner_api.go +++ b/app/submodule/chain/miner_api.go @@ -1,20 +1,27 @@ package chain import ( + "bytes" "context" + "encoding/json" "errors" "fmt" + "reflect" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/dline" - cbor "github.com/ipfs/go-ipld-cbor" + "github.com/ipfs/go-cid" + cbornode "github.com/ipfs/go-ipld-cbor" "github.com/libp2p/go-libp2p-core/peer" + cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/venus/pkg/state/tree" + "github.com/filecoin-project/venus/pkg/vm/register" "github.com/filecoin-project/venus/venus-shared/actors/adt" "github.com/filecoin-project/venus/venus-shared/actors/builtin" _init "github.com/filecoin-project/venus/venus-shared/actors/builtin/init" @@ -25,6 +32,7 @@ import ( "github.com/filecoin-project/venus/venus-shared/actors/policy" v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1" "github.com/filecoin-project/venus/venus-shared/types" + "github.com/filecoin-project/venus/venus-shared/utils" ) var _ v1api.IMinerState = &minerStateAPI{} @@ -179,6 +187,10 @@ func (msa *minerStateAPI) StateMinerFaults(ctx context.Context, maddr address.Ad return lminer.AllPartSectors(mas, lminer.Partition.FaultySectors) } +func (msa *minerStateAPI) StateAllMinerFaults(ctx context.Context, lookback abi.ChainEpoch, endTsk types.TipSetKey) ([]*types.Fault, error) { + return nil, fmt.Errorf("fixme") +} + // StateMinerProvingDeadline calculates the deadline at some epoch for a proving period // and returns the deadline-related calculations. func (msa *minerStateAPI) StateMinerProvingDeadline(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (*dline.Info, error) { @@ -564,7 +576,7 @@ func (msa *minerStateAPI) StateLookupRobustAddress(ctx context.Context, idAddr a return address.Undef, fmt.Errorf("failed to decode provided address as id addr: %w", err) } - cst := cbor.NewCborStore(msa.ChainReader.Blockstore()) + cst := cbornode.NewCborStore(msa.ChainReader.Blockstore()) wrapStore := adt.WrapStore(ctx, cst) _, state, err := msa.Stmgr.ParentStateTsk(ctx, tsk) @@ -840,3 +852,169 @@ func (msa *minerStateAPI) StateVerifiedClientStatus(ctx context.Context, addr ad return &dcap, nil } + +func (msa *minerStateAPI) StateChangedActors(ctx context.Context, old cid.Cid, new cid.Cid) (map[string]types.Actor, error) { + store := msa.ChainReader.Store(ctx) + + oldTree, err := tree.LoadState(ctx, store, old) + if err != nil { + return nil, fmt.Errorf("failed to load old state tree: %w", err) + } + + newTree, err := tree.LoadState(ctx, store, new) + if err != nil { + return nil, fmt.Errorf("failed to load new state tree: %w", err) + } + + return tree.Diff(oldTree, newTree) +} + +func (msa *minerStateAPI) StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.ActorState, error) { + _, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk) + if err != nil { + return nil, fmt.Errorf("loading tipset:%s parent state view: %v", tsk, err) + } + + act, err := view.LoadActor(ctx, actor) + if err != nil { + return nil, err + } + + blk, err := msa.ChainReader.Blockstore().Get(ctx, act.Head) + if err != nil { + return nil, fmt.Errorf("getting actor head: %w", err) + } + + oif, err := register.DumpActorState(register.GetDefaultActros(), act, blk.RawData()) + if err != nil { + return nil, fmt.Errorf("dumping actor state (a:%s): %w", actor, err) + } + + return &types.ActorState{ + Balance: act.Balance, + Code: act.Code, + State: oif, + }, nil +} + +func (msa *minerStateAPI) StateDecodeParams(ctx context.Context, toAddr address.Address, method abi.MethodNum, params []byte, tsk types.TipSetKey) (interface{}, error) { + _, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk) + if err != nil { + return nil, fmt.Errorf("loading tipset:%s parent state view: %v", tsk, err) + } + + act, err := view.LoadActor(ctx, toAddr) + if err != nil { + return nil, err + } + + methodMeta, found := utils.MethodsMap[act.Code][method] + if !found { + return nil, fmt.Errorf("method %d not found on actor %s", method, act.Code) + } + + paramType := reflect.New(methodMeta.Params.Elem()).Interface().(cbg.CBORUnmarshaler) + + if err = paramType.UnmarshalCBOR(bytes.NewReader(params)); err != nil { + return nil, err + } + + return paramType, nil +} + +func (msa *minerStateAPI) StateEncodeParams(ctx context.Context, toActCode cid.Cid, method abi.MethodNum, params json.RawMessage) ([]byte, error) { + methodMeta, found := utils.MethodsMap[toActCode][method] + if !found { + return nil, fmt.Errorf("method %d not found on actor %s", method, toActCode) + } + + paramType := reflect.New(methodMeta.Params.Elem()).Interface().(cbg.CBORUnmarshaler) + + if err := json.Unmarshal(params, ¶mType); err != nil { + return nil, fmt.Errorf("json unmarshal: %w", err) + } + + var cbb bytes.Buffer + if err := paramType.(cbor.Marshaler).MarshalCBOR(&cbb); err != nil { + return nil, fmt.Errorf("cbor marshal: %w", err) + } + + return cbb.Bytes(), nil +} + +func (msa *minerStateAPI) StateListMessages(ctx context.Context, match *types.MessageMatch, tsk types.TipSetKey, toheight abi.ChainEpoch) ([]cid.Cid, error) { + ts, err := msa.ChainReader.GetTipSet(ctx, tsk) + if err != nil { + return nil, fmt.Errorf("loading tipset %s: %w", tsk, err) + } + + if ts == nil { + ts = msa.ChainReader.GetHead() + } + + if match.To == address.Undef && match.From == address.Undef { + return nil, fmt.Errorf("must specify at least To or From in message filter") + } else if match.To != address.Undef { + _, err := msa.StateLookupID(ctx, match.To, tsk) + + // if the recipient doesn't exist at the start point, we're not gonna find any matches + if errors.Is(err, types.ErrActorNotFound) { + return nil, nil + } + + if err != nil { + return nil, fmt.Errorf("looking up match.To: %w", err) + } + } else if match.From != address.Undef { + _, err := msa.StateLookupID(ctx, match.From, tsk) + + // if the sender doesn't exist at the start point, we're not gonna find any matches + if errors.Is(err, types.ErrActorNotFound) { + return nil, nil + } + + if err != nil { + return nil, fmt.Errorf("looking up match.From: %w", err) + } + } + + // TODO: This should probably match on both ID and robust address, no? + matchFunc := func(msg *types.Message) bool { + if match.From != address.Undef && match.From != msg.From { + return false + } + + if match.To != address.Undef && match.To != msg.To { + return false + } + + return true + } + + var out []cid.Cid + for ts.Height() >= toheight { + msgs, err := msa.MessageStore.MessagesForTipset(ts) + if err != nil { + return nil, fmt.Errorf("failed to get messages for tipset (%s): %w", ts.Key(), err) + } + + for _, msg := range msgs { + if matchFunc(msg.VMMessage()) { + out = append(out, msg.Cid()) + } + } + + if ts.Height() == 0 { + break + } + + next, err := msa.ChainReader.GetTipSet(ctx, ts.Parents()) + if err != nil { + return nil, fmt.Errorf("loading next tipset: %w", err) + } + + ts = next + } + + return out, nil +} diff --git a/pkg/vm/dispatch/loader.go b/pkg/vm/dispatch/loader.go index 7899966c1f..2e1d6eda94 100644 --- a/pkg/vm/dispatch/loader.go +++ b/pkg/vm/dispatch/loader.go @@ -44,11 +44,21 @@ func (cl CodeLoader) GetUnsafeActorImpl(code cid.Cid) (Dispatcher, error) { //todo version check actor, ok := cl.actors[code] if !ok { - return nil, fmt.Errorf("unable to get actorv for code %s", code) + return nil, fmt.Errorf("unable to get actor for code %s", code) } return &actorDispatcher{code: code, actor: actor.vmActor}, nil } +func (cl CodeLoader) GetVMActor(code cid.Cid) (rtt.VMActor, error) { + //todo version check + actor, ok := cl.actors[code] + if !ok { + return nil, fmt.Errorf("unable to get actor for code %s", code) + } + + return actor.vmActor, nil +} + // CodeLoaderBuilder helps you build a CodeLoader. type CodeLoaderBuilder struct { actors map[cid.Cid]ActorInfo diff --git a/pkg/vm/register/default.go b/pkg/vm/register/default.go index 8491c2a9f3..1c09dcddb1 100644 --- a/pkg/vm/register/default.go +++ b/pkg/vm/register/default.go @@ -1,6 +1,8 @@ package register import ( + "bytes" + "fmt" "sync" /* inline-gen template @@ -21,6 +23,8 @@ import ( "github.com/filecoin-project/venus/pkg/vm/dispatch" "github.com/filecoin-project/venus/venus-shared/actors" + "github.com/filecoin-project/venus/venus-shared/actors/builtin" + "github.com/filecoin-project/venus/venus-shared/types" ) // defaultActors is list of all actors that ship with Filecoin. @@ -52,3 +56,21 @@ func GetDefaultActros() *dispatch.CodeLoader { return &defaultActors } + +func DumpActorState(codeLoader *dispatch.CodeLoader, act *types.Actor, b []byte) (interface{}, error) { + if builtin.IsAccountActor(act.Code) { // Account code special case + return nil, nil + } + + vmActor, err := codeLoader.GetVMActor(act.Code) + if err != nil { + return nil, fmt.Errorf("state type for actor %s not found", act.Code) + } + + um := vmActor.State() + if err := um.UnmarshalCBOR(bytes.NewReader(b)); err != nil { + return nil, fmt.Errorf("unmarshaling actor state: %w", err) + } + + return um, nil +} diff --git a/venus-devtool/api-gen/example.go b/venus-devtool/api-gen/example.go index 36ce2a8097..2752407556 100644 --- a/venus-devtool/api-gen/example.go +++ b/venus-devtool/api-gen/example.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "go/token" "os" @@ -141,6 +142,10 @@ func init() { Msg: ExampleValue("init", reflect.TypeOf(&types.Message{}), nil).(*types.Message), MsgRct: ExampleValue("init", reflect.TypeOf(&types.MessageReceipt{}), nil).(*types.MessageReceipt), }) + addExample(map[string]types.Actor{ + "t01236": ExampleValue("init", reflect.TypeOf(types.Actor{}), nil).(types.Actor), + }) + addExample(json.RawMessage(`"json raw message"`)) addExample(map[address.Address]*types.Actor{ addr: { Code: c, diff --git a/venus-devtool/api-gen/proxy.go b/venus-devtool/api-gen/proxy.go index 6df3efc38a..d404dec9ee 100644 --- a/venus-devtool/api-gen/proxy.go +++ b/venus-devtool/api-gen/proxy.go @@ -251,6 +251,10 @@ func resolveDep(typ ast.Expr, ifaceMeta *util.InterfaceMeta, deps map[string]uti return nil + case *ast.InterfaceType: + + return nil + default: return fmt.Errorf("found unexpected type: %T", typ) } diff --git a/venus-shared/api/chain/v1/chain.go b/venus-shared/api/chain/v1/chain.go index 44202ddc7e..a62afc3b71 100644 --- a/venus-shared/api/chain/v1/chain.go +++ b/venus-shared/api/chain/v1/chain.go @@ -2,6 +2,7 @@ package v1 import ( "context" + "encoding/json" "time" "github.com/filecoin-project/go-address" @@ -113,6 +114,10 @@ type IChainInfo interface { } type IMinerState interface { + StateReadState(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.ActorState, error) //perm:read + StateListMessages(ctx context.Context, match *types.MessageMatch, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) //perm:read + StateDecodeParams(ctx context.Context, toAddr address.Address, method abi.MethodNum, params []byte, tsk types.TipSetKey) (interface{}, error) //perm:read + StateEncodeParams(ctx context.Context, toActCode cid.Cid, method abi.MethodNum, params json.RawMessage) ([]byte, error) //perm:read StateMinerSectorAllocated(ctx context.Context, maddr address.Address, s abi.SectorNumber, tsk types.TipSetKey) (bool, error) //perm:read StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) //perm:read StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error) //perm:read @@ -120,8 +125,9 @@ type IMinerState interface { StateMinerSectorSize(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (abi.SectorSize, error) //perm:read StateMinerInfo(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (types.MinerInfo, error) //perm:read StateMinerWorkerAddress(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (address.Address, error) //perm:read - StateMinerRecoveries(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) //perm:read StateMinerFaults(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) //perm:read + StateAllMinerFaults(ctx context.Context, lookback abi.ChainEpoch, ts types.TipSetKey) ([]*types.Fault, error) //perm:read + StateMinerRecoveries(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) //perm:read StateMinerProvingDeadline(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (*dline.Info, error) //perm:read StateMinerPartitions(ctx context.Context, maddr address.Address, dlIdx uint64, tsk types.TipSetKey) ([]types.Partition, error) //perm:read StateMinerDeadlines(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]types.Deadline, error) //perm:read @@ -141,6 +147,7 @@ type IMinerState interface { StateMinerPower(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.MinerPower, error) //perm:read StateMinerAvailableBalance(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (big.Int, error) //perm:read StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*lminer.SectorExpiration, error) //perm:read + StateChangedActors(context.Context, cid.Cid, cid.Cid) (map[string]types.Actor, error) //perm:read StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.MinerSectors, error) //perm:read StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.MarketBalance, error) //perm:read StateDealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk types.TipSetKey) (types.DealCollateralBounds, error) //perm:read diff --git a/venus-shared/api/chain/v1/method.md b/venus-shared/api/chain/v1/method.md index dbec3ca668..5044bd94b5 100644 --- a/venus-shared/api/chain/v1/method.md +++ b/venus-shared/api/chain/v1/method.md @@ -79,9 +79,14 @@ * [MpoolSetConfig](#MpoolSetConfig) * [MpoolSub](#MpoolSub) * [MinerState](#MinerState) + * [StateAllMinerFaults](#StateAllMinerFaults) + * [StateChangedActors](#StateChangedActors) * [StateCirculatingSupply](#StateCirculatingSupply) * [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds) + * [StateDecodeParams](#StateDecodeParams) + * [StateEncodeParams](#StateEncodeParams) * [StateListActors](#StateListActors) + * [StateListMessages](#StateListMessages) * [StateListMiners](#StateListMiners) * [StateLookupID](#StateLookupID) * [StateLookupRobustAddress](#StateLookupRobustAddress) @@ -104,6 +109,7 @@ * [StateMinerSectorSize](#StateMinerSectorSize) * [StateMinerSectors](#StateMinerSectors) * [StateMinerWorkerAddress](#StateMinerWorkerAddress) + * [StateReadState](#StateReadState) * [StateSectorExpiration](#StateSectorExpiration) * [StateSectorGetInfo](#StateSectorGetInfo) * [StateSectorPartition](#StateSectorPartition) @@ -2613,6 +2619,69 @@ Response: ## MinerState +### StateAllMinerFaults + + +Perms: read + +Inputs: +```json +[ + 10101, + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ] +] +``` + +Response: +```json +[ + { + "Miner": "f01234", + "Epoch": 10101 + } +] +``` + +### StateChangedActors + + +Perms: read + +Inputs: +```json +[ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + } +] +``` + +Response: +```json +{ + "t01236": { + "Code": { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + "Head": { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + "Nonce": 42, + "Balance": "0" + } +} +``` + ### StateCirculatingSupply @@ -2663,6 +2732,48 @@ Response: } ``` +### StateDecodeParams + + +Perms: read + +Inputs: +```json +[ + "f01234", + 1, + "Ynl0ZSBhcnJheQ==", + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ] +] +``` + +Response: `{}` + +### StateEncodeParams + + +Perms: read + +Inputs: +```json +[ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + 1, + "json raw message" +] +``` + +Response: `"Ynl0ZSBhcnJheQ=="` + ### StateListActors @@ -2689,6 +2800,39 @@ Response: ] ``` +### StateListMessages + + +Perms: read + +Inputs: +```json +[ + { + "To": "f01234", + "From": "f01234" + }, + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ], + 10101 +] +``` + +Response: +```json +[ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + } +] +``` + ### StateListMiners @@ -3422,6 +3566,37 @@ Inputs: Response: `"f01234"` +### StateReadState + + +Perms: read + +Inputs: +```json +[ + "f01234", + [ + { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + { + "/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve" + } + ] +] +``` + +Response: +```json +{ + "Balance": "0", + "Code": { + "/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4" + }, + "State": {} +} +``` + ### StateSectorExpiration diff --git a/venus-shared/api/chain/v1/mock/mock_fullnode.go b/venus-shared/api/chain/v1/mock/mock_fullnode.go index a576b9c2c3..58c00bda72 100644 --- a/venus-shared/api/chain/v1/mock/mock_fullnode.go +++ b/venus-shared/api/chain/v1/mock/mock_fullnode.go @@ -6,6 +6,7 @@ package mock import ( context "context" + json "encoding/json" reflect "reflect" time "time" @@ -1772,6 +1773,21 @@ func (mr *MockFullNodeMockRecorder) StateActorCodeCIDs(arg0, arg1 interface{}) * return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateActorCodeCIDs", reflect.TypeOf((*MockFullNode)(nil).StateActorCodeCIDs), arg0, arg1) } +// StateAllMinerFaults mocks base method. +func (m *MockFullNode) StateAllMinerFaults(arg0 context.Context, arg1 abi.ChainEpoch, arg2 types.TipSetKey) ([]*types.Fault, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateAllMinerFaults", arg0, arg1, arg2) + ret0, _ := ret[0].([]*types.Fault) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateAllMinerFaults indicates an expected call of StateAllMinerFaults. +func (mr *MockFullNodeMockRecorder) StateAllMinerFaults(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateAllMinerFaults", reflect.TypeOf((*MockFullNode)(nil).StateAllMinerFaults), arg0, arg1, arg2) +} + // StateCall mocks base method. func (m *MockFullNode) StateCall(arg0 context.Context, arg1 *internal.Message, arg2 types.TipSetKey) (*types.InvocResult, error) { m.ctrl.T.Helper() @@ -1787,6 +1803,21 @@ func (mr *MockFullNodeMockRecorder) StateCall(arg0, arg1, arg2 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateCall", reflect.TypeOf((*MockFullNode)(nil).StateCall), arg0, arg1, arg2) } +// StateChangedActors mocks base method. +func (m *MockFullNode) StateChangedActors(arg0 context.Context, arg1, arg2 cid.Cid) (map[string]internal.Actor, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateChangedActors", arg0, arg1, arg2) + ret0, _ := ret[0].(map[string]internal.Actor) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateChangedActors indicates an expected call of StateChangedActors. +func (mr *MockFullNodeMockRecorder) StateChangedActors(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateChangedActors", reflect.TypeOf((*MockFullNode)(nil).StateChangedActors), arg0, arg1, arg2) +} + // StateCirculatingSupply mocks base method. func (m *MockFullNode) StateCirculatingSupply(arg0 context.Context, arg1 types.TipSetKey) (big.Int, error) { m.ctrl.T.Helper() @@ -1817,6 +1848,36 @@ func (mr *MockFullNodeMockRecorder) StateDealProviderCollateralBounds(arg0, arg1 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateDealProviderCollateralBounds", reflect.TypeOf((*MockFullNode)(nil).StateDealProviderCollateralBounds), arg0, arg1, arg2, arg3) } +// StateDecodeParams mocks base method. +func (m *MockFullNode) StateDecodeParams(arg0 context.Context, arg1 address.Address, arg2 abi.MethodNum, arg3 []byte, arg4 types.TipSetKey) (interface{}, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateDecodeParams", arg0, arg1, arg2, arg3, arg4) + ret0, _ := ret[0].(interface{}) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateDecodeParams indicates an expected call of StateDecodeParams. +func (mr *MockFullNodeMockRecorder) StateDecodeParams(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateDecodeParams", reflect.TypeOf((*MockFullNode)(nil).StateDecodeParams), arg0, arg1, arg2, arg3, arg4) +} + +// StateEncodeParams mocks base method. +func (m *MockFullNode) StateEncodeParams(arg0 context.Context, arg1 cid.Cid, arg2 abi.MethodNum, arg3 json.RawMessage) ([]byte, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateEncodeParams", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].([]byte) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateEncodeParams indicates an expected call of StateEncodeParams. +func (mr *MockFullNodeMockRecorder) StateEncodeParams(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateEncodeParams", reflect.TypeOf((*MockFullNode)(nil).StateEncodeParams), arg0, arg1, arg2, arg3) +} + // StateGetActor mocks base method. func (m *MockFullNode) StateGetActor(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (*internal.Actor, error) { m.ctrl.T.Helper() @@ -1907,6 +1968,21 @@ func (mr *MockFullNodeMockRecorder) StateListActors(arg0, arg1 interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateListActors", reflect.TypeOf((*MockFullNode)(nil).StateListActors), arg0, arg1) } +// StateListMessages mocks base method. +func (m *MockFullNode) StateListMessages(arg0 context.Context, arg1 *types.MessageMatch, arg2 types.TipSetKey, arg3 abi.ChainEpoch) ([]cid.Cid, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateListMessages", arg0, arg1, arg2, arg3) + ret0, _ := ret[0].([]cid.Cid) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateListMessages indicates an expected call of StateListMessages. +func (mr *MockFullNodeMockRecorder) StateListMessages(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateListMessages", reflect.TypeOf((*MockFullNode)(nil).StateListMessages), arg0, arg1, arg2, arg3) +} + // StateListMiners mocks base method. func (m *MockFullNode) StateListMiners(arg0 context.Context, arg1 types.TipSetKey) ([]address.Address, error) { m.ctrl.T.Helper() @@ -2282,6 +2358,21 @@ func (mr *MockFullNodeMockRecorder) StateNetworkVersion(arg0, arg1 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateNetworkVersion", reflect.TypeOf((*MockFullNode)(nil).StateNetworkVersion), arg0, arg1) } +// StateReadState mocks base method. +func (m *MockFullNode) StateReadState(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (*types.ActorState, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateReadState", arg0, arg1, arg2) + ret0, _ := ret[0].(*types.ActorState) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateReadState indicates an expected call of StateReadState. +func (mr *MockFullNodeMockRecorder) StateReadState(arg0, arg1, arg2 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateReadState", reflect.TypeOf((*MockFullNode)(nil).StateReadState), arg0, arg1, arg2) +} + // StateSearchMsg mocks base method. func (m *MockFullNode) StateSearchMsg(arg0 context.Context, arg1 types.TipSetKey, arg2 cid.Cid, arg3 abi.ChainEpoch, arg4 bool) (*types.MsgLookup, error) { m.ctrl.T.Helper() diff --git a/venus-shared/api/chain/v1/proxy_gen.go b/venus-shared/api/chain/v1/proxy_gen.go index 2846834ba7..711b65e872 100644 --- a/venus-shared/api/chain/v1/proxy_gen.go +++ b/venus-shared/api/chain/v1/proxy_gen.go @@ -3,6 +3,7 @@ package v1 import ( "context" + "encoding/json" "time" address "github.com/filecoin-project/go-address" @@ -76,9 +77,14 @@ func (s *IActorStruct) StateGetActor(p0 context.Context, p1 address.Address, p2 type IMinerStateStruct struct { Internal struct { + StateAllMinerFaults func(ctx context.Context, lookback abi.ChainEpoch, ts types.TipSetKey) ([]*types.Fault, error) `perm:"read"` + StateChangedActors func(context.Context, cid.Cid, cid.Cid) (map[string]types.Actor, error) `perm:"read"` StateCirculatingSupply func(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) `perm:"read"` StateDealProviderCollateralBounds func(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk types.TipSetKey) (types.DealCollateralBounds, error) `perm:"read"` + StateDecodeParams func(ctx context.Context, toAddr address.Address, method abi.MethodNum, params []byte, tsk types.TipSetKey) (interface{}, error) `perm:"read"` + StateEncodeParams func(ctx context.Context, toActCode cid.Cid, method abi.MethodNum, params json.RawMessage) ([]byte, error) `perm:"read"` StateListActors func(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error) `perm:"read"` + StateListMessages func(ctx context.Context, match *types.MessageMatch, tsk types.TipSetKey, toht abi.ChainEpoch) ([]cid.Cid, error) `perm:"read"` StateListMiners func(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error) `perm:"read"` StateLookupID func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) `perm:"read"` StateLookupRobustAddress func(context.Context, address.Address, types.TipSetKey) (address.Address, error) `perm:"read"` @@ -101,6 +107,7 @@ type IMinerStateStruct struct { StateMinerSectorSize func(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (abi.SectorSize, error) `perm:"read"` StateMinerSectors func(ctx context.Context, maddr address.Address, sectorNos *bitfield.BitField, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) `perm:"read"` StateMinerWorkerAddress func(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (address.Address, error) `perm:"read"` + StateReadState func(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.ActorState, error) `perm:"read"` StateSectorExpiration func(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*lminer.SectorExpiration, error) `perm:"read"` StateSectorGetInfo func(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` StateSectorPartition func(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*lminer.SectorLocation, error) `perm:"read"` @@ -110,15 +117,30 @@ type IMinerStateStruct struct { } } +func (s *IMinerStateStruct) StateAllMinerFaults(p0 context.Context, p1 abi.ChainEpoch, p2 types.TipSetKey) ([]*types.Fault, error) { + return s.Internal.StateAllMinerFaults(p0, p1, p2) +} +func (s *IMinerStateStruct) StateChangedActors(p0 context.Context, p1 cid.Cid, p2 cid.Cid) (map[string]types.Actor, error) { + return s.Internal.StateChangedActors(p0, p1, p2) +} func (s *IMinerStateStruct) StateCirculatingSupply(p0 context.Context, p1 types.TipSetKey) (abi.TokenAmount, error) { return s.Internal.StateCirculatingSupply(p0, p1) } func (s *IMinerStateStruct) StateDealProviderCollateralBounds(p0 context.Context, p1 abi.PaddedPieceSize, p2 bool, p3 types.TipSetKey) (types.DealCollateralBounds, error) { return s.Internal.StateDealProviderCollateralBounds(p0, p1, p2, p3) } +func (s *IMinerStateStruct) StateDecodeParams(p0 context.Context, p1 address.Address, p2 abi.MethodNum, p3 []byte, p4 types.TipSetKey) (interface{}, error) { + return s.Internal.StateDecodeParams(p0, p1, p2, p3, p4) +} +func (s *IMinerStateStruct) StateEncodeParams(p0 context.Context, p1 cid.Cid, p2 abi.MethodNum, p3 json.RawMessage) ([]byte, error) { + return s.Internal.StateEncodeParams(p0, p1, p2, p3) +} func (s *IMinerStateStruct) StateListActors(p0 context.Context, p1 types.TipSetKey) ([]address.Address, error) { return s.Internal.StateListActors(p0, p1) } +func (s *IMinerStateStruct) StateListMessages(p0 context.Context, p1 *types.MessageMatch, p2 types.TipSetKey, p3 abi.ChainEpoch) ([]cid.Cid, error) { + return s.Internal.StateListMessages(p0, p1, p2, p3) +} func (s *IMinerStateStruct) StateListMiners(p0 context.Context, p1 types.TipSetKey) ([]address.Address, error) { return s.Internal.StateListMiners(p0, p1) } @@ -185,6 +207,9 @@ func (s *IMinerStateStruct) StateMinerSectors(p0 context.Context, p1 address.Add func (s *IMinerStateStruct) StateMinerWorkerAddress(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (address.Address, error) { return s.Internal.StateMinerWorkerAddress(p0, p1, p2) } +func (s *IMinerStateStruct) StateReadState(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*types.ActorState, error) { + return s.Internal.StateReadState(p0, p1, p2) +} func (s *IMinerStateStruct) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorExpiration, error) { return s.Internal.StateSectorExpiration(p0, p1, p2, p3) } diff --git a/venus-shared/types/api_types.go b/venus-shared/types/api_types.go index 5fbd77c4a8..b0faf8dc77 100644 --- a/venus-shared/types/api_types.go +++ b/venus-shared/types/api_types.go @@ -12,10 +12,16 @@ import ( "github.com/libp2p/go-libp2p-core/peer" "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/venus/venus-shared/actors/builtin" "github.com/filecoin-project/venus/venus-shared/actors/builtin/power" ) +type ComputeStateOutput struct { + Root cid.Cid + Trace []*InvocResult +} + type HeadChangeType string // HeadChangeTopic is the topic used to publish new heads. @@ -57,6 +63,12 @@ type MessageCID struct { Message *Message } +type ActorState struct { + Balance BigInt + Code cid.Cid + State interface{} +} + type NetworkName string const ( @@ -91,6 +103,16 @@ type Partition struct { ActiveSectors bitfield.BitField } +type Fault struct { + Miner address.Address + Epoch abi.ChainEpoch +} + +type MessageMatch struct { + To address.Address + From address.Address +} + // SectorInfo provides information about a sector construction type SectorInfo struct { Size abi.SectorSize From 3b7713b57bc6c892c9a5061a9206f9cb7cc82648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E9=A1=B5=E7=B4=A0=E4=B9=A6?= <2931107265@qq.com> Date: Tue, 23 Aug 2022 16:36:16 +0800 Subject: [PATCH 2/2] fix(CI): check compatible-apis --- venus-shared/compatible-checks/api-diff.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index 8fd0b434e9..31c597483a 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -202,17 +202,11 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c + SetConcurrent + SetPassword - Shutdown - - StateAllMinerFaults - - StateChangedActors - StateCompute - StateComputeDataCID - - StateDecodeParams - - StateEncodeParams > StateGetNetworkParams {[func(context.Context) (*types.NetworkParams, error) <> func(context.Context) (*api.NetworkParams, error)] base=func out type: #0 input; nested={[*types.NetworkParams <> *api.NetworkParams] base=pointed type; nested={[types.NetworkParams <> api.NetworkParams] base=struct field; nested={[types.NetworkParams <> api.NetworkParams] base=exported field type: #5 field named ForkUpgradeParams; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=struct field; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=exported field name: #8 field, BreezeGasTampingDuration != UpgradePriceListOopsHeight; nested=nil}}}}}} - - StateListMessages + StateMinerSectorSize + StateMinerWorkerAddress - - StateReadState - StateReplay > StateSectorPreCommitInfo {[func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) <> func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorPreCommitOnChainInfo, error)] base=func out type: #0 input; nested={[miner.SectorPreCommitOnChainInfo <> *miner.SectorPreCommitOnChainInfo] base=type kinds: struct != ptr; nested=nil}} - SyncCheckBad