Skip to content

Commit b98afe3

Browse files
committed
Clean up delta view usage in fvm/environment
Note that we still need initialize TransactionState using delta view in various places for now
1 parent 6cb572d commit b98afe3

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

fvm/environment/contract_updater.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ func (lists *sortableContractUpdates) Less(i, j int) bool {
5757
}
5858
}
5959

60-
// ContractUpdater handles all smart contracts modification. It also captures
61-
// all changes as deltas and only commit them when called so smart contract
62-
// updates can be delayed until end of the tx execution.
60+
// ContractUpdater handles all smart contracts modification. It captures
61+
// contract updates and defer the updates to the end of the txn execution.
6362
//
6463
// Note that scripts cannot modify smart contracts, but must expose the API in
6564
// compliance with the runtime environment interface.

fvm/environment/derived_data_invalidator_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,9 @@ func TestMeterParamOverridesUpdated(t *testing.T) {
257257
snapshotTree)
258258
require.NoError(t, err)
259259

260-
view := delta.NewDeltaView(snapshotTree.Append(executionSnapshot))
261-
nestedTxn := state.NewTransactionState(view, state.DefaultParameters())
260+
nestedTxn := state.NewTransactionState(
261+
delta.NewDeltaView(snapshotTree.Append(executionSnapshot)),
262+
state.DefaultParameters())
262263

263264
derivedBlockData := derived.NewEmptyDerivedBlockData()
264265
derivedTxnData, err := derivedBlockData.NewDerivedTransactionData(0, 0)
@@ -300,7 +301,10 @@ func TestMeterParamOverridesUpdated(t *testing.T) {
300301
require.Equal(t, expected, invalidator.MeterParamOverridesUpdated)
301302
}
302303

303-
for _, registerId := range view.Finalize().AllRegisterIDs() {
304+
executionSnapshot, err = nestedTxn.FinalizeMainTransaction()
305+
require.NoError(t, err)
306+
307+
for _, registerId := range executionSnapshot.AllRegisterIDs() {
304308
checkForUpdates(registerId, true)
305309
checkForUpdates(
306310
flow.NewRegisterID("other owner", registerId.Key),

fvm/environment/programs_test.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ var (
8989
)
9090

9191
func setupProgramsTest(t *testing.T) storage.SnapshotTree {
92-
view := delta.NewDeltaView(nil)
92+
txnState := storage.SerialTransaction{
93+
NestedTransaction: state.NewTransactionState(
94+
delta.NewDeltaView(nil),
95+
state.DefaultParameters()),
96+
}
9397

94-
accounts := environment.NewAccounts(
95-
storage.SerialTransaction{
96-
NestedTransaction: state.NewTransactionState(
97-
view,
98-
state.DefaultParameters()),
99-
})
98+
accounts := environment.NewAccounts(txnState)
10099

101100
err := accounts.Create(nil, addressA)
102101
require.NoError(t, err)
@@ -107,7 +106,10 @@ func setupProgramsTest(t *testing.T) storage.SnapshotTree {
107106
err = accounts.Create(nil, addressC)
108107
require.NoError(t, err)
109108

110-
return storage.NewSnapshotTree(nil).Append(view.Finalize())
109+
executionSnapshot, err := txnState.FinalizeMainTransaction()
110+
require.NoError(t, err)
111+
112+
return storage.NewSnapshotTree(nil).Append(executionSnapshot)
111113
}
112114

113115
func getTestContract(
@@ -261,7 +263,7 @@ func Test_Programs(t *testing.T) {
261263

262264
require.Contains(t, output.Logs, "\"hello from A\"")
263265

264-
// same transaction should produce the exact same views
266+
// same transaction should produce the exact same execution snapshots
265267
// but only because we don't do any conditional update in a tx
266268
compareExecutionSnapshots(t, executionSnapshotA, executionSnapshotA2)
267269
})
@@ -338,7 +340,7 @@ func Test_Programs(t *testing.T) {
338340
// rerun transaction
339341

340342
// execute transaction again, this time make sure it doesn't load code
341-
execB2Snapshot := delta.NewDeltaView(state.NewReadFuncStorageSnapshot(
343+
execB2Snapshot := state.NewReadFuncStorageSnapshot(
342344
func(id flow.RegisterID) (flow.RegisterValue, error) {
343345
idA := flow.ContractRegisterID(
344346
flow.BytesToAddress([]byte(id.Owner)),
@@ -351,7 +353,7 @@ func Test_Programs(t *testing.T) {
351353
require.NotEqual(t, id.Key, idB.Key)
352354

353355
return mainSnapshot.Get(id)
354-
}))
356+
})
355357

356358
executionSnapshotB2, output, err := vm.RunV2(
357359
context,
@@ -779,14 +781,6 @@ func updateContractTx(name, code string, address flow.Address) *flow.Transaction
779781
).AddAuthorizer(address)
780782
}
781783

782-
// compareViews compares views using only data that matters (ie. two different hasher instances
783-
// trips the library comparison, even if actual SPoCKs are the same)
784-
func compareViews(t *testing.T, a, b *delta.View) {
785-
require.Equal(t, a.Delta(), b.Delta())
786-
require.Equal(t, a.Interactions(), b.Interactions())
787-
require.Equal(t, a.SpockSecret(), b.SpockSecret())
788-
}
789-
790784
func compareExecutionSnapshots(t *testing.T, a, b *state.ExecutionSnapshot) {
791785
require.Equal(t, a.WriteSet, b.WriteSet)
792786
require.Equal(t, a.ReadSet, b.ReadSet)

0 commit comments

Comments
 (0)