Skip to content

Commit

Permalink
Added api call to get actors cids
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball committed Jun 23, 2022
1 parent 824da5e commit e684248
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 17 deletions.
4 changes: 4 additions & 0 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"time"

abinetwork "github.com/filecoin-project/go-state-types/network"

blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
Expand Down Expand Up @@ -584,6 +586,8 @@ type FullNode interface {
StateVMCirculatingSupplyInternal(context.Context, types.TipSetKey) (CirculatingSupply, error) //perm:read
// StateNetworkVersion returns the network version at the given tipset
StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error) //perm:read
// StateActorCids 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

// 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
1 change: 1 addition & 0 deletions api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func init() {
addExample(&si)
addExample(retrievalmarket.DealID(5))
addExample(abi.ActorID(1000))
addExample(map[string]cid.Cid{})
addExample(map[string][]api.SealedRef{
"98000": {
api.SealedRef{
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.

4 changes: 4 additions & 0 deletions api/v0api/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package v0api
import (
"context"

abinetwork "github.com/filecoin-project/go-state-types/network"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
datatransfer "github.com/filecoin-project/go-data-transfer"
Expand Down Expand Up @@ -603,6 +605,8 @@ type FullNode interface {
StateVMCirculatingSupplyInternal(context.Context, types.TipSetKey) (api.CirculatingSupply, error) //perm:read
// StateNetworkVersion returns the network version at the given tipset
StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error) //perm:read
// StateActorCids 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

// 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.
2 changes: 1 addition & 1 deletion chain/actors/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func ReadManifest(ctx context.Context, store cbor.IpldStore, mfCid cid.Cid) (map
return metadata, nil
}

// GetActorCodeID looks up a builtin actor's code CID by actor version and canonical actor name name.
// GetActorCodeID looks up a builtin actor's code CID by actor version and canonical actor name.
func GetActorCodeID(av Version, name string) (cid.Cid, bool) {
manifestMx.RLock()
defer manifestMx.RUnlock()
Expand Down
21 changes: 6 additions & 15 deletions cli/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,24 +1927,15 @@ 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")

var actorKeys = actors.GetBuiltinActorsKeys()
for _, name := range actorKeys {
sysActorCID, ok := actors.GetActorCodeID(actorVersion, name)
if !ok {
return xerrors.Errorf("error getting actor %v code id for actor version %d", name,
actorVersion)
}
_, _ = fmt.Fprintf(tw, "%v\t%v\n", name, sysActorCID)

actorsCids, err := api.StateActorCodeCIDs(ctx, nv)
if err != nil {
return err
}
for name, cid := range actorsCids {
_, _ = fmt.Fprintf(tw, "%v\t%v\n", name, cid)
}
return tw.Flush()
},
Expand Down
16 changes: 16 additions & 0 deletions documentation/en/api-v0-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
* [PaychVoucherSubmit](#PaychVoucherSubmit)
* [State](#State)
* [StateAccountKey](#StateAccountKey)
* [StateActorCodeCIDs](#StateActorCodeCIDs)
* [StateAllMinerFaults](#StateAllMinerFaults)
* [StateCall](#StateCall)
* [StateChangedActors](#StateChangedActors)
Expand Down Expand Up @@ -4639,6 +4640,21 @@ Inputs:

Response: `"f01234"`

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


Perms: read

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

Response: `{}`

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

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

Response: `"f01234"`

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


Perms: read

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

Response: `{}`

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

Expand Down
31 changes: 30 additions & 1 deletion node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"fmt"
"strconv"

"github.com/filecoin-project/lotus/chain/actors"

"github.com/libp2p/go-libp2p-core/peer"

"github.com/filecoin-project/go-state-types/crypto"

"github.com/filecoin-project/go-state-types/cbor"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-cid"
"go.uber.org/fx"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -1460,6 +1462,33 @@ func (m *StateModule) StateNetworkVersion(ctx context.Context, tsk types.TipSetK
return m.StateManager.GetNetworkVersion(ctx, ts.Height()), nil
}

func (a *StateAPI) StateActorCodeCIDs(ctx context.Context, nv network.Version) (map[string]cid.Cid, error) {
actorVersion, err := actors.VersionForNetwork(nv)
if err != nil {
return nil, xerrors.Errorf("invalid network version")
}

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

manifestCid, ok := actors.GetManifest(actorVersion)
if !ok {
return nil, xerrors.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, xerrors.Errorf("didn't find actor %v code id for actor version %d", name,
actorVersion)
}
cids[name] = actorCID
}
return cids, nil
}

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

0 comments on commit e684248

Please sign in to comment.