Skip to content

Commit 6c31def

Browse files
authored
feat: api: api call to get actors cids (#4985)
* feat: api: api call to get actors cids * chore: add functional comment
1 parent 1a9f737 commit 6c31def

File tree

12 files changed

+110
-15
lines changed

12 files changed

+110
-15
lines changed

app/submodule/chain/chaininfo_api.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
logging "github.com/ipfs/go-log/v2"
1717

1818
"github.com/filecoin-project/venus/pkg/chain"
19+
"github.com/filecoin-project/venus/venus-shared/actors"
1920
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
2021
"github.com/filecoin-project/venus/venus-shared/types"
2122
)
@@ -678,3 +679,31 @@ func (cia *chainInfoAPI) StateGetNetworkParams(ctx context.Context) (*types.Netw
678679

679680
return params, nil
680681
}
682+
683+
// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
684+
func (cia *chainInfoAPI) StateActorCodeCIDs(ctx context.Context, nv network.Version) (map[string]cid.Cid, error) {
685+
actorVersion, err := actors.VersionForNetwork(nv)
686+
if err != nil {
687+
return nil, fmt.Errorf("invalid network version")
688+
}
689+
690+
cids := make(map[string]cid.Cid)
691+
692+
manifestCid, ok := actors.GetManifest(actorVersion)
693+
if !ok {
694+
return nil, fmt.Errorf("cannot get manifest CID")
695+
}
696+
697+
cids["_manifest"] = manifestCid
698+
699+
var actorKeys = actors.GetBuiltinActorsKeys()
700+
for _, name := range actorKeys {
701+
actorCID, ok := actors.GetActorCodeID(actorVersion, name)
702+
if !ok {
703+
return nil, fmt.Errorf("didn't find actor %v code id for actor version %d", name,
704+
actorVersion)
705+
}
706+
cids[name] = actorCID
707+
}
708+
return cids, nil
709+
}

cmd/state.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -636,23 +636,16 @@ var stateSysActorCIDsCmd = &cmds.Command{
636636
}
637637
buf.WriteString(fmt.Sprintf("Actor Version: %d\n", actorVersion))
638638

639-
manifestCid, ok := actors.GetManifest(actorVersion)
640-
if !ok {
641-
return fmt.Errorf("cannot get manifest CID")
642-
}
643-
buf.WriteString(fmt.Sprintf("Manifest CID: %v\n\n", manifestCid))
644-
645639
tw := tablewriter.New(tablewriter.Col("Actor"), tablewriter.Col("CID"))
646640

647-
for _, name := range actors.GetBuiltinActorsKeys() {
648-
sysActorCID, ok := actors.GetActorCodeID(actorVersion, name)
649-
if !ok {
650-
return fmt.Errorf("error getting actor %v code id for actor version %d", name,
651-
actorVersion)
652-
}
641+
actorsCids, err := env.(*node.Env).ChainAPI.StateActorCodeCIDs(ctx, nv)
642+
if err != nil {
643+
return err
644+
}
645+
for name, cid := range actorsCids {
653646
tw.Write(map[string]interface{}{
654647
"Actor": name,
655-
"CID": sysActorCID.String(),
648+
"CID": cid.String(),
656649
})
657650
}
658651

venus-devtool/api-gen/example.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ func init() {
136136
addExample(network.ReachabilityPublic)
137137
addExample(map[string]int{"name": 42})
138138
addExample(map[string]time.Time{"name": time.Unix(1615243938, 0).UTC()})
139+
addExample(map[string]cid.Cid{})
139140
addExample(&types.ExecutionTrace{
140141
Msg: ExampleValue("init", reflect.TypeOf(&types.Message{}), nil).(*types.Message),
141142
MsgRct: ExampleValue("init", reflect.TypeOf(&types.MessageReceipt{}), nil).(*types.MessageReceipt),

venus-shared/api/chain/v0/chain.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ type IChainInfo interface {
7777
ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*types.HeadChange, error) //perm:read
7878
// StateGetNetworkParams return current network params
7979
StateGetNetworkParams(ctx context.Context) (*types.NetworkParams, error) //perm:read
80+
// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
81+
StateActorCodeCIDs(context.Context, network.Version) (map[string]cid.Cid, error) //perm:read
8082
}
8183

8284
type IMinerState interface {

venus-shared/api/chain/v0/method.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* [MessageWait](#MessageWait)
4040
* [ProtocolParameters](#ProtocolParameters)
4141
* [ResolveToKeyAddr](#ResolveToKeyAddr)
42+
* [StateActorCodeCIDs](#StateActorCodeCIDs)
4243
* [StateGetNetworkParams](#StateGetNetworkParams)
4344
* [StateGetReceipt](#StateGetReceipt)
4445
* [StateNetworkName](#StateNetworkName)
@@ -1261,6 +1262,21 @@ Inputs:
12611262

12621263
Response: `"f01234"`
12631264

1265+
### StateActorCodeCIDs
1266+
StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
1267+
1268+
1269+
Perms: read
1270+
1271+
Inputs:
1272+
```json
1273+
[
1274+
16
1275+
]
1276+
```
1277+
1278+
Response: `{}`
1279+
12641280
### StateGetNetworkParams
12651281
StateGetNetworkParams return current network params
12661282

venus-shared/api/chain/v0/mock/mock_fullnode.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

venus-shared/api/chain/v0/proxy_gen.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

venus-shared/api/chain/v1/chain.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ type IChainInfo interface {
118118
ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*types.HeadChange, error) //perm:read
119119
// StateGetNetworkParams return current network params
120120
StateGetNetworkParams(ctx context.Context) (*types.NetworkParams, error) //perm:read
121+
// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
122+
StateActorCodeCIDs(context.Context, network.Version) (map[string]cid.Cid, error) //perm:read
121123
}
122124

123125
type IMinerState interface {

venus-shared/api/chain/v1/method.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* [MessageWait](#MessageWait)
4141
* [ProtocolParameters](#ProtocolParameters)
4242
* [ResolveToKeyAddr](#ResolveToKeyAddr)
43+
* [StateActorCodeCIDs](#StateActorCodeCIDs)
4344
* [StateGetBeaconEntry](#StateGetBeaconEntry)
4445
* [StateGetNetworkParams](#StateGetNetworkParams)
4546
* [StateGetRandomnessFromBeacon](#StateGetRandomnessFromBeacon)
@@ -1299,6 +1300,21 @@ Inputs:
12991300

13001301
Response: `"f01234"`
13011302

1303+
### StateActorCodeCIDs
1304+
StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
1305+
1306+
1307+
Perms: read
1308+
1309+
Inputs:
1310+
```json
1311+
[
1312+
16
1313+
]
1314+
```
1315+
1316+
Response: `{}`
1317+
13021318
### StateGetBeaconEntry
13031319
StateGetBeaconEntry returns the beacon entry for the given filecoin epoch. If
13041320
the entry has not yet been produced, the call will block until the entry

venus-shared/api/chain/v1/mock/mock_fullnode.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)