6
6
"fmt"
7
7
8
8
"github.com/filecoin-project/go-address"
9
- "github.com/filecoin-project/go-state-types/exitcode"
10
9
"github.com/filecoin-project/lotus/chain/types"
11
10
"github.com/ipfs/go-cid"
12
11
logging "github.com/ipfs/go-log/v2"
@@ -108,59 +107,20 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
108
107
// unknown type.
109
108
// If the message was executed it means we are out of step with Lotus behaviour somehow. This probably
110
109
// indicates that Lily actor type detection is out of date.
111
- log .Errorw ("parsing VM message" , "source_cid" , parentMsg .Cid , "source_receipt" , parentMsg .Ret , "child_cid" , childCid , "child_receipt" , child .Receipt )
110
+ errMsg := fmt .Sprintf ("parsing VM message. source_cid %s, source_receipt %+v child_cid %s child_receipt %+v" , parentMsg .Cid , parentMsg .Ret , childCid , child .Receipt )
111
+ log .Error (errMsg )
112
112
errorsDetected = append (errorsDetected , & messages.MessageError {
113
113
Cid : parentMsg .Cid ,
114
- Error : fmt .Errorf ("failed to get to actor code for message: %s to address %s" , childCid , child .Message .To ).Error (),
114
+ Error : fmt .Errorf ("failed to get to actor code for message: %s to address %s: %s " , childCid , child .Message .To , errMsg ).Error (),
115
115
})
116
116
continue
117
117
}
118
118
119
- // if the to actor code was not found we cannot parse params or return, record the message and continue
120
- if ! found ||
121
- // if the exit code indicates an issue with params or method we cannot parse the message params
122
- child .Receipt .ExitCode == exitcode .ErrSerialization ||
123
- child .Receipt .ExitCode == exitcode .ErrIllegalArgument ||
124
- child .Receipt .ExitCode == exitcode .SysErrInvalidMethod ||
125
- // UsrErrUnsupportedMethod TODO: https://github.com/filecoin-project/go-state-types/pull/44
126
- child .Receipt .ExitCode == exitcode .ExitCode (22 ) {
127
-
128
- // append results and continue
129
- vmMessageResults = append (vmMessageResults , & messagemodel.VMMessage {
130
- Height : int64 (parentMsg .Height ),
131
- StateRoot : parentMsg .StateRoot .String (),
132
- Source : parentMsg .Cid .String (),
133
- Cid : childCid .String (),
134
- From : child .Message .From .String (),
135
- To : child .Message .To .String (),
136
- Value : child .Message .Value .String (),
137
- GasUsed : child .Receipt .GasUsed ,
138
- ExitCode : int64 (child .Receipt .ExitCode ), // exit code is guaranteed to be non-zero which will indicate why actor was not found (i.e. message that created the actor failed to apply)
139
- ActorCode : toCode .String (), // since the actor code wasn't found this will be the string of an undefined CID.
140
- Method : uint64 (child .Message .Method ),
141
- Params : "" ,
142
- Returns : "" ,
143
- })
144
- continue
145
- }
146
-
147
- // the to actor code was found and its exit code indicates the params should be parsable. We can safely
148
- // attempt to parse message params and return, but exit code may still be non-zero here.
149
-
150
- params , _ , err := util .ParseParams (child .Message .Params , child .Message .Method , toCode )
151
- if err != nil {
152
- // a failure here indicates an error in message param parsing, or in exitcode checks above.
153
- errorsDetected = append (errorsDetected , & messages.MessageError {
154
- Cid : parentMsg .Cid ,
155
- // hex encode the params for reproduction in a unit test.
156
- Error : fmt .Errorf ("failed parse child message params cid: %s to code: %s method: %d params (hex encoded): %s : %w" ,
157
- childCid , toCode , child .Message .Method , hex .EncodeToString (child .Message .Params ), err ).Error (),
158
- })
159
- // don't append message to result as it may contain invalud data.
160
- continue
119
+ toActorCode := "<Unknown>"
120
+ if ! toCode .Equals (cid .Undef ) {
121
+ toActorCode = toCode .String ()
161
122
}
162
123
163
- // params successfully parsed.
164
124
vmMsg := & messagemodel.VMMessage {
165
125
Height : int64 (parentMsg .Height ),
166
126
StateRoot : parentMsg .StateRoot .String (),
@@ -171,16 +131,30 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
171
131
Value : child .Message .Value .String (),
172
132
GasUsed : child .Receipt .GasUsed ,
173
133
ExitCode : int64 (child .Receipt .ExitCode ),
174
- ActorCode : toCode . String () ,
134
+ ActorCode : toActorCode ,
175
135
Method : uint64 (child .Message .Method ),
176
- Params : params ,
136
+ // Params will be filled below if exit code is non-zero
177
137
// Return will be filled below if exit code is non-zero
178
138
}
179
139
180
- // only parse return of successful messages since unsuccessful messages don't return a parseable value.
140
+ // only parse params and return of successful messages since unsuccessful messages don't return a parseable value.
181
141
// As an example: a message may return ErrForbidden, it will have valid params, but will not contain a
182
142
// parsable return value in its receipt.
183
143
if child .Receipt .ExitCode .IsSuccess () {
144
+ params , _ , err := util .ParseParams (child .Message .Params , child .Message .Method , toCode )
145
+ if err != nil {
146
+ // a failure here indicates an error in message param parsing, or in exitcode checks above.
147
+ errorsDetected = append (errorsDetected , & messages.MessageError {
148
+ Cid : parentMsg .Cid ,
149
+ // hex encode the params for reproduction in a unit test.
150
+ Error : fmt .Errorf ("failed parse child message params cid: %s to code: %s method: %d params (hex encoded): %s : %w" ,
151
+ childCid , toCode , child .Message .Method , hex .EncodeToString (child .Message .Params ), err ).Error (),
152
+ })
153
+ } else {
154
+ // add the message params
155
+ vmMsg .Params = params
156
+ }
157
+
184
158
ret , _ , err := util .ParseReturn (child .Receipt .Return , child .Message .Method , toCode )
185
159
if err != nil {
186
160
errorsDetected = append (errorsDetected , & messages.MessageError {
@@ -189,12 +163,12 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
189
163
Error : fmt .Errorf ("failed parse child message return cid: %s to code: %s method: %d return (hex encoded): %s : %w" ,
190
164
childCid , toCode , child .Message .Method , hex .EncodeToString (child .Receipt .Return ), err ).Error (),
191
165
})
192
- // don't append message to result as it may contain invalid data.
193
- continue
166
+ } else {
167
+ // add the message return.
168
+ vmMsg .Returns = ret
194
169
}
195
- // add the message return.
196
- vmMsg .Returns = ret
197
170
}
171
+
198
172
// append message to results
199
173
vmMessageResults = append (vmMessageResults , vmMsg )
200
174
}
0 commit comments