Merge pull request #126 from filecoin-project/feat/sector-commitments
implement sector commitments and proof verification
This commit is contained in:
commit
5b63e6aefc
10
api/api.go
10
api/api.go
@ -46,6 +46,12 @@ type BlockMessages struct {
|
|||||||
SecpkMessages []*types.SignedMessage
|
SecpkMessages []*types.SignedMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SectorInfo struct {
|
||||||
|
SectorID uint64
|
||||||
|
CommD []byte
|
||||||
|
CommR []byte
|
||||||
|
}
|
||||||
|
|
||||||
type Common interface {
|
type Common interface {
|
||||||
// Auth
|
// Auth
|
||||||
AuthVerify(ctx context.Context, token string) ([]string, error)
|
AuthVerify(ctx context.Context, token string) ([]string, error)
|
||||||
@ -78,6 +84,7 @@ type FullNode interface {
|
|||||||
ChainWaitMsg(context.Context, cid.Cid) (*MsgWait, error)
|
ChainWaitMsg(context.Context, cid.Cid) (*MsgWait, error)
|
||||||
ChainGetBlock(context.Context, cid.Cid) (*types.BlockHeader, error)
|
ChainGetBlock(context.Context, cid.Cid) (*types.BlockHeader, error)
|
||||||
ChainGetBlockMessages(context.Context, cid.Cid) (*BlockMessages, error)
|
ChainGetBlockMessages(context.Context, cid.Cid) (*BlockMessages, error)
|
||||||
|
ChainGetBlockReceipts(context.Context, cid.Cid) ([]*types.MessageReceipt, error)
|
||||||
|
|
||||||
// if tipset is nil, we'll use heaviest
|
// if tipset is nil, we'll use heaviest
|
||||||
ChainCall(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error)
|
ChainCall(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error)
|
||||||
@ -117,6 +124,9 @@ type FullNode interface {
|
|||||||
ClientListImports(ctx context.Context) ([]Import, error)
|
ClientListImports(ctx context.Context) ([]Import, error)
|
||||||
|
|
||||||
//ClientListAsks() []Ask
|
//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
|
// Full API is a low-level interface to the Filecoin network storage miner node
|
||||||
|
@ -46,6 +46,7 @@ type FullNodeStruct struct {
|
|||||||
ChainWaitMsg func(context.Context, cid.Cid) (*MsgWait, error) `perm:"read"`
|
ChainWaitMsg func(context.Context, cid.Cid) (*MsgWait, error) `perm:"read"`
|
||||||
ChainGetBlock func(context.Context, cid.Cid) (*types.BlockHeader, error) `perm:"read"`
|
ChainGetBlock func(context.Context, cid.Cid) (*types.BlockHeader, error) `perm:"read"`
|
||||||
ChainGetBlockMessages func(context.Context, cid.Cid) (*BlockMessages, error) `perm:"read"`
|
ChainGetBlockMessages func(context.Context, cid.Cid) (*BlockMessages, error) `perm:"read"`
|
||||||
|
ChainGetBlockReceipts func(context.Context, cid.Cid) ([]*types.MessageReceipt, error) `perm:"read"`
|
||||||
ChainCall func(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error) `perm:"read"`
|
ChainCall func(context.Context, *types.Message, *types.TipSet) (*types.MessageReceipt, error) `perm:"read"`
|
||||||
|
|
||||||
MpoolPending func(context.Context, *types.TipSet) ([]*types.SignedMessage, error) `perm:"read"`
|
MpoolPending func(context.Context, *types.TipSet) ([]*types.SignedMessage, error) `perm:"read"`
|
||||||
@ -63,6 +64,9 @@ type FullNodeStruct struct {
|
|||||||
|
|
||||||
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"`
|
ClientImport func(ctx context.Context, path string) (cid.Cid, error) `perm:"write"`
|
||||||
ClientListImports func(ctx context.Context) ([]Import, error) `perm:"read"`
|
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"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,10 +196,22 @@ func (c *FullNodeStruct) ChainGetBlockMessages(ctx context.Context, b cid.Cid) (
|
|||||||
return c.Internal.ChainGetBlockMessages(ctx, b)
|
return c.Internal.ChainGetBlockMessages(ctx, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) ChainGetBlockReceipts(ctx context.Context, b cid.Cid) ([]*types.MessageReceipt, error) {
|
||||||
|
return c.Internal.ChainGetBlockReceipts(ctx, b)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan *store.HeadChange, error) {
|
func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan *store.HeadChange, error) {
|
||||||
return c.Internal.ChainNotify(ctx)
|
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) {
|
func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, error) {
|
||||||
return c.Internal.StoreGarbageData(ctx)
|
return c.Internal.StoreGarbageData(ctx)
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
@ -190,7 +191,7 @@ func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CommitSectorParams struct {
|
type CommitSectorParams struct {
|
||||||
SectorId types.BigInt
|
SectorID types.BigInt
|
||||||
CommD []byte
|
CommD []byte
|
||||||
CommR []byte
|
CommR []byte
|
||||||
CommRStar []byte
|
CommRStar []byte
|
||||||
@ -208,12 +209,17 @@ func (sma StorageMinerActor) CommitSector(act *types.Actor, vmctx types.VMContex
|
|||||||
return nil, err
|
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!")
|
return nil, aerrors.New(1, "bad proof!")
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure the miner isnt trying to submit a pre-existing sector
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// 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
|
// sector ID. The `faults`, `recovered`, and `done` parameters of the
|
||||||
// SubmitPoSt method express indices into this sector set.
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func SectorIsUnique(cst *hamt.CborIpldStore, sroot cid.Cid, sid types.BigInt) (bool, ActorError) {
|
||||||
nd, err := hamt.LoadNode(context.TODO(), cst, sroot)
|
nd, err := hamt.LoadNode(context.TODO(), cst, sroot)
|
||||||
if err != nil {
|
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 _, err := nd.Find(context.TODO(), sid.String()); err != nil {
|
||||||
if xerrors.Is(err, hamt.ErrNotFound) {
|
if xerrors.Is(err, hamt.ErrNotFound) {
|
||||||
return true, nil
|
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
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddToSectorSet(ss cid.Cid, sectorID types.BigInt, commR, commD []byte) (cid.Cid, ActorError) {
|
func AddToSectorSet(ctx context.Context, cst *hamt.CborIpldStore, ss cid.Cid, sectorID types.BigInt, commR, commD []byte) (cid.Cid, ActorError) {
|
||||||
panic("NYI")
|
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 {
|
func ValidatePoRep(maddr address.Address, ssize types.BigInt, params *CommitSectorParams) (bool, ActorError) {
|
||||||
return true
|
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 {
|
func CollateralForPower(power types.BigInt) types.BigInt {
|
||||||
|
@ -12,6 +12,7 @@ var (
|
|||||||
func SerializeParams(i interface{}) ([]byte, aerrors.ActorError) {
|
func SerializeParams(i interface{}) ([]byte, aerrors.ActorError) {
|
||||||
dump, err := cbor.DumpObject(i)
|
dump, err := cbor.DumpObject(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// TODO: shouldnt this be a fatal error?
|
||||||
return nil, aerrors.Absorb(err, 1, "failed to encode parameter")
|
return nil, aerrors.Absorb(err, 1, "failed to encode parameter")
|
||||||
}
|
}
|
||||||
return dump, nil
|
return dump, nil
|
||||||
|
@ -70,7 +70,7 @@ func MinerCreateBlock(ctx context.Context, cs *store.ChainStore, miner address.A
|
|||||||
return nil, errors.Wrap(err, "apply message failure")
|
return nil, errors.Wrap(err, "apply message failure")
|
||||||
}
|
}
|
||||||
|
|
||||||
receipts = append(receipts, rec)
|
receipts = append(receipts, rec.MessageReceipt)
|
||||||
}
|
}
|
||||||
for _, msg := range secpkMessages {
|
for _, msg := range secpkMessages {
|
||||||
rec, err := vmi.ApplyMessage(ctx, &msg.Message)
|
rec, err := vmi.ApplyMessage(ctx, &msg.Message)
|
||||||
|
@ -41,6 +41,15 @@ func BigFromBytes(b []byte) BigInt {
|
|||||||
return BigInt{i}
|
return BigInt{i}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BigFromString(s string) (BigInt, error) {
|
||||||
|
v, ok := big.NewInt(0).SetString(s, 10)
|
||||||
|
if !ok {
|
||||||
|
return BigInt{}, fmt.Errorf("failed to parse string as a big int")
|
||||||
|
}
|
||||||
|
|
||||||
|
return BigInt{v}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func BigMul(a, b BigInt) BigInt {
|
func BigMul(a, b BigInt) BigInt {
|
||||||
return BigInt{big.NewInt(0).Mul(a.Int, b.Int)}
|
return BigInt{big.NewInt(0).Mul(a.Int, b.Int)}
|
||||||
}
|
}
|
||||||
|
@ -114,14 +114,16 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
|||||||
param := reflect.New(paramT)
|
param := reflect.New(paramT)
|
||||||
|
|
||||||
inBytes := in[2].Interface().([]byte)
|
inBytes := in[2].Interface().([]byte)
|
||||||
err := cbor.DecodeInto(inBytes, param.Interface())
|
if len(inBytes) > 0 {
|
||||||
if err != nil {
|
err := cbor.DecodeInto(inBytes, param.Interface())
|
||||||
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
|
if err != nil {
|
||||||
return []reflect.Value{
|
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
|
||||||
reflect.ValueOf([]byte{}),
|
return []reflect.Value{
|
||||||
// Below is a hack, fixed in Go 1.13
|
reflect.ValueOf([]byte{}),
|
||||||
// https://git.io/fjXU6
|
// Below is a hack, fixed in Go 1.13
|
||||||
reflect.ValueOf(&aerr).Elem(),
|
// https://git.io/fjXU6
|
||||||
|
reflect.ValueOf(&aerr).Elem(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
cli/chain.go
11
cli/chain.go
@ -86,15 +86,22 @@ var chainGetBlock = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recpts, err := api.ChainGetBlockReceipts(ctx, bcid)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
cblock := struct {
|
cblock := struct {
|
||||||
types.BlockHeader
|
types.BlockHeader
|
||||||
BlsMessages []*types.Message
|
BlsMessages []*types.Message
|
||||||
SecpkMessages []*types.SignedMessage
|
SecpkMessages []*types.SignedMessage
|
||||||
|
MessageReceipts []*types.MessageReceipt
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
cblock.BlockHeader = *blk
|
cblock.BlockHeader = *blk
|
||||||
cblock.BlsMessages = msgs.BlsMessages
|
cblock.BlsMessages = msgs.BlsMessages
|
||||||
cblock.SecpkMessages = msgs.SecpkMessages
|
cblock.SecpkMessages = msgs.SecpkMessages
|
||||||
|
cblock.MessageReceipts = recpts
|
||||||
|
|
||||||
out, err := json.MarshalIndent(cblock, "", " ")
|
out, err := json.MarshalIndent(cblock, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -108,4 +108,6 @@ var Commands = []*cli.Command{
|
|||||||
versionCmd,
|
versionCmd,
|
||||||
walletCmd,
|
walletCmd,
|
||||||
createMinerCmd,
|
createMinerCmd,
|
||||||
|
stateCmd,
|
||||||
|
sendCmd,
|
||||||
}
|
}
|
||||||
|
94
cli/send.go
Normal file
94
cli/send.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
|
types "github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var sendCmd = &cli.Command{
|
||||||
|
Name: "send",
|
||||||
|
Usage: "send funds between accounts",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "source",
|
||||||
|
Usage: "optinally specifiy the account to send funds from",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
api, err := GetAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
if cctx.Args().Len() != 2 {
|
||||||
|
return fmt.Errorf("'send' expects two arguments, target and amount")
|
||||||
|
}
|
||||||
|
|
||||||
|
toAddr, err := address.NewFromString(cctx.Args().Get(0))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err := types.BigFromString(cctx.Args().Get(1))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var fromAddr address.Address
|
||||||
|
if from := cctx.String("source"); from == "" {
|
||||||
|
defaddr, err := api.WalletDefaultAddress(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fromAddr = defaddr
|
||||||
|
} else {
|
||||||
|
addr, err := address.NewFromString(from)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fromAddr = addr
|
||||||
|
}
|
||||||
|
|
||||||
|
nonce, err := api.MpoolGetNonce(ctx, fromAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := &types.Message{
|
||||||
|
From: fromAddr,
|
||||||
|
To: toAddr,
|
||||||
|
Value: val,
|
||||||
|
Nonce: nonce,
|
||||||
|
GasLimit: types.NewInt(10000),
|
||||||
|
GasPrice: types.NewInt(1),
|
||||||
|
}
|
||||||
|
|
||||||
|
sermsg, err := msg.Serialize()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := api.WalletSign(ctx, fromAddr, sermsg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
smsg := &types.SignedMessage{
|
||||||
|
Message: *msg,
|
||||||
|
Signature: *sig,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := api.MpoolPush(ctx, smsg); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
140
cli/state.go
Normal file
140
cli/state.go
Normal 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
|
||||||
|
},
|
||||||
|
}
|
2
go.mod
2
go.mod
@ -21,7 +21,7 @@ require (
|
|||||||
github.com/ipfs/go-ds-badger v0.0.5
|
github.com/ipfs/go-ds-badger v0.0.5
|
||||||
github.com/ipfs/go-filestore v0.0.2
|
github.com/ipfs/go-filestore v0.0.2
|
||||||
github.com/ipfs/go-fs-lock v0.0.1
|
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-blockstore v0.0.1
|
||||||
github.com/ipfs/go-ipfs-chunker v0.0.1
|
github.com/ipfs/go-ipfs-chunker v0.0.1
|
||||||
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
|
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
|
||||||
|
8
go.sum
8
go.sum
@ -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-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 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.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 h1:O9n3PbmTYZoNhkgkEyrXTznbmktIXif62xLX+8dPHzc=
|
||||||
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
|
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=
|
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-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 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-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.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 v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
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-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 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-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 h1:/eS3yfGjQKG+9kayBkj0ip1BGhq6zJ3eaVksphxAaek=
|
||||||
github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a/go.mod h1:7AyxJNCJ7SBZ1MfVQCWD6Uqo2oubI2Eq2y2eqf+A5r0=
|
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=
|
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-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 h1:SaXEMXhWzMJThc05vu6uh61Q245r4KaWMrsTedk0FDc=
|
||||||
golang.org/x/sys v0.0.0-20190730183949-1393eb018365/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
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.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
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-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-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-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-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 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
@ -3,8 +3,6 @@ package sectorbuilder
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/common/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: really need to get a callbacks API from the rust-sectorbuilder
|
// TODO: really need to get a callbacks API from the rust-sectorbuilder
|
||||||
@ -21,7 +19,7 @@ func (sb *SectorBuilder) pollForSealedSectors(ctx context.Context) {
|
|||||||
watching[s.SectorID] = true
|
watching[s.SectorID] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
tick := time.Tick(time.Second * 30)
|
tick := time.Tick(time.Second * 5)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-tick:
|
case <-tick:
|
||||||
@ -33,6 +31,7 @@ func (sb *SectorBuilder) pollForSealedSectors(ctx context.Context) {
|
|||||||
log.Errorf("in loop: failed to get staged sectors: %s", err)
|
log.Errorf("in loop: failed to get staged sectors: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range staged {
|
for _, s := range staged {
|
||||||
watching[s.SectorID] = true
|
watching[s.SectorID] = true
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,17 @@ package sectorbuilder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/binary"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
|
||||||
|
|
||||||
|
logging "github.com/ipfs/go-log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var log = logging.Logger("sectorbuilder")
|
||||||
|
|
||||||
type SectorSealingStatus = sectorbuilder.SectorSealingStatus
|
type SectorSealingStatus = sectorbuilder.SectorSealingStatus
|
||||||
|
|
||||||
type StagedSectorMetadata = sectorbuilder.StagedSectorMetadata
|
type StagedSectorMetadata = sectorbuilder.StagedSectorMetadata
|
||||||
@ -29,19 +34,31 @@ type SectorBuilderConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
|
func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
|
||||||
var proverId [31]byte
|
proverId := addressToProverID(cfg.Miner)
|
||||||
copy(proverId[:], cfg.Miner.Payload())
|
|
||||||
|
|
||||||
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 2, 2, 1, cfg.MetadataDir, [31]byte{}, cfg.SealedDir, cfg.StagedDir, 16)
|
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 1, 1, 1, cfg.MetadataDir, proverId, cfg.SealedDir, cfg.StagedDir, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &SectorBuilder{
|
return &SectorBuilder{
|
||||||
handle: sbp,
|
handle: sbp,
|
||||||
|
sschan: make(chan SectorSealingStatus, 32),
|
||||||
}, nil
|
}, 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) {
|
func (sb *SectorBuilder) Run(ctx context.Context) {
|
||||||
go sb.pollForSealedSectors(ctx)
|
go sb.pollForSealedSectors(ctx)
|
||||||
}
|
}
|
||||||
@ -84,9 +101,15 @@ func (sb *SectorBuilder) SealedSectorChan() <-chan SectorSealingStatus {
|
|||||||
|
|
||||||
var UserBytesForSectorSize = sectorbuilder.GetMaxUserBytesPerStagedSector
|
var UserBytesForSectorSize = sectorbuilder.GetMaxUserBytesPerStagedSector
|
||||||
|
|
||||||
func VerifySeal(sectorSize uint64, commR, commD, commRStar [CommLen]byte, proverID address.Address, sectorID uint64, proof []byte) (bool, error) {
|
func VerifySeal(sectorSize uint64, commR, commD, commRStar []byte, proverID address.Address, sectorID uint64, proof []byte) (bool, error) {
|
||||||
panic("TODO")
|
var commRa, commDa, commRStara [32]byte
|
||||||
// return sectorbuilder.VerifySeal(sectorSize, commR, commD, commRStar, providerID, sectorID, proof)
|
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) {
|
func VerifyPost(sectorSize uint64, sortedCommRs [][CommLen]byte, challengeSeed [CommLen]byte, proofs [][]byte, faults []uint64) (bool, error) {
|
||||||
|
65
lib/sectorbuilder/sectorbuilder_test.go
Normal file
65
lib/sectorbuilder/sectorbuilder_test.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package sectorbuilder
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSealAndVerify(t *testing.T) {
|
||||||
|
t.Skip("this is slow")
|
||||||
|
dir, err := ioutil.TempDir("", "sbtest")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
addr, err := address.NewFromString("t1tct3nfaw2q543xtybxcyw4deyxmfwkjk43u4t5y")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sb, err := New(&SectorBuilderConfig{
|
||||||
|
SectorSize: 1024,
|
||||||
|
SealedDir: dir,
|
||||||
|
StagedDir: dir,
|
||||||
|
MetadataDir: dir,
|
||||||
|
Miner: addr,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
sb.Run(ctx)
|
||||||
|
|
||||||
|
fi, err := ioutil.TempFile("", "sbtestfi")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer fi.Close()
|
||||||
|
|
||||||
|
io.CopyN(fi, rand.New(rand.NewSource(42)), 1016)
|
||||||
|
|
||||||
|
if _, err := sb.AddPiece("foo", 1016, fi.Name()); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ssinfo := <-sb.SealedSectorChan()
|
||||||
|
fmt.Println("sector sealed...")
|
||||||
|
|
||||||
|
ok, err := VerifySeal(1024, ssinfo.CommR[:], ssinfo.CommD[:], ssinfo.CommRStar[:], addr, ssinfo.SectorID, ssinfo.Proof)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("proof failed to validate")
|
||||||
|
}
|
||||||
|
}
|
@ -211,7 +211,7 @@ func Online() Option {
|
|||||||
|
|
||||||
// Storage miner
|
// Storage miner
|
||||||
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeStorageMiner },
|
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeStorageMiner },
|
||||||
Override(new(*sectorbuilder.SectorBuilder), sectorbuilder.New),
|
Override(new(*sectorbuilder.SectorBuilder), modules.SectorBuilder),
|
||||||
Override(new(*storage.Miner), modules.StorageMiner),
|
Override(new(*storage.Miner), modules.StorageMiner),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -2,13 +2,17 @@ package impl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/api"
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
"github.com/filecoin-project/go-lotus/chain"
|
"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/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/gen"
|
"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/store"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
"github.com/filecoin-project/go-lotus/chain/vm"
|
"github.com/filecoin-project/go-lotus/chain/vm"
|
||||||
@ -17,6 +21,8 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/node/client"
|
"github.com/filecoin-project/go-lotus/node/client"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"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"
|
logging "github.com/ipfs/go-log"
|
||||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||||
)
|
)
|
||||||
@ -94,6 +100,31 @@ func (a *FullNodeAPI) ChainGetBlockMessages(ctx context.Context, msg cid.Cid) (*
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *FullNodeAPI) ChainGetBlockReceipts(ctx context.Context, bcid cid.Cid) ([]*types.MessageReceipt, error) {
|
||||||
|
b, err := a.Chain.GetBlock(bcid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: need to get the number of messages better than this
|
||||||
|
bm, sm, err := a.Chain.MessagesForBlock(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var out []*types.MessageReceipt
|
||||||
|
for i := 0; i < len(bm)+len(sm); i++ {
|
||||||
|
r, err := a.Chain.GetReceipt(b, i)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
out = append(out, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *FullNodeAPI) ChainCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
|
func (a *FullNodeAPI) ChainCall(ctx context.Context, msg *types.Message, ts *types.TipSet) (*types.MessageReceipt, error) {
|
||||||
if ts == nil {
|
if ts == nil {
|
||||||
ts = a.Chain.GetHeaviestTipSet()
|
ts = a.Chain.GetHeaviestTipSet()
|
||||||
@ -120,6 +151,9 @@ func (a *FullNodeAPI) ChainCall(ctx context.Context, msg *types.Message, ts *typ
|
|||||||
|
|
||||||
// TODO: maybe just use the invoker directly?
|
// TODO: maybe just use the invoker directly?
|
||||||
ret, err := vmi.ApplyMessage(ctx, msg)
|
ret, err := vmi.ApplyMessage(ctx, msg)
|
||||||
|
if ret.ActorErr != nil {
|
||||||
|
log.Warnf("chain call failed: %s", ret.ActorErr)
|
||||||
|
}
|
||||||
return &ret.MessageReceipt, err
|
return &ret.MessageReceipt, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,4 +235,122 @@ func (a *FullNodeAPI) WalletDefaultAddress(ctx context.Context) (address.Address
|
|||||||
return addrs[0], nil
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("miner sector count: ", minerState.SectorSetSize)
|
||||||
|
|
||||||
|
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{}
|
var _ api.FullNode = &FullNodeAPI{}
|
||||||
|
@ -18,8 +18,22 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/storage"
|
"github.com/filecoin-project/go-lotus/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SectorBuilderConfig(storagePath string) func() (*sectorbuilder.SectorBuilderConfig, error) {
|
func minerAddrFromDS(ds dtypes.MetadataDS) (address.Address, error) {
|
||||||
return func() (*sectorbuilder.SectorBuilderConfig, error) {
|
maddrb, err := ds.Get(datastore.NewKey("miner-address"))
|
||||||
|
if err != nil {
|
||||||
|
return address.Undef, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return address.NewFromBytes(maddrb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SectorBuilderConfig(storagePath string) func(dtypes.MetadataDS) (*sectorbuilder.SectorBuilderConfig, error) {
|
||||||
|
return func(ds dtypes.MetadataDS) (*sectorbuilder.SectorBuilderConfig, error) {
|
||||||
|
minerAddr, err := minerAddrFromDS(ds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
sp, err := homedir.Expand(storagePath)
|
sp, err := homedir.Expand(storagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -29,12 +43,6 @@ func SectorBuilderConfig(storagePath string) func() (*sectorbuilder.SectorBuilde
|
|||||||
sealed := filepath.Join(sp, "sealed")
|
sealed := filepath.Join(sp, "sealed")
|
||||||
staging := filepath.Join(sp, "staging")
|
staging := filepath.Join(sp, "staging")
|
||||||
|
|
||||||
// TODO: get the address of the miner actor
|
|
||||||
minerAddr, err := address.NewIDAddress(42)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sb := §orbuilder.SectorBuilderConfig{
|
sb := §orbuilder.SectorBuilderConfig{
|
||||||
Miner: minerAddr,
|
Miner: minerAddr,
|
||||||
SectorSize: 1024,
|
SectorSize: 1024,
|
||||||
@ -66,12 +74,7 @@ func SectorBuilder(mctx helpers.MetricsCtx, lc fx.Lifecycle, sbc *sectorbuilder.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func StorageMiner(mctx helpers.MetricsCtx, lc fx.Lifecycle, api api.FullNode, h host.Host, ds dtypes.MetadataDS, sb *sectorbuilder.SectorBuilder, w *wallet.Wallet) (*storage.Miner, error) {
|
func StorageMiner(mctx helpers.MetricsCtx, lc fx.Lifecycle, api api.FullNode, h host.Host, ds dtypes.MetadataDS, sb *sectorbuilder.SectorBuilder, w *wallet.Wallet) (*storage.Miner, error) {
|
||||||
maddrb, err := ds.Get(datastore.NewKey("miner-address"))
|
maddr, err := minerAddrFromDS(ds)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
maddr, err := address.NewFromBytes(maddrb)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,16 @@ func (m *Miner) handlePostingSealedSectors(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSealingStatus) error {
|
func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSealingStatus) error {
|
||||||
|
ok, err := sectorbuilder.VerifySeal(1024, sinfo.CommR[:], sinfo.CommD[:], sinfo.CommRStar[:], m.maddr, sinfo.SectorID, sinfo.Proof)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("failed to verify seal we just created: ", err)
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
log.Error("seal we just created failed verification")
|
||||||
|
}
|
||||||
|
|
||||||
params := &actors.CommitSectorParams{
|
params := &actors.CommitSectorParams{
|
||||||
SectorId: types.NewInt(sinfo.SectorID),
|
SectorID: types.NewInt(sinfo.SectorID),
|
||||||
CommD: sinfo.CommD[:],
|
CommD: sinfo.CommD[:],
|
||||||
CommR: sinfo.CommR[:],
|
CommR: sinfo.CommR[:],
|
||||||
CommRStar: sinfo.CommRStar[:],
|
CommRStar: sinfo.CommRStar[:],
|
||||||
@ -114,7 +122,7 @@ func (m *Miner) commitSector(ctx context.Context, sinfo sectorbuilder.SectorSeal
|
|||||||
Method: actors.MAMethods.CommitSector,
|
Method: actors.MAMethods.CommitSector,
|
||||||
Params: enc,
|
Params: enc,
|
||||||
Value: types.NewInt(0), // TODO: need to ensure sufficient collateral
|
Value: types.NewInt(0), // TODO: need to ensure sufficient collateral
|
||||||
GasLimit: types.NewInt(10000 /* i dont know help */),
|
GasLimit: types.NewInt(1000 /* i dont know help */),
|
||||||
GasPrice: types.NewInt(1),
|
GasPrice: types.NewInt(1),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +173,6 @@ func (m *Miner) runPreflightChecks(ctx context.Context) error {
|
|||||||
|
|
||||||
m.worker = worker
|
m.worker = worker
|
||||||
|
|
||||||
// try signing something with that key to make sure we can
|
|
||||||
has, err := m.w.HasKey(worker)
|
has, err := m.w.HasKey(worker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to check wallet for worker key")
|
return errors.Wrap(err, "failed to check wallet for worker key")
|
||||||
|
Loading…
Reference in New Issue
Block a user