Skip to content

Commit 11fa55d

Browse files
authored
Merge pull request #8146 from onflow/bastian/cadence-vm-build-tag
[Cadence VM] Enable Cadence VM by default behind build tag
2 parents 48fedf5 + 9d520d8 commit 11fa55d

File tree

38 files changed

+409
-500
lines changed

38 files changed

+409
-500
lines changed

Makefile

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,9 @@ update-cadence-version:
7070

7171
.PHONY: unittest-main
7272
unittest-main:
73-
# test all packages
74-
# TODO: CGO_CFLAGS=$(CRYPTO_FLAG) go test $(if $(VERBOSE),-v,) -coverprofile=$(COVER_PROFILE) -covermode=atomic $(if $(RACE_DETECTOR),-race,) $(if $(JSON_OUTPUT),-json,) $(if $(NUM_RUNS),-count $(NUM_RUNS),) $(GO_TEST_PACKAGES)
75-
ifneq ($(filter github.com/onflow/flow-go/fvm,$(GO_TEST_PACKAGES)),)
76-
CGO_CFLAGS=$(CRYPTO_FLAG) go test $(if $(VERBOSE),-v,) -coverprofile=$(COVER_PROFILE) -covermode=atomic $(if $(RACE_DETECTOR),-race,) $(if $(JSON_OUTPUT),-json,) $(if $(NUM_RUNS),-count $(NUM_RUNS),) \
77-
github.com/onflow/flow-go/fvm github.com/onflow/flow-go/fvm/evm github.com/onflow/flow-go/fvm/evm/stdlib -testWithVMTransactionExecution=true -testWithVMScriptExecution=true
78-
endif
79-
ifneq ($(filter github.com/onflow/flow-go/engine/execution/state/bootstrap,$(GO_TEST_PACKAGES)),)
80-
CGO_CFLAGS=$(CRYPTO_FLAG) go test $(if $(VERBOSE),-v,) -coverprofile=$(COVER_PROFILE) -covermode=atomic $(if $(RACE_DETECTOR),-race,) $(if $(JSON_OUTPUT),-json,) $(if $(NUM_RUNS),-count $(NUM_RUNS),) \
81-
github.com/onflow/flow-go/engine/execution/state/bootstrap -testWithVMTransactionExecution=true -testWithVMScriptExecution=true
82-
endif
83-
ifneq ($(filter github.com/onflow/flow-go/engine/access/rpc/backend,$(GO_TEST_PACKAGES)),)
84-
CGO_CFLAGS=$(CRYPTO_FLAG) go test $(if $(VERBOSE),-v,) -coverprofile=$(COVER_PROFILE) -covermode=atomic $(if $(RACE_DETECTOR),-race,) $(if $(JSON_OUTPUT),-json,) $(if $(NUM_RUNS),-count $(NUM_RUNS),) \
85-
github.com/onflow/flow-go/engine/access/rpc/backend -testWithVMScriptExecution=true
86-
endif
73+
CGO_CFLAGS=$(CRYPTO_FLAG) go test $(if $(VERBOSE),-v,) -coverprofile=$(COVER_PROFILE) -covermode=atomic $(if $(RACE_DETECTOR),-race,) $(if $(JSON_OUTPUT),-json,) $(if $(NUM_RUNS),-count $(NUM_RUNS),) $(GO_TEST_PACKAGES)
74+
# Re-run tests with Cadence VM enabled
75+
CGO_CFLAGS=$(CRYPTO_FLAG) go test -tags cadence_vm $(if $(VERBOSE),-v,) -coverprofile=$(COVER_PROFILE) -covermode=atomic $(if $(RACE_DETECTOR),-race,) $(if $(JSON_OUTPUT),-json,) $(if $(NUM_RUNS),-count $(NUM_RUNS),) $(GO_TEST_PACKAGES)
8776

8877
.PHONY: install-mock-generators
8978
install-mock-generators:

cmd/node_builder.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,6 @@ type BaseConfig struct {
187187
BitswapReprovideEnabled bool
188188

189189
TransactionFeesDisabled bool
190-
191-
// VMTransactionExecutionEnabled configures whether transactions are executed with the Cadence compiler/VM
192-
// instead of the Cadence interpreter.
193-
VMTransactionExecutionEnabled bool
194-
195-
// VMScriptExecutionEnabled configures whether transactions are executed with the Cadence compiler/VM
196-
// instead of the Cadence interpreter.
197-
VMScriptExecutionEnabled bool
198190
}
199191

200192
// NodeConfig contains all the derived parameters such the NodeID, private keys etc. and initialized instances of

cmd/scaffold.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,6 @@ func (fnb *FlowNodeBuilder) BaseFlags() {
284284
false,
285285
"Disables calling the transaction fee deduction. This is only for testing purposes. To disable fees on a network it is better to set the fee price to 0.0 .")
286286

287-
fnb.flags.BoolVar(&fnb.VMScriptExecutionEnabled,
288-
"vm-script-execution-enabled",
289-
false,
290-
"Enables execution of scripts with the Cadence compiler/VM instead of the Cadence interpreter",
291-
)
292-
293-
fnb.flags.BoolVar(&fnb.VMTransactionExecutionEnabled,
294-
"vm-transaction-execution-enabled",
295-
false,
296-
"Enables execution of transactions with the Cadence compiler/VM instead of the Cadence interpreter",
297-
)
298287
}
299288

300289
// TODO: remove after mainnet27 spork
@@ -1557,8 +1546,6 @@ func (fnb *FlowNodeBuilder) initFvmOptions() {
15571546
fnb.RootChainID,
15581547
fnb.Storage.Headers,
15591548
fnb.BaseConfig.TransactionFeesDisabled,
1560-
fnb.BaseConfig.VMScriptExecutionEnabled,
1561-
fnb.BaseConfig.VMTransactionExecutionEnabled,
15621549
)
15631550
}
15641551

cmd/util/cmd/debug-script/cmd.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"google.golang.org/grpc"
1111
"google.golang.org/grpc/credentials/insecure"
1212

13+
"github.com/onflow/flow-go/fvm"
1314
"github.com/onflow/flow-go/model/flow"
1415
"github.com/onflow/flow-go/utils/debug"
1516
)
@@ -119,7 +120,11 @@ func run(*cobra.Command, []string) {
119120

120121
blockSnapshot := debug.NewCachingStorageSnapshot(remoteSnapshot)
121122

122-
debugger := debug.NewRemoteDebugger(chain, log.Logger, flagUseVM, flagUseVM)
123+
debugger := debug.NewRemoteDebugger(
124+
chain,
125+
log.Logger,
126+
fvm.WithCadenceVMEnabled(flagUseVM),
127+
)
123128

124129
// TODO: add support for arguments
125130
var arguments [][]byte

cmd/util/cmd/debug-tx/cmd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ func RunTransaction(
454454
Str("tx", tx.ID().String()).
455455
Logger()
456456

457-
var fvmOptions []fvm.Option
457+
fvmOptions := []fvm.Option{
458+
fvm.WithCadenceVMEnabled(useVM),
459+
}
458460

459461
if spanExporter != nil {
460462

@@ -486,8 +488,6 @@ func RunTransaction(
486488
debugger := debug.NewRemoteDebugger(
487489
chain,
488490
log,
489-
useVM,
490-
useVM,
491491
fvmOptions...,
492492
)
493493

cmd/util/cmd/verify_execution_result/cmd.go

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ import (
1616
)
1717

1818
var (
19-
flagLastK uint64
20-
flagDatadir string
21-
flagChunkDataPackDir string
22-
flagChain string
23-
flagFromTo string
24-
flagWorkerCount uint // number of workers to verify the blocks concurrently
25-
flagStopOnMismatch bool
26-
flagTransactionFeesDisabled bool
27-
flagScheduledCallbacksEnabled bool
28-
flagVMScriptExecutionEnabled bool
29-
flagVMTransactionExecutionEnabled bool
19+
flagLastK uint64
20+
flagDatadir string
21+
flagChunkDataPackDir string
22+
flagChain string
23+
flagFromTo string
24+
flagWorkerCount uint // number of workers to verify the blocks concurrently
25+
flagStopOnMismatch bool
26+
flagTransactionFeesDisabled bool
27+
flagScheduledCallbacksEnabled bool
3028
)
3129

3230
// # verify the last 100 sealed blocks
@@ -63,20 +61,6 @@ func init() {
6361
Cmd.Flags().BoolVar(&flagTransactionFeesDisabled, "fees_disabled", false, "disable transaction fees")
6462

6563
Cmd.Flags().BoolVar(&flagScheduledCallbacksEnabled, "scheduled_callbacks_enabled", fvm.DefaultScheduledCallbacksEnabled, "enable scheduled callbacks")
66-
67-
Cmd.Flags().BoolVar(
68-
&flagVMScriptExecutionEnabled,
69-
"vm_script_execution_enabled",
70-
false,
71-
"enable script execution with VM",
72-
)
73-
74-
Cmd.Flags().BoolVar(
75-
&flagVMTransactionExecutionEnabled,
76-
"vm_transaction_execution_enabled",
77-
false,
78-
"enable transaction execution with VM",
79-
)
8064
}
8165

8266
func run(*cobra.Command, []string) {
@@ -123,8 +107,6 @@ func run(*cobra.Command, []string) {
123107
flagStopOnMismatch,
124108
flagTransactionFeesDisabled,
125109
flagScheduledCallbacksEnabled,
126-
flagVMScriptExecutionEnabled,
127-
flagVMTransactionExecutionEnabled,
128110
)
129111
if err != nil {
130112
lg.Fatal().Err(err).Msgf("could not verify range from %d to %d", from, to)
@@ -142,8 +124,6 @@ func run(*cobra.Command, []string) {
142124
flagStopOnMismatch,
143125
flagTransactionFeesDisabled,
144126
flagScheduledCallbacksEnabled,
145-
flagVMScriptExecutionEnabled,
146-
flagVMTransactionExecutionEnabled,
147127
)
148128
if err != nil {
149129
lg.Fatal().Err(err).Msg("could not verify last k height")

engine/access/rpc/backend/script_executor_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package backend
22

33
import (
44
"context"
5-
"flag"
65
"math"
76
"testing"
87
"time"
@@ -35,12 +34,6 @@ import (
3534
"github.com/onflow/flow-go/utils/unittest/mocks"
3635
)
3736

38-
var testWithVMScriptExecution = flag.Bool(
39-
"testWithVMScriptExecution",
40-
false,
41-
"Run scripts in tests using the Cadence compiler/VM",
42-
)
43-
4437
// ScriptExecutorSuite is a test suite for testing the ScriptExecutor.
4538
// It sets up the necessary components and dependencies for executing scripts.
4639
type ScriptExecutorSuite struct {
@@ -125,7 +118,6 @@ func (s *ScriptExecutorSuite) SetupTest() {
125118
fvm.WithChain(s.chain),
126119
fvm.WithAuthorizationChecksEnabled(false),
127120
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
128-
fvm.WithVMScriptExecutionEnabled(*testWithVMScriptExecution),
129121
)
130122

131123
s.dbDir = unittest.TempDir(s.T())

engine/execution/state/bootstrap/bootstrap_test.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package bootstrap
22

33
import (
44
"encoding/hex"
5-
"flag"
65
"fmt"
76
"testing"
87

@@ -21,18 +20,6 @@ import (
2120
"github.com/onflow/flow-go/utils/unittest"
2221
)
2322

24-
var testWithVMTransactionExecution = flag.Bool(
25-
"testWithVMTransactionExecution",
26-
false,
27-
"Run transactions in tests using the Cadence compiler/VM",
28-
)
29-
30-
var testWithVMScriptExecution = flag.Bool(
31-
"testWithVMScriptExecution",
32-
false,
33-
"Run scripts in tests using the Cadence compiler/VM",
34-
)
35-
3623
func TestBootstrapLedger(t *testing.T) {
3724
unittest.RunWithTempDir(t, func(dbDir string) {
3825

@@ -70,7 +57,9 @@ func TestBootstrapLedger(t *testing.T) {
7057
}
7158

7259
func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
73-
expectedStateCommitmentBytes, _ := hex.DecodeString("bec4478e1b3aa1fd822c796411e69bd85ef9529b9ef93e231d4b02470d49b4f0")
60+
expectedStateCommitmentBytes, _ := hex.DecodeString(
61+
"4c71561153301a0dea2e6cc74255ff6473b5ef4b66c7701bbcf8358249ce2048",
62+
)
7463
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
7564
require.NoError(t, err)
7665

@@ -117,7 +106,9 @@ func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
117106
// - transaction fee deduction
118107
// This tests that the state commitment has not changed for the bookkeeping parts of the transaction.
119108
func TestBootstrapLedger_EmptyTransaction(t *testing.T) {
120-
expectedStateCommitmentBytes, _ := hex.DecodeString("b21c4cea6518d92c34d2eeff1a02f7e1b7b75f9c0e0e52069905bb728361d039")
109+
expectedStateCommitmentBytes, _ := hex.DecodeString(
110+
"def8795537883765992fda2ef6aafd6b0448bd0cf514f551ee7e7803cd13d11f",
111+
)
121112
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
122113
require.NoError(t, err)
123114

@@ -157,8 +148,6 @@ func TestBootstrapLedger_EmptyTransaction(t *testing.T) {
157148
fvm.WithAccountStorageLimit(true),
158149
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
159150
fvm.WithAuthorizationChecksEnabled(false),
160-
fvm.WithVMTransactionExecutionEnabled(*testWithVMTransactionExecution),
161-
fvm.WithVMScriptExecutionEnabled(*testWithVMScriptExecution),
162151
)
163152

164153
sc := systemcontracts.SystemContractsForChain(chain.ChainID())

engine/verification/verifier/verifiers.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ func VerifyLastKHeight(
4141
stopOnMismatch bool,
4242
transactionFeesDisabled bool,
4343
scheduledCallbacksEnabled bool,
44-
vmScriptExecutionEnabled bool,
45-
vmTransactionExecutionEnabled bool,
4644
) (err error) {
4745
closer, storages, chunkDataPacks, state, verifier, err := initStorages(
4846
lockManager,
@@ -51,8 +49,6 @@ func VerifyLastKHeight(
5149
chunkDataPackDir,
5250
transactionFeesDisabled,
5351
scheduledCallbacksEnabled,
54-
vmScriptExecutionEnabled,
55-
vmTransactionExecutionEnabled,
5652
)
5753
if err != nil {
5854
return fmt.Errorf("could not init storages: %w", err)
@@ -109,8 +105,6 @@ func VerifyRange(
109105
stopOnMismatch bool,
110106
transactionFeesDisabled bool,
111107
scheduledCallbacksEnabled bool,
112-
vmScriptExecutionEnabled bool,
113-
vmTransactionExecutionEnabled bool,
114108
) (err error) {
115109
closer, storages, chunkDataPacks, state, verifier, err := initStorages(
116110
lockManager,
@@ -119,8 +113,6 @@ func VerifyRange(
119113
chunkDataPackDir,
120114
transactionFeesDisabled,
121115
scheduledCallbacksEnabled,
122-
vmScriptExecutionEnabled,
123-
vmTransactionExecutionEnabled,
124116
)
125117
if err != nil {
126118
return fmt.Errorf("could not init storages: %w", err)
@@ -251,8 +243,6 @@ func initStorages(
251243
chunkDataPackDir string,
252244
transactionFeesDisabled bool,
253245
scheduledCallbacksEnabled bool,
254-
vmScriptExecutionEnabled bool,
255-
vmTransactionExecutionEnabled bool,
256246
) (
257247
func() error,
258248
*store.All,
@@ -288,8 +278,6 @@ func initStorages(
288278
storages.Headers,
289279
transactionFeesDisabled,
290280
scheduledCallbacksEnabled,
291-
vmScriptExecutionEnabled,
292-
vmTransactionExecutionEnabled,
293281
)
294282

295283
closer := func() error {
@@ -370,17 +358,13 @@ func makeVerifier(
370358
headers storage.Headers,
371359
transactionFeesDisabled bool,
372360
scheduledCallbacksEnabled bool,
373-
vmScriptExecutionEnabled bool,
374-
vmTransactionExecutionEnabled bool,
375361
) module.ChunkVerifier {
376362

377363
vm := fvm.NewVirtualMachine()
378364
fvmOptions := initialize.InitFvmOptions(
379365
chainID,
380366
headers,
381367
transactionFeesDisabled,
382-
vmScriptExecutionEnabled,
383-
vmTransactionExecutionEnabled,
384368
)
385369
fvmOptions = append(
386370
[]fvm.Option{fvm.WithLogger(logger)},

fvm/blueprints/contracts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func setContractAuthorizersTransaction(
5151
for _, address := range authorized {
5252
addressValues = append(
5353
addressValues,
54-
cadence.BytesToAddress(address.Bytes()))
54+
cadence.Address(address))
5555
}
5656

5757
addressesArg, err := jsoncdc.Encode(cadence.NewArray(addressValues))

0 commit comments

Comments
 (0)