storageminer: Split PaymentVerify into 2 methods
This commit is contained in:
parent
b35f2942bb
commit
760ebc341f
@ -19,8 +19,8 @@ func init() {
|
|||||||
cbor.RegisterCborType(CommitSectorParams{})
|
cbor.RegisterCborType(CommitSectorParams{})
|
||||||
cbor.RegisterCborType(MinerInfo{})
|
cbor.RegisterCborType(MinerInfo{})
|
||||||
cbor.RegisterCborType(SubmitPoStParams{})
|
cbor.RegisterCborType(SubmitPoStParams{})
|
||||||
cbor.RegisterCborType(StorageVoucherData{})
|
cbor.RegisterCborType(PieceInclVoucherData{})
|
||||||
cbor.RegisterCborType(StoragePaymentVerifyProof{})
|
cbor.RegisterCborType(InclusionProof{})
|
||||||
cbor.RegisterCborType(PaymentVerifyParams{})
|
cbor.RegisterCborType(PaymentVerifyParams{})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,26 +99,27 @@ type StorageMinerConstructorParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type maMethods struct {
|
type maMethods struct {
|
||||||
Constructor uint64
|
Constructor uint64
|
||||||
CommitSector uint64
|
CommitSector uint64
|
||||||
SubmitPoSt uint64
|
SubmitPoSt uint64
|
||||||
SlashStorageFault uint64
|
SlashStorageFault uint64
|
||||||
GetCurrentProvingSet uint64
|
GetCurrentProvingSet uint64
|
||||||
ArbitrateDeal uint64
|
ArbitrateDeal uint64
|
||||||
DePledge uint64
|
DePledge uint64
|
||||||
GetOwner uint64
|
GetOwner uint64
|
||||||
GetWorkerAddr uint64
|
GetWorkerAddr uint64
|
||||||
GetPower uint64
|
GetPower uint64
|
||||||
GetPeerID uint64
|
GetPeerID uint64
|
||||||
GetSectorSize uint64
|
GetSectorSize uint64
|
||||||
UpdatePeerID uint64
|
UpdatePeerID uint64
|
||||||
ChangeWorker uint64
|
ChangeWorker uint64
|
||||||
IsSlashed uint64
|
IsSlashed uint64
|
||||||
IsLate uint64
|
IsLate uint64
|
||||||
PaymentVerify 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{} {
|
func (sma StorageMinerActor) Exports() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
@ -138,7 +139,8 @@ func (sma StorageMinerActor) Exports() []interface{} {
|
|||||||
//14: sma.ChangeWorker,
|
//14: sma.ChangeWorker,
|
||||||
//15: sma.IsSlashed,
|
//15: sma.IsSlashed,
|
||||||
//16: sma.IsLate,
|
//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
|
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
|
CommP []byte
|
||||||
PieceSize types.BigInt
|
PieceSize types.BigInt
|
||||||
}
|
}
|
||||||
|
|
||||||
type StoragePaymentVerifyProof struct {
|
type InclusionProof struct {
|
||||||
Sector types.BigInt
|
Sector types.BigInt // for CommD, also verifies the sector is in sector set
|
||||||
Proof []byte
|
Proof []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type PaymentVerifyParams struct {
|
func (sma StorageMinerActor) PaymentVerifyInclusion(act *types.Actor, vmctx types.VMContext, params *PaymentVerifyParams) ([]byte, ActorError) {
|
||||||
Extra []byte // StorageVoucherData
|
// params.Extra - PieceInclVoucherData
|
||||||
Proof []byte // StoragePaymentVerifyProof
|
// params.Proof - InclusionProof
|
||||||
}
|
|
||||||
|
|
||||||
func (sma StorageMinerActor) PaymentVerify(act *types.Actor, vmctx types.VMContext, params *PaymentVerifyParams) ([]byte, ActorError) {
|
_, self, aerr := loadState(vmctx)
|
||||||
_, self, err := loadState(vmctx)
|
if aerr != nil {
|
||||||
if err != nil {
|
return nil, aerr
|
||||||
return nil, err
|
}
|
||||||
|
mi, aerr := loadMinerInfo(vmctx, self)
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
}
|
}
|
||||||
|
|
||||||
mi, err := loadMinerInfo(vmctx, self)
|
var voucherData PieceInclVoucherData
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var voucherData StorageVoucherData
|
|
||||||
if err := cbor.DecodeInto(params.Extra, &voucherData); err != nil {
|
if err := cbor.DecodeInto(params.Extra, &voucherData); err != nil {
|
||||||
return nil, aerrors.Escalate(err, "failed to decode storage voucher data for verification")
|
return nil, aerrors.Escalate(err, "failed to decode storage voucher data for verification")
|
||||||
}
|
}
|
||||||
|
var proof InclusionProof
|
||||||
var proof StoragePaymentVerifyProof
|
|
||||||
if err := cbor.DecodeInto(params.Proof, &proof); err != nil {
|
if err := cbor.DecodeInto(params.Proof, &proof); err != nil {
|
||||||
return nil, aerrors.Escalate(err, "failed to decode storage payment proof")
|
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")
|
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)
|
||||||
ok, err := sectorbuilder.VerifyPieceInclusionProof(mi.SectorSize.Uint64(), voucherData.PieceSize.Uint64(), voucherData.CommP, commD, params.Proof)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, aerrors.Escalate(err, "verify piece inclusion proof failed")
|
||||||
return nil, aerrors.Escalate(err, "verify piece inclusion proof failed")
|
|
||||||
}
|
|
||||||
if !ok {
|
|
||||||
return nil, aerrors.New(2, "piece inclusion proof was invalid")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@ -196,19 +196,19 @@ type ClientDealProposal struct {
|
|||||||
MinerID peer.ID
|
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)
|
commP, size, err := c.commP(ctx, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &actors.StorageVoucherData{
|
return &actors.PieceInclVoucherData{
|
||||||
CommP: commP,
|
CommP: commP,
|
||||||
PieceSize: types.NewInt(uint64(size)),
|
PieceSize: types.NewInt(uint64(size)),
|
||||||
}, nil
|
}, 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
|
// TODO: use data
|
||||||
proposal := StorageDealProposal{
|
proposal := StorageDealProposal{
|
||||||
PieceRef: p.Data.String(),
|
PieceRef: p.Data.String(),
|
||||||
|
@ -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?
|
// TimeLock: 0, // TODO: do we want to use this somehow?
|
||||||
Extra: &types.ModVerifyParams{
|
Extra: &types.ModVerifyParams{
|
||||||
Actor: miner,
|
Actor: miner,
|
||||||
Method: actors.MAMethods.PaymentVerify,
|
Method: actors.MAMethods.PaymentVerifyInclusion,
|
||||||
Data: voucherData,
|
Data: voucherData,
|
||||||
},
|
},
|
||||||
Lane: 0,
|
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)
|
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
|
return &c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user