Skip to content

Commit

Permalink
Api call to get actor cids works for versions < 16
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Jun 28, 2022
1 parent ed735a3 commit d43a062
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 14 deletions.
2 changes: 2 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,8 @@ type FullNode interface {
StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error) //perm:read
// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
StateActorCodeCIDs(context.Context, abinetwork.Version) (map[string]cid.Cid, error) //perm:read
// StateActorManifestCID returns the CID of the builtin actors manifest for the given network version
StateActorManifestCID(context.Context, abinetwork.Version) (cid.Cid, error) //perm:read

// StateGetRandomnessFromTickets is used to sample the chain for randomness.
StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) //perm:read
Expand Down
15 changes: 15 additions & 0 deletions api/mocks/mock_full.go

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

13 changes: 13 additions & 0 deletions api/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 api/v0api/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ type FullNode interface {
StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error) //perm:read
// StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version
StateActorCodeCIDs(context.Context, abinetwork.Version) (map[string]cid.Cid, error) //perm:read
// StateActorManifestCID returns the CID of the builtin actors manifest for the given network version
StateActorManifestCID(context.Context, abinetwork.Version) (cid.Cid, error) //perm:read

// StateGetRandomnessFromTickets is used to sample the chain for randomness.
StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) //perm:read
Expand Down
13 changes: 13 additions & 0 deletions api/v0api/proxy_gen.go

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

15 changes: 15 additions & 0 deletions api/v0api/v0mocks/mock_full.go

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

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
9 changes: 9 additions & 0 deletions chain/actors/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ func GetActorCodeID(av Version, name string) (cid.Cid, bool) {
return c, ok
}

// GetActorCodeIDs looks up a builtin actor's code CID by actor version.
func GetActorCodeIDs(av Version) (map[string]cid.Cid, bool) {
manifestMx.RLock()
defer manifestMx.RUnlock()

cids, ok := manifests[av]
return cids, ok
}

func GetActorMetaByCode(c cid.Cid) (string, Version, bool) {
manifestMx.RLock()
defer manifestMx.RUnlock()
Expand Down
6 changes: 6 additions & 0 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,12 @@ var StateSysActorCIDsCmd = &cli.Command{
}
fmt.Printf("Actor Version: %d\n", actorVersion)

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

tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
_, _ = fmt.Fprintln(tw, "\nActor\tCID\t")

Expand Down
21 changes: 21 additions & 0 deletions documentation/en/api-v0-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
* [State](#State)
* [StateAccountKey](#StateAccountKey)
* [StateActorCodeCIDs](#StateActorCodeCIDs)
* [StateActorManifestCID](#StateActorManifestCID)
* [StateAllMinerFaults](#StateAllMinerFaults)
* [StateCall](#StateCall)
* [StateChangedActors](#StateChangedActors)
Expand Down Expand Up @@ -4655,6 +4656,26 @@ Inputs:

Response: `{}`

### StateActorManifestCID
StateActorManifestCID returns the CID of the builtin actors manifest for the given network version


Perms: read

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

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

### StateAllMinerFaults
StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset

Expand Down
21 changes: 21 additions & 0 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
* [State](#State)
* [StateAccountKey](#StateAccountKey)
* [StateActorCodeCIDs](#StateActorCodeCIDs)
* [StateActorManifestCID](#StateActorManifestCID)
* [StateAllMinerFaults](#StateAllMinerFaults)
* [StateCall](#StateCall)
* [StateChangedActors](#StateChangedActors)
Expand Down Expand Up @@ -5065,6 +5066,26 @@ Inputs:

Response: `{}`

### StateActorManifestCID
StateActorManifestCID returns the CID of the builtin actors manifest for the given network version


Perms: read

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

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

### StateAllMinerFaults
StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset

Expand Down
29 changes: 15 additions & 14 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1468,25 +1468,26 @@ func (a *StateAPI) StateActorCodeCIDs(ctx context.Context, nv network.Version) (
return nil, xerrors.Errorf("invalid network version")
}

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

manifestCid, ok := actors.GetManifest(actorVersion)
cids, ok := actors.GetActorCodeIDs(actorVersion)
if !ok {
return nil, xerrors.Errorf("cannot get manifest CID")
return nil, xerrors.Errorf("could not find cids for network version %d, actors version %d", nv, actorVersion)
}

cids["_manifest"] = manifestCid
return cids, nil
}

var actorKeys = actors.GetBuiltinActorsKeys()
for _, name := range actorKeys {
actorCID, ok := actors.GetActorCodeID(actorVersion, name)
if !ok {
return nil, xerrors.Errorf("didn't find actor %v code id for actor version %d", name,
actorVersion)
}
cids[name] = actorCID
func (a *StateAPI) StateActorManifestCID(ctx context.Context, nv network.Version) (cid.Cid, error) {
actorVersion, err := actors.VersionForNetwork(nv)
if err != nil {
return cid.Undef, xerrors.Errorf("invalid network version")
}
return cids, nil

c, ok := actors.GetManifest(actorVersion)
if !ok {
return cid.Undef, xerrors.Errorf("could not find manifest cid for network version %d, actors version %d", nv, actorVersion)
}

return c, nil
}

func (a *StateAPI) StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) {
Expand Down

0 comments on commit d43a062

Please sign in to comment.