Skip to content

Commit d202820

Browse files
committed
enable Cadence VM by default behind build tag, remove command-line flags in tools and tests
1 parent deefc37 commit d202820

File tree

29 files changed

+252
-333
lines changed

29 files changed

+252
-333
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
@@ -425,7 +425,9 @@ func RunTransaction(
425425
Str("tx", tx.ID().String()).
426426
Logger()
427427

428-
var fvmOptions []fvm.Option
428+
fvmOptions := []fvm.Option{
429+
fvm.WithCadenceVMEnabled(useVM),
430+
}
429431

430432
if spanExporter != nil {
431433

@@ -455,8 +457,6 @@ func RunTransaction(
455457
debugger := debug.NewRemoteDebugger(
456458
chain,
457459
log,
458-
useVM,
459-
useVM,
460460
fvmOptions...,
461461
)
462462

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: 18 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

@@ -13,6 +12,7 @@ import (
1312
"github.com/onflow/flow-go/engine/execution/state"
1413
"github.com/onflow/flow-go/engine/execution/storehouse"
1514
"github.com/onflow/flow-go/fvm"
15+
"github.com/onflow/flow-go/fvm/cadence_vm"
1616
"github.com/onflow/flow-go/fvm/systemcontracts"
1717
completeLedger "github.com/onflow/flow-go/ledger/complete"
1818
"github.com/onflow/flow-go/ledger/complete/wal/fixtures"
@@ -21,18 +21,6 @@ import (
2121
"github.com/onflow/flow-go/utils/unittest"
2222
)
2323

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-
3624
func TestBootstrapLedger(t *testing.T) {
3725
unittest.RunWithTempDir(t, func(dbDir string) {
3826

@@ -70,7 +58,10 @@ func TestBootstrapLedger(t *testing.T) {
7058
}
7159

7260
func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
73-
expectedStateCommitmentBytes, _ := hex.DecodeString("bec4478e1b3aa1fd822c796411e69bd85ef9529b9ef93e231d4b02470d49b4f0")
61+
expectedStateCommitmentBytes, _ := hex.DecodeString(ifCompile(
62+
"3ee915c0ecaf1399d00cc6a768517aa074139ca07045d4e63a1745fc81e1bdf0",
63+
"bec4478e1b3aa1fd822c796411e69bd85ef9529b9ef93e231d4b02470d49b4f0",
64+
))
7465
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
7566
require.NoError(t, err)
7667

@@ -106,6 +97,13 @@ func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
10697
})
10798
}
10899

100+
func ifCompile[T any](a, b T) T {
101+
if cadence_vm.DefaultEnabled {
102+
return a
103+
}
104+
return b
105+
}
106+
109107
// TestBootstrapLedger_EmptyTransaction bootstraps a ledger with:
110108
// - transaction fees
111109
// - storage fees
@@ -117,7 +115,12 @@ func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
117115
// - transaction fee deduction
118116
// This tests that the state commitment has not changed for the bookkeeping parts of the transaction.
119117
func TestBootstrapLedger_EmptyTransaction(t *testing.T) {
120-
expectedStateCommitmentBytes, _ := hex.DecodeString("b21c4cea6518d92c34d2eeff1a02f7e1b7b75f9c0e0e52069905bb728361d039")
118+
expectedStateCommitmentBytes, _ := hex.DecodeString(
119+
ifCompile(
120+
"505aa62b494f262df6830b4ace90ee35d5e4574155db4361eff5e97ae4377d31",
121+
"b21c4cea6518d92c34d2eeff1a02f7e1b7b75f9c0e0e52069905bb728361d039",
122+
),
123+
)
121124
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
122125
require.NoError(t, err)
123126

@@ -157,8 +160,6 @@ func TestBootstrapLedger_EmptyTransaction(t *testing.T) {
157160
fvm.WithAccountStorageLimit(true),
158161
fvm.WithSequenceNumberCheckAndIncrementEnabled(false),
159162
fvm.WithAuthorizationChecksEnabled(false),
160-
fvm.WithVMTransactionExecutionEnabled(*testWithVMTransactionExecution),
161-
fvm.WithVMScriptExecutionEnabled(*testWithVMScriptExecution),
162163
)
163164

164165
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)