Clean up storage deal structures
This commit is contained in:
parent
8127676f73
commit
f0653decf3
@ -3,6 +3,7 @@ package actors
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-amt-ipld"
|
"github.com/filecoin-project/go-amt-ipld"
|
||||||
@ -131,35 +132,19 @@ func (sdp *StorageDealProposal) Verify() error {
|
|||||||
return sdp.ProposerSignature.Verify(sdp.Client, buf.Bytes())
|
return sdp.ProposerSignature.Verify(sdp.Client, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *StorageDeal) Sign(ctx context.Context, sign SignFunc) error {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
if err := d.Proposal.MarshalCBOR(&buf); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
sig, err := sign(ctx, buf.Bytes())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
d.CounterSignature = sig
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *StorageDeal) Verify(proposerWorker address.Address) error {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
if err := d.Proposal.MarshalCBOR(&buf); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return d.CounterSignature.Verify(proposerWorker, buf.Bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
type StorageDeal struct {
|
|
||||||
Proposal StorageDealProposal
|
|
||||||
CounterSignature *types.Signature
|
|
||||||
}
|
|
||||||
|
|
||||||
type OnChainDeal struct {
|
type OnChainDeal struct {
|
||||||
Deal StorageDeal
|
PieceRef []byte // cid bytes // TODO: spec says to use cid.Cid, probably not a good idea
|
||||||
|
PieceSize uint64
|
||||||
|
PieceSerialization SerializationMode // Needs to be here as it tells how data in the sector maps to PieceRef cid
|
||||||
|
|
||||||
|
Client address.Address
|
||||||
|
Provider address.Address
|
||||||
|
|
||||||
|
ProposalExpiration uint64
|
||||||
|
Duration uint64 // TODO: spec
|
||||||
|
|
||||||
|
StoragePricePerEpoch types.BigInt
|
||||||
|
StorageCollateral types.BigInt
|
||||||
ActivationEpoch uint64 // 0 = inactive
|
ActivationEpoch uint64 // 0 = inactive
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,6 +230,7 @@ func (sma StorageMarketActor) AddBalance(act *types.Actor, vmctx types.VMContext
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setMarketBalances(vmctx types.VMContext, nd *hamt.Node, set map[address.Address]StorageParticipantBalance) (cid.Cid, ActorError) {
|
func setMarketBalances(vmctx types.VMContext, nd *hamt.Node, set map[address.Address]StorageParticipantBalance) (cid.Cid, ActorError) {
|
||||||
|
// TODO: iterating over a map might happen in the wrong order, this could have gas implications
|
||||||
for addr, b := range set {
|
for addr, b := range set {
|
||||||
balance := b // to stop linter complaining
|
balance := b // to stop linter complaining
|
||||||
if err := nd.Set(vmctx.Context(), string(addr.Bytes()), &balance); err != nil {
|
if err := nd.Set(vmctx.Context(), string(addr.Bytes()), &balance); err != nil {
|
||||||
@ -297,7 +283,7 @@ func (sma StorageMarketActor) CheckLockedBalance(act *types.Actor, vmctx types.V
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
type PublishStorageDealsParams struct {
|
type PublishStorageDealsParams struct {
|
||||||
Deals []StorageDeal
|
Deals []StorageDealProposal
|
||||||
}
|
}
|
||||||
|
|
||||||
type PublishStorageDealResponse struct {
|
type PublishStorageDealResponse struct {
|
||||||
@ -326,7 +312,7 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
|
|||||||
DealIDs: make([]uint64, len(params.Deals)),
|
DealIDs: make([]uint64, len(params.Deals)),
|
||||||
}
|
}
|
||||||
|
|
||||||
workerBytes, aerr := vmctx.Send(params.Deals[0].Proposal.Provider, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
|
workerBytes, aerr := vmctx.Send(params.Deals[0].Provider, MAMethods.GetWorkerAddr, types.NewInt(0), nil)
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
return nil, aerr
|
return nil, aerr
|
||||||
}
|
}
|
||||||
@ -342,7 +328,21 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := deals.Set(self.NextDealID, &OnChainDeal{Deal: deal})
|
err := deals.Set(self.NextDealID, &OnChainDeal{
|
||||||
|
PieceRef: deal.PieceRef,
|
||||||
|
PieceSize: deal.PieceSize,
|
||||||
|
PieceSerialization: deal.PieceSerialization, // TODO: this isnt needed anymore, right?
|
||||||
|
|
||||||
|
Client: deal.Client,
|
||||||
|
Provider: deal.Provider,
|
||||||
|
|
||||||
|
ProposalExpiration: deal.ProposalExpiration,
|
||||||
|
Duration: deal.Duration,
|
||||||
|
|
||||||
|
StoragePricePerEpoch: deal.StoragePricePerEpoch,
|
||||||
|
StorageCollateral: deal.StorageCollateral,
|
||||||
|
ActivationEpoch: 0,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.HandleExternalError(err, "setting deal in deal AMT")
|
return nil, aerrors.HandleExternalError(err, "setting deal in deal AMT")
|
||||||
}
|
}
|
||||||
@ -376,34 +376,28 @@ func (sma StorageMarketActor) PublishStorageDeals(act *types.Actor, vmctx types.
|
|||||||
return outBuf.Bytes(), nil
|
return outBuf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDeal, providerWorker address.Address) aerrors.ActorError {
|
func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDealProposal, providerWorker address.Address) aerrors.ActorError {
|
||||||
if vmctx.BlockHeight() > deal.Proposal.ProposalExpiration {
|
if vmctx.BlockHeight() > deal.ProposalExpiration {
|
||||||
return aerrors.New(1, "deal proposal already expired")
|
return aerrors.New(1, "deal proposal already expired")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := deal.Proposal.Verify(); err != nil {
|
if vmctx.Message().From != providerWorker {
|
||||||
return aerrors.Absorb(err, 2, "verifying proposer signature")
|
return aerrors.New(2, "Deals must be submitted by the miner worker")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := deal.Verify(providerWorker)
|
if err := deal.Verify(); err != nil {
|
||||||
if err != nil {
|
return aerrors.Absorb(err, 3, "verifying proposer signature")
|
||||||
return aerrors.Absorb(err, 2, "verifying provider signature")
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: maybe this is actually fine
|
|
||||||
if vmctx.Message().From != providerWorker && vmctx.Message().From != deal.Proposal.Client {
|
|
||||||
return aerrors.New(4, "message not sent by deal participant")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do some caching (changes gas so needs to be in spec too)
|
// TODO: do some caching (changes gas so needs to be in spec too)
|
||||||
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), st.Balances, deal.Proposal.Client, providerWorker)
|
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), st.Balances, deal.Client, providerWorker)
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
return aerrors.Wrap(aerr, "getting client, and provider balances")
|
return aerrors.Wrap(aerr, "getting client, and provider balances")
|
||||||
}
|
}
|
||||||
clientBalance := b[0]
|
clientBalance := b[0]
|
||||||
providerBalance := b[1]
|
providerBalance := b[1]
|
||||||
|
|
||||||
totalPrice := deal.Proposal.TotalStoragePrice()
|
totalPrice := deal.TotalStoragePrice()
|
||||||
|
|
||||||
if clientBalance.Available.LessThan(totalPrice) {
|
if clientBalance.Available.LessThan(totalPrice) {
|
||||||
return aerrors.Newf(5, "client doesn't have enough available funds to cover storage price; %d < %d", clientBalance.Available, totalPrice)
|
return aerrors.Newf(5, "client doesn't have enough available funds to cover storage price; %d < %d", clientBalance.Available, totalPrice)
|
||||||
@ -412,16 +406,16 @@ func (st *StorageMarketState) validateDeal(vmctx types.VMContext, deal StorageDe
|
|||||||
clientBalance = lockFunds(clientBalance, totalPrice)
|
clientBalance = lockFunds(clientBalance, totalPrice)
|
||||||
|
|
||||||
// TODO: REVIEW: Not clear who pays for this
|
// TODO: REVIEW: Not clear who pays for this
|
||||||
if providerBalance.Available.LessThan(deal.Proposal.StorageCollateral) {
|
if providerBalance.Available.LessThan(deal.StorageCollateral) {
|
||||||
return aerrors.Newf(6, "provider doesn't have enough available funds to cover StorageCollateral; %d < %d", providerBalance.Available, deal.Proposal.StorageCollateral)
|
return aerrors.Newf(6, "provider doesn't have enough available funds to cover StorageCollateral; %d < %d", providerBalance.Available, deal.StorageCollateral)
|
||||||
}
|
}
|
||||||
|
|
||||||
providerBalance = lockFunds(providerBalance, deal.Proposal.StorageCollateral)
|
providerBalance = lockFunds(providerBalance, deal.StorageCollateral)
|
||||||
|
|
||||||
// TODO: piece checks (e.g. size > sectorSize)?
|
// TODO: piece checks (e.g. size > sectorSize)?
|
||||||
|
|
||||||
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
|
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
|
||||||
deal.Proposal.Client: clientBalance,
|
deal.Client: clientBalance,
|
||||||
providerWorker: providerBalance,
|
providerWorker: providerBalance,
|
||||||
})
|
})
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
@ -458,11 +452,11 @@ func (sma StorageMarketActor) ActivateStorageDeals(act *types.Actor, vmctx types
|
|||||||
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
|
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if vmctx.Message().From != dealInfo.Deal.Proposal.Provider {
|
if vmctx.Message().From != dealInfo.Provider {
|
||||||
return nil, aerrors.New(1, "ActivateStorageDeals can only be called by the deal provider")
|
return nil, aerrors.New(1, "ActivateStorageDeals can only be called by the deal provider")
|
||||||
}
|
}
|
||||||
|
|
||||||
if vmctx.BlockHeight() > dealInfo.Deal.Proposal.ProposalExpiration {
|
if vmctx.BlockHeight() > dealInfo.ProposalExpiration {
|
||||||
return nil, aerrors.New(2, "deal cannot be activated: proposal expired")
|
return nil, aerrors.New(2, "deal cannot be activated: proposal expired")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,7 +527,7 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
|
|||||||
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
|
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if dealInfo.Deal.Proposal.Provider != vmctx.Message().From {
|
if dealInfo.Provider != vmctx.Message().From {
|
||||||
return nil, aerrors.New(3, "ProcessStorageDealsPayment can only be called by deal provider")
|
return nil, aerrors.New(3, "ProcessStorageDealsPayment can only be called by deal provider")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,15 +536,15 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
|
|||||||
return nil, aerrors.New(4, "ActivationEpoch lower than block height")
|
return nil, aerrors.New(4, "ActivationEpoch lower than block height")
|
||||||
}
|
}
|
||||||
|
|
||||||
if vmctx.BlockHeight() > dealInfo.ActivationEpoch+dealInfo.Deal.Proposal.Duration {
|
if vmctx.BlockHeight() > dealInfo.ActivationEpoch+dealInfo.Duration {
|
||||||
// Deal expired, miner should drop it
|
// Deal expired, miner should drop it
|
||||||
// TODO: process payment for the remainder of last proving period
|
// TODO: process payment for the remainder of last proving period
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
toPay := types.BigMul(dealInfo.Deal.Proposal.StoragePricePerEpoch, types.NewInt(build.SlashablePowerDelay))
|
toPay := types.BigMul(dealInfo.StoragePricePerEpoch, types.NewInt(build.SlashablePowerDelay))
|
||||||
|
|
||||||
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), self.Balances, dealInfo.Deal.Proposal.Client, providerWorker)
|
b, bnd, aerr := GetMarketBalances(vmctx.Context(), vmctx.Ipld(), self.Balances, dealInfo.Client, providerWorker)
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
return nil, aerr
|
return nil, aerr
|
||||||
}
|
}
|
||||||
@ -561,7 +555,7 @@ func (sma StorageMarketActor) ProcessStorageDealsPayment(act *types.Actor, vmctx
|
|||||||
|
|
||||||
// TODO: call set once
|
// TODO: call set once
|
||||||
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
|
bcid, aerr := setMarketBalances(vmctx, bnd, map[address.Address]StorageParticipantBalance{
|
||||||
dealInfo.Deal.Proposal.Client: clientBal,
|
dealInfo.Client: clientBal,
|
||||||
providerWorker: providerBal,
|
providerWorker: providerBal,
|
||||||
})
|
})
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
@ -625,15 +619,15 @@ func (sma StorageMarketActor) ComputeDataCommitment(act *types.Actor, vmctx type
|
|||||||
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
|
return nil, aerrors.HandleExternalError(err, "getting deal info failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if dealInfo.Deal.Proposal.Provider != vmctx.Message().From {
|
if dealInfo.Provider != vmctx.Message().From {
|
||||||
return nil, aerrors.New(5, "referenced deal was not from caller")
|
return nil, aerrors.New(5, "referenced deal was not from caller")
|
||||||
}
|
}
|
||||||
|
|
||||||
var commP [32]byte
|
var commP [32]byte
|
||||||
copy(commP[:], dealInfo.Deal.Proposal.PieceRef)
|
copy(commP[:], dealInfo.PieceRef)
|
||||||
|
|
||||||
pieces = append(pieces, sectorbuilder.PublicPieceInfo{
|
pieces = append(pieces, sectorbuilder.PublicPieceInfo{
|
||||||
Size: dealInfo.Deal.Proposal.PieceSize,
|
Size: dealInfo.PieceSize,
|
||||||
CommP: commP,
|
CommP: commP,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3350,75 +3350,6 @@ func (t *StorageDealProposal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *StorageDeal) MarshalCBOR(w io.Writer) error {
|
|
||||||
if t == nil {
|
|
||||||
_, err := w.Write(cbg.CborNull)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := w.Write([]byte{130}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// t.t.Proposal (actors.StorageDealProposal) (struct)
|
|
||||||
if err := t.Proposal.MarshalCBOR(w); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// t.t.CounterSignature (types.Signature) (struct)
|
|
||||||
if err := t.CounterSignature.MarshalCBOR(w); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *StorageDeal) UnmarshalCBOR(r io.Reader) error {
|
|
||||||
br := cbg.GetPeeker(r)
|
|
||||||
|
|
||||||
maj, extra, err := cbg.CborReadHeader(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if maj != cbg.MajArray {
|
|
||||||
return fmt.Errorf("cbor input should be of type array")
|
|
||||||
}
|
|
||||||
|
|
||||||
if extra != 2 {
|
|
||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
|
||||||
}
|
|
||||||
|
|
||||||
// t.t.Proposal (actors.StorageDealProposal) (struct)
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
if err := t.Proposal.UnmarshalCBOR(br); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
// t.t.CounterSignature (types.Signature) (struct)
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
pb, err := br.PeekByte()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if pb == cbg.CborNull[0] {
|
|
||||||
var nbuf [1]byte
|
|
||||||
if _, err := br.Read(nbuf[:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
t.CounterSignature = new(types.Signature)
|
|
||||||
if err := t.CounterSignature.UnmarshalCBOR(br); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *PublishStorageDealsParams) MarshalCBOR(w io.Writer) error {
|
func (t *PublishStorageDealsParams) MarshalCBOR(w io.Writer) error {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
_, err := w.Write(cbg.CborNull)
|
_, err := w.Write(cbg.CborNull)
|
||||||
@ -3428,7 +3359,7 @@ func (t *PublishStorageDealsParams) MarshalCBOR(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.Deals ([]actors.StorageDeal) (slice)
|
// t.t.Deals ([]actors.StorageDealProposal) (slice)
|
||||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Deals)))); err != nil {
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajArray, uint64(len(t.Deals)))); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -3455,7 +3386,7 @@ func (t *PublishStorageDealsParams) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
return fmt.Errorf("cbor input had wrong number of fields")
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.Deals ([]actors.StorageDeal) (slice)
|
// t.t.Deals ([]actors.StorageDealProposal) (slice)
|
||||||
|
|
||||||
maj, extra, err = cbg.CborReadHeader(br)
|
maj, extra, err = cbg.CborReadHeader(br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -3469,11 +3400,11 @@ func (t *PublishStorageDealsParams) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("expected cbor array")
|
return fmt.Errorf("expected cbor array")
|
||||||
}
|
}
|
||||||
if extra > 0 {
|
if extra > 0 {
|
||||||
t.Deals = make([]StorageDeal, extra)
|
t.Deals = make([]StorageDealProposal, extra)
|
||||||
}
|
}
|
||||||
for i := 0; i < int(extra); i++ {
|
for i := 0; i < int(extra); i++ {
|
||||||
|
|
||||||
var v StorageDeal
|
var v StorageDealProposal
|
||||||
if err := v.UnmarshalCBOR(br); err != nil {
|
if err := v.UnmarshalCBOR(br); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -3696,12 +3627,55 @@ func (t *OnChainDeal) MarshalCBOR(w io.Writer) error {
|
|||||||
_, err := w.Write(cbg.CborNull)
|
_, err := w.Write(cbg.CborNull)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := w.Write([]byte{130}); err != nil {
|
if _, err := w.Write([]byte{138}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.Deal (actors.StorageDeal) (struct)
|
// t.t.PieceRef ([]uint8) (slice)
|
||||||
if err := t.Deal.MarshalCBOR(w); err != nil {
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.PieceRef)))); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := w.Write(t.PieceRef); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.PieceSize (uint64) (uint64)
|
||||||
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PieceSize))); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.PieceSerialization (uint64) (uint64)
|
||||||
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.PieceSerialization))); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.Client (address.Address) (struct)
|
||||||
|
if err := t.Client.MarshalCBOR(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.Provider (address.Address) (struct)
|
||||||
|
if err := t.Provider.MarshalCBOR(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.ProposalExpiration (uint64) (uint64)
|
||||||
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ProposalExpiration))); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.Duration (uint64) (uint64)
|
||||||
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.Duration))); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.StoragePricePerEpoch (types.BigInt) (struct)
|
||||||
|
if err := t.StoragePricePerEpoch.MarshalCBOR(w); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// t.t.StorageCollateral (types.BigInt) (struct)
|
||||||
|
if err := t.StorageCollateral.MarshalCBOR(w); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3723,15 +3697,99 @@ func (t *OnChainDeal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("cbor input should be of type array")
|
return fmt.Errorf("cbor input should be of type array")
|
||||||
}
|
}
|
||||||
|
|
||||||
if extra != 2 {
|
if extra != 10 {
|
||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
return fmt.Errorf("cbor input had wrong number of fields")
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.Deal (actors.StorageDeal) (struct)
|
// t.t.PieceRef ([]uint8) (slice)
|
||||||
|
|
||||||
|
maj, extra, err = cbg.CborReadHeader(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if extra > 8192 {
|
||||||
|
return fmt.Errorf("t.PieceRef: array too large (%d)", extra)
|
||||||
|
}
|
||||||
|
|
||||||
|
if maj != cbg.MajByteString {
|
||||||
|
return fmt.Errorf("expected byte array")
|
||||||
|
}
|
||||||
|
t.PieceRef = make([]byte, extra)
|
||||||
|
if _, err := io.ReadFull(br, t.PieceRef); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// t.t.PieceSize (uint64) (uint64)
|
||||||
|
|
||||||
|
maj, extra, err = cbg.CborReadHeader(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if maj != cbg.MajUnsignedInt {
|
||||||
|
return fmt.Errorf("wrong type for uint64 field")
|
||||||
|
}
|
||||||
|
t.PieceSize = uint64(extra)
|
||||||
|
// t.t.PieceSerialization (uint64) (uint64)
|
||||||
|
|
||||||
|
maj, extra, err = cbg.CborReadHeader(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if maj != cbg.MajUnsignedInt {
|
||||||
|
return fmt.Errorf("wrong type for uint64 field")
|
||||||
|
}
|
||||||
|
t.PieceSerialization = uint64(extra)
|
||||||
|
// t.t.Client (address.Address) (struct)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if err := t.Deal.UnmarshalCBOR(br); err != nil {
|
if err := t.Client.UnmarshalCBOR(br); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// t.t.Provider (address.Address) (struct)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
if err := t.Provider.UnmarshalCBOR(br); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// t.t.ProposalExpiration (uint64) (uint64)
|
||||||
|
|
||||||
|
maj, extra, err = cbg.CborReadHeader(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if maj != cbg.MajUnsignedInt {
|
||||||
|
return fmt.Errorf("wrong type for uint64 field")
|
||||||
|
}
|
||||||
|
t.ProposalExpiration = uint64(extra)
|
||||||
|
// t.t.Duration (uint64) (uint64)
|
||||||
|
|
||||||
|
maj, extra, err = cbg.CborReadHeader(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if maj != cbg.MajUnsignedInt {
|
||||||
|
return fmt.Errorf("wrong type for uint64 field")
|
||||||
|
}
|
||||||
|
t.Duration = uint64(extra)
|
||||||
|
// t.t.StoragePricePerEpoch (types.BigInt) (struct)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
if err := t.StoragePricePerEpoch.UnmarshalCBOR(br); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// t.t.StorageCollateral (types.BigInt) (struct)
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
if err := t.StorageCollateral.UnmarshalCBOR(br); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
cid "github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
@ -192,7 +192,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
|
|||||||
_, err := w.Write(cbg.CborNull)
|
_, err := w.Write(cbg.CborNull)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := w.Write([]byte{133}); err != nil {
|
if _, err := w.Write([]byte{132}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,23 +215,10 @@ func (t *Response) MarshalCBOR(w io.Writer) error {
|
|||||||
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
|
return xerrors.Errorf("failed to write cid field t.Proposal: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.StorageDeal (actors.StorageDeal) (struct)
|
// t.t.StorageDealSubmission (types.SignedMessage) (struct)
|
||||||
if err := t.StorageDeal.MarshalCBOR(w); err != nil {
|
if err := t.StorageDealSubmission.MarshalCBOR(w); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.PublishMessage (cid.Cid) (struct)
|
|
||||||
|
|
||||||
if t.PublishMessage == nil {
|
|
||||||
if _, err := w.Write(cbg.CborNull); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if err := cbg.WriteCid(w, *t.PublishMessage); err != nil {
|
|
||||||
return xerrors.Errorf("failed to write cid field t.PublishMessage: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +233,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("cbor input should be of type array")
|
return fmt.Errorf("cbor input should be of type array")
|
||||||
}
|
}
|
||||||
|
|
||||||
if extra != 5 {
|
if extra != 4 {
|
||||||
return fmt.Errorf("cbor input had wrong number of fields")
|
return fmt.Errorf("cbor input had wrong number of fields")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +269,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
|
|||||||
t.Proposal = c
|
t.Proposal = c
|
||||||
|
|
||||||
}
|
}
|
||||||
// t.t.StorageDeal (actors.StorageDeal) (struct)
|
// t.t.StorageDealSubmission (types.SignedMessage) (struct)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -296,36 +283,12 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.StorageDeal = new(actors.StorageDeal)
|
t.StorageDealSubmission = new(types.SignedMessage)
|
||||||
if err := t.StorageDeal.UnmarshalCBOR(br); err != nil {
|
if err := t.StorageDealSubmission.UnmarshalCBOR(br); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
// t.t.PublishMessage (cid.Cid) (struct)
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
pb, err := br.PeekByte()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if pb == cbg.CborNull[0] {
|
|
||||||
var nbuf [1]byte
|
|
||||||
if _, err := br.Read(nbuf[:]); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
c, err := cbg.ReadCid(br)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("failed to read cid field t.PublishMessage: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.PublishMessage = &c
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -593,18 +556,10 @@ func (t *ClientDeal) MarshalCBOR(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.t.PublishMessage (cid.Cid) (struct)
|
// t.t.PublishMessage (types.SignedMessage) (struct)
|
||||||
|
if err := t.PublishMessage.MarshalCBOR(w); err != nil {
|
||||||
if t.PublishMessage == nil {
|
|
||||||
if _, err := w.Write(cbg.CborNull); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if err := cbg.WriteCid(w, *t.PublishMessage); err != nil {
|
|
||||||
return xerrors.Errorf("failed to write cid field t.PublishMessage: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -683,7 +638,7 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return fmt.Errorf("wrong type for uint64 field")
|
return fmt.Errorf("wrong type for uint64 field")
|
||||||
}
|
}
|
||||||
t.DealID = uint64(extra)
|
t.DealID = uint64(extra)
|
||||||
// t.t.PublishMessage (cid.Cid) (struct)
|
// t.t.PublishMessage (types.SignedMessage) (struct)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -697,13 +652,10 @@ func (t *ClientDeal) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
t.PublishMessage = new(types.SignedMessage)
|
||||||
c, err := cbg.ReadCid(br)
|
if err := t.PublishMessage.UnmarshalCBOR(br); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
return xerrors.Errorf("failed to read cid field t.PublishMessage: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.PublishMessage = &c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ type ClientDeal struct {
|
|||||||
MinerWorker address.Address
|
MinerWorker address.Address
|
||||||
DealID uint64
|
DealID uint64
|
||||||
|
|
||||||
PublishMessage *cid.Cid
|
PublishMessage *types.SignedMessage
|
||||||
|
|
||||||
s inet.Stream
|
s inet.Stream
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,9 @@ func (c *Client) new(ctx context.Context, deal ClientDeal) (func(*ClientDeal), e
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: verify StorageDealSubmission
|
||||||
|
|
||||||
if err := c.disconnect(deal); err != nil {
|
if err := c.disconnect(deal); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -54,18 +57,14 @@ func (c *Client) new(ctx context.Context, deal ClientDeal) (func(*ClientDeal), e
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(info *ClientDeal) {
|
return func(info *ClientDeal) {
|
||||||
info.PublishMessage = resp.PublishMessage
|
info.PublishMessage = resp.StorageDealSubmission
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDeal), error) {
|
func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDeal), error) {
|
||||||
log.Infow("DEAL ACCEPTED!")
|
log.Infow("DEAL ACCEPTED!")
|
||||||
|
|
||||||
pubmsg, err := c.chain.GetMessage(*deal.PublishMessage)
|
pubmsg := deal.PublishMessage.Message
|
||||||
if err != nil {
|
|
||||||
return nil, xerrors.Errorf("getting deal pubsish message: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pw, err := stmgr.GetMinerWorker(ctx, c.sm, nil, deal.Proposal.Provider)
|
pw, err := stmgr.GetMinerWorker(ctx, c.sm, nil, deal.Proposal.Provider)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("getting miner worker failed: %w", err)
|
return nil, xerrors.Errorf("getting miner worker failed: %w", err)
|
||||||
@ -91,7 +90,7 @@ func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDea
|
|||||||
dealIdx := -1
|
dealIdx := -1
|
||||||
for i, storageDeal := range params.Deals {
|
for i, storageDeal := range params.Deals {
|
||||||
// TODO: make it less hacky
|
// TODO: make it less hacky
|
||||||
eq, err := cborutil.Equals(&deal.Proposal, &storageDeal.Proposal)
|
eq, err := cborutil.Equals(&deal.Proposal, &storageDeal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -102,11 +101,11 @@ func (c *Client) accepted(ctx context.Context, deal ClientDeal) (func(*ClientDea
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dealIdx == -1 {
|
if dealIdx == -1 {
|
||||||
return nil, xerrors.Errorf("deal publish didn't contain our deal (message cid: %s)", deal.PublishMessage)
|
return nil, xerrors.Errorf("deal publish didn't contain our deal (message cid: %s)", deal.PublishMessage.Cid())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: timeout
|
// TODO: timeout
|
||||||
_, ret, err := c.sm.WaitForMessage(ctx, *deal.PublishMessage)
|
_, ret, err := c.sm.WaitForMessage(ctx, deal.PublishMessage.Cid())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("waiting for deal publish message: %w", err)
|
return nil, xerrors.Errorf("waiting for deal publish message: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -93,15 +93,8 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
|
|||||||
|
|
||||||
log.Info("publishing deal")
|
log.Info("publishing deal")
|
||||||
|
|
||||||
storageDeal := actors.StorageDeal{
|
|
||||||
Proposal: deal.Proposal,
|
|
||||||
}
|
|
||||||
if err := api.SignWith(ctx, p.full.WalletSign, waddr, &storageDeal); err != nil {
|
|
||||||
return nil, xerrors.Errorf("signing storage deal failed: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
params, err := actors.SerializeParams(&actors.PublishStorageDealsParams{
|
params, err := actors.SerializeParams(&actors.PublishStorageDealsParams{
|
||||||
Deals: []actors.StorageDeal{storageDeal},
|
Deals: []actors.StorageDealProposal{deal.Proposal},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("serializing PublishStorageDeals params failed: ", err)
|
return nil, xerrors.Errorf("serializing PublishStorageDeals params failed: ", err)
|
||||||
@ -136,13 +129,11 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("fetching data for a deal %d", resp.DealIDs[0])
|
log.Infof("fetching data for a deal %d", resp.DealIDs[0])
|
||||||
mcid := smsg.Cid()
|
|
||||||
err = p.sendSignedResponse(&Response{
|
err = p.sendSignedResponse(&Response{
|
||||||
State: api.DealAccepted,
|
State: api.DealAccepted,
|
||||||
|
|
||||||
Proposal: deal.ProposalCid,
|
Proposal: deal.ProposalCid,
|
||||||
PublishMessage: &mcid,
|
StorageDealSubmission: smsg,
|
||||||
StorageDeal: &storageDeal,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -58,8 +58,7 @@ type Response struct {
|
|||||||
Proposal cid.Cid
|
Proposal cid.Cid
|
||||||
|
|
||||||
// DealAccepted
|
// DealAccepted
|
||||||
StorageDeal *actors.StorageDeal
|
StorageDealSubmission *types.SignedMessage
|
||||||
PublishMessage *cid.Cid
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Do we actually need this to be signed?
|
// TODO: Do we actually need this to be signed?
|
||||||
|
@ -197,7 +197,7 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDeal) (cid.Cid, error) {
|
func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors.StorageDealProposal) (cid.Cid, error) {
|
||||||
cst := hamt.CSTFromBstore(bs)
|
cst := hamt.CSTFromBstore(bs)
|
||||||
nd := hamt.NewNode(cst)
|
nd := hamt.NewNode(cst)
|
||||||
emptyHAMT, err := cst.Put(context.TODO(), nd)
|
emptyHAMT, err := cst.Put(context.TODO(), nd)
|
||||||
@ -210,7 +210,15 @@ func SetupStorageMarketActor(bs bstore.Blockstore, sroot cid.Cid, deals []actors
|
|||||||
cdeals := make([]cbg.CBORMarshaler, len(deals))
|
cdeals := make([]cbg.CBORMarshaler, len(deals))
|
||||||
for i, deal := range deals {
|
for i, deal := range deals {
|
||||||
cdeals[i] = &actors.OnChainDeal{
|
cdeals[i] = &actors.OnChainDeal{
|
||||||
Deal: deal,
|
PieceRef: deal.PieceRef,
|
||||||
|
PieceSize: deal.PieceSize,
|
||||||
|
PieceSerialization: deal.PieceSerialization,
|
||||||
|
Client: deal.Client,
|
||||||
|
Provider: deal.Provider,
|
||||||
|
ProposalExpiration: deal.ProposalExpiration,
|
||||||
|
Duration: deal.Duration,
|
||||||
|
StoragePricePerEpoch: deal.StoragePricePerEpoch,
|
||||||
|
StorageCollateral: deal.StorageCollateral,
|
||||||
ActivationEpoch: 1,
|
ActivationEpoch: 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -267,7 +275,7 @@ func mustEnc(i cbg.CBORMarshaler) []byte {
|
|||||||
return enc
|
return enc
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, gmcfg *GenMinerCfg) (cid.Cid, []actors.StorageDeal, error) {
|
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, gmcfg *GenMinerCfg) (cid.Cid, []actors.StorageDealProposal, error) {
|
||||||
vm, err := vm.NewVM(sroot, 0, nil, actors.NetworkAddress, cs.Blockstore())
|
vm, err := vm.NewVM(sroot, 0, nil, actors.NetworkAddress, cs.Blockstore())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, nil, xerrors.Errorf("failed to create NewVM: %w", err)
|
return cid.Undef, nil, xerrors.Errorf("failed to create NewVM: %w", err)
|
||||||
@ -281,7 +289,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
|||||||
return cid.Undef, nil, xerrors.Errorf("miner address list, and preseal count doesn't match (%d != %d)", len(gmcfg.MinerAddrs), len(gmcfg.PreSeals))
|
return cid.Undef, nil, xerrors.Errorf("miner address list, and preseal count doesn't match (%d != %d)", len(gmcfg.MinerAddrs), len(gmcfg.PreSeals))
|
||||||
}
|
}
|
||||||
|
|
||||||
var deals []actors.StorageDeal
|
var deals []actors.StorageDealProposal
|
||||||
|
|
||||||
for i, maddr := range gmcfg.MinerAddrs {
|
for i, maddr := range gmcfg.MinerAddrs {
|
||||||
ps, psok := gmcfg.PreSeals[maddr.String()]
|
ps, psok := gmcfg.PreSeals[maddr.String()]
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
cid "github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
@ -2,11 +2,11 @@ package seed
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -53,7 +53,6 @@ func PreSeal(maddr address.Address, ssize uint64, offset uint64, sectors int, sb
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
r := rand.New(rand.NewSource(101))
|
|
||||||
size := sectorbuilder.UserBytesForSectorSize(ssize)
|
size := sectorbuilder.UserBytesForSectorSize(ssize)
|
||||||
|
|
||||||
var sealedSectors []*genesis.PreSeal
|
var sealedSectors []*genesis.PreSeal
|
||||||
@ -63,7 +62,7 @@ func PreSeal(maddr address.Address, ssize uint64, offset uint64, sectors int, sb
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pi, err := sb.AddPiece(size, sid, r, nil)
|
pi, err := sb.AddPiece(size, sid, rand.Reader, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -153,20 +152,12 @@ func createDeals(m *genesis.GenesisMiner, k *wallet.Key, maddr address.Address,
|
|||||||
ProposerSignature: nil,
|
ProposerSignature: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: pretty sure we don't even need to sign this
|
||||||
if err := api.SignWith(context.TODO(), wallet.KeyWallet(k).Sign, k.Address, proposal); err != nil {
|
if err := api.SignWith(context.TODO(), wallet.KeyWallet(k).Sign, k.Address, proposal); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
deal := &actors.StorageDeal{
|
sector.Deal = *proposal
|
||||||
Proposal: *proposal,
|
|
||||||
CounterSignature: nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := api.SignWith(context.TODO(), wallet.KeyWallet(k).Sign, k.Address, deal); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
sector.Deal = *deal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -267,7 +268,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
proposalCid, err := sector.Deal.Proposal.Cid()
|
proposalCid, err := sector.Deal.Cid()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -275,7 +276,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
|
|||||||
dealKey := datastore.NewKey(deals.ProviderDsPrefix).ChildString(proposalCid.String())
|
dealKey := datastore.NewKey(deals.ProviderDsPrefix).ChildString(proposalCid.String())
|
||||||
|
|
||||||
deal := &deals.MinerDeal{
|
deal := &deals.MinerDeal{
|
||||||
Proposal: sector.Deal.Proposal,
|
Proposal: sector.Deal,
|
||||||
ProposalCid: proposalCid,
|
ProposalCid: proposalCid,
|
||||||
State: lapi.DealComplete,
|
State: lapi.DealComplete,
|
||||||
Ref: proposalCid, // TODO: This is super wrong, but there
|
Ref: proposalCid, // TODO: This is super wrong, but there
|
||||||
@ -298,7 +299,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, presealDir strin
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.StorageDeal) (uint64, error) {
|
func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.StorageDealProposal) (uint64, error) {
|
||||||
// TODO: find a better way
|
// TODO: find a better way
|
||||||
// (this is only used by genesis miners)
|
// (this is only used by genesis miners)
|
||||||
|
|
||||||
@ -308,11 +309,7 @@ func findMarketDealID(ctx context.Context, api lapi.FullNode, deal actors.Storag
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range deals {
|
for k, v := range deals {
|
||||||
eq, err := cborutil.Equals(&v.Deal, &deal)
|
if bytes.Equal(v.PieceRef, deal.PieceRef) {
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
if eq {
|
|
||||||
return strconv.ParseUint(k, 10, 64)
|
return strconv.ParseUint(k, 10, 64)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,6 @@ func main() {
|
|||||||
actors.StorageMarketState{},
|
actors.StorageMarketState{},
|
||||||
actors.WithdrawBalanceParams{},
|
actors.WithdrawBalanceParams{},
|
||||||
actors.StorageDealProposal{},
|
actors.StorageDealProposal{},
|
||||||
actors.StorageDeal{},
|
|
||||||
actors.PublishStorageDealsParams{},
|
actors.PublishStorageDealsParams{},
|
||||||
actors.PublishStorageDealResponse{},
|
actors.PublishStorageDealResponse{},
|
||||||
actors.ActivateStorageDealsParams{},
|
actors.ActivateStorageDealsParams{},
|
||||||
|
@ -10,7 +10,7 @@ type PreSeal struct {
|
|||||||
CommR [32]byte
|
CommR [32]byte
|
||||||
CommD [32]byte
|
CommD [32]byte
|
||||||
SectorID uint64
|
SectorID uint64
|
||||||
Deal actors.StorageDeal
|
Deal actors.StorageDealProposal
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenesisMiner struct {
|
type GenesisMiner struct {
|
||||||
|
@ -20,7 +20,7 @@ func (m *Miner) storeGarbage(ctx context.Context, sectorID uint64, existingPiece
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
deals := make([]actors.StorageDeal, len(sizes))
|
deals := make([]actors.StorageDealProposal, len(sizes))
|
||||||
for i, size := range sizes {
|
for i, size := range sizes {
|
||||||
release := m.sb.RateLimit()
|
release := m.sb.RateLimit()
|
||||||
commP, err := sectorbuilder.GeneratePieceCommitment(io.LimitReader(rand.New(rand.NewSource(42)), int64(size)), size)
|
commP, err := sectorbuilder.GeneratePieceCommitment(io.LimitReader(rand.New(rand.NewSource(42)), int64(size)), size)
|
||||||
@ -47,14 +47,7 @@ func (m *Miner) storeGarbage(ctx context.Context, sectorID uint64, existingPiece
|
|||||||
return nil, xerrors.Errorf("signing storage deal failed: ", err)
|
return nil, xerrors.Errorf("signing storage deal failed: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
storageDeal := actors.StorageDeal{
|
deals[i] = sdp
|
||||||
Proposal: sdp,
|
|
||||||
}
|
|
||||||
if err := api.SignWith(ctx, m.api.WalletSign, m.worker, &storageDeal); err != nil {
|
|
||||||
return nil, xerrors.Errorf("signing storage deal failed: ", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
deals[i] = storageDeal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params, aerr := actors.SerializeParams(&actors.PublishStorageDealsParams{
|
params, aerr := actors.SerializeParams(&actors.PublishStorageDealsParams{
|
||||||
|
Loading…
Reference in New Issue
Block a user