Skip to content

Commit

Permalink
refactor fvmOpts
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Dec 12, 2024
1 parent 4ffa7a6 commit fee03b1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
24 changes: 2 additions & 22 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
"google.golang.org/api/option"

"github.com/onflow/flow-go/crypto"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/fvm/environment"
"github.com/onflow/flow-go/fvm/initialize"

"github.com/onflow/flow-go/admin"
"github.com/onflow/flow-go/admin/commands"
Expand Down Expand Up @@ -1564,26 +1563,7 @@ func (fnb *FlowNodeBuilder) initLocal() error {
}

func (fnb *FlowNodeBuilder) initFvmOptions() {
blockFinder := environment.NewBlockFinder(fnb.Storage.Headers)
vmOpts := []fvm.Option{
fvm.WithChain(fnb.RootChainID.Chain()),
fvm.WithBlocks(blockFinder),
fvm.WithAccountStorageLimit(true),
// temporarily enable dependency check for all networks
fvm.WithDependencyCheckEnabled(true),
}
if fnb.RootChainID == flow.Testnet || fnb.RootChainID == flow.Sandboxnet || fnb.RootChainID == flow.Mainnet {
vmOpts = append(vmOpts,
fvm.WithTransactionFeesEnabled(true),
)
}
if fnb.RootChainID == flow.Testnet || fnb.RootChainID == flow.Sandboxnet || fnb.RootChainID == flow.Localnet || fnb.RootChainID == flow.Benchnet {
vmOpts = append(vmOpts,
fvm.WithContractDeploymentRestricted(false),
)
}

fnb.FvmOptions = vmOpts
fnb.FvmOptions = initialize.InitFvmOptions(fnb.RootChainID, fnb.Storage.Headers)
}

// handleModules initializes the given module.
Expand Down
14 changes: 12 additions & 2 deletions engine/verification/verifier/verifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ func VerifyLastKHeight(k uint64, chainID flow.ChainID, protocolDataDir string, c
return fmt.Errorf("could not get last sealed height: %w", err)
}

root := state.Params().SealedRoot().Height
rootHeader, err := state.Params().SealedRoot()
if err != nil {
return fmt.Errorf("could not get sealed root: %w", err)
}

root := rootHeader.Height

// preventing overflow
if k > lastSealed.Height+1 {
Expand Down Expand Up @@ -93,7 +98,12 @@ func VerifyRange(

log.Info().Msgf("verifying blocks from %d to %d", from, to)

root := state.Params().SealedRoot().Height
rootHeader, err := state.Params().SealedRoot()
if err != nil {
return fmt.Errorf("could not get sealed root: %w", err)
}

root := rootHeader.Height

if from <= root {
return fmt.Errorf("cannot verify blocks before the root block, from: %d, root: %d", from, root)
Expand Down
15 changes: 8 additions & 7 deletions fvm/initialize/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@ func InitFvmOptions(chainID flow.ChainID, headers storage.Headers) []fvm.Option
fvm.WithChain(chainID.Chain()),
fvm.WithBlocks(blockFinder),
fvm.WithAccountStorageLimit(true),
// temporarily enable dependency check for all networks
fvm.WithDependencyCheckEnabled(true),
}
switch chainID {
case flow.Testnet,
flow.Sandboxnet,
flow.Previewnet,
flow.Mainnet:
vmOpts = append(vmOpts,
fvm.WithTransactionFeesEnabled(true),
)
}
switch chainID {
case flow.Testnet,
flow.Sandboxnet,
flow.Previewnet,
flow.Localnet,
flow.Benchnet:
if chainID == flow.Testnet || chainID == flow.Sandboxnet || chainID == flow.Mainnet {
vmOpts = append(vmOpts,
fvm.WithTransactionFeesEnabled(true),
)
}
if chainID == flow.Testnet || chainID == flow.Sandboxnet || chainID == flow.Localnet || chainID == flow.Benchnet {
vmOpts = append(vmOpts,
fvm.WithContractDeploymentRestricted(false),
)
Expand Down

0 comments on commit fee03b1

Please sign in to comment.