Skip to content

Commit 332ebd6

Browse files
authored
Merge pull request #503 from Zondax/dev
New Release
2 parents afdac8c + 9024ed6 commit 332ebd6

File tree

6 files changed

+337
-12
lines changed

6 files changed

+337
-12
lines changed

actors/v2/verifiedRegistry/params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ var universalReceiverParams = map[string]func() cbg.CBORUnmarshaler{
407407
}
408408

409409
var allocationRequests = map[string]func() cbg.CBORUnmarshaler{
410-
tools.V17.String(): func() cbg.CBORUnmarshaler { return new(types.AllocationRequests) },
411-
tools.V18.String(): func() cbg.CBORUnmarshaler { return new(verifregv10.AllocationRequests) },
410+
tools.V17.String(): func() cbg.CBORUnmarshaler { return new(types.AllocationRequests[*verifregv9.ClaimExtensionRequest]) },
411+
tools.V18.String(): func() cbg.CBORUnmarshaler { return new(types.AllocationRequests[*verifregv10.ClaimExtensionRequest]) },
412412

413413
tools.V19.String(): func() cbg.CBORUnmarshaler { return new(verifregv11.AllocationRequests) },
414414
tools.V20.String(): func() cbg.CBORUnmarshaler { return new(verifregv11.AllocationRequests) },

actors/v2/verifiedRegistry/types/allocationRequestv9.go renamed to actors/v2/verifiedRegistry/types/allocationRequest.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import (
66

77
"github.com/filecoin-project/go-address"
88
"github.com/filecoin-project/go-state-types/abi"
9-
v9 "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
109
"github.com/ipfs/go-cid"
1110
cbg "github.com/whyrusleeping/cbor-gen"
1211
"golang.org/x/xerrors"
1312
)
1413

15-
// We need custom parsing for AllocationRequest in NV17 because the Provider field in go-state-types is a uint64 but in builtin-actors it is an address.Address
16-
type AllocationRequests struct {
17-
Allocations []AllocationRequest `json:"Allocations"`
18-
Extensions []v9.ClaimExtensionRequest `json:"Extensions"`
14+
// We need custom parsing for AllocationRequest in NV17 and NV18 because the Provider field in go-state-types is a uint64 but in builtin-actors it is an address.Address
15+
type AllocationRequests[T cbg.CBORUnmarshaler] struct {
16+
Allocations []AllocationRequest `json:"Allocations"`
17+
Extensions []T `json:"Extensions"`
1918
}
2019

2120
type AllocationRequest struct {
@@ -27,8 +26,8 @@ type AllocationRequest struct {
2726
Expiration abi.ChainEpoch
2827
}
2928

30-
func (t *AllocationRequests) UnmarshalCBOR(r io.Reader) (err error) {
31-
*t = AllocationRequests{}
29+
func (t *AllocationRequests[T]) UnmarshalCBOR(r io.Reader) (err error) {
30+
*t = AllocationRequests[T]{}
3231

3332
cr := cbg.NewCborReader(r)
3433

@@ -90,7 +89,7 @@ func (t *AllocationRequests) UnmarshalCBOR(r io.Reader) (err error) {
9089
}
9190

9291
if extra > 0 {
93-
t.Extensions = make([]v9.ClaimExtensionRequest, extra)
92+
t.Extensions = make([]T, extra)
9493
}
9594

9695
for i := 0; i < int(extra); i++ {

tools/common/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/zondax/fil-parser/parser/helper"
1818
"github.com/zondax/fil-parser/types"
1919
"github.com/zondax/golem/pkg/logger"
20+
rosettaFilecoinLibActors "github.com/zondax/rosetta-filecoin-lib/actors"
2021
"golang.org/x/exp/constraints"
2122
)
2223

@@ -27,7 +28,7 @@ const (
2728
func GetActorNameFromAddress(helper *helper.Helper, addr address.Address, height int64, tipsetKey filTypes.TipSetKey) (string, error) {
2829
// #nosec G115
2930
actorName, err := helper.GetActorNameFromAddress(addr, height, tipsetKey)
30-
if err != nil {
31+
if (actorName == rosettaFilecoinLibActors.UnknownStr || actorName == "") && err != nil {
3132
if errors.Is(err, cache.ErrBadAddress) {
3233
// the bad address may have been set due to a previous failed request to the node
3334
// clear the cache to allow trying again when reprocessed

tools/deals/activations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (eg *eventGenerator) parseVerifyDealsForActivation(tx *types.Transaction, p
135135
VerifiedDealWeight abi.DealWeight // Total space*time of submitted verified deals.
136136
}
137137
*/
138-
if version.NodeVersion() > minVersion && version.NodeVersion() <= maxVersion {
138+
if version.NodeVersion() > minVersion && version.NodeVersion() < maxVersion {
139139
// number of SectorDeals and SectorWeights will always be the same are they are processed in an all or nothing manner
140140
sectorDeals, err := common.GetSlice[map[string]interface{}](params, KeySectors, false)
141141
if err != nil {

tools/deals/deals_test.go

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package deals_test
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/filecoin-project/go-state-types/exitcode"
8+
"github.com/filecoin-project/go-state-types/manifest"
9+
filApiTypes "github.com/filecoin-project/lotus/api/types"
10+
filTypes "github.com/filecoin-project/lotus/chain/types"
11+
"github.com/filecoin-project/lotus/node/modules/dtypes"
12+
cid "github.com/ipfs/go-cid"
13+
"github.com/stretchr/testify/mock"
14+
"github.com/stretchr/testify/require"
15+
filMetrics "github.com/zondax/fil-parser/metrics"
16+
"github.com/zondax/fil-parser/parser"
17+
"github.com/zondax/fil-parser/parser/helper"
18+
"github.com/zondax/fil-parser/tools"
19+
"github.com/zondax/fil-parser/tools/deals"
20+
"github.com/zondax/fil-parser/tools/mocks"
21+
"github.com/zondax/fil-parser/types"
22+
"github.com/zondax/golem/pkg/logger"
23+
metrics2 "github.com/zondax/golem/pkg/metrics"
24+
rosettaFilecoinLib "github.com/zondax/rosetta-filecoin-lib"
25+
)
26+
27+
var (
28+
tipsetCid = "bafy2bzaceaacubfrkq2wng5vcm53r7u5v5pjjs72s6kgqbm44dyfyik4y2azc"
29+
txCid = "bafy2bzaceadjahvfnskpsz33ansyymo7uoqm7iyapx5cjpja3327pffvml7je"
30+
actorCidStr = "bafkqae3gnfwc6mjpon2g64tbm5sw2ylsnnsxi"
31+
txFrom = "f2ncucfhaemzclocsau6o4u5b5bigjvpii2ql4rhi"
32+
txTo = "f05"
33+
actorCid cid.Cid
34+
)
35+
36+
func init() {
37+
var err error
38+
actorCid, err = cid.Parse(actorCidStr)
39+
if err != nil {
40+
panic(err)
41+
}
42+
}
43+
44+
func setupTest(_ *testing.T, network string) deals.EventGenerator {
45+
logger := logger.NewDevelopmentLogger()
46+
metrics := filMetrics.NewMetricsClient(metrics2.NewNoopMetrics())
47+
48+
node := &mocks.FullNode{}
49+
node.On("StateNetworkName", mock.Anything).Return(dtypes.NetworkName(network), nil)
50+
node.On("StateNetworkVersion", mock.Anything, mock.Anything).Return(filApiTypes.NetworkVersion(16), nil)
51+
node.On("StateActorCodeCIDs", mock.Anything, mock.Anything).Return(map[string]cid.Cid{
52+
manifest.MarketKey: actorCid,
53+
}, nil)
54+
55+
cache := &mocks.IActorsCache{}
56+
cache.On("StoreAddressInfo", mock.Anything).Return(nil)
57+
cache.On("GetActorCode", mock.Anything, mock.Anything, mock.Anything).Return(actorCidStr, nil)
58+
cache.On("GetActorNameFromAddress", mock.Anything, mock.Anything, mock.Anything).Return(manifest.MinerKey, nil)
59+
60+
lib := rosettaFilecoinLib.NewRosettaConstructionFilecoin(node)
61+
helper := helper.NewHelper(lib, cache, node, logger, metrics)
62+
63+
return deals.NewEventGenerator(helper, logger, metrics, network, parser.Config{})
64+
}
65+
66+
func TestParseVerifyDealsForActivation(t *testing.T) {
67+
eg := setupTest(t, "mainnet")
68+
69+
tests := []struct {
70+
name string
71+
txType string
72+
txFrom string
73+
txTo string
74+
metadata string
75+
height uint64
76+
}{
77+
78+
{
79+
name: "NV3",
80+
txType: parser.MethodVerifyDealsForActivation,
81+
txFrom: txFrom,
82+
txTo: txTo,
83+
metadata: `{"MethodNum":"5","Params":{"DealIDs":null,"SectorExpiry":1644975,"SectorStart":94001},"Return":{"DealWeight":"0","VerifiedDealWeight":"0"}}`,
84+
height: 94000,
85+
},
86+
{
87+
name: "NV10",
88+
txType: parser.MethodVerifyDealsForActivation,
89+
txFrom: txFrom,
90+
txTo: txTo,
91+
metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorExpiry":2097712,"DealIDs":[1596539]}]},"Return":{"Sectors":[{"DealSpace":34359738368,"DealWeight":"0","VerifiedDealWeight":"52446704644915200"}]}}`,
92+
height: 550350,
93+
},
94+
{
95+
name: "NV15",
96+
txType: parser.MethodVerifyDealsForActivation,
97+
txFrom: txFrom,
98+
txTo: txTo,
99+
metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorExpiry":3149856,"DealIDs":[4137277]}]},"Return":{"Sectors":[{"DealSpace":34359738368,"DealWeight":"0","VerifiedDealWeight":"52941484877414400"}]}}`,
100+
height: 1594681,
101+
},
102+
{
103+
name: "NV17",
104+
txType: parser.MethodVerifyDealsForActivation,
105+
txFrom: txFrom,
106+
txTo: txTo,
107+
metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorType":8,"SectorExpiry":3938176,"DealIDs":[17514444]}]},"Return":{"Sectors":[{"CommD":{"/":"baga6ea4seaqcvxnumewlmsy3dgd6fzqzkmx6gwg2hrlea3mfsgsp342hmqausea"}}]}}`,
108+
height: 2383682,
109+
},
110+
{
111+
name: "NV18",
112+
txType: parser.MethodVerifyDealsForActivation,
113+
txFrom: txFrom,
114+
txTo: txTo,
115+
metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorType":9,"SectorExpiry":3752099,"DealIDs":[28436872,28436293]}]},"Return":{"Sectors":[{"CommD":{"/":"baga6ea4seaqezng67jc7t2mowage34tt4emcd4w7d5jnpusv5obmpexsq335ihy"}}]}}`,
116+
height: 2683349,
117+
},
118+
{
119+
name: "NV19",
120+
txType: parser.MethodVerifyDealsForActivation,
121+
txFrom: txFrom,
122+
txTo: txTo,
123+
metadata: `{"MethodNum":"5","Params":{"Sectors":[{"SectorType":8,"SectorExpiry":4364609,"DealIDs":[34223220]}]},"Return":{"Sectors":[{"CommD":{"/":"baga6ea4seaqbro6cy6d6hp7ywf3ktxt3hygi376cannpbint5sqeih6nintqioq"}}]}}`,
124+
height: 2809801,
125+
},
126+
}
127+
128+
for _, test := range tests {
129+
t.Run(test.name, func(t *testing.T) {
130+
_, err := eg.GenerateDealsEvents(context.Background(), []*types.Transaction{
131+
{
132+
TxBasicBlockData: types.TxBasicBlockData{
133+
BasicBlockData: types.BasicBlockData{
134+
Height: test.height,
135+
},
136+
},
137+
TxCid: txCid,
138+
TxType: test.txType,
139+
TxFrom: test.txFrom,
140+
TxTo: test.txTo,
141+
TxMetadata: test.metadata,
142+
Status: tools.GetExitCodeStatus(exitcode.Ok),
143+
SubcallStatus: tools.GetExitCodeStatus(exitcode.Ok),
144+
},
145+
}, tipsetCid, filTypes.EmptyTSK)
146+
require.NoError(t, err)
147+
148+
})
149+
}
150+
}

0 commit comments

Comments
 (0)