storageminer: Initial PaymentVerify implementation
This commit is contained in:
parent
4c5ffb185e
commit
1579137236
@ -2,15 +2,14 @@ package actors
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"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"
|
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
cid "github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
hamt "github.com/ipfs/go-hamt-ipld"
|
"github.com/ipfs/go-hamt-ipld"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
)
|
)
|
||||||
@ -112,9 +111,12 @@ type maMethods struct {
|
|||||||
GetSectorSize uint64
|
GetSectorSize uint64
|
||||||
UpdatePeerID uint64
|
UpdatePeerID uint64
|
||||||
ChangeWorker uint64
|
ChangeWorker uint64
|
||||||
|
IsSlashed uint64
|
||||||
|
IsLate uint64
|
||||||
|
PaymentVerify uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
|
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}
|
||||||
|
|
||||||
func (sma StorageMinerActor) Exports() []interface{} {
|
func (sma StorageMinerActor) Exports() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
@ -132,6 +134,9 @@ func (sma StorageMinerActor) Exports() []interface{} {
|
|||||||
12: sma.GetSectorSize,
|
12: sma.GetSectorSize,
|
||||||
13: sma.UpdatePeerID,
|
13: sma.UpdatePeerID,
|
||||||
//14: sma.ChangeWorker,
|
//14: sma.ChangeWorker,
|
||||||
|
//15: sma.IsSlashed,
|
||||||
|
//16: sma.IsLate,
|
||||||
|
17: sma.PaymentVerify,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,6 +381,38 @@ func AddToSectorSet(ctx context.Context, cst *hamt.CborIpldStore, ss cid.Cid, se
|
|||||||
return ssroot, nil
|
return ssroot, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetFromSectorSet(ctx context.Context, cst *hamt.CborIpldStore, ss cid.Cid, sectorID types.BigInt) (bool, []byte, []byte, ActorError) {
|
||||||
|
nd, err := hamt.LoadNode(ctx, cst, ss)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, nil, aerrors.Escalate(err, "could not load HAMT node")
|
||||||
|
}
|
||||||
|
|
||||||
|
infoIf, err := nd.Find(ctx, sectorID.String())
|
||||||
|
if err == hamt.ErrNotFound {
|
||||||
|
return false, nil, nil, nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, nil, aerrors.Escalate(err, "failed to find sector in sector set")
|
||||||
|
}
|
||||||
|
|
||||||
|
infoB, ok := infoIf.([]byte)
|
||||||
|
if !ok {
|
||||||
|
return false, nil, nil, aerrors.Escalate(xerrors.New("casting infoIf to []byte failed"), "") // TODO: Review: how to create aerrror without retcode?
|
||||||
|
}
|
||||||
|
|
||||||
|
var comms [][]byte // [ [commR], [commD] ]
|
||||||
|
err = cbor.DecodeInto(infoB, &comms)
|
||||||
|
if err != nil {
|
||||||
|
return false, nil, nil, aerrors.Escalate(err, "failed to decode sector set entry")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(comms) != 2 {
|
||||||
|
return false, nil, nil, aerrors.Escalate(xerrors.New("sector set entry should only have 2 elements"), "")
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, comms[0], comms[1], nil
|
||||||
|
}
|
||||||
|
|
||||||
func ValidatePoRep(maddr address.Address, ssize types.BigInt, params *CommitSectorParams) (bool, ActorError) {
|
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)
|
ok, err := sectorbuilder.VerifySeal(ssize.Uint64(), params.CommR, params.CommD, params.CommRStar, maddr, params.SectorID.Uint64(), params.Proof)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -493,3 +530,50 @@ func (sma StorageMinerActor) GetSectorSize(act *types.Actor, vmctx types.VMConte
|
|||||||
|
|
||||||
return mi.SectorSize.Bytes(), nil
|
return mi.SectorSize.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StorageVoucherData struct { // TODO: Update spec at https://github.com/filecoin-project/specs/blob/master/actors.md#paymentverify
|
||||||
|
CommP []byte
|
||||||
|
PieceSize []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type PaymentVerifyParams struct {
|
||||||
|
Extra StorageVoucherData
|
||||||
|
|
||||||
|
Sector []byte
|
||||||
|
Proof []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sma StorageMinerActor) PaymentVerify(act *types.Actor, vmctx types.VMContext, params *PaymentVerifyParams) ([]byte, ActorError) {
|
||||||
|
_, self, err := loadState(vmctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
mi, err := loadMinerInfo(vmctx, self)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sectorID := types.BigFromBytes(params.Sector)
|
||||||
|
|
||||||
|
ok, _, commD, aerr := GetFromSectorSet(context.TODO(), vmctx.Ipld(), self.Sectors, sectorID)
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil, aerrors.New(1, "miner does not have required sector")
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.Extra.CommP != nil {
|
||||||
|
pieceSize := types.BigFromBytes(params.Extra.PieceSize)
|
||||||
|
|
||||||
|
ok, err := sectorbuilder.VerifyPieceInclusionProof(mi.SectorSize.Uint64(), pieceSize.Uint64(), params.Extra.CommP, commD, params.Proof)
|
||||||
|
if err != nil {
|
||||||
|
return nil, aerrors.Escalate(err, "verify piece inclusion proof failed")
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil, aerrors.New(2, "piece inclusion proof was invalid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
@ -100,6 +100,14 @@ func VerifySeal(sectorSize uint64, commR, commD, commRStar []byte, proverID addr
|
|||||||
return sectorbuilder.VerifySeal(sectorSize, commRa, commDa, commRStara, proverIDa, sectorIDa, proof)
|
return sectorbuilder.VerifySeal(sectorSize, commRa, commDa, commRStara, proverIDa, sectorIDa, proof)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func VerifyPieceInclusionProof(sectorSize uint64, pieceSize uint64, commP []byte, commD []byte, proof []byte) (bool, error) {
|
||||||
|
var commPa, commDa [32]byte
|
||||||
|
copy(commPa[:], commP)
|
||||||
|
copy(commDa[:], commD)
|
||||||
|
|
||||||
|
return sectorbuilder.VerifyPieceInclusionProof(sectorSize, pieceSize, commPa, commDa, 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) {
|
||||||
// sectorbuilder.VerifyPost()
|
// sectorbuilder.VerifyPost()
|
||||||
panic("no")
|
panic("no")
|
||||||
|
Loading…
Reference in New Issue
Block a user