implement sector commitments and proof verification

This commit is contained in:
whyrusleeping 2019-08-06 23:35:57 -07:00
parent e43ee3cdb9
commit b7c6333fef
12 changed files with 379 additions and 30 deletions

View File

@ -46,6 +46,12 @@ type BlockMessages struct {
SecpkMessages []*types.SignedMessage
}
type SectorInfo struct {
SectorID uint64
CommD []byte
CommR []byte
}
type Common interface {
// Auth
AuthVerify(ctx context.Context, token string) ([]string, error)
@ -117,6 +123,9 @@ type FullNode interface {
ClientListImports(ctx context.Context) ([]Import, error)
//ClientListAsks() []Ask
StateMinerSectors(context.Context, address.Address) ([]*SectorInfo, error)
StateMinerProvingSet(context.Context, address.Address) ([]*SectorInfo, error)
}
// Full API is a low-level interface to the Filecoin network storage miner node

View File

@ -63,6 +63,9 @@ type FullNodeStruct struct {
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"`
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
StateMinerSectors func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
StateMinerProvingSet func(context.Context, address.Address) ([]*SectorInfo, error) `perm:"read"`
}
}
@ -196,6 +199,14 @@ func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan *store.HeadCha
return c.Internal.ChainNotify(ctx)
}
func (c *FullNodeStruct) StateMinerSectors(ctx context.Context, addr address.Address) ([]*SectorInfo, error) {
return c.Internal.StateMinerSectors(ctx, addr)
}
func (c *FullNodeStruct) StateMinerProvingSet(ctx context.Context, addr address.Address) ([]*SectorInfo, error) {
return c.Internal.StateMinerProvingSet(ctx, addr)
}
func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, error) {
return c.Internal.StoreGarbageData(ctx)
}

View File

@ -6,6 +6,7 @@ import (
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/chain/types"
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
"golang.org/x/xerrors"
cid "github.com/ipfs/go-cid"
@ -190,7 +191,7 @@ func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx typ
}
type CommitSectorParams struct {
SectorId types.BigInt
SectorID types.BigInt
CommD []byte
CommR []byte
CommRStar []byte
@ -208,12 +209,17 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
return nil, err
}
if !ValidatePoRep(mi.SectorSize, params) {
// TODO: this needs to get normalized to either the ID address or the actor address
maddr := vmctx.Message().To
if ok, err := ValidatePoRep(maddr, mi.SectorSize, params); err != nil {
return nil, err
} else if !ok {
return nil, aerrors.New(1, "bad proof!")
}
// make sure the miner isnt trying to submit a pre-existing sector
unique, err := SectorIsUnique(vmctx.Ipld(), self.Sectors, params.SectorId)
unique, err := SectorIsUnique(vmctx.Ipld(), self.Sectors, params.SectorID)
if err != nil {
return nil, err
}
@ -237,7 +243,7 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
// Note: There must exist a unique index in the miner's sector set for each
// sector ID. The `faults`, `recovered`, and `done` parameters of the
// SubmitPoSt method express indices into this sector set.
nssroot, err := AddToSectorSet(self.Sectors, params.SectorId, params.CommR, params.CommD)
nssroot, err := AddToSectorSet(context.TODO(), vmctx.Ipld(), self.Sectors, params.SectorID, params.CommR, params.CommD)
if err != nil {
return nil, err
}
@ -330,25 +336,53 @@ func (sma StorageMinerActor) GetPower(act *types.Actor, vmctx types.VMContext, p
func SectorIsUnique(cst *hamt.CborIpldStore, sroot cid.Cid, sid types.BigInt) (bool, ActorError) {
nd, err := hamt.LoadNode(context.TODO(), cst, sroot)
if err != nil {
return false, aerrors.Absorb(err, 1, "could not load node in HAMT")
return false, aerrors.Escalate(err, "could not load node in HAMT")
}
if _, err := nd.Find(context.TODO(), sid.String()); err != nil {
if xerrors.Is(err, hamt.ErrNotFound) {
return true, nil
}
return false, aerrors.Absorb(err, 1, "could not find node in HAMT")
return false, aerrors.Escalate(err, "could not find node in HAMT")
}
return false, nil
}
func AddToSectorSet(ss cid.Cid, sectorID types.BigInt, commR, commD []byte) (cid.Cid, ActorError) {
panic("NYI")
func AddToSectorSet(ctx context.Context, cst *hamt.CborIpldStore, ss cid.Cid, sectorID types.BigInt, commR, commD []byte) (cid.Cid, ActorError) {
nd, err := hamt.LoadNode(ctx, cst, ss)
if err != nil {
return cid.Undef, aerrors.Escalate(err, "could not load HAMT node")
}
enc, aerr := SerializeParams([][]byte{commR, commD})
if err != nil {
return cid.Undef, aerrors.Wrap(aerr, "failed to serialize commR and commD for sector set")
}
if err := nd.Set(ctx, sectorID.String(), enc); err != nil {
return cid.Undef, aerrors.Escalate(err, "failed to set new sector in sector set")
}
if err := nd.Flush(ctx); err != nil {
return cid.Undef, aerrors.Escalate(err, "failed to flush sector set")
}
ssroot, err := cst.Put(ctx, nd)
if err != nil {
return cid.Undef, aerrors.Escalate(err, "failed to store new sector set root")
}
return ssroot, nil
}
func ValidatePoRep(ssize types.BigInt, params *CommitSectorParams) bool {
return true
func ValidatePoRep(maddr address.Address, ssize types.BigInt, params *CommitSectorParams) (bool, ActorError) {
ok, err := sectorbuilder.VerifySeal(ssize.Uint64(), params.CommR, params.CommD, params.CommRStar, maddr, params.SectorID.Uint64(), params.Proof)
if err != nil {
return false, aerrors.Escalate(err, "verify seal failed")
}
return ok, nil
}
func CollateralForPower(power types.BigInt) types.BigInt {

View File

@ -12,6 +12,7 @@ var (
func SerializeParams(i interface{}) ([]byte, aerrors.ActorError) {
dump, err := cbor.DumpObject(i)
if err != nil {
// TODO: shouldnt this be a fatal error?
return nil, aerrors.Absorb(err, 1, "failed to encode parameter")
}
return dump, nil

View File

@ -114,14 +114,16 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
param := reflect.New(paramT)
inBytes := in[2].Interface().([]byte)
err := cbor.DecodeInto(inBytes, param.Interface())
if err != nil {
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
return []reflect.Value{
reflect.ValueOf([]byte{}),
// Below is a hack, fixed in Go 1.13
// https://git.io/fjXU6
reflect.ValueOf(&aerr).Elem(),
if len(inBytes) > 0 {
err := cbor.DecodeInto(inBytes, param.Interface())
if err != nil {
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
return []reflect.Value{
reflect.ValueOf([]byte{}),
// Below is a hack, fixed in Go 1.13
// https://git.io/fjXU6
reflect.ValueOf(&aerr).Elem(),
}
}
}

View File

@ -108,4 +108,5 @@ var Commands = []*cli.Command{
versionCmd,
walletCmd,
createMinerCmd,
stateCmd,
}

140
cli/state.go Normal file
View File

@ -0,0 +1,140 @@
package cli
import (
"fmt"
"math/big"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-lotus/chain/actors"
"github.com/filecoin-project/go-lotus/chain/address"
types "github.com/filecoin-project/go-lotus/chain/types"
)
var stateCmd = &cli.Command{
Name: "state",
Usage: "Interact with and query filecoin chain state",
Subcommands: []*cli.Command{
statePowerCmd,
stateSectorsCmd,
stateProvingSetCmd,
},
}
var statePowerCmd = &cli.Command{
Name: "power",
Usage: "Query network or miner power",
Action: func(cctx *cli.Context) error {
api, err := GetAPI(cctx)
if err != nil {
return err
}
ctx := ReqContext(cctx)
var msg *types.Message
if cctx.Args().Present() {
maddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
enc, err := actors.SerializeParams(&actors.PowerLookupParams{
Miner: maddr,
})
if err != nil {
return err
}
msg = &types.Message{
To: actors.StorageMarketAddress,
From: actors.StorageMarketAddress,
Method: actors.SMAMethods.PowerLookup,
Params: enc,
}
} else {
msg = &types.Message{
To: actors.StorageMarketAddress,
From: actors.StorageMarketAddress,
Method: actors.SMAMethods.GetTotalStorage,
}
}
ret, err := api.ChainCall(ctx, msg, nil)
if err != nil {
return err
}
if ret.ExitCode != 0 {
return fmt.Errorf("call to get power failed: %d", ret.ExitCode)
}
v := big.NewInt(0).SetBytes(ret.Return)
fmt.Println(v.String())
return nil
},
}
var stateSectorsCmd = &cli.Command{
Name: "sectors",
Usage: "Query the sector set of a miner",
Action: func(cctx *cli.Context) error {
api, err := GetAPI(cctx)
if err != nil {
return err
}
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify miner to list sectors for")
}
maddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
sectors, err := api.StateMinerSectors(ctx, maddr)
if err != nil {
return err
}
for _, s := range sectors {
fmt.Printf("%d: %x %x\n", s.SectorID, s.CommR, s.CommD)
}
return nil
},
}
var stateProvingSetCmd = &cli.Command{
Name: "proving",
Usage: "Query the proving set of a miner",
Action: func(cctx *cli.Context) error {
api, err := GetAPI(cctx)
if err != nil {
return err
}
ctx := ReqContext(cctx)
if !cctx.Args().Present() {
return fmt.Errorf("must specify miner to list sectors for")
}
maddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
sectors, err := api.StateMinerProvingSet(ctx, maddr)
if err != nil {
return err
}
for _, s := range sectors {
fmt.Printf("%d: %x %x\n", s.SectorID, s.CommR, s.CommD)
}
return nil
},
}

10
go.mod
View File

@ -21,7 +21,7 @@ require (
github.com/ipfs/go-ds-badger v0.0.5
github.com/ipfs/go-filestore v0.0.2
github.com/ipfs/go-fs-lock v0.0.1
github.com/ipfs/go-hamt-ipld v0.0.10
github.com/ipfs/go-hamt-ipld v0.0.11
github.com/ipfs/go-ipfs-blockstore v0.0.1
github.com/ipfs/go-ipfs-chunker v0.0.1
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
@ -61,10 +61,10 @@ require (
github.com/multiformats/go-multiaddr-net v0.0.1
github.com/multiformats/go-multihash v0.0.6
github.com/pkg/errors v0.8.1
github.com/polydawn/refmt v0.0.0-20190731040541-eff0b363297a
github.com/polydawn/refmt v0.0.0-20190804001829-26ba426d088b
github.com/prometheus/common v0.6.0
github.com/smartystreets/assertions v1.0.1 // indirect
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 // indirect
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
github.com/stretchr/testify v1.3.0
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
@ -76,8 +76,8 @@ require (
go4.org v0.0.0-20190313082347-94abd6928b1d // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/sys v0.0.0-20190730183949-1393eb018365 // indirect
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa // indirect
golang.org/x/tools v0.0.0-20190806215303-88ddfcebc769 // indirect
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7
gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect

8
go.sum
View File

@ -159,6 +159,8 @@ github.com/ipfs/go-fs-lock v0.0.1 h1:XHX8uW4jQBYWHj59XXcjg7BHlHxV9ZOYs6Y43yb7/l0
github.com/ipfs/go-fs-lock v0.0.1/go.mod h1:DNBekbboPKcxs1aukPSaOtFA3QfSdi5C855v0i9XJ8Y=
github.com/ipfs/go-hamt-ipld v0.0.10 h1:jmJGsV/8OPpBEmO+b1nAPpqX8SG2kLeYveKk8F7IxG4=
github.com/ipfs/go-hamt-ipld v0.0.10/go.mod h1:WrX60HHX2SeMb602Z1s9Ztnf/4fzNHzwH9gxNTVpEmk=
github.com/ipfs/go-hamt-ipld v0.0.11 h1:iUHlbycdlheWf7QLU3FjHonK2lEnd+/85SeM5gvcUZE=
github.com/ipfs/go-hamt-ipld v0.0.11/go.mod h1:WrX60HHX2SeMb602Z1s9Ztnf/4fzNHzwH9gxNTVpEmk=
github.com/ipfs/go-ipfs-blockstore v0.0.1 h1:O9n3PbmTYZoNhkgkEyrXTznbmktIXif62xLX+8dPHzc=
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
@ -463,6 +465,8 @@ github.com/polydawn/refmt v0.0.0-20190408063855-01bf1e26dd14 h1:2m16U/rLwVaRdz7A
github.com/polydawn/refmt v0.0.0-20190408063855-01bf1e26dd14/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/polydawn/refmt v0.0.0-20190731040541-eff0b363297a h1:TdavzKWkPcC2G+6rKJclm/JfrWC6WZFfLUR7EJJX8MA=
github.com/polydawn/refmt v0.0.0-20190731040541-eff0b363297a/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/polydawn/refmt v0.0.0-20190804001829-26ba426d088b h1:JWrXOvqGFU2mv58NZSqEinWkezjkcGam1jNKSIV5Meg=
github.com/polydawn/refmt v0.0.0-20190804001829-26ba426d088b/go.mod h1:uIp+gprXxxrWSjjklXD+mN4wed/tMfjMMmN/9+JsA9o=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
@ -488,6 +492,7 @@ github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 h1:N8Bg45zpk/UcpNGnfJt2y/3lRWASHNTUET8owPYCgYI=
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek=
github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0=
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 h1:RC6RW7j+1+HkWaX/Yh71Ee5ZHaHYt7ZP4sQgUrm6cDU=
@ -626,6 +631,8 @@ golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190730183949-1393eb018365 h1:SaXEMXhWzMJThc05vu6uh61Q245r4KaWMrsTedk0FDc=
golang.org/x/sys v0.0.0-20190730183949-1393eb018365/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa h1:KIDDMLT1O0Nr7TSxp8xM5tJcdn8tgyAONntO829og1M=
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@ -637,6 +644,7 @@ golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190806215303-88ddfcebc769/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -2,6 +2,7 @@ package sectorbuilder
import (
"context"
"encoding/binary"
"unsafe"
"github.com/filecoin-project/go-lotus/chain/address"
@ -29,10 +30,9 @@ type SectorBuilderConfig struct {
}
func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
var proverId [31]byte
copy(proverId[:], cfg.Miner.Payload())
proverId := addressToProverID(cfg.Miner)
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 2, 2, 1, cfg.MetadataDir, [31]byte{}, cfg.SealedDir, cfg.StagedDir, 16)
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 2, 2, 1, cfg.MetadataDir, proverId, cfg.SealedDir, cfg.StagedDir, 16)
if err != nil {
return nil, err
}
@ -42,6 +42,18 @@ func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
}, nil
}
func addressToProverID(a address.Address) [31]byte {
var proverId [31]byte
copy(proverId[:], a.Payload())
return proverId
}
func sectorIDtoBytes(sid uint64) [31]byte {
var out [31]byte
binary.LittleEndian.PutUint64(out[:], sid)
return out
}
func (sb *SectorBuilder) Run(ctx context.Context) {
go sb.pollForSealedSectors(ctx)
}
@ -84,9 +96,15 @@ func (sb *SectorBuilder) SealedSectorChan() <-chan SectorSealingStatus {
var UserBytesForSectorSize = sectorbuilder.GetMaxUserBytesPerStagedSector
func VerifySeal(sectorSize uint64, commR, commD, commRStar [CommLen]byte, proverID address.Address, sectorID uint64, proof []byte) (bool, error) {
panic("TODO")
// return sectorbuilder.VerifySeal(sectorSize, commR, commD, commRStar, providerID, sectorID, proof)
func VerifySeal(sectorSize uint64, commR, commD, commRStar []byte, proverID address.Address, sectorID uint64, proof []byte) (bool, error) {
var commRa, commDa, commRStara [32]byte
copy(commRa[:], commR)
copy(commDa[:], commD)
copy(commRStara[:], commRStar)
proverIDa := addressToProverID(proverID)
sectorIDa := sectorIDtoBytes(sectorID)
return sectorbuilder.VerifySeal(sectorSize, commRa, commDa, commRStara, proverIDa, sectorIDa, proof)
}
func VerifyPost(sectorSize uint64, sortedCommRs [][CommLen]byte, challengeSeed [CommLen]byte, proofs [][]byte, faults []uint64) (bool, error) {

View File

@ -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{}

View File

@ -97,7 +97,7 @@ func (m *Miner) handlePostingSealedSectors(ctx context.Context) {
func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSealingStatus) error {
params := &actors.CommitSectorParams{
SectorId: types.NewInt(sinfo.SectorID),
SectorID: types.NewInt(sinfo.SectorID),
CommD: sinfo.CommD[:],
CommR: sinfo.CommR[:],
CommRStar: sinfo.CommRStar[:],