Skip to content

Feat/0x5459/improve actor control list #714

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 5 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 6 additions & 7 deletions venus-sector-manager/cmd/venus-sector-manager/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
"github.com/urfave/cli/v2"

"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/cmd/venus-sector-manager/internal"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/core"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/dep"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/modules"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/pkg/confmgr"
vsmplugin "github.com/ipfs-force-community/venus-cluster/vsm-plugin"
)

var daemonCmd = &cli.Command{
Expand Down Expand Up @@ -104,8 +102,7 @@ var daemonRunCmd = &cli.Command{
EnableSectorIndexer: !cctx.Bool(daemonRunProxySectorIndexerOffFlag.Name),
}

var node core.SealerAPI
var loadedPlugins *vsmplugin.LoadedPlugins
var apiServer *APIServer
stopper, err := dix.New(
gctx,
dep.Product(),
Expand All @@ -122,12 +119,14 @@ var daemonRunCmd = &cli.Command{
dep.Miner(),
),
dix.If(cctx.Bool("ext-prover"), dep.ExtProver()),
dep.Sealer(&node, &loadedPlugins),
dep.Sealer(),
dix.Override(new(*APIServer), NewAPIServer),
dix.Populate(dep.InvokePopulate, &apiServer),
)
if err != nil {
return fmt.Errorf("construct sealer api: %w", err)
return fmt.Errorf("construct api: %w", err)
}

return serveSealerAPI(gctx, stopper, node, cctx.String("listen"), loadedPlugins)
return serveAPI(gctx, stopper, apiServer, cctx.String("listen"))
},
}
13 changes: 7 additions & 6 deletions venus-sector-manager/cmd/venus-sector-manager/internal/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,32 @@ func HomeFromCLICtx(cctx *cli.Context) (*homedir.Home, error) {
return home, nil
}

type API struct {
type APIClient struct {
fx.In
Chain chain.API
Messager messager.API
Market market.API
Sealer core.SealerCliClient
Miner core.MinerAPIClient
}

func extractAPI(cctx *cli.Context, target ...interface{}) (*API, context.Context, stopper, error) {
func extractAPI(cctx *cli.Context, target ...interface{}) (*APIClient, context.Context, stopper, error) {
gctx, gcancel := NewSigContext(cctx.Context)

var a API
var a APIClient
wants := append([]interface{}{&a}, target...)

stopper, err := dix.New(
gctx,
dep.API(wants...),
dep.APIClient(wants...),
DepsFromCLICtx(cctx),
dix.Override(new(dep.GlobalContext), gctx),
dix.Override(new(dep.ListenAddress), dep.ListenAddress(cctx.String(SealerListenFlag.Name))),
)

if err != nil {
gcancel()
return nil, nil, nil, fmt.Errorf("construct sealer api: %w", err)
return nil, nil, nil, fmt.Errorf("construct api: %w", err)
}

return &a, gctx, func() {
Expand Down Expand Up @@ -167,7 +168,7 @@ func ShouldSectorNumber(s string) (abi.SectorNumber, error) {
return abi.SectorNumber(num), nil
}

func waitMessage(ctx context.Context, api *API, rawMsg *messager.UnsignedMessage, exid string, mlog *logging.ZapLogger, ret cbor.Unmarshaler) error {
func waitMessage(ctx context.Context, api *APIClient, rawMsg *messager.UnsignedMessage, exid string, mlog *logging.ZapLogger, ret cbor.Unmarshaler) error {
if mlog == nil {
mlog = Log.With("action", "wait-message")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import (
"fmt"
"os"
"strconv"
"strings"

"text/tabwriter"

"github.com/fatih/color"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
Expand All @@ -15,6 +19,7 @@ import (
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/actors/adt"
"github.com/filecoin-project/venus/venus-shared/actors/builtin"
"github.com/filecoin-project/venus/venus-shared/actors/builtin/miner"
"github.com/filecoin-project/venus/venus-shared/types"
cbor "github.com/ipfs/go-ipld-cbor"
Expand Down Expand Up @@ -379,20 +384,84 @@ var utilSealerActorControlList = &cli.Command{
return err
}

mi, err := api.Chain.StateMinerInfo(ctx, maddr, types.EmptyTSK)
minerInfo, err := api.Chain.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}

fmt.Fprintln(os.Stdout, "Owner:")
fmt.Fprintf(os.Stdout, "\t%s\n", mi.Owner.String())
mid, err := address.IDFromAddress(maddr)
if err != nil {
return fmt.Errorf("invalid miner addr '%s': %w", maddr, err)
}
minerConfig, err := api.Miner.GetMinerConfig(ctx, abi.ActorID(mid))
if err != nil {
return fmt.Errorf("get miner config: %w", err)
}

tw := tabwriter.NewWriter(os.Stdout, 2, 10, 2, ' ', 0)
defer tw.Flush()
_, _ = fmt.Fprintln(tw, "name\tID\tkey\tuse\tbalance")

printKey := func(name string, addr address.Address) {
var actor *types.Actor
if actor, err = api.Chain.StateGetActor(ctx, addr, types.EmptyTSK); err != nil {
fmt.Printf("%s\t%s: error getting actor: %s\n", name, addr, err)
return
}

var k = addr
// `a` maybe a `robust`, in that case, `StateAccountKey` returns an error.
if builtin.IsAccountActor(actor.Code) {
if k, err = api.Chain.StateAccountKey(ctx, addr, types.EmptyTSK); err != nil {
fmt.Printf("%s\t%s: error getting account key: %s\n", name, addr, err)
return
}
}
kstr := k.String()
if !cctx.Bool("verbose") {
if len(kstr) > 9 {
kstr = kstr[:6] + "..."
}
}

balance := types.FIL(actor.Balance).String()
switch {
case actor.Balance.LessThan(types.FromFil(10)):
balance = color.RedString(balance)
case actor.Balance.LessThan(types.FromFil(50)):
balance = color.YellowString(balance)
default:
balance = color.GreenString(balance)
}

var uses []string
if addr == minerInfo.Worker {
uses = append(uses, color.YellowString("other"))
}
if addr == minerConfig.Commitment.Pre.Sender.Std() {
uses = append(uses, color.CyanString("precommit"))
}
if addr == minerConfig.Commitment.Prove.Sender.Std() {
uses = append(uses, color.BlueString("provecommit"))
}
if addr == minerConfig.Commitment.Terminate.Sender.Std() {
uses = append(uses, color.YellowString("terminate"))
}
if addr == minerConfig.PoSt.Sender.Std() {
uses = append(uses, color.GreenString("post"))
}
if addr == minerConfig.SnapUp.Sender.Std() {
uses = append(uses, color.MagentaString("snapup"))
}

fmt.Fprintln(os.Stdout, "Worker:")
fmt.Fprintf(os.Stdout, "\t%s\n", mi.Worker.String())
_, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", name, addr, kstr, strings.Join(uses, " "), balance)
}

fmt.Fprintln(os.Stdout, "Control:")
for _, ca := range mi.ControlAddresses {
fmt.Fprintf(os.Stdout, "\t%s\n", ca.String())
printKey("owner", minerInfo.Owner)
printKey("worker", minerInfo.Worker)
printKey("beneficiary", minerInfo.Beneficiary)
for i, ca := range minerInfo.ControlAddresses {
printKey(fmt.Sprintf("control-%d", i), ca)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ func openDestDatastore(repoPath string) (datastore.Batching, error) {
})
}

func sectorState2SectorInfo(ctx context.Context, api *API, state *core.SectorState) (*lotusminer.SectorSealingInfo, error) {
func sectorState2SectorInfo(ctx context.Context, api *APIClient, state *core.SectorState) (*lotusminer.SectorSealingInfo, error) {
var toChainCid = func(mid string) *cid.Cid {
undefCid := cid.NewCidV0(u.Hash([]byte("undef")))
c := &undefCid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var utilWorkerResumeCmd = &cli.Command{
},
}

func resolveWorkerDest(ctx context.Context, a *API, name string) (string, error) {
func resolveWorkerDest(ctx context.Context, a *APIClient, name string) (string, error) {
var info *core.WorkerPingInfo
var err error
if a != nil {
Expand Down
7 changes: 3 additions & 4 deletions venus-sector-manager/cmd/venus-sector-manager/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/urfave/cli/v2"

"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/cmd/venus-sector-manager/internal"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/core"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/dep"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/modules/util"
)
Expand Down Expand Up @@ -45,20 +44,20 @@ var mockCmd = &cli.Command{
gctx, gcancel := internal.NewSigContext(cctx.Context)
defer gcancel()

var node core.SealerAPI
var apiServer *APIServer
stopper, err := dix.New(
gctx,
dix.Override(new(dep.GlobalContext), gctx),
dix.Override(new(abi.ActorID), abi.ActorID(cctx.Uint64("miner"))),
dix.Override(new(abi.RegisteredSealProof), proofType),
dep.Mock(),
dep.MockSealer(&node),
dep.MockSealer(&apiServer),
)

if err != nil {
return fmt.Errorf("construct mock api: %w", err)
}

return serveSealerAPI(gctx, stopper, node, cctx.String("listen"), nil)
return serveAPI(gctx, stopper, apiServer, cctx.String("listen"))
},
}
64 changes: 49 additions & 15 deletions venus-sector-manager/cmd/venus-sector-manager/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,52 @@ import (
vsmplugin "github.com/ipfs-force-community/venus-cluster/vsm-plugin"
)

func serveSealerAPI(ctx context.Context, stopper dix.StopFunc, node core.SealerAPI, addr string, plugins *vsmplugin.LoadedPlugins) error {
mux, err := buildRPCServer(node, plugins)
func NewAPIServer(sealerAPI core.SealerAPI, minerAPI core.MinerAPI, plugins *vsmplugin.LoadedPlugins) *APIServer {
return &APIServer{
sealerAPI: sealerAPI,
minerAPI: minerAPI,
plugins: plugins,
}
}

type handler struct {
namespace string
hdl interface{}
}

type APIServer struct {
sealerAPI core.SealerAPI
minerAPI core.MinerAPI
plugins *vsmplugin.LoadedPlugins
}

func (api *APIServer) handlers() []handler {
handlers := make([]handler, 0, 2)
handlers = append(handlers, handler{
namespace: core.SealerAPINamespace,
hdl: api.sealerAPI,
})
handlers = append(handlers, handler{
namespace: core.MinerAPINamespace,
hdl: api.minerAPI,
})
if api.plugins != nil {
_ = api.plugins.Foreach(vsmplugin.RegisterJsonRpc, func(plugin *vsmplugin.Plugin) error {
m := vsmplugin.DeclareRegisterJsonRpcManifest(plugin.Manifest)
namespace, hdl := m.Handler()
log.Infof("register json rpc handler by plugin(%s). namespace: '%s'", plugin.Name, namespace)
handlers = append(handlers, handler{
namespace: namespace,
hdl: hdl,
})
return nil
})
}
return handlers
}

func serveAPI(ctx context.Context, stopper dix.StopFunc, apiServer *APIServer, addr string) error {
mux, err := buildRPCServer(apiServer)
if err != nil {
return fmt.Errorf("construct rpc server: %w", err)
}
Expand Down Expand Up @@ -61,23 +105,13 @@ func serveSealerAPI(ctx context.Context, stopper dix.StopFunc, node core.SealerA
return nil
}

func buildRPCServer(hdl interface{}, plugins *vsmplugin.LoadedPlugins, opts ...jsonrpc.ServerOption) (*http.ServeMux, error) {
func buildRPCServer(apiServer *APIServer, opts ...jsonrpc.ServerOption) (*http.ServeMux, error) {
// use field
opts = append(opts, jsonrpc.WithProxyBind(jsonrpc.PBField))
hdl = proxy.MetricedSealerAPI(core.APINamespace, hdl)

server := jsonrpc.NewServer(opts...)

server.Register(core.APINamespace, hdl)

if plugins != nil {
_ = plugins.Foreach(vsmplugin.RegisterJsonRpc, func(plugin *vsmplugin.Plugin) error {
m := vsmplugin.DeclareRegisterJsonRpcManifest(plugin.Manifest)
namespace, hdl := m.Handler()
log.Infof("register json rpc handler by plugin(%s). namespace: '%s'", plugin.Name, namespace)
server.Register(namespace, proxy.MetricedSealerAPI(namespace, hdl))
return nil
})
for _, hdl := range apiServer.handlers() {
server.Register(hdl.namespace, proxy.MetricedAPI(hdl.namespace, hdl.hdl))
}

http.Handle(fmt.Sprintf("/rpc/v%d", core.MajorVersion), server)
Expand Down
13 changes: 9 additions & 4 deletions venus-sector-manager/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (

"github.com/filecoin-project/venus/venus-shared/actors/builtin"
"github.com/filecoin-project/venus/venus-shared/types"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/modules"
)

const (
APINamespace = "Venus"
MajorVersion = 0
// TODO: The sealerAPI namespace is Venus due to historical reasons,
// and we should consider changing it to a more appropriate name in future versions
SealerAPINamespace = "Venus"
MinerAPINamespace = "Damocles.miner"
MajorVersion = 0
)

var Empty Meta
Expand Down Expand Up @@ -119,6 +123,7 @@ type RandomnessAPI interface {
GetWindowPoStCommitRand(context.Context, types.TipSetKey, abi.ChainEpoch) (WindowPoStRandomness, error)
}

type MinerInfoAPI interface {
Get(context.Context, abi.ActorID) (*MinerInfo, error)
type MinerAPI interface {
GetInfo(context.Context, abi.ActorID) (*MinerInfo, error)
GetMinerConfig(context.Context, abi.ActorID) (*modules.MinerConfig, error)
}
15 changes: 15 additions & 0 deletions venus-sector-manager/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs-force-community/venus-cluster/venus-sector-manager/modules"

"github.com/filecoin-project/venus/venus-shared/actors/builtin"
)
Expand Down Expand Up @@ -167,3 +168,17 @@ type SealerCliClient struct {

SubmitProof func(context.Context, abi.SectorID, ProofOnChainInfo, bool) (SubmitProofResp, error)
}

var UnavailableMinerAPIClient = MinerAPIClient{
GetInfo: func(context.Context, abi.ActorID) (*MinerInfo, error) {
panic("damocles miner client unavailable")
},
GetMinerConfig: func(context.Context, abi.ActorID) (*modules.MinerConfig, error) {
panic("damocles miner client unavailable")
},
}

type MinerAPIClient struct {
GetInfo func(context.Context, abi.ActorID) (*MinerInfo, error)
GetMinerConfig func(context.Context, abi.ActorID) (*modules.MinerConfig, error)
}
3 changes: 2 additions & 1 deletion venus-sector-manager/dep/poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ func RunPoSter(
capi chain.API,
rapi core.RandomnessAPI,
mapi messager.API,
minerAPI core.MinerAPI,
) error {
p, err := poster.NewPoSter(scfg, capi, mapi, rapi, chain.NewMinerInfoAPI(capi), prover, verifier, sectorTracker)
p, err := poster.NewPoSter(scfg, capi, mapi, rapi, minerAPI, prover, verifier, sectorTracker)
if err != nil {
return err
}
Expand Down
Loading