Skip to content

Commit a240e54

Browse files
committed
add review comments
1 parent 373bd67 commit a240e54

File tree

4 files changed

+47
-64
lines changed

4 files changed

+47
-64
lines changed

cmd/scaffold.go

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ import (
3333
"github.com/onflow/flow-go/cmd/build"
3434
"github.com/onflow/flow-go/config"
3535
"github.com/onflow/flow-go/consensus/hotstuff/persister"
36-
"github.com/onflow/flow-go/fvm"
37-
"github.com/onflow/flow-go/fvm/environment"
36+
"github.com/onflow/flow-go/fvm/initialize"
3837
"github.com/onflow/flow-go/model/flow"
3938
"github.com/onflow/flow-go/model/flow/filter"
4039
"github.com/onflow/flow-go/module"
@@ -1522,32 +1521,9 @@ func (fnb *FlowNodeBuilder) initLocal() error {
15221521
}
15231522

15241523
func (fnb *FlowNodeBuilder) initFvmOptions() {
1525-
blockFinder := environment.NewBlockFinder(fnb.Storage.Headers)
1526-
vmOpts := []fvm.Option{
1527-
fvm.WithChain(fnb.RootChainID.Chain()),
1528-
fvm.WithBlocks(blockFinder),
1529-
fvm.WithAccountStorageLimit(true),
1530-
}
1531-
switch fnb.RootChainID {
1532-
case flow.Testnet,
1533-
flow.Sandboxnet,
1534-
flow.Previewnet,
1535-
flow.Mainnet:
1536-
vmOpts = append(vmOpts,
1537-
fvm.WithTransactionFeesEnabled(true),
1538-
)
1539-
}
1540-
switch fnb.RootChainID {
1541-
case flow.Testnet,
1542-
flow.Sandboxnet,
1543-
flow.Previewnet,
1544-
flow.Localnet,
1545-
flow.Benchnet:
1546-
vmOpts = append(vmOpts,
1547-
fvm.WithContractDeploymentRestricted(false),
1548-
)
1549-
}
1550-
fnb.FvmOptions = vmOpts
1524+
fnb.FvmOptions = initialize.InitFvmOptions(
1525+
fnb.RootChainID, fnb.Storage.Headers,
1526+
)
15511527
}
15521528

15531529
// handleModules initializes the given module.

cmd/util/cmd/verify_execution_result/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func init() {
4444
"last k sealed blocks to verify")
4545

4646
Cmd.Flags().StringVar(&flagFromTo, "from_to", "",
47-
"the height range to verify blocks, i.e, 1-1000, 1000-2000, 2000-3000, etc.")
47+
"the height range to verify blocks (inclusive), i.e, 1-1000, 1000-2000, 2000-3000, etc.")
4848
}
4949

5050
func run(*cobra.Command, []string) {

engine/verification/verifier/verifiers.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/onflow/flow-go/cmd/util/cmd/common"
1111
"github.com/onflow/flow-go/engine/execution/computation"
1212
"github.com/onflow/flow-go/fvm"
13-
"github.com/onflow/flow-go/fvm/environment"
13+
"github.com/onflow/flow-go/fvm/initialize"
1414
"github.com/onflow/flow-go/model/flow"
1515
"github.com/onflow/flow-go/model/verification/convert"
1616
"github.com/onflow/flow-go/module"
@@ -124,10 +124,6 @@ func verifyHeight(
124124

125125
blockID := header.ID()
126126

127-
if err != nil {
128-
return fmt.Errorf("could not get block ID by height %d: %w", height, err)
129-
}
130-
131127
result, err := results.ByBlockID(blockID)
132128
if err != nil {
133129
return fmt.Errorf("could not get execution result by block ID %s: %w", blockID, err)
@@ -160,7 +156,7 @@ func makeVerifier(
160156
) module.ChunkVerifier {
161157

162158
vm := fvm.NewVirtualMachine()
163-
fvmOptions := initFvmOptions(chainID, headers)
159+
fvmOptions := initialize.InitFvmOptions(chainID, headers)
164160
fvmOptions = append(
165161
[]fvm.Option{fvm.WithLogger(logger)},
166162
fvmOptions...,
@@ -173,32 +169,3 @@ func makeVerifier(
173169
chunkVerifier := chunks.NewChunkVerifier(vm, vmCtx, logger)
174170
return chunkVerifier
175171
}
176-
177-
func initFvmOptions(chainID flow.ChainID, headers storage.Headers) []fvm.Option {
178-
blockFinder := environment.NewBlockFinder(headers)
179-
vmOpts := []fvm.Option{
180-
fvm.WithChain(chainID.Chain()),
181-
fvm.WithBlocks(blockFinder),
182-
fvm.WithAccountStorageLimit(true),
183-
}
184-
switch chainID {
185-
case flow.Testnet,
186-
flow.Sandboxnet,
187-
flow.Previewnet,
188-
flow.Mainnet:
189-
vmOpts = append(vmOpts,
190-
fvm.WithTransactionFeesEnabled(true),
191-
)
192-
}
193-
switch chainID {
194-
case flow.Testnet,
195-
flow.Sandboxnet,
196-
flow.Previewnet,
197-
flow.Localnet,
198-
flow.Benchnet:
199-
vmOpts = append(vmOpts,
200-
fvm.WithContractDeploymentRestricted(false),
201-
)
202-
}
203-
return vmOpts
204-
}

fvm/initialize/options.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package initialize
2+
3+
import (
4+
"github.com/onflow/flow-go/fvm"
5+
"github.com/onflow/flow-go/fvm/environment"
6+
"github.com/onflow/flow-go/model/flow"
7+
"github.com/onflow/flow-go/storage"
8+
)
9+
10+
// InitFvmOptions initializes the FVM options based on the chain ID and headers.
11+
// This function is extracted so that it can be reused in multiple places,
12+
// and ensure that the FVM options are consistent across different components.
13+
func InitFvmOptions(chainID flow.ChainID, headers storage.Headers) []fvm.Option {
14+
blockFinder := environment.NewBlockFinder(headers)
15+
vmOpts := []fvm.Option{
16+
fvm.WithChain(chainID.Chain()),
17+
fvm.WithBlocks(blockFinder),
18+
fvm.WithAccountStorageLimit(true),
19+
}
20+
switch chainID {
21+
case flow.Testnet,
22+
flow.Sandboxnet,
23+
flow.Previewnet,
24+
flow.Mainnet:
25+
vmOpts = append(vmOpts,
26+
fvm.WithTransactionFeesEnabled(true),
27+
)
28+
}
29+
switch chainID {
30+
case flow.Testnet,
31+
flow.Sandboxnet,
32+
flow.Previewnet,
33+
flow.Localnet,
34+
flow.Benchnet:
35+
vmOpts = append(vmOpts,
36+
fvm.WithContractDeploymentRestricted(false),
37+
)
38+
}
39+
return vmOpts
40+
}

0 commit comments

Comments
 (0)