implement sector commitments and proof verification
This commit is contained in:
@@ -2,13 +2,17 @@ package impl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/api"
|
||||
"github.com/filecoin-project/go-lotus/chain"
|
||||
"github.com/filecoin-project/go-lotus/chain/actors"
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/gen"
|
||||
"github.com/filecoin-project/go-lotus/chain/state"
|
||||
"github.com/filecoin-project/go-lotus/chain/store"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/chain/vm"
|
||||
@@ -17,6 +21,8 @@ import (
|
||||
"github.com/filecoin-project/go-lotus/node/client"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
hamt "github.com/ipfs/go-hamt-ipld"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
logging "github.com/ipfs/go-log"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
)
|
||||
@@ -120,6 +126,9 @@ func (a *FullNodeAPI) ChainCall(ctx context.Context, msg *types.Message, ts *typ
|
||||
|
||||
// TODO: maybe just use the invoker directly?
|
||||
ret, err := vmi.ApplyMessage(ctx, msg)
|
||||
if ret.ActorErr != nil {
|
||||
log.Warnf("chain call failed: %s", ret.ActorErr)
|
||||
}
|
||||
return &ret.MessageReceipt, err
|
||||
}
|
||||
|
||||
@@ -201,4 +210,120 @@ func (a *FullNodeAPI) WalletDefaultAddress(ctx context.Context) (address.Address
|
||||
return addrs[0], nil
|
||||
}
|
||||
|
||||
func (a *FullNodeAPI) StateMinerSectors(ctx context.Context, addr address.Address) ([]*api.SectorInfo, error) {
|
||||
ts := a.Chain.GetHeaviestTipSet()
|
||||
|
||||
stc, err := a.Chain.TipSetState(ts.Cids())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cst := hamt.CSTFromBstore(a.Chain.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
|
||||
}
|
||||
|
||||
func (a *FullNodeAPI) StateMinerProvingSet(ctx context.Context, addr address.Address) ([]*api.SectorInfo, error) {
|
||||
ts := a.Chain.GetHeaviestTipSet()
|
||||
|
||||
stc, err := a.Chain.TipSetState(ts.Cids())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cst := hamt.CSTFromBstore(a.Chain.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.ProvingSet)
|
||||
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
|
||||
}
|
||||
|
||||
var _ api.FullNode = &FullNodeAPI{}
|
||||
|
||||
Reference in New Issue
Block a user