Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

fix #1248 changing the deal label to bytes not strings #1496

Merged
merged 11 commits into from
Oct 14, 2021
Next Next commit
changing the deal label to bytes not strings
  • Loading branch information
laudiacay committed Sep 24, 2021
commit 855718b82bbee43b41746be24c7dfb3a92e3a851
413 changes: 413 additions & 0 deletions actors/builtin/market/cbor_gen.go

Large diffs are not rendered by default.

87 changes: 59 additions & 28 deletions actors/builtin/market/deal.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package market

import (
"bytes"

addr "github.com/filecoin-project/go-address"
abi "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto"
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/ipfs/go-cid"
)

//var PieceCIDPrefix = cid.Prefix{
Expand All @@ -12,6 +19,8 @@ import (
//}
var PieceCIDPrefix = market0.PieceCIDPrefix

type DealProposal0 = market0.DealProposal
laudiacay marked this conversation as resolved.
Show resolved Hide resolved

// Note: Deal Collateral is only released and returned to clients and miners
// when the storage deal stops counting towards power. In the current iteration,
// it will be released when the sector containing the storage deals expires,
Expand All @@ -20,33 +29,55 @@ var PieceCIDPrefix = market0.PieceCIDPrefix
// minimal deals that last for a long time.
// Note: ClientCollateralPerEpoch may not be needed and removed pending future confirmation.
// There will be a Minimum value for both client and provider deal collateral.
//type DealProposal struct {
// PieceCID cid.Cid `checked:"true"` // Checked in validateDeal, CommP
// PieceSize abi.PaddedPieceSize
// VerifiedDeal bool
// Client addr.Address
// Provider addr.Address
//
// // Label is an arbitrary client chosen label to apply to the deal
// // TODO: Limit the size of this: https://github.com/filecoin-project/specs-actors/issues/897
// Label string
//
// // Nominal start epoch. Deal payment is linear between StartEpoch and EndEpoch,
// // with total amount StoragePricePerEpoch * (EndEpoch - StartEpoch).
// // Storage deal must appear in a sealed (proven) sector no later than StartEpoch,
// // otherwise it is invalid.
// StartEpoch abi.ChainEpoch
// EndEpoch abi.ChainEpoch
// StoragePricePerEpoch abi.TokenAmount
//
// ProviderCollateral abi.TokenAmount
// ClientCollateral abi.TokenAmount
//}
type DealProposal = market0.DealProposal
type DealProposal struct {
PieceCID cid.Cid `checked:"true"` // Checked in validateDeal, CommP
PieceSize abi.PaddedPieceSize
VerifiedDeal bool
Client addr.Address
Provider addr.Address

// Label is an arbitrary client chosen label to apply to the deal
// TODO: Limit the size of this: https://github.com/filecoin-project/specs-actors/issues/897
laudiacay marked this conversation as resolved.
Show resolved Hide resolved
Label []byte

// Nominal start epoch. Deal payment is linear between StartEpoch and EndEpoch,
// with total amount StoragePricePerEpoch * (EndEpoch - StartEpoch).
// Storage deal must appear in a sealed (proven) sector no later than StartEpoch,
// otherwise it is invalid.
StartEpoch abi.ChainEpoch
EndEpoch abi.ChainEpoch
StoragePricePerEpoch abi.TokenAmount

ProviderCollateral abi.TokenAmount
ClientCollateral abi.TokenAmount
}

// ClientDealProposal is a DealProposal signed by a client
//type ClientDealProposal struct {
// Proposal DealProposal
// ClientSignature crypto.Signature
//}
type ClientDealProposal = market0.ClientDealProposal
type ClientDealProposal struct {
Proposal DealProposal
ClientSignature crypto.Signature
}

func (p *DealProposal) Duration() abi.ChainEpoch {
return p.EndEpoch - p.StartEpoch
}

func (p *DealProposal) TotalStorageFee() abi.TokenAmount {
return big.Mul(p.StoragePricePerEpoch, big.NewInt(int64(p.Duration())))
}

func (p *DealProposal) ClientBalanceRequirement() abi.TokenAmount {
return big.Add(p.ClientCollateral, p.TotalStorageFee())
}

func (p *DealProposal) ProviderBalanceRequirement() abi.TokenAmount {
return p.ProviderCollateral
}

func (p *DealProposal) Cid() (cid.Cid, error) {
buf := new(bytes.Buffer)
if err := p.MarshalCBOR(buf); err != nil {
return cid.Undef, err
}
return abi.CidBuilder.Sum(buf.Bytes())
}
7 changes: 3 additions & 4 deletions actors/builtin/market/market_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ func (a Actor) AddBalance(rt Runtime, providerOrClientAddress *addr.Address) *ab
return nil
}

//type PublishStorageDealsParams struct {
// Deals []ClientDealProposal
//}
type PublishStorageDealsParams = market0.PublishStorageDealsParams
type PublishStorageDealsParams struct {
Deals []ClientDealProposal
}

//type PublishStorageDealsReturn struct {
// IDs []abi.DealID
Expand Down
10 changes: 5 additions & 5 deletions actors/builtin/market/market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2412,7 +2412,7 @@ func TestMarketActorDeals(t *testing.T) {
rt.Verify()
}

dealProposal.Label = "foo"
dealProposal.Label = []byte("foo")

// Same deal with a different label should work
{
Expand Down Expand Up @@ -2440,7 +2440,7 @@ func TestMaxDealLabelSize(t *testing.T) {
actor.addParticipantFunds(rt, client, abi.NewTokenAmount(20000000))

dealProposal := generateDealProposal(client, provider, abi.ChainEpoch(1), abi.ChainEpoch(200*builtin.EpochsInDay))
dealProposal.Label = string(make([]byte, market.DealMaxLabelSize))
dealProposal.Label = make([]byte, market.DealMaxLabelSize)
params := &market.PublishStorageDealsParams{Deals: []market.ClientDealProposal{{Proposal: dealProposal}}}

// Label at max size should work.
Expand All @@ -2449,7 +2449,7 @@ func TestMaxDealLabelSize(t *testing.T) {
actor.publishDeals(rt, minerAddrs, publishDealReq{deal: dealProposal})
}

dealProposal.Label = string(make([]byte, market.DealMaxLabelSize+1))
dealProposal.Label = make([]byte, market.DealMaxLabelSize+1)

// Label greater than max size should fail.
{
Expand Down Expand Up @@ -3263,7 +3263,7 @@ func (h *marketActorTestHarness) generateAndPublishDealForPiece(rt *mock.Runtime
clientCollateral := big.NewInt(10)
providerCollateral := big.NewInt(10)

deal := market.DealProposal{PieceCID: pieceCID, PieceSize: pieceSize, Client: client, Provider: minerAddrs.provider, Label: "label", StartEpoch: startEpoch,
deal := market.DealProposal{PieceCID: pieceCID, PieceSize: pieceSize, Client: client, Provider: minerAddrs.provider, Label: []byte("label"), StartEpoch: startEpoch,
EndEpoch: endEpoch, StoragePricePerEpoch: storagePerEpoch, ProviderCollateral: providerCollateral, ClientCollateral: clientCollateral}

// add funds
Expand Down Expand Up @@ -3315,7 +3315,7 @@ func generateDealProposalWithCollateral(client, provider address.Address, provid
pieceSize := abi.PaddedPieceSize(2048)
storagePerEpoch := big.NewInt(10)

return market.DealProposal{PieceCID: pieceCid, PieceSize: pieceSize, Client: client, Provider: provider, Label: "label", StartEpoch: startEpoch,
return market.DealProposal{PieceCID: pieceCid, PieceSize: pieceSize, Client: client, Provider: provider, Label: []byte("label"), StartEpoch: startEpoch,
EndEpoch: endEpoch, StoragePricePerEpoch: storagePerEpoch, ProviderCollateral: providerCollateral, ClientCollateral: clientCollateral}
}

Expand Down
2 changes: 1 addition & 1 deletion actors/test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func publishDeal(t *testing.T, v *vm.VM, provider, dealClient, minerID addr.Addr
VerifiedDeal: verifiedDeal,
Client: dealClient,
Provider: minerID,
Label: dealLabel,
Label: []byte(dealLabel),
StartEpoch: dealStart,
EndEpoch: dealStart + dealLifetime,
StoragePricePerEpoch: abi.NewTokenAmount(1 << 20),
Expand Down
6 changes: 3 additions & 3 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func main() {
market.State{},
// method params and returns
//market.WithdrawBalanceParams{}, // Aliased from v0
//market.PublishStorageDealsParams{}, // Aliased from v0
market.PublishStorageDealsParams{},
//market.PublishStorageDealsReturn{}, // Aliased from v0
//market.ActivateDealsParams{}, // Aliased from v0
market.VerifyDealsForActivationParams{},
Expand All @@ -158,8 +158,8 @@ func main() {
market.ComputeDataCommitmentReturn{},
//market.OnMinerSectorsTerminateParams{}, // Aliased from v0
// other types
//market.DealProposal{}, // Aliased from v0
//market.ClientDealProposal{}, // Aliased from v0
market.DealProposal{},
market.ClientDealProposal{},
market.SectorDeals{},
market.SectorWeights{},
market.DealState{},
Expand Down
2 changes: 1 addition & 1 deletion support/agent/deal_client_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (dca *DealClientAgent) createDeal(s SimState, provider DealProvider) error
VerifiedDeal: false,
Client: dca.account,
Provider: provider.Address(),
Label: dca.account.String() + ":" + strconv.Itoa(dca.DealCount),
Label: []byte(dca.account.String() + ":" + strconv.Itoa(dca.DealCount)),
StartEpoch: dealStart,
EndEpoch: dealEnd,
StoragePricePerEpoch: price,
Expand Down
2 changes: 1 addition & 1 deletion test-vectors/determinism-check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- de328620513afeb9b1baaf0e1c02d7b268955a62ec152f603d158ff908608d7e
- 4e7d6414d0d1c069f628de097a74035c46a81371ed83fb7cd9956331a0afb629