storageminer: Split PaymentVerify into 2 methods

This commit is contained in:
Łukasz Magiera 2019-08-15 22:57:14 +02:00
parent b35f2942bb
commit 760ebc341f
3 changed files with 82 additions and 52 deletions

View File

@ -19,8 +19,8 @@ func init() {
cbor.RegisterCborType(CommitSectorParams{})
cbor.RegisterCborType(MinerInfo{})
cbor.RegisterCborType(SubmitPoStParams{})
cbor.RegisterCborType(StorageVoucherData{})
cbor.RegisterCborType(StoragePaymentVerifyProof{})
cbor.RegisterCborType(PieceInclVoucherData{})
cbor.RegisterCborType(InclusionProof{})
cbor.RegisterCborType(PaymentVerifyParams{})
}
@ -99,26 +99,27 @@ type StorageMinerConstructorParams struct {
}
type maMethods struct {
Constructor uint64
CommitSector uint64
SubmitPoSt uint64
SlashStorageFault uint64
GetCurrentProvingSet uint64
ArbitrateDeal uint64
DePledge uint64
GetOwner uint64
GetWorkerAddr uint64
GetPower uint64
GetPeerID uint64
GetSectorSize uint64
UpdatePeerID uint64
ChangeWorker uint64
IsSlashed uint64
IsLate uint64
PaymentVerify uint64
Constructor uint64
CommitSector uint64
SubmitPoSt uint64
SlashStorageFault uint64
GetCurrentProvingSet uint64
ArbitrateDeal uint64
DePledge uint64
GetOwner uint64
GetWorkerAddr uint64
GetPower uint64
GetPeerID uint64
GetSectorSize uint64
UpdatePeerID uint64
ChangeWorker uint64
IsSlashed uint64
IsLate uint64
PaymentVerifyInclusion uint64
PaymentVerifySector uint64
}
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}
var MAMethods = maMethods{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}
func (sma StorageMinerActor) Exports() []interface{} {
return []interface{}{
@ -138,7 +139,8 @@ func (sma StorageMinerActor) Exports() []interface{} {
//14: sma.ChangeWorker,
//15: sma.IsSlashed,
//16: sma.IsLate,
17: sma.PaymentVerify,
17: sma.PaymentVerifyInclusion,
18: sma.PaymentVerifySector,
}
}
@ -533,38 +535,39 @@ func (sma StorageMinerActor) GetSectorSize(act *types.Actor, vmctx types.VMConte
return mi.SectorSize.Bytes(), nil
}
type StorageVoucherData struct { // TODO: Update spec at https://github.com/filecoin-project/specs/blob/master/actors.md#paymentverify
type PaymentVerifyParams struct {
Extra []byte
Proof []byte
}
type PieceInclVoucherData struct { // TODO: Update spec at https://github.com/filecoin-project/specs/blob/master/actors.md#paymentverify
CommP []byte
PieceSize types.BigInt
}
type StoragePaymentVerifyProof struct {
Sector types.BigInt
type InclusionProof struct {
Sector types.BigInt // for CommD, also verifies the sector is in sector set
Proof []byte
}
type PaymentVerifyParams struct {
Extra []byte // StorageVoucherData
Proof []byte // StoragePaymentVerifyProof
}
func (sma StorageMinerActor) PaymentVerifyInclusion(act *types.Actor, vmctx types.VMContext, params *PaymentVerifyParams) ([]byte, ActorError) {
// params.Extra - PieceInclVoucherData
// params.Proof - InclusionProof
func (sma StorageMinerActor) PaymentVerify(act *types.Actor, vmctx types.VMContext, params *PaymentVerifyParams) ([]byte, ActorError) {
_, self, err := loadState(vmctx)
if err != nil {
return nil, err
_, self, aerr := loadState(vmctx)
if aerr != nil {
return nil, aerr
}
mi, aerr := loadMinerInfo(vmctx, self)
if aerr != nil {
return nil, aerr
}
mi, err := loadMinerInfo(vmctx, self)
if err != nil {
return nil, err
}
var voucherData StorageVoucherData
var voucherData PieceInclVoucherData
if err := cbor.DecodeInto(params.Extra, &voucherData); err != nil {
return nil, aerrors.Escalate(err, "failed to decode storage voucher data for verification")
}
var proof StoragePaymentVerifyProof
var proof InclusionProof
if err := cbor.DecodeInto(params.Proof, &proof); err != nil {
return nil, aerrors.Escalate(err, "failed to decode storage payment proof")
}
@ -577,14 +580,40 @@ func (sma StorageMinerActor) PaymentVerify(act *types.Actor, vmctx types.VMConte
return nil, aerrors.New(1, "miner does not have required sector")
}
if voucherData.CommP != nil {
ok, err := sectorbuilder.VerifyPieceInclusionProof(mi.SectorSize.Uint64(), voucherData.PieceSize.Uint64(), voucherData.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")
}
ok, err := sectorbuilder.VerifyPieceInclusionProof(mi.SectorSize.Uint64(), voucherData.PieceSize.Uint64(), voucherData.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
}
func (sma StorageMinerActor) PaymentVerifySector(act *types.Actor, vmctx types.VMContext, params *PaymentVerifyParams) ([]byte, ActorError) {
// params.Extra - BigInt - sector id
// params.Proof - nil
_, self, aerr := loadState(vmctx)
if aerr != nil {
return nil, aerr
}
// TODO: ensure no sector ID reusability within related deal lifetime
sector := types.BigFromBytes(params.Extra)
if len(params.Proof) > 0 {
return nil, aerrors.New(1, "unexpected proof bytes")
}
ok, _, _, aerr := GetFromSectorSet(context.TODO(), vmctx.Ipld(), self.Sectors, sector)
if aerr != nil {
return nil, aerr
}
if !ok {
return nil, aerrors.New(2, "miner does not have required sector")
}
return nil, nil
}

View File

@ -196,19 +196,19 @@ type ClientDealProposal struct {
MinerID peer.ID
}
func (c *Client) VerifyParams(ctx context.Context, data cid.Cid) (*actors.StorageVoucherData, error) {
func (c *Client) VerifyParams(ctx context.Context, data cid.Cid) (*actors.PieceInclVoucherData, error) {
commP, size, err := c.commP(ctx, data)
if err != nil {
return nil, err
}
return &actors.StorageVoucherData{
return &actors.PieceInclVoucherData{
CommP: commP,
PieceSize: types.NewInt(uint64(size)),
}, nil
}
func (c *Client) Start(ctx context.Context, p ClientDealProposal, vd *actors.StorageVoucherData) (cid.Cid, error) {
func (c *Client) Start(ctx context.Context, p ClientDealProposal, vd *actors.PieceInclVoucherData) (cid.Cid, error) {
// TODO: use data
proposal := StorageDealProposal{
PieceRef: p.Data.String(),

View File

@ -92,7 +92,7 @@ func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner a
// TimeLock: 0, // TODO: do we want to use this somehow?
Extra: &types.ModVerifyParams{
Actor: miner,
Method: actors.MAMethods.PaymentVerify,
Method: actors.MAMethods.PaymentVerifyInclusion,
Data: voucherData,
},
Lane: 0,
@ -121,6 +121,7 @@ func (a *FullNodeAPI) ClientStartDeal(ctx context.Context, data cid.Cid, miner a
}
c, err := a.DealClient.Start(ctx, proposal, vd)
// TODO: send updated voucher with PaymentVerifySector for cheaper validation (validate the sector the miner sent us first!)
return &c, err
}