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

Commit 1d8b7d5

Browse files
laudiacayZenGround0
authored andcommitted
fix #1248 changing the deal label to bytes not strings (#1496)
* changing the deal label to bytes not strings * removing a todo comment for something that was actually a to-done * wrote migration.... how do i test?? * fixing tests, determinism-gen * left some debugging prints in there * fixes some of the code review * fixing one more issue * fixing rest of code review things- all that's left isss testing * half a test * there's a bug in the migration, test is done * fixing code review
1 parent 77d002a commit 1d8b7d5

File tree

14 files changed

+901
-96
lines changed

14 files changed

+901
-96
lines changed

actors/builtin/market/cbor_gen.go

Lines changed: 348 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actors/builtin/market/deal.go

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package market
22

33
import (
4+
"bytes"
5+
6+
addr "github.com/filecoin-project/go-address"
7+
abi "github.com/filecoin-project/go-state-types/abi"
8+
"github.com/filecoin-project/go-state-types/big"
9+
"github.com/filecoin-project/go-state-types/crypto"
410
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
11+
"github.com/ipfs/go-cid"
512
)
613

714
//var PieceCIDPrefix = cid.Prefix{
@@ -20,33 +27,54 @@ var PieceCIDPrefix = market0.PieceCIDPrefix
2027
// minimal deals that last for a long time.
2128
// Note: ClientCollateralPerEpoch may not be needed and removed pending future confirmation.
2229
// There will be a Minimum value for both client and provider deal collateral.
23-
//type DealProposal struct {
24-
// PieceCID cid.Cid `checked:"true"` // Checked in validateDeal, CommP
25-
// PieceSize abi.PaddedPieceSize
26-
// VerifiedDeal bool
27-
// Client addr.Address
28-
// Provider addr.Address
29-
//
30-
// // Label is an arbitrary client chosen label to apply to the deal
31-
// // TODO: Limit the size of this: https://github.com/filecoin-project/specs-actors/issues/897
32-
// Label string
33-
//
34-
// // Nominal start epoch. Deal payment is linear between StartEpoch and EndEpoch,
35-
// // with total amount StoragePricePerEpoch * (EndEpoch - StartEpoch).
36-
// // Storage deal must appear in a sealed (proven) sector no later than StartEpoch,
37-
// // otherwise it is invalid.
38-
// StartEpoch abi.ChainEpoch
39-
// EndEpoch abi.ChainEpoch
40-
// StoragePricePerEpoch abi.TokenAmount
41-
//
42-
// ProviderCollateral abi.TokenAmount
43-
// ClientCollateral abi.TokenAmount
44-
//}
45-
type DealProposal = market0.DealProposal
30+
type DealProposal struct {
31+
PieceCID cid.Cid `checked:"true"` // Checked in validateDeal, CommP
32+
PieceSize abi.PaddedPieceSize
33+
VerifiedDeal bool
34+
Client addr.Address
35+
Provider addr.Address
36+
37+
// Label is an arbitrary client chosen label to apply to the deal
38+
Label []byte
39+
40+
// Nominal start epoch. Deal payment is linear between StartEpoch and EndEpoch,
41+
// with total amount StoragePricePerEpoch * (EndEpoch - StartEpoch).
42+
// Storage deal must appear in a sealed (proven) sector no later than StartEpoch,
43+
// otherwise it is invalid.
44+
StartEpoch abi.ChainEpoch
45+
EndEpoch abi.ChainEpoch
46+
StoragePricePerEpoch abi.TokenAmount
47+
48+
ProviderCollateral abi.TokenAmount
49+
ClientCollateral abi.TokenAmount
50+
}
4651

4752
// ClientDealProposal is a DealProposal signed by a client
48-
// type ClientDealProposal struct {
49-
// Proposal DealProposal
50-
// ClientSignature crypto.Signature
51-
// }
52-
type ClientDealProposal = market0.ClientDealProposal
53+
type ClientDealProposal struct {
54+
Proposal DealProposal
55+
ClientSignature crypto.Signature
56+
}
57+
58+
func (p *DealProposal) Duration() abi.ChainEpoch {
59+
return p.EndEpoch - p.StartEpoch
60+
}
61+
62+
func (p *DealProposal) TotalStorageFee() abi.TokenAmount {
63+
return big.Mul(p.StoragePricePerEpoch, big.NewInt(int64(p.Duration())))
64+
}
65+
66+
func (p *DealProposal) ClientBalanceRequirement() abi.TokenAmount {
67+
return big.Add(p.ClientCollateral, p.TotalStorageFee())
68+
}
69+
70+
func (p *DealProposal) ProviderBalanceRequirement() abi.TokenAmount {
71+
return p.ProviderCollateral
72+
}
73+
74+
func (p *DealProposal) Cid() (cid.Cid, error) {
75+
buf := new(bytes.Buffer)
76+
if err := p.MarshalCBOR(buf); err != nil {
77+
return cid.Undef, err
78+
}
79+
return abi.CidBuilder.Sum(buf.Bytes())
80+
}

actors/builtin/market/market_actor.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,9 @@ func (a Actor) AddBalance(rt Runtime, providerOrClientAddress *addr.Address) *ab
137137
return nil
138138
}
139139

140-
// type PublishStorageDealsParams struct {
141-
// Deals []ClientDealProposal
142-
// }
143-
type PublishStorageDealsParams = market0.PublishStorageDealsParams
140+
type PublishStorageDealsParams struct {
141+
Deals []ClientDealProposal
142+
}
144143

145144
type PublishStorageDealsReturn struct {
146145
IDs []abi.DealID
@@ -447,8 +446,8 @@ func (a Actor) ActivateDeals(rt Runtime, params *ActivateDealsParams) *abi.Empty
447446

448447
err = msm.dealStates.Set(dealID, &DealState{
449448
SectorStartEpoch: currEpoch,
450-
LastUpdatedEpoch: epochUndefined,
451-
SlashEpoch: epochUndefined,
449+
LastUpdatedEpoch: EpochUndefined,
450+
SlashEpoch: EpochUndefined,
452451
})
453452
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to set deal state %d", dealID)
454453
}
@@ -547,7 +546,7 @@ func (a Actor) OnMinerSectorsTerminate(rt Runtime, params *OnMinerSectorsTermina
547546
}
548547

549548
// if a deal is already slashed, we don't need to do anything here.
550-
if state.SlashEpoch != epochUndefined {
549+
if state.SlashEpoch != EpochUndefined {
551550
rt.Log(rtt.INFO, "deal %d already slashed", dealID)
552551
continue
553552
}
@@ -616,7 +615,7 @@ func (a Actor) CronTick(rt Runtime, _ *abi.EmptyValue) *abi.EmptyValue {
616615
}
617616

618617
// if this is the first cron tick for the deal, it should be in the pending state.
619-
if state.LastUpdatedEpoch == epochUndefined {
618+
if state.LastUpdatedEpoch == EpochUndefined {
620619
pdErr := msm.pendingDeals.Delete(abi.CidKey(dcid))
621620
builtin.RequireNoErr(rt, pdErr, exitcode.ErrIllegalState, "failed to delete pending proposal %v", dcid)
622621
}
@@ -625,7 +624,7 @@ func (a Actor) CronTick(rt Runtime, _ *abi.EmptyValue) *abi.EmptyValue {
625624
builtin.RequireState(rt, slashAmount.GreaterThanEqual(big.Zero()), "computed negative slash amount %v for deal %d", slashAmount, dealID)
626625

627626
if removeDeal {
628-
builtin.RequireState(rt, nextEpoch == epochUndefined, "removed deal %d should have no scheduled epoch (got %d)", dealID, nextEpoch)
627+
builtin.RequireState(rt, nextEpoch == EpochUndefined, "removed deal %d should have no scheduled epoch (got %d)", dealID, nextEpoch)
629628
amountSlashed = big.Add(amountSlashed, slashAmount)
630629

631630
// Delete proposal and state simultaneously.

actors/builtin/market/market_state.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/filecoin-project/specs-actors/v7/actors/util/adt"
1414
)
1515

16-
const epochUndefined = abi.ChainEpoch(-1)
16+
const EpochUndefined = abi.ChainEpoch(-1)
1717

1818
// BalanceLockingReason is the reason behind locking an amount.
1919
type BalanceLockingReason int
@@ -108,15 +108,15 @@ func ConstructState(store adt.Store) (*State, error) {
108108
func (m *marketStateMutation) updatePendingDealState(rt Runtime, state *DealState, deal *DealProposal, epoch abi.ChainEpoch) (amountSlashed abi.TokenAmount, nextEpoch abi.ChainEpoch, removeDeal bool) {
109109
amountSlashed = abi.NewTokenAmount(0)
110110

111-
everUpdated := state.LastUpdatedEpoch != epochUndefined
112-
everSlashed := state.SlashEpoch != epochUndefined
111+
everUpdated := state.LastUpdatedEpoch != EpochUndefined
112+
everSlashed := state.SlashEpoch != EpochUndefined
113113

114114
builtin.RequireState(rt, !everUpdated || (state.LastUpdatedEpoch <= epoch), "deal updated at future epoch %d", state.LastUpdatedEpoch)
115115

116116
// This would be the case that the first callback somehow triggers before it is scheduled to
117117
// This is expected not to be able to happen
118118
if deal.StartEpoch > epoch {
119-
return amountSlashed, epochUndefined, false
119+
return amountSlashed, EpochUndefined, false
120120
}
121121

122122
paymentEndEpoch := deal.EndEpoch
@@ -164,12 +164,12 @@ func (m *marketStateMutation) updatePendingDealState(rt Runtime, state *DealStat
164164
amountSlashed = deal.ProviderCollateral
165165
err = m.slashBalance(deal.Provider, amountSlashed, ProviderCollateral)
166166
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "slashing balance")
167-
return amountSlashed, epochUndefined, true
167+
return amountSlashed, EpochUndefined, true
168168
}
169169

170170
if epoch >= deal.EndEpoch {
171171
m.processDealExpired(rt, deal, state)
172-
return amountSlashed, epochUndefined, true
172+
return amountSlashed, EpochUndefined, true
173173
}
174174

175175
// We're explicitly not inspecting the end epoch and may process a deal's expiration late, in order to prevent an outsider
@@ -206,7 +206,7 @@ func (m *marketStateMutation) processDealInitTimedOut(rt Runtime, deal *DealProp
206206

207207
// Normal expiration. Unlock collaterals for both provider and client.
208208
func (m *marketStateMutation) processDealExpired(rt Runtime, deal *DealProposal, state *DealState) {
209-
builtin.RequireState(rt, state.SectorStartEpoch != epochUndefined, "sector start epoch undefined")
209+
builtin.RequireState(rt, state.SectorStartEpoch != EpochUndefined, "sector start epoch undefined")
210210

211211
// Note: payment has already been completed at this point (_rtProcessDealPaymentEpochsElapsed)
212212
err := m.unlockBalance(deal.Provider, deal.ProviderCollateral, ProviderCollateral)

actors/builtin/market/market_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,7 @@ func TestMarketActorDeals(t *testing.T) {
24152415
rt.Verify()
24162416
}
24172417

2418-
dealProposal.Label = "foo"
2418+
dealProposal.Label = []byte("foo")
24192419

24202420
// Same deal with a different label should work
24212421
{
@@ -2443,7 +2443,7 @@ func TestMaxDealLabelSize(t *testing.T) {
24432443
actor.addParticipantFunds(rt, client, abi.NewTokenAmount(20000000))
24442444

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

24492449
// Label at max size should work.
@@ -2452,7 +2452,7 @@ func TestMaxDealLabelSize(t *testing.T) {
24522452
actor.publishDeals(rt, minerAddrs, publishDealReq{deal: dealProposal})
24532453
}
24542454

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

24572457
// Label greater than max size should fail.
24582458
{
@@ -3266,7 +3266,7 @@ func (h *marketActorTestHarness) generateAndPublishDealForPiece(rt *mock.Runtime
32663266
clientCollateral := big.NewInt(10)
32673267
providerCollateral := big.NewInt(10)
32683268

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

32723272
// add funds
@@ -3318,7 +3318,7 @@ func generateDealProposalWithCollateral(client, provider address.Address, provid
33183318
pieceSize := abi.PaddedPieceSize(2048)
33193319
storagePerEpoch := big.NewInt(10)
33203320

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

actors/builtin/market/testing.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,19 @@ func CheckStateInvariants(st *State, store adt.Store, balance abi.TokenAmount, c
115115
"deal %d state start epoch undefined: %v", dealID, dealState)
116116

117117
acc.Require(
118-
dealState.LastUpdatedEpoch == epochUndefined || dealState.LastUpdatedEpoch >= dealState.SectorStartEpoch,
118+
dealState.LastUpdatedEpoch == EpochUndefined || dealState.LastUpdatedEpoch >= dealState.SectorStartEpoch,
119119
"deal %d state last updated before sector start: %v", dealID, dealState)
120120

121121
acc.Require(
122-
dealState.LastUpdatedEpoch == epochUndefined || dealState.LastUpdatedEpoch <= currEpoch,
122+
dealState.LastUpdatedEpoch == EpochUndefined || dealState.LastUpdatedEpoch <= currEpoch,
123123
"deal %d last updated epoch %d after current %d", dealID, dealState.LastUpdatedEpoch, currEpoch)
124124

125125
acc.Require(
126-
dealState.SlashEpoch == epochUndefined || dealState.SlashEpoch >= dealState.SectorStartEpoch,
126+
dealState.SlashEpoch == EpochUndefined || dealState.SlashEpoch >= dealState.SectorStartEpoch,
127127
"deal %d state slashed before sector start: %v", dealID, dealState)
128128

129129
acc.Require(
130-
dealState.SlashEpoch == epochUndefined || dealState.SlashEpoch <= currEpoch,
130+
dealState.SlashEpoch == EpochUndefined || dealState.SlashEpoch <= currEpoch,
131131
"deal %d state slashed after current epoch %d: %v", dealID, currEpoch, dealState)
132132

133133
stats, found := proposalStats[abi.DealID(dealID)]

actors/builtin/market/types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ func (t *DealMetaArray) Get(id abi.DealID) (*DealState, bool, error) {
7878
}
7979
if !found {
8080
return &DealState{
81-
SectorStartEpoch: epochUndefined,
82-
LastUpdatedEpoch: epochUndefined,
83-
SlashEpoch: epochUndefined,
81+
SectorStartEpoch: EpochUndefined,
82+
LastUpdatedEpoch: EpochUndefined,
83+
SlashEpoch: EpochUndefined,
8484
}, false, nil
8585
}
8686
return &value, true, nil

0 commit comments

Comments
 (0)