simplify stateminersectors impl
This commit is contained in:
parent
9763810100
commit
02887a63a3
@ -2,11 +2,8 @@ package full
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/ipfs/go-hamt-ipld"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
@ -36,61 +33,7 @@ type StateAPI struct {
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerSectors(ctx context.Context, addr address.Address) ([]*api.SectorInfo, error) {
|
||||
ts := a.StateManager.ChainStore().GetHeaviestTipSet()
|
||||
|
||||
stc, err := a.StateManager.TipSetState(ts.Cids())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cst := hamt.CSTFromBstore(a.StateManager.ChainStore().Blockstore())
|
||||
|
||||
st, err := state.LoadStateTree(cst, stc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
act, err := st.GetActor(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var minerState actors.StorageMinerActorState
|
||||
if err := cst.Get(ctx, act.Head, &minerState); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nd, err := hamt.LoadNode(ctx, cst, minerState.Sectors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var sinfos []*api.SectorInfo
|
||||
// Note to self: the hamt isnt a great data structure to use here... need to implement the sector set
|
||||
err = nd.ForEach(ctx, func(k string, val interface{}) error {
|
||||
sid, err := strconv.ParseUint(k, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
bval, ok := val.([]byte)
|
||||
if !ok {
|
||||
return fmt.Errorf("expected to get bytes in sector set hamt")
|
||||
}
|
||||
|
||||
var comms [][]byte
|
||||
if err := cbor.DecodeInto(bval, &comms); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sinfos = append(sinfos, &api.SectorInfo{
|
||||
SectorID: sid,
|
||||
CommR: comms[0],
|
||||
CommD: comms[1],
|
||||
})
|
||||
return nil
|
||||
})
|
||||
return sinfos, nil
|
||||
return stmgr.GetMinerSectorSet(ctx, a.StateManager, nil, addr)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerProvingSet(ctx context.Context, addr address.Address, ts *types.TipSet) ([]*api.SectorInfo, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user