Skip to content

Commit 1448987

Browse files
authored
Fix activate deals for NV22 (#508)
* feat: allow nil activations and use failcodes * test: add activate deals test * test: add test case
1 parent 9024ed6 commit 1448987

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

tools/deals/activations.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515
const (
1616
KeySectors = "Sectors"
1717
KeyActivations = "Activations"
18+
KeyActivationResults = "ActivationResults"
19+
KeyFailCodes = "FailCodes"
20+
KeyIdx = "Idx"
1821
KeyDealWeight = "DealWeight"
1922
KeyVerifiedDealWeight = "VerifiedDealWeight"
2023
KeyNonVerifiedDealSpace = "NonVerifiedDealSpace"
@@ -239,15 +242,35 @@ func (eg *eventGenerator) parseActivateDeals(tx *types.Transaction, params, ret
239242
if err != nil {
240243
return nil, nil, err
241244
}
242-
activations, err := common.GetSlice[map[string]interface{}](ret, KeyActivations, false)
245+
// activations can be nil if all activations failed
246+
activations, err := common.GetSlice[map[string]interface{}](ret, KeyActivations, true)
243247
if err != nil {
244248
return nil, nil, err
245249
}
246-
if len(sectorDeals) != len(activations) {
247-
return nil, nil, fmt.Errorf("sectorDeals and activations have different lengths: sectorDeals(%d) != activations(%d)", len(sectorDeals), len(activations))
250+
251+
activationResults, err := common.GetItem[map[string]interface{}](ret, KeyActivationResults, true)
252+
if err != nil {
253+
return nil, nil, err
254+
}
255+
failedActivations := map[int64]bool{}
256+
if len(activationResults) > 0 {
257+
failCodes, err := common.GetSlice[map[string]interface{}](activationResults, KeyFailCodes, true)
258+
if err != nil {
259+
return nil, nil, err
260+
}
261+
for _, failCode := range failCodes {
262+
idx, err := common.GetInteger[int64](failCode, KeyIdx, false)
263+
if err != nil {
264+
return nil, nil, err
265+
}
266+
failedActivations[idx] = true
267+
}
248268
}
249269

250270
for i := range sectorDeals {
271+
if failedActivations[int64(i)] {
272+
continue
273+
}
251274
if err := parseDeals(sectorDeals[i], activations[i]); err != nil {
252275
return nil, nil, err
253276
}

tools/deals/deals_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,88 @@ func TestParseVerifyDealsForActivation(t *testing.T) {
148148
})
149149
}
150150
}
151+
152+
func TestActivateDeals(t *testing.T) {
153+
eg := setupTest(t, "mainnet")
154+
155+
tests := []struct {
156+
name string
157+
txType string
158+
txFrom string
159+
txTo string
160+
metadata string
161+
height uint64
162+
}{
163+
164+
{
165+
name: "NV3",
166+
txType: parser.MethodActivateDeals,
167+
txFrom: txFrom,
168+
txTo: txTo,
169+
metadata: `{"MethodNum":"6","Params":{"DealIDs":null,"SectorExpiry":1646434}}`,
170+
height: 94000,
171+
},
172+
{
173+
name: "NV10",
174+
txType: parser.MethodActivateDeals,
175+
txFrom: txFrom,
176+
txTo: txTo,
177+
metadata: `{"MethodNum":"6","Params":{"DealIDs":[1596649,1596648],"SectorExpiry":1079530}}`,
178+
height: 550367,
179+
},
180+
{
181+
name: "NV17",
182+
txType: parser.MethodActivateDeals,
183+
txFrom: txFrom,
184+
txTo: txTo,
185+
metadata: `{"MethodNum":"6","Params":{"DealIDs":[17507589],"SectorExpiry":3937912}}`,
186+
height: 2383680,
187+
},
188+
{
189+
name: "NV22 - null activations",
190+
txType: parser.MethodActivateDeals,
191+
txFrom: txFrom,
192+
txTo: txTo,
193+
metadata: `{"MethodNum":"6","Params":{"Sectors":[{"SectorNumber":5868,"SectorType":8,"SectorExpiry":5388210,"DealIDs":[79175167]}],"ComputeCID":false},"Return":{"ActivationResults":{"SuccessCount":0,"FailCodes":[{"Idx":0,"Code":16}]},"Activations":null}}`,
194+
height: 3857557,
195+
},
196+
{
197+
name: "NV22",
198+
txType: parser.MethodActivateDeals,
199+
txFrom: txFrom,
200+
txTo: txTo,
201+
metadata: `{"MethodNum":"6","Params":{"Sectors":[{"SectorNumber":37656,"SectorType":8,"SectorExpiry":4920235,"DealIDs":[78950968]},{"SectorNumber":37888,"SectorType":8,"SectorExpiry":4920235,"DealIDs":[78951195]},{"SectorNumber":37549,"SectorType":8,"SectorExpiry":4920235,"DealIDs":[79166044]}],"ComputeCID":false},"Return":{"ActivationResults":{"SuccessCount":3,"FailCodes":null},"Activations":[{"NonVerifiedDealSpace":"0","VerifiedInfos":[{"Client":3061409,"AllocationId":61239862,"Data":{"/":"baga6ea4seaqgvrjfj65lawcocwvrpgq7h53oghvto6akrys6wllhbbckchfgefy"},"Size":34359738368}],"UnsealedCid":{}},{"NonVerifiedDealSpace":"0","VerifiedInfos":[{"Client":3061409,"AllocationId":61240089,"Data":{"/":"baga6ea4seaqbuieim7slc3wu7kms436xpnorao5jxr6tqftnqsysfxcp5dnduia"},"Size":34359738368}],"UnsealedCid":{}},{"NonVerifiedDealSpace":"0","VerifiedInfos":[{"Client":3061409,"AllocationId":61454935,"Data":{"/":"baga6ea4seaqfodzysx243k4s6ieuxzzoawew4ckycynubcd5t67vxctunfjt6pq"},"Size":34359738368}],"UnsealedCid":{}}]}}`,
202+
height: 3857557,
203+
},
204+
{
205+
name: "NV22 - failed activation",
206+
txType: parser.MethodActivateDeals,
207+
txFrom: txFrom,
208+
txTo: txTo,
209+
metadata: `{"MethodNum":"6","Params":{"Sectors":[{"SectorNumber":37656,"SectorType":8,"SectorExpiry":4920235,"DealIDs":[78950968]},{"SectorNumber":37888,"SectorType":8,"SectorExpiry":4920235,"DealIDs":[78951195]},{"SectorNumber":37549,"SectorType":8,"SectorExpiry":4920235,"DealIDs":[79166044]}],"ComputeCID":false},"Return":{"ActivationResults":{"SuccessCount":2,"FailCodes":[{"Idx":1,"Code":16}]},"Activations":[{"NonVerifiedDealSpace":"0","VerifiedInfos":[{"Client":3061409,"AllocationId":61239862,"Data":{"/":"baga6ea4seaqgvrjfj65lawcocwvrpgq7h53oghvto6akrys6wllhbbckchfgefy"},"Size":34359738368}],"UnsealedCid":{}},{"NonVerifiedDealSpace":"0","VerifiedInfos":[{"Client":3061409,"AllocationId":61240089,"Data":{"/":"baga6ea4seaqbuieim7slc3wu7kms436xpnorao5jxr6tqftnqsysfxcp5dnduia"},"Size":34359738368}],"UnsealedCid":{}},{"NonVerifiedDealSpace":"0","VerifiedInfos":[{"Client":3061409,"AllocationId":61454935,"Data":{"/":"baga6ea4seaqfodzysx243k4s6ieuxzzoawew4ckycynubcd5t67vxctunfjt6pq"},"Size":34359738368}],"UnsealedCid":{}}]}}`,
210+
height: 3857557,
211+
},
212+
}
213+
214+
for _, test := range tests {
215+
t.Run(test.name, func(t *testing.T) {
216+
_, err := eg.GenerateDealsEvents(context.Background(), []*types.Transaction{
217+
{
218+
TxBasicBlockData: types.TxBasicBlockData{
219+
BasicBlockData: types.BasicBlockData{
220+
Height: test.height,
221+
},
222+
},
223+
TxCid: txCid,
224+
TxType: test.txType,
225+
TxFrom: test.txFrom,
226+
TxTo: test.txTo,
227+
TxMetadata: test.metadata,
228+
Status: tools.GetExitCodeStatus(exitcode.Ok),
229+
SubcallStatus: tools.GetExitCodeStatus(exitcode.Ok),
230+
},
231+
}, tipsetCid, filTypes.EmptyTSK)
232+
require.NoError(t, err)
233+
})
234+
}
235+
}

0 commit comments

Comments
 (0)