|
7 | 7 | "github.com/onflow/cadence" |
8 | 8 | "github.com/onflow/cadence/common" |
9 | 9 | "github.com/rs/zerolog" |
10 | | - "github.com/rs/zerolog/log" |
11 | 10 |
|
12 | 11 | "github.com/onflow/flow-go/fvm/inspection" |
13 | 12 |
|
@@ -72,6 +71,25 @@ func (output *ProcedureOutput) PopulateEnvironmentValues( |
72 | 71 | return nil |
73 | 72 | } |
74 | 73 |
|
| 74 | +func (output *ProcedureOutput) PopulateInspectionResults( |
| 75 | + log zerolog.Logger, |
| 76 | + ctx Context, |
| 77 | + env environment.Environment, |
| 78 | + storageSnapshot snapshot.StorageSnapshot, |
| 79 | + executionSnapshot *snapshot.ExecutionSnapshot, |
| 80 | +) { |
| 81 | + |
| 82 | + evts := make([]flow.Event, 0, len(output.Events)+len(output.ServiceEvents)) |
| 83 | + evts = append(evts, output.Events...) |
| 84 | + evts = append(evts, output.ServiceEvents...) |
| 85 | + |
| 86 | + log.Debug().Str("module", "tc-inspector"). |
| 87 | + Int("inspectors", len(ctx.Inspectors)). |
| 88 | + Msg("populating environment values for procedure output") |
| 89 | + inspectionResults := inspectProcedureResults(log, ctx, storageSnapshot, executionSnapshot, evts) |
| 90 | + output.InspectionResults = inspectionResults |
| 91 | +} |
| 92 | + |
75 | 93 | type ProcedureExecutor interface { |
76 | 94 | Preprocess() error |
77 | 95 | Execute() error |
@@ -124,17 +142,6 @@ type VM interface { |
124 | 142 | ProcedureOutput, |
125 | 143 | error, |
126 | 144 | ) |
127 | | - |
128 | | - // Inspect runs configured inspectors on the procedure results. |
129 | | - // This is used by the block computer which manages transaction execution |
130 | | - // manually via NewExecutor rather than using Run. |
131 | | - Inspect( |
132 | | - ctx Context, |
133 | | - proc Procedure, |
134 | | - storageSnapshot snapshot.StorageSnapshot, |
135 | | - executionSnapshot *snapshot.ExecutionSnapshot, |
136 | | - output ProcedureOutput, |
137 | | - ) []inspection.Result |
138 | 145 | } |
139 | 146 |
|
140 | 147 | var _ VM = (*VirtualMachine)(nil) |
@@ -214,56 +221,22 @@ func (vm *VirtualMachine) Run( |
214 | 221 | return nil, ProcedureOutput{}, err |
215 | 222 | } |
216 | 223 |
|
217 | | - // This is of informative nature right now so this placement is ok |
218 | | - // In the future we will need to move this inside the procedure if we want it to affect execution |
219 | | - output := executor.Output() |
220 | | - log.Debug().Str("module", "tc-inspector"). |
221 | | - Str("procedure-type", string(proc.Type())). |
222 | | - Int("inspectors", len(ctx.Inspectors)). |
223 | | - Msg("populating environment values for procedure output") |
224 | | - inspectionResults := vm.inspectProcedureResults(ctx.Logger, ctx, proc, storageSnapshot, executionSnapshot, output) |
225 | | - output.InspectionResults = inspectionResults |
226 | | - |
227 | | - return executionSnapshot, output, nil |
228 | | -} |
229 | | - |
230 | | -// Inspect runs configured inspectors on the procedure results. |
231 | | -// This is used by the block computer which manages transaction execution |
232 | | -// manually via NewExecutor rather than using Run. |
233 | | -func (vm *VirtualMachine) Inspect( |
234 | | - ctx Context, |
235 | | - proc Procedure, |
236 | | - storageSnapshot snapshot.StorageSnapshot, |
237 | | - executionSnapshot *snapshot.ExecutionSnapshot, |
238 | | - output ProcedureOutput, |
239 | | -) []inspection.Result { |
240 | | - return vm.inspectProcedureResults(ctx.Logger, ctx, proc, storageSnapshot, executionSnapshot, output) |
| 224 | + return executionSnapshot, executor.Output(), nil |
241 | 225 | } |
242 | 226 |
|
243 | | -func (vm *VirtualMachine) inspectProcedureResults( |
| 227 | +func inspectProcedureResults( |
244 | 228 | logger zerolog.Logger, |
245 | 229 | context Context, |
246 | | - proc Procedure, |
247 | 230 | storageSnapshot snapshot.StorageSnapshot, |
248 | 231 | executionSnapshot *snapshot.ExecutionSnapshot, |
249 | | - output ProcedureOutput, |
| 232 | + events []flow.Event, |
250 | 233 | ) []inspection.Result { |
251 | | - // TODO(janezp): this should be decided by the inspector |
252 | | - if proc.Type() != TransactionProcedureType { |
253 | | - logger.Debug().Str("module", "tc-inspector").Msg("skipping inspection for non-transaction procedure") |
254 | | - return nil |
255 | | - } |
256 | | - |
257 | | - // TODO(janezp): inspector should be able to receive ProcedureOutput directly |
258 | | - evts := make([]flow.Event, 0, len(output.Events)+len(output.ServiceEvents)) |
259 | | - evts = append(evts, output.Events...) |
260 | | - evts = append(evts, output.ServiceEvents...) |
261 | | - |
262 | 234 | inspectionResults := make([]inspection.Result, len(context.Inspectors)) |
263 | 235 | logger.Debug().Str("module", "tc-inspector").Int("num_inspectors", len(context.Inspectors)).Msg("inspecting procedure results") |
264 | 236 | var err error |
265 | 237 | for i, inspector := range context.Inspectors { |
266 | | - inspectionResults[i], err = inspector.Inspect(logger, storageSnapshot, executionSnapshot, evts) |
| 238 | + // TODO(janezp): inspector should be able to receive ProcedureOutput directly |
| 239 | + inspectionResults[i], err = inspector.Inspect(logger, storageSnapshot, executionSnapshot, events) |
267 | 240 | if err != nil { |
268 | 241 | logger.Warn().Str("module", "tc-inspector").Err(err).Msg("failed to inspect procedure results") |
269 | 242 | } |
|
0 commit comments