Skip to content

feat: api: api call to get actors cids #4985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/submodule/chain/chaininfo_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
logging "github.com/ipfs/go-log/v2"

"github.com/filecoin-project/venus/pkg/chain"
"github.com/filecoin-project/venus/venus-shared/actors"
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
"github.com/filecoin-project/venus/venus-shared/types"
)
Expand Down Expand Up @@ -678,3 +679,31 @@ func (cia *chainInfoAPI) StateGetNetworkParams(ctx context.Context) (*types.Netw

return params, nil
}

// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
func (cia *chainInfoAPI) StateActorCodeCIDs(ctx context.Context, nv network.Version) (map[string]cid.Cid, error) {
actorVersion, err := actors.VersionForNetwork(nv)
if err != nil {
return nil, fmt.Errorf("invalid network version")
}

cids := make(map[string]cid.Cid)

manifestCid, ok := actors.GetManifest(actorVersion)
if !ok {
return nil, fmt.Errorf("cannot get manifest CID")
}

cids["_manifest"] = manifestCid

var actorKeys = actors.GetBuiltinActorsKeys()
for _, name := range actorKeys {
actorCID, ok := actors.GetActorCodeID(actorVersion, name)
if !ok {
return nil, fmt.Errorf("didn't find actor %v code id for actor version %d", name,
actorVersion)
}
cids[name] = actorCID
}
return cids, nil
}
19 changes: 6 additions & 13 deletions cmd/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,23 +636,16 @@ var stateSysActorCIDsCmd = &cmds.Command{
}
buf.WriteString(fmt.Sprintf("Actor Version: %d\n", actorVersion))

manifestCid, ok := actors.GetManifest(actorVersion)
if !ok {
return fmt.Errorf("cannot get manifest CID")
}
buf.WriteString(fmt.Sprintf("Manifest CID: %v\n\n", manifestCid))

tw := tablewriter.New(tablewriter.Col("Actor"), tablewriter.Col("CID"))

for _, name := range actors.GetBuiltinActorsKeys() {
sysActorCID, ok := actors.GetActorCodeID(actorVersion, name)
if !ok {
return fmt.Errorf("error getting actor %v code id for actor version %d", name,
actorVersion)
}
actorsCids, err := env.(*node.Env).ChainAPI.StateActorCodeCIDs(ctx, nv)
if err != nil {
return err
}
for name, cid := range actorsCids {
tw.Write(map[string]interface{}{
"Actor": name,
"CID": sysActorCID.String(),
"CID": cid.String(),
})
}

Expand Down
1 change: 1 addition & 0 deletions venus-devtool/api-gen/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func init() {
addExample(network.ReachabilityPublic)
addExample(map[string]int{"name": 42})
addExample(map[string]time.Time{"name": time.Unix(1615243938, 0).UTC()})
addExample(map[string]cid.Cid{})
addExample(&types.ExecutionTrace{
Msg: ExampleValue("init", reflect.TypeOf(&types.Message{}), nil).(*types.Message),
MsgRct: ExampleValue("init", reflect.TypeOf(&types.MessageReceipt{}), nil).(*types.MessageReceipt),
Expand Down
2 changes: 2 additions & 0 deletions venus-shared/api/chain/v0/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ type IChainInfo interface {
ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*types.HeadChange, error) //perm:read
// StateGetNetworkParams return current network params
StateGetNetworkParams(ctx context.Context) (*types.NetworkParams, error) //perm:read
// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
StateActorCodeCIDs(context.Context, network.Version) (map[string]cid.Cid, error) //perm:read
}

type IMinerState interface {
Expand Down
16 changes: 16 additions & 0 deletions venus-shared/api/chain/v0/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* [MessageWait](#MessageWait)
* [ProtocolParameters](#ProtocolParameters)
* [ResolveToKeyAddr](#ResolveToKeyAddr)
* [StateActorCodeCIDs](#StateActorCodeCIDs)
* [StateGetNetworkParams](#StateGetNetworkParams)
* [StateGetReceipt](#StateGetReceipt)
* [StateNetworkName](#StateNetworkName)
Expand Down Expand Up @@ -1261,6 +1262,21 @@ Inputs:

Response: `"f01234"`

### StateActorCodeCIDs
StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version


Perms: read

Inputs:
```json
[
16
]
```

Response: `{}`

### StateGetNetworkParams
StateGetNetworkParams return current network params

Expand Down
15 changes: 15 additions & 0 deletions venus-shared/api/chain/v0/mock/mock_fullnode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions venus-shared/api/chain/v0/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions venus-shared/api/chain/v1/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ type IChainInfo interface {
ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*types.HeadChange, error) //perm:read
// StateGetNetworkParams return current network params
StateGetNetworkParams(ctx context.Context) (*types.NetworkParams, error) //perm:read
// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
StateActorCodeCIDs(context.Context, network.Version) (map[string]cid.Cid, error) //perm:read
}

type IMinerState interface {
Expand Down
16 changes: 16 additions & 0 deletions venus-shared/api/chain/v1/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* [MessageWait](#MessageWait)
* [ProtocolParameters](#ProtocolParameters)
* [ResolveToKeyAddr](#ResolveToKeyAddr)
* [StateActorCodeCIDs](#StateActorCodeCIDs)
* [StateGetBeaconEntry](#StateGetBeaconEntry)
* [StateGetNetworkParams](#StateGetNetworkParams)
* [StateGetRandomnessFromBeacon](#StateGetRandomnessFromBeacon)
Expand Down Expand Up @@ -1299,6 +1300,21 @@ Inputs:

Response: `"f01234"`

### StateActorCodeCIDs
StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version


Perms: read

Inputs:
```json
[
16
]
```

Response: `{}`

### 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
Expand Down
15 changes: 15 additions & 0 deletions venus-shared/api/chain/v1/mock/mock_fullnode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions venus-shared/api/chain/v1/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions venus-shared/compatible-checks/api-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v0.FullNode <> github.c
+ SetPassword
- Shutdown
> StateAccountKey {[func(context.Context, address.Address, types.TipSetKey) (address.Address, error) <> func(context.Context, address.Address, types.TipSetKey) (address.Address, error)] base=func in type: #2 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}}
- StateActorCodeCIDs
- StateAllMinerFaults
> StateCall {[func(context.Context, *internal.Message, types.TipSetKey) (*types.InvocResult, error) <> func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error)] base=func in type: #2 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}}
- StateChangedActors
Expand Down Expand Up @@ -326,7 +325,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c
+ SetPassword
- Shutdown
> StateAccountKey {[func(context.Context, address.Address, types.TipSetKey) (address.Address, error) <> func(context.Context, address.Address, types.TipSetKey) (address.Address, error)] base=func in type: #2 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}}
- StateActorCodeCIDs
- StateAllMinerFaults
> StateCall {[func(context.Context, *internal.Message, types.TipSetKey) (*types.InvocResult, error) <> func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error)] base=func in type: #2 input; nested={[types.TipSetKey <> types.TipSetKey] base=codec marshaler implementations for codec Cbor: true != false; nested=nil}}
- StateChangedActors
Expand Down