Skip to content

Commit 814e98d

Browse files
bors[bot]janezpodhostnikpattyshack
authored
Merge #4059 #4066
4059: Track script/transaction procedure program depedencies r=janezpodhostnik a=janezpodhostnik ref: onflow/cadence#1684 Change the dependency stack for transaction/script programs to always have root dependencies. The root dependencies in this case are dependencies of the script/transaction procedure itself. The reason we want this is to have a map of "seen" imports, so we know when we need to reapply metering and when not... which is the next/last step in this PR chain. I added a reset (which is called when switching from the transactions happy path/normal execution to the transaction failure path/fee deduction) that clears all non address programs and dependencies tracked, to avoid any potential cache poisoning. 4066: Remove derived block/txn data from (most) tests r=pattyshack a=pattyshack Derived txn data is now an optional parameter. The explicit setup is no longer needed (except for programs test and benchmark) Co-authored-by: Janez Podhostnik <[email protected]> Co-authored-by: Patrick Lee <[email protected]>
3 parents b0f973e + 69fa06c + ddfe982 commit 814e98d

File tree

12 files changed

+225
-356
lines changed

12 files changed

+225
-356
lines changed

cmd/util/ledger/reporters/fungible_token_tracker_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/onflow/flow-go/cmd/util/ledger/reporters"
1616
"github.com/onflow/flow-go/engine/execution/state/delta"
1717
"github.com/onflow/flow-go/fvm"
18-
"github.com/onflow/flow-go/fvm/derived"
1918
"github.com/onflow/flow-go/ledger"
2019
"github.com/onflow/flow-go/model/flow"
2120
"github.com/onflow/flow-go/utils/unittest"
@@ -49,12 +48,10 @@ func TestFungibleTokenTracker(t *testing.T) {
4948
reporters.NewStorageSnapshotFromPayload(payloads))
5049

5150
vm := fvm.NewVirtualMachine()
52-
derivedBlockData := derived.NewEmptyDerivedBlockData()
5351
opts := []fvm.Option{
5452
fvm.WithChain(chain),
5553
fvm.WithAuthorizationChecksEnabled(false),
5654
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
57-
fvm.WithDerivedBlockData(derivedBlockData),
5855
}
5956
ctx := fvm.NewContext(opts...)
6057
bootstrapOptions := []fvm.BootstrapProcedureOption{
@@ -103,7 +100,7 @@ func TestFungibleTokenTracker(t *testing.T) {
103100
SetScript(deployingTestContractScript).
104101
AddAuthorizer(chain.ServiceAddress())
105102

106-
tx := fvm.Transaction(txBody, derivedBlockData.NextTxIndexForTestingOnly())
103+
tx := fvm.Transaction(txBody, 0)
107104
snapshot, output, err := vm.RunV2(ctx, tx, view)
108105
require.NoError(t, err)
109106
require.NoError(t, output.Err)
@@ -132,7 +129,7 @@ func TestFungibleTokenTracker(t *testing.T) {
132129
AddArgument(jsoncdc.MustEncode(cadence.UFix64(105))).
133130
AddAuthorizer(chain.ServiceAddress())
134131

135-
tx = fvm.Transaction(txBody, derivedBlockData.NextTxIndexForTestingOnly())
132+
tx = fvm.Transaction(txBody, 0)
136133
snapshot, output, err = vm.RunV2(ctx, tx, view)
137134
require.NoError(t, err)
138135
require.NoError(t, output.Err)

engine/execution/computation/manager_benchmark_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func createAccounts(b *testing.B, vm fvm.VM, ledger state.View, num int) *testAc
5151
addresses, err := testutil.CreateAccounts(
5252
vm,
5353
ledger,
54-
derived.NewEmptyDerivedBlockData(),
5554
privateKeys,
5655
chain)
5756
require.NoError(b, err)

engine/execution/computation/manager_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestComputeBlockWithStorage(t *testing.T) {
6060
require.NoError(t, err)
6161

6262
ledger := testutil.RootBootstrappedLedger(vm, execCtx)
63-
accounts, err := testutil.CreateAccounts(vm, ledger, derived.NewEmptyDerivedBlockData(), privateKeys, chain)
63+
accounts, err := testutil.CreateAccounts(vm, ledger, privateKeys, chain)
6464
require.NoError(t, err)
6565

6666
tx1 := testutil.DeployCounterContractTransaction(accounts[0], chain)
@@ -705,7 +705,7 @@ func Test_EventEncodingFailsOnlyTxAndCarriesOn(t *testing.T) {
705705
privateKeys, err := testutil.GenerateAccountPrivateKeys(1)
706706
require.NoError(t, err)
707707
ledger := testutil.RootBootstrappedLedger(vm, execCtx)
708-
accounts, err := testutil.CreateAccounts(vm, ledger, derived.NewEmptyDerivedBlockData(), privateKeys, chain)
708+
accounts, err := testutil.CreateAccounts(vm, ledger, privateKeys, chain)
709709
require.NoError(t, err)
710710

711711
// setup transactions
@@ -861,14 +861,12 @@ func TestScriptStorageMutationsDiscarded(t *testing.T) {
861861
vm := manager.vm
862862
view := testutil.RootBootstrappedLedger(vm, ctx)
863863

864-
derivedBlockData := derived.NewEmptyDerivedBlockData()
865-
866864
// Create an account private key.
867865
privateKeys, err := testutil.GenerateAccountPrivateKeys(1)
868866
require.NoError(t, err)
869867

870868
// Bootstrap a ledger, creating accounts with the provided private keys and the root account.
871-
accounts, err := testutil.CreateAccounts(vm, view, derivedBlockData, privateKeys, chain)
869+
accounts, err := testutil.CreateAccounts(vm, view, privateKeys, chain)
872870
require.NoError(t, err)
873871
account := accounts[0]
874872
address := cadence.NewAddress(account)

engine/execution/computation/programs_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func TestPrograms_TestContractUpdates(t *testing.T) {
4747
accounts, err := testutil.CreateAccounts(
4848
vm,
4949
ledger,
50-
derived.NewEmptyDerivedBlockData(),
5150
privateKeys,
5251
chain)
5352
require.NoError(t, err)
@@ -214,7 +213,6 @@ func TestPrograms_TestBlockForks(t *testing.T) {
214213
accounts, err := testutil.CreateAccounts(
215214
vm,
216215
ledger,
217-
derived.NewEmptyDerivedBlockData(),
218216
privateKeys,
219217
chain)
220218
require.NoError(t, err)

engine/execution/testutil/fixtures.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/onflow/flow-go/engine/execution/state/delta"
1717
"github.com/onflow/flow-go/engine/execution/utils"
1818
"github.com/onflow/flow-go/fvm"
19-
"github.com/onflow/flow-go/fvm/derived"
2019
"github.com/onflow/flow-go/fvm/state"
2120
"github.com/onflow/flow-go/model/flow"
2221
"github.com/onflow/flow-go/module/epochs"
@@ -190,25 +189,22 @@ func GenerateAccountPrivateKey() (flow.AccountPrivateKey, error) {
190189
func CreateAccounts(
191190
vm fvm.VM,
192191
view state.View,
193-
derivedBlockData *derived.DerivedBlockData,
194192
privateKeys []flow.AccountPrivateKey,
195193
chain flow.Chain,
196194
) ([]flow.Address, error) {
197-
return CreateAccountsWithSimpleAddresses(vm, view, derivedBlockData, privateKeys, chain)
195+
return CreateAccountsWithSimpleAddresses(vm, view, privateKeys, chain)
198196
}
199197

200198
func CreateAccountsWithSimpleAddresses(
201199
vm fvm.VM,
202200
view state.View,
203-
derivedBlockData *derived.DerivedBlockData,
204201
privateKeys []flow.AccountPrivateKey,
205202
chain flow.Chain,
206203
) ([]flow.Address, error) {
207204
ctx := fvm.NewContext(
208205
fvm.WithChain(chain),
209206
fvm.WithAuthorizationChecksEnabled(false),
210207
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
211-
fvm.WithDerivedBlockData(derivedBlockData),
212208
)
213209

214210
var accounts []flow.Address
@@ -251,9 +247,7 @@ func CreateAccountsWithSimpleAddresses(
251247
AddArgument(encCadPublicKey).
252248
AddAuthorizer(serviceAddress)
253249

254-
tx := fvm.Transaction(
255-
txBody,
256-
derivedBlockData.NextTxIndexForTestingOnly())
250+
tx := fvm.Transaction(txBody, 0)
257251
err := vm.Run(ctx, tx, view)
258252
if err != nil {
259253
return nil, err

0 commit comments

Comments
 (0)