Skip to content

Commit d204e2a

Browse files
Merge #4127
4127: Add FinalizeMainTransaction method to TransactionState r=pattyshack a=pattyshack This also include fixes to script execution (to ensure the returned execution snapshot reflects all changes) and a bunch of renaming within TransactionState Co-authored-by: Patrick Lee <[email protected]>
2 parents 1b5e2ac + e5278e5 commit d204e2a

File tree

4 files changed

+167
-99
lines changed

4 files changed

+167
-99
lines changed

fvm/fvm.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ func (vm *VirtualMachine) RunV2(
176176
}
177177

178178
// TODO(patrick): initialize view inside TransactionState
179-
view := delta.NewDeltaView(storageSnapshot)
180179
nestedTxn := state.NewTransactionState(
181-
view,
180+
delta.NewDeltaView(storageSnapshot),
182181
state.DefaultParameters().
183182
WithMeterParameters(getBasicMeterParameters(ctx, proc)).
184183
WithMaxKeySizeAllowed(ctx.MaxStateKeySize).
@@ -207,7 +206,12 @@ func (vm *VirtualMachine) RunV2(
207206
}
208207
}
209208

210-
return view.Finalize(), executor.Output(), nil
209+
executionSnapshot, err := txnState.FinalizeMainTransaction()
210+
if err != nil {
211+
return nil, ProcedureOutput{}, err
212+
}
213+
214+
return executionSnapshot, executor.Output(), nil
211215
}
212216

213217
func (vm *VirtualMachine) Run(

fvm/script.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ func (executor *scriptExecutor) execute() error {
187187
return err
188188
}
189189

190+
errs := errors.NewErrorsCollector()
191+
errs.Collect(executor.executeScript())
192+
193+
_, err = executor.txnState.CommitNestedTransaction(txnId)
194+
errs.Collect(err)
195+
196+
return errs.ErrorOrNil()
197+
}
198+
199+
func (executor *scriptExecutor) executeScript() error {
190200
rt := executor.env.BorrowCadenceRuntime()
191201
defer executor.env.ReturnCadenceRuntime(rt)
192202

@@ -196,17 +206,10 @@ func (executor *scriptExecutor) execute() error {
196206
Arguments: executor.proc.Arguments,
197207
},
198208
common.ScriptLocation(executor.proc.ID))
199-
200209
if err != nil {
201210
return err
202211
}
203212

204213
executor.output.Value = value
205-
err = executor.output.PopulateEnvironmentValues(executor.env)
206-
if err != nil {
207-
return err
208-
}
209-
210-
_, err = executor.txnState.CommitNestedTransaction(txnId)
211-
return err
214+
return executor.output.PopulateEnvironmentValues(executor.env)
212215
}

0 commit comments

Comments
 (0)