From fd7a0e1922b78a40b7685bc4792fdc0ccf35ea28 Mon Sep 17 00:00:00 2001 From: Aayush Date: Mon, 24 Apr 2023 11:02:43 -0400 Subject: [PATCH] feat: shed: refactor market cron-state command --- cmd/lotus-shed/market.go | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/lotus-shed/market.go b/cmd/lotus-shed/market.go index 98e3d36b7..4436e3c40 100644 --- a/cmd/lotus-shed/market.go +++ b/cmd/lotus-shed/market.go @@ -7,7 +7,6 @@ import ( "os" "path" - "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" dsq "github.com/ipfs/go-datastore/query" levelds "github.com/ipfs/go-ds-leveldb" @@ -65,26 +64,22 @@ var marketCronStateCmd = &cli.Command{ if err != nil { return err } - a, err := api.StateReadState(ctx, builtin.StorageMarketActorAddr, ts.Key()) - if err != nil { - return err - } - st, ok := a.State.(map[string]interface{}) - if !ok { - return xerrors.Errorf("failed to cast state map to expected form") - } - dealOpsRaw, ok := st["DealOpsByEpoch"].(map[string]interface{}) - if !ok { - return xerrors.Errorf("failed to read sectors root from state") - } - // string is of the form "/:bafy.." so [2:] to drop the path - dealOpsRoot, err := cid.Parse(dealOpsRaw["/"]) - if err != nil { - return err - } + bs := ReadOnlyAPIBlockstore{api} adtStore := adt.WrapStore(ctx, ipldcbor.NewCborStore(&bs)) - dealOpsEpochSet, err := adt.AsMap(adtStore, dealOpsRoot, builtin.DefaultHamtBitwidth) + + mAct, err := api.StateGetActor(ctx, builtin.StorageMarketActorAddr, ts.Key()) + if err != nil { + return err + } + + var mSt market11.State + err = adtStore.Get(ctx, mAct.Head, &mSt) + if err != nil { + return err + } + + dealOpsEpochSet, err := adt.AsMap(adtStore, mSt.DealOpsByEpoch, builtin.DefaultHamtBitwidth) if err != nil { return err } @@ -100,7 +95,7 @@ var marketCronStateCmd = &cli.Command{ return err } - dealOpsMultiMap, err := market11.AsSetMultimap(adtStore, dealOpsRoot, builtin.DefaultHamtBitwidth, builtin.DefaultHamtBitwidth) + dealOpsMultiMap, err := market11.AsSetMultimap(adtStore, mSt.DealOpsByEpoch, builtin.DefaultHamtBitwidth, builtin.DefaultHamtBitwidth) if err != nil { return err }