66 "fmt"
77
88 "github.com/filecoin-project/go-address"
9- "github.com/filecoin-project/go-state-types/exitcode"
109 "github.com/filecoin-project/lotus/chain/types"
1110 "github.com/ipfs/go-cid"
1211 logging "github.com/ipfs/go-log/v2"
@@ -108,59 +107,20 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
108107 // unknown type.
109108 // If the message was executed it means we are out of step with Lotus behaviour somehow. This probably
110109 // 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 )
112112 errorsDetected = append (errorsDetected , & messages.MessageError {
113113 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 (),
115115 })
116116 continue
117117 }
118118
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 ()
161122 }
162123
163- // params successfully parsed.
164124 vmMsg := & messagemodel.VMMessage {
165125 Height : int64 (parentMsg .Height ),
166126 StateRoot : parentMsg .StateRoot .String (),
@@ -171,16 +131,30 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
171131 Value : child .Message .Value .String (),
172132 GasUsed : child .Receipt .GasUsed ,
173133 ExitCode : int64 (child .Receipt .ExitCode ),
174- ActorCode : toCode . String () ,
134+ ActorCode : toActorCode ,
175135 Method : uint64 (child .Message .Method ),
176- Params : params ,
136+ // Params will be filled below if exit code is non-zero
177137 // Return will be filled below if exit code is non-zero
178138 }
179139
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.
181141 // As an example: a message may return ErrForbidden, it will have valid params, but will not contain a
182142 // parsable return value in its receipt.
183143 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+
184158 ret , _ , err := util .ParseReturn (child .Receipt .Return , child .Message .Method , toCode )
185159 if err != nil {
186160 errorsDetected = append (errorsDetected , & messages.MessageError {
@@ -189,12 +163,12 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut
189163 Error : fmt .Errorf ("failed parse child message return cid: %s to code: %s method: %d return (hex encoded): %s : %w" ,
190164 childCid , toCode , child .Message .Method , hex .EncodeToString (child .Receipt .Return ), err ).Error (),
191165 })
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
194169 }
195- // add the message return.
196- vmMsg .Returns = ret
197170 }
171+
198172 // append message to results
199173 vmMessageResults = append (vmMessageResults , vmMsg )
200174 }
0 commit comments