1
1
package main
2
2
3
3
import (
4
+ "bytes"
5
+ "encoding/binary"
4
6
"encoding/json"
5
7
"fmt"
6
8
"os"
7
9
8
10
"github.com/ipfs/go-cid"
9
11
ipldcbor "github.com/ipfs/go-ipld-cbor"
10
12
"github.com/urfave/cli/v2"
13
+ cbg "github.com/whyrusleeping/cbor-gen"
11
14
"golang.org/x/xerrors"
12
15
13
16
"github.com/filecoin-project/go-address"
14
17
"github.com/filecoin-project/go-bitfield"
15
18
"github.com/filecoin-project/go-state-types/abi"
19
+ "github.com/filecoin-project/go-state-types/builtin"
16
20
miner11 "github.com/filecoin-project/go-state-types/builtin/v11/miner"
17
21
"github.com/filecoin-project/go-state-types/builtin/v11/util/adt"
22
+ power "github.com/filecoin-project/go-state-types/builtin/v15/power"
18
23
19
24
"github.com/filecoin-project/lotus/api"
20
25
"github.com/filecoin-project/lotus/build/buildconstants"
@@ -28,6 +33,7 @@ var cronWcCmd = &cli.Command{
28
33
Subcommands : []* cli.Command {
29
34
minerDeadlineCronCountCmd ,
30
35
minerDeadlinePartitionMeasurementCmd ,
36
+ cronQueueCountCmd ,
31
37
},
32
38
}
33
39
@@ -269,6 +275,64 @@ var minerDeadlinePartitionMeasurementCmd = &cli.Command{
269
275
},
270
276
}
271
277
278
+ var cronQueueCountCmd = & cli.Command {
279
+ Name : "queue" ,
280
+ Description : "list all entries in the cron queue" ,
281
+ Action : func (c * cli.Context ) error {
282
+ n , acloser , err := lcli .GetFullNodeAPI (c )
283
+ if err != nil {
284
+ return err
285
+ }
286
+ defer acloser ()
287
+ ctx := lcli .ReqContext (c )
288
+
289
+ bs := ReadOnlyAPIBlockstore {n }
290
+ adtStore := adt .WrapStore (ctx , ipldcbor .NewCborStore (& bs ))
291
+
292
+ // Get power actor state
293
+ powerActor , err := n .StateGetActor (ctx , builtin .StoragePowerActorAddr , types .EmptyTSK )
294
+ if err != nil {
295
+ return xerrors .Errorf ("failed to get power actor: %w" , err )
296
+ }
297
+
298
+ var powerState power.State
299
+ if err := adtStore .Get (ctx , powerActor .Head , & powerState ); err != nil {
300
+ return xerrors .Errorf ("failed to load power state: %w" , err )
301
+ }
302
+
303
+ // Load cron queue
304
+ q , err := adt .AsMap (adtStore , powerState .CronEventQueue , power .CronQueueHamtBitwidth )
305
+ if err != nil {
306
+ return xerrors .Errorf ("failed to load cron queue hamt: %w" , err )
307
+ }
308
+ amtRoot := cbg.CborCid {}
309
+ if err := q .ForEach (& amtRoot , func (epoch string ) error {
310
+ epochInt , err := binary .ReadVarint (bytes .NewReader ([]byte (epoch )))
311
+ if err != nil {
312
+ return xerrors .Errorf ("failed to parse epoch: %w" , err )
313
+ }
314
+ events , err := adt .AsArray (adtStore , cid .Cid (amtRoot ), power .CronQueueAmtBitwidth )
315
+ if err != nil {
316
+ return xerrors .Errorf ("failed to load cron queue amt: %w" , err )
317
+ }
318
+ var event power.CronEvent
319
+ if err := events .ForEach (& event , func (i int64 ) error {
320
+ fmt .Printf ("Epoch: %d, Miner: %s\n " , epochInt , event .MinerAddr )
321
+ return nil
322
+ }); err != nil {
323
+ return xerrors .Errorf ("failed to iterate cron events: %w" , err )
324
+ }
325
+
326
+ return nil
327
+
328
+ }); err != nil {
329
+ return xerrors .Errorf ("failed to iterate cron events: %w" , err )
330
+ }
331
+ return nil
332
+
333
+ },
334
+ }
335
+
272
336
var minerDeadlineCronCountCmd = & cli.Command {
273
337
Name : "deadline" ,
274
338
Description : "list all addresses of miners with active deadline crons" ,
0 commit comments