Skip to content

Commit

Permalink
Merge pull request #6259 from onflow/bastian/update-atree-inlining-ca…
Browse files Browse the repository at this point in the history
…dence-v1.0-16
  • Loading branch information
turbolent authored Jul 24, 2024
2 parents 9b93276 + cf321f5 commit 14e2bc4
Show file tree
Hide file tree
Showing 40 changed files with 1,866 additions and 424 deletions.
37 changes: 37 additions & 0 deletions cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
stateSyncCommands "github.com/onflow/flow-go/admin/commands/state_synchronization"
storageCommands "github.com/onflow/flow-go/admin/commands/storage"
"github.com/onflow/flow-go/cmd"
"github.com/onflow/flow-go/cmd/build"
"github.com/onflow/flow-go/consensus"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/committees"
Expand All @@ -52,6 +53,7 @@ import (
followereng "github.com/onflow/flow-go/engine/common/follower"
"github.com/onflow/flow-go/engine/common/requester"
synceng "github.com/onflow/flow-go/engine/common/synchronization"
"github.com/onflow/flow-go/engine/common/version"
"github.com/onflow/flow-go/engine/execution/computation/query"
"github.com/onflow/flow-go/fvm/storage/derived"
"github.com/onflow/flow-go/ledger"
Expand Down Expand Up @@ -164,6 +166,7 @@ type AccessNodeConfig struct {
registerCacheSize uint
programCacheSize uint
checkPayerBalance bool
versionControlEnabled bool
}

type PublicNetworkConfig struct {
Expand Down Expand Up @@ -264,6 +267,7 @@ func DefaultAccessNodeConfig() *AccessNodeConfig {
registerCacheSize: 0,
programCacheSize: 0,
checkPayerBalance: false,
versionControlEnabled: true,
}
}

Expand Down Expand Up @@ -311,6 +315,7 @@ type FlowAccessNodeBuilder struct {
ExecutionDataPruner *pruner.Pruner
ExecutionDataDatastore *badger.Datastore
ExecutionDataTracker tracker.Storage
versionControl *version.VersionControl

// The sync engine participants provider is the libp2p peer store for the access node
// which is not available until after the network has started.
Expand Down Expand Up @@ -1226,6 +1231,10 @@ func (builder *FlowAccessNodeBuilder) extraFlags() {
"circuit-breaker-max-requests",
defaultConfig.rpcConf.BackendConfig.CircuitBreakerConfig.MaxRequests,
"maximum number of requests to check if connection restored after timeout. Default value is 1")
flags.BoolVar(&builder.versionControlEnabled,
"version-control-enabled",
defaultConfig.versionControlEnabled,
"whether to enable the version control feature. Default value is true")
// ExecutionDataRequester config
flags.BoolVar(&builder.executionDataSyncEnabled,
"execution-data-sync-enabled",
Expand Down Expand Up @@ -1937,6 +1946,34 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
return builder.RequestEng, nil
})

if builder.versionControlEnabled {
builder.Component("version control", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
nodeVersion, err := build.Semver()
if err != nil {
return nil, fmt.Errorf("could not load node version for version control. "+
"version (%s) is not semver compliant: %w. Make sure a valid semantic version is provided in the VERSION environment variable", build.Version(), err)
}

versionControl, err := version.NewVersionControl(
builder.Logger,
node.Storage.VersionBeacons,
nodeVersion,
builder.SealedRootBlock.Header.Height,
builder.LastFinalizedHeader.Height,
)
if err != nil {
return nil, fmt.Errorf("could not create version control: %w", err)
}

// VersionControl needs to consume BlockFinalized events.
node.ProtocolEvents.AddConsumer(versionControl)

builder.versionControl = versionControl

return versionControl, nil
})
}

if builder.supportsObserver {
builder.Component("public sync request handler", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
syncRequestHandler, err := synceng.NewRequestHandlerEngine(
Expand Down
37 changes: 36 additions & 1 deletion cmd/observer/node_builder/observer_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/onflow/flow-go/admin/commands"
stateSyncCommands "github.com/onflow/flow-go/admin/commands/state_synchronization"
"github.com/onflow/flow-go/cmd"
"github.com/onflow/flow-go/cmd/build"
"github.com/onflow/flow-go/consensus"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/consensus/hotstuff/committees"
Expand All @@ -51,6 +52,7 @@ import (
"github.com/onflow/flow-go/engine/access/subscription"
"github.com/onflow/flow-go/engine/common/follower"
synceng "github.com/onflow/flow-go/engine/common/synchronization"
"github.com/onflow/flow-go/engine/common/version"
"github.com/onflow/flow-go/engine/execution/computation/query"
"github.com/onflow/flow-go/fvm/storage/derived"
"github.com/onflow/flow-go/ledger"
Expand Down Expand Up @@ -155,6 +157,7 @@ type ObserverServiceConfig struct {
executionDataPrunerHeightRangeTarget uint64
executionDataPrunerThreshold uint64
localServiceAPIEnabled bool
versionControlEnabled bool
executionDataDir string
executionDataStartHeight uint64
executionDataConfig edrequester.ExecutionDataConfig
Expand Down Expand Up @@ -227,6 +230,7 @@ func DefaultObserverServiceConfig() *ObserverServiceConfig {
executionDataPrunerHeightRangeTarget: 0,
executionDataPrunerThreshold: 100_000,
localServiceAPIEnabled: false,
versionControlEnabled: true,
executionDataDir: filepath.Join(homedir, ".flow", "execution_data"),
executionDataStartHeight: 0,
executionDataConfig: edrequester.ExecutionDataConfig{
Expand Down Expand Up @@ -267,6 +271,7 @@ type ObserverServiceBuilder struct {
ExecutionIndexerCore *indexer.IndexerCore
TxResultsIndex *index.TransactionResultsIndex
IndexerDependencies *cmd.DependencyList
versionControl *version.VersionControl

ExecutionDataDownloader execution_data.Downloader
ExecutionDataRequester state_synchronization.ExecutionDataRequester
Expand Down Expand Up @@ -664,6 +669,10 @@ func (builder *ObserverServiceBuilder) extraFlags() {
"execution-data-indexing-enabled",
defaultConfig.executionDataIndexingEnabled,
"whether to enable the execution data indexing")
flags.BoolVar(&builder.versionControlEnabled,
"version-control-enabled",
defaultConfig.versionControlEnabled,
"whether to enable the version control feature. Default value is true")
flags.BoolVar(&builder.localServiceAPIEnabled, "local-service-api-enabled", defaultConfig.localServiceAPIEnabled, "whether to use local indexed data for api queries")
flags.StringVar(&builder.registersDBPath, "execution-state-dir", defaultConfig.registersDBPath, "directory to use for execution-state database")
flags.StringVar(&builder.checkpointFile, "execution-state-checkpoint", defaultConfig.checkpointFile, "execution-state checkpoint file")
Expand Down Expand Up @@ -1685,7 +1694,6 @@ func (builder *ObserverServiceBuilder) enqueueConnectWithStakedAN() {
}

func (builder *ObserverServiceBuilder) enqueueRPCServer() {

builder.Module("transaction metrics", func(node *cmd.NodeConfig) error {
var err error
builder.TransactionTimings, err = stdmap.NewTransactionTimings(1500 * 300) // assume 1500 TPS * 300 seconds
Expand Down Expand Up @@ -1783,6 +1791,33 @@ func (builder *ObserverServiceBuilder) enqueueRPCServer() {
builder.ScriptExecutor = backend.NewScriptExecutor(builder.Logger, builder.scriptExecMinBlock, builder.scriptExecMaxBlock)
return nil
})
if builder.versionControlEnabled {
builder.Component("version control", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
nodeVersion, err := build.Semver()
if err != nil {
return nil, fmt.Errorf("could not load node version for version control. "+
"version (%s) is not semver compliant: %w. Make sure a valid semantic version is provided in the VERSION environment variable", build.Version(), err)
}

versionControl, err := version.NewVersionControl(
builder.Logger,
node.Storage.VersionBeacons,
nodeVersion,
builder.SealedRootBlock.Header.Height,
builder.LastFinalizedHeader.Height,
)
if err != nil {
return nil, fmt.Errorf("could not create version control: %w", err)
}

// VersionControl needs to consume BlockFinalized events.
node.ProtocolEvents.AddConsumer(versionControl)

builder.versionControl = versionControl

return versionControl, nil
})
}
builder.Component("RPC engine", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
accessMetrics := builder.AccessMetrics
config := builder.rpcConf
Expand Down
4 changes: 2 additions & 2 deletions cmd/util/cmd/execution-state-extract/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ func run(*cobra.Command, []string) {
switch chainID {
case flow.Emulator:
burnerContractChange = migrations.BurnerContractChangeDeploy
evmContractChange = migrations.EVMContractChangeDeploy
evmContractChange = migrations.EVMContractChangeDeployMinimalAndUpdateFull
case flow.Testnet, flow.Mainnet:
burnerContractChange = migrations.BurnerContractChangeUpdate
evmContractChange = migrations.EVMContractChangeUpdate
evmContractChange = migrations.EVMContractChangeUpdateFull
}

stagedContracts, err := migrations.StagedContractsFromCSV(flagStagedContractsFile)
Expand Down
27 changes: 27 additions & 0 deletions cmd/util/ledger/migrations/burner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package migrations

import (
coreContracts "github.com/onflow/flow-core-contracts/lib/go/contracts"
"github.com/rs/zerolog"

"github.com/onflow/flow-go/model/flow"
)

func NewBurnerDeploymentMigration(
chainID flow.ChainID,
logger zerolog.Logger,
) RegistersMigration {
address := BurnerAddressForChain(chainID)
return NewDeploymentMigration(
chainID,
Contract{
Name: "Burner",
Code: coreContracts.Burner(),
},
address,
map[flow.Address]struct{}{
address: {},
},
logger,
)
}
29 changes: 27 additions & 2 deletions cmd/util/ledger/migrations/cadence.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,23 @@ func NewCadence1ContractsMigrations(
)
}

if opts.EVMContractChange == EVMContractChangeDeploy {
switch opts.EVMContractChange {
case EVMContractChangeNone:
// NO-OP

case EVMContractChangeUpdateFull:
// handled in system contract updates (SystemContractChanges)

case EVMContractChangeDeployFull,
EVMContractChangeDeployMinimalAndUpdateFull:

full := opts.EVMContractChange == EVMContractChangeDeployFull

migs = append(
migs,
NamedMigration{
Name: "evm-deployment-migration",
Migrate: NewEVMDeploymentMigration(opts.ChainID, log),
Migrate: NewEVMDeploymentMigration(opts.ChainID, log, full),
},
)
}
Expand Down Expand Up @@ -551,5 +562,19 @@ func NewCadence1Migrations(
)...,
)

switch opts.EVMContractChange {
case EVMContractChangeNone,
EVMContractChangeDeployFull:
// NO-OP
case EVMContractChangeUpdateFull, EVMContractChangeDeployMinimalAndUpdateFull:
migs = append(
migs,
NamedMigration{
Name: "evm-setup-migration",
Migrate: NewEVMSetupMigration(opts.ChainID, log),
},
)
}

return migs
}
20 changes: 17 additions & 3 deletions cmd/util/ledger/migrations/change_contract_code_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ type EVMContractChange uint8

const (
EVMContractChangeNone EVMContractChange = iota
EVMContractChangeDeploy
EVMContractChangeUpdate
// EVMContractChangeDeployFull deploys the full EVM contract
EVMContractChangeDeployFull
// EVMContractChangeUpdateFull updates the existing EVM contract to the latest, full EVM contract
EVMContractChangeUpdateFull
// EVMContractChangeDeployMinimalAndUpdateFull deploys the minimal EVM contract
// and updates it to the latest, full EVM contract
EVMContractChangeDeployMinimalAndUpdateFull
)

type BurnerContractChange uint8
Expand Down Expand Up @@ -216,7 +221,16 @@ func SystemContractChanges(chainID flow.ChainID, options SystemContractsMigratio
}

// EVM contract
if options.EVM == EVMContractChangeUpdate {
switch options.EVM {
case EVMContractChangeNone:
// NO-OP

case EVMContractChangeDeployFull:
// handled in migration pipeline (NewCadence1ContractsMigrations)

case EVMContractChangeUpdateFull,
EVMContractChangeDeployMinimalAndUpdateFull:

contractChanges = append(
contractChanges,
NewSystemContractChange(
Expand Down
46 changes: 0 additions & 46 deletions cmd/util/ledger/migrations/deploy_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package migrations
import (
"github.com/onflow/cadence"
jsoncdc "github.com/onflow/cadence/encoding/json"
coreContracts "github.com/onflow/flow-core-contracts/lib/go/contracts"
"github.com/rs/zerolog"

evm "github.com/onflow/flow-go/fvm/evm/stdlib"
"github.com/onflow/flow-go/fvm/systemcontracts"
"github.com/onflow/flow-go/model/flow"
)

Expand Down Expand Up @@ -40,46 +37,3 @@ func NewDeploymentMigration(
expectedWriteAddresses,
)
}

func NewBurnerDeploymentMigration(
chainID flow.ChainID,
logger zerolog.Logger,
) RegistersMigration {
address := BurnerAddressForChain(chainID)
return NewDeploymentMigration(
chainID,
Contract{
Name: "Burner",
Code: coreContracts.Burner(),
},
address,
map[flow.Address]struct{}{
address: {},
},
logger,
)
}

func NewEVMDeploymentMigration(
chainID flow.ChainID,
logger zerolog.Logger,
) RegistersMigration {
systemContracts := systemcontracts.SystemContractsForChain(chainID)
address := systemContracts.EVMContract.Address
return NewDeploymentMigration(
chainID,
Contract{
Name: systemContracts.EVMContract.Name,
Code: evm.ContractCode(
systemContracts.NonFungibleToken.Address,
systemContracts.FungibleToken.Address,
systemContracts.FlowToken.Address,
),
},
address,
map[flow.Address]struct{}{
address: {},
},
logger,
)
}
Loading

0 comments on commit 14e2bc4

Please sign in to comment.