Skip to content
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

feat(shed): cron queue inspection util #12825

Merged
merged 4 commits into from
Jan 13, 2025
Merged
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
64 changes: 64 additions & 0 deletions cmd/lotus-shed/cron-count.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package main

import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"os"

"github.com/ipfs/go-cid"
ipldcbor "github.com/ipfs/go-ipld-cbor"
"github.com/urfave/cli/v2"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin"
miner11 "github.com/filecoin-project/go-state-types/builtin/v11/miner"
"github.com/filecoin-project/go-state-types/builtin/v11/util/adt"
power "github.com/filecoin-project/go-state-types/builtin/v15/power"

"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build/buildconstants"
Expand All @@ -28,6 +33,7 @@ var cronWcCmd = &cli.Command{
Subcommands: []*cli.Command{
minerDeadlineCronCountCmd,
minerDeadlinePartitionMeasurementCmd,
cronQueueCountCmd,
},
}

Expand Down Expand Up @@ -269,6 +275,64 @@ var minerDeadlinePartitionMeasurementCmd = &cli.Command{
},
}

var cronQueueCountCmd = &cli.Command{
Name: "queue",
Description: "list all entries in the cron queue",
Action: func(c *cli.Context) error {
n, acloser, err := lcli.GetFullNodeAPI(c)
if err != nil {
return err
}
defer acloser()
ctx := lcli.ReqContext(c)

bs := ReadOnlyAPIBlockstore{n}
adtStore := adt.WrapStore(ctx, ipldcbor.NewCborStore(&bs))

// Get power actor state
powerActor, err := n.StateGetActor(ctx, builtin.StoragePowerActorAddr, types.EmptyTSK)
if err != nil {
return xerrors.Errorf("failed to get power actor: %w", err)
}

var powerState power.State
if err := adtStore.Get(ctx, powerActor.Head, &powerState); err != nil {
return xerrors.Errorf("failed to load power state: %w", err)
}

// Load cron queue
q, err := adt.AsMap(adtStore, powerState.CronEventQueue, power.CronQueueHamtBitwidth)
if err != nil {
return xerrors.Errorf("failed to load cron queue hamt: %w", err)
}
amtRoot := cbg.CborCid{}
if err := q.ForEach(&amtRoot, func(epoch string) error {
epochInt, err := binary.ReadVarint(bytes.NewReader([]byte(epoch)))
if err != nil {
return xerrors.Errorf("failed to parse epoch: %w", err)
}
events, err := adt.AsArray(adtStore, cid.Cid(amtRoot), power.CronQueueAmtBitwidth)
if err != nil {
return xerrors.Errorf("failed to load cron queue amt: %w", err)
}
var event power.CronEvent
if err := events.ForEach(&event, func(i int64) error {
fmt.Printf("Epoch: %d, Miner: %s\n", epochInt, event.MinerAddr)
return nil
}); err != nil {
return xerrors.Errorf("failed to iterate cron events: %w", err)
}

return nil

}); err != nil {
return xerrors.Errorf("failed to iterate cron events: %w", err)
}
return nil

},
}

var minerDeadlineCronCountCmd = &cli.Command{
Name: "deadline",
Description: "list all addresses of miners with active deadline crons",
Expand Down
Loading