@@ -90,106 +90,113 @@ func (c *ContractDealMonitor) Start(ctx context.Context) error {
90
90
}
91
91
return
92
92
case resp := <- responseCh :
93
- err := func () error {
94
- event := resp .Result .(map [string ]interface {})
95
- topicContractAddress := event ["address" ].(string )
96
- topicDealProposalID := event ["topics" ].([]interface {})[1 ].(string )
97
-
98
- // allowlist check
99
- if len (c .cfg .AllowlistContracts ) != 0 && ! slices .Contains (c .cfg .AllowlistContracts , topicContractAddress ) {
100
- return fmt .Errorf ("allowlist does not contain this contract address: %s" , topicContractAddress )
101
- }
102
-
103
- res , err := c .getDealProposal (ctx , topicContractAddress , topicDealProposalID , fromEthAddr )
104
- if err != nil {
105
- return fmt .Errorf ("eth call for get deal proposal failed: %w" , err )
106
- }
107
-
108
- resParams , err := c .getExtraData (ctx , topicContractAddress , topicDealProposalID , fromEthAddr )
109
- if err != nil {
110
- return fmt .Errorf ("eth call for extra data failed: %w" , err )
111
- }
112
-
113
- var dpc market.DealProposal
114
- err = dpc .UnmarshalCBOR (bytes .NewReader (res ))
115
- if err != nil {
116
- return fmt .Errorf ("cbor unmarshal failed: %w" , err )
117
- }
118
-
119
- var pv1 types.ContractParamsVersion1
120
- err = pv1 .UnmarshalCBOR (bytes .NewReader (resParams ))
121
- if err != nil {
122
- return fmt .Errorf ("params cbor unmarshal failed: %w" , err )
123
- }
124
-
125
- rootCidStr , err := dpc .Label .ToString ()
126
- if err != nil {
127
- return fmt .Errorf ("getting cid from label failed: %w" , err )
128
- }
129
-
130
- rootCid , err := cid .Parse (rootCidStr )
131
- if err != nil {
132
- return fmt .Errorf ("parsing cid failed: %w" , err )
133
- }
134
-
135
- prop := market.DealProposal {
136
- PieceCID : dpc .PieceCID ,
137
- PieceSize : dpc .PieceSize ,
138
- VerifiedDeal : dpc .VerifiedDeal ,
139
- Client : dpc .Client ,
140
- Provider : c .maddr ,
141
-
142
- Label : dpc .Label ,
93
+ func () {
94
+ defer func () {
95
+ if r := recover (); r != nil {
96
+ log .Errorw ("recovered from panic from handling eth_subscribe event" , "recover" , r )
97
+ }
98
+ }()
99
+
100
+ err := func () error {
101
+ event := resp .Result .(map [string ]interface {})
102
+ topicContractAddress := event ["address" ].(string )
103
+ topicDealProposalID := event ["topics" ].([]interface {})[1 ].(string )
104
+
105
+ // allowlist check
106
+ if len (c .cfg .AllowlistContracts ) != 0 && ! slices .Contains (c .cfg .AllowlistContracts , topicContractAddress ) {
107
+ return fmt .Errorf ("allowlist does not contain this contract address: %s" , topicContractAddress )
108
+ }
109
+
110
+ res , err := c .getDealProposal (ctx , topicContractAddress , topicDealProposalID , fromEthAddr )
111
+ if err != nil {
112
+ return fmt .Errorf ("eth call for get deal proposal failed: %w" , err )
113
+ }
114
+
115
+ resParams , err := c .getExtraData (ctx , topicContractAddress , topicDealProposalID , fromEthAddr )
116
+ if err != nil {
117
+ return fmt .Errorf ("eth call for extra data failed: %w" , err )
118
+ }
119
+
120
+ var dpc market.DealProposal
121
+ err = dpc .UnmarshalCBOR (bytes .NewReader (res ))
122
+ if err != nil {
123
+ return fmt .Errorf ("cbor unmarshal failed: %w" , err )
124
+ }
125
+
126
+ var pv1 types.ContractParamsVersion1
127
+ err = pv1 .UnmarshalCBOR (bytes .NewReader (resParams ))
128
+ if err != nil {
129
+ return fmt .Errorf ("params cbor unmarshal failed: %w" , err )
130
+ }
131
+
132
+ rootCidStr , err := dpc .Label .ToString ()
133
+ if err != nil {
134
+ return fmt .Errorf ("getting cid from label failed: %w" , err )
135
+ }
136
+
137
+ rootCid , err := cid .Parse (rootCidStr )
138
+ if err != nil {
139
+ return fmt .Errorf ("parsing cid failed: %w" , err )
140
+ }
141
+
142
+ prop := market.DealProposal {
143
+ PieceCID : dpc .PieceCID ,
144
+ PieceSize : dpc .PieceSize ,
145
+ VerifiedDeal : dpc .VerifiedDeal ,
146
+ Client : dpc .Client ,
147
+ Provider : c .maddr ,
148
+
149
+ Label : dpc .Label ,
150
+
151
+ StartEpoch : dpc .StartEpoch ,
152
+ EndEpoch : dpc .EndEpoch ,
153
+ StoragePricePerEpoch : dpc .StoragePricePerEpoch ,
154
+
155
+ ProviderCollateral : dpc .ProviderCollateral ,
156
+ ClientCollateral : dpc .ClientCollateral ,
157
+ }
158
+
159
+ proposal := types.DealParams {
160
+ DealUUID : uuid .New (),
161
+ IsOffline : false ,
162
+ ClientDealProposal : market.ClientDealProposal {
163
+ Proposal : prop ,
164
+ // signature is garbage, but it still needs to serialize, so shouldnt be empty!!
165
+ ClientSignature : crypto.Signature {
166
+ Type : crypto .SigTypeBLS ,
167
+ Data : []byte {0xde , 0xad },
168
+ },
169
+ },
170
+ DealDataRoot : rootCid ,
171
+ Transfer : types.Transfer {
172
+ Type : "http" ,
173
+ Params : []byte (fmt .Sprintf (`{"URL":"%s"}` , pv1 .LocationRef )),
174
+ Size : pv1 .CarSize ,
175
+ },
176
+ RemoveUnsealedCopy : pv1 .RemoveUnsealedCopy ,
177
+ SkipIPNIAnnounce : pv1 .SkipIpniAnnounce ,
178
+ }
143
179
144
- StartEpoch : dpc .StartEpoch ,
145
- EndEpoch : dpc .EndEpoch ,
146
- StoragePricePerEpoch : dpc .StoragePricePerEpoch ,
180
+ log .Infow ("received contract deal proposal" , "id" , proposal .DealUUID , "client-peer" , dpc .Client )
147
181
148
- ProviderCollateral : dpc .ProviderCollateral ,
149
- ClientCollateral : dpc .ClientCollateral ,
150
- }
182
+ reason , err := c .prov .ExecuteDeal (context .Background (), & proposal , "" )
183
+ if err != nil {
184
+ log .Warnw ("contract deal proposal failed" , "id" , proposal .DealUUID , "err" , err , "reason" , reason .Reason )
185
+ return nil
186
+ }
151
187
152
- proposal := types.DealParams {
153
- DealUUID : uuid .New (),
154
- IsOffline : false ,
155
- ClientDealProposal : market.ClientDealProposal {
156
- Proposal : prop ,
157
- // signature is garbage, but it still needs to serialize, so shouldnt be empty!!
158
- ClientSignature : crypto.Signature {
159
- Type : crypto .SigTypeBLS ,
160
- Data : []byte {0xde , 0xad },
161
- },
162
- },
163
- DealDataRoot : rootCid ,
164
- Transfer : types.Transfer {
165
- Type : "http" ,
166
- Params : []byte (fmt .Sprintf (`{"URL":"%s"}` , pv1 .LocationRef )),
167
- Size : pv1 .CarSize ,
168
- },
169
- //TODO: maybe add to pv1?? RemoveUnsealedCopy: paramsAndVersion.RemoveUnsealedCopy,
170
- RemoveUnsealedCopy : false ,
171
- SkipIPNIAnnounce : pv1 .SkipIpniAnnounce ,
172
- }
188
+ if reason .Accepted {
189
+ log .Infow ("contract deal proposal accepted" , "id" , proposal .DealUUID )
190
+ } else {
191
+ log .Warnw ("contract deal proposal rejected" , "id" , proposal .DealUUID , "err" , err , "reason" , reason .Reason )
192
+ }
173
193
174
- log .Infow ("received contract deal proposal" , "id" , proposal .DealUUID , "client-peer" , dpc .Client )
175
-
176
- reason , err := c .prov .ExecuteDeal (context .Background (), & proposal , "" )
177
- if err != nil {
178
- log .Warnw ("contract deal proposal failed" , "id" , proposal .DealUUID , "err" , err , "reason" , reason .Reason )
179
194
return nil
195
+ }()
196
+ if err != nil {
197
+ log .Errorw ("handling DealProposalCreate event erred" , "err" , err )
180
198
}
181
-
182
- if reason .Accepted {
183
- log .Infow ("contract deal proposal accepted" , "id" , proposal .DealUUID )
184
- } else {
185
- log .Warnw ("contract deal proposal rejected" , "id" , proposal .DealUUID , "err" , err , "reason" , reason .Reason )
186
- }
187
-
188
- return nil
189
199
}()
190
- if err != nil {
191
- log .Errorw ("handling DealProposalCreate event erred" , "err" , err )
192
- }
193
200
}
194
201
}
195
202
}()
@@ -244,6 +251,7 @@ func lengthPrefixPointsTo(output []byte) (int, int, error) {
244
251
if size .Cmp (boutputLen ) > 0 {
245
252
return 0 , 0 , fmt .Errorf ("length insufficient %v require %v" , boutputLen , size )
246
253
}
254
+
247
255
return int (boffset .Uint64 ()), int (lengthBig .Uint64 ()), nil
248
256
}
249
257
0 commit comments