Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get execution version from snapshot instead of state #6867

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/access/node_builder/access_node_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import (
"github.com/onflow/flow-go/engine/common/stop"
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"
"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 @@ -991,7 +992,7 @@ func (builder *FlowAccessNodeBuilder) BuildExecutionSyncComponents() *FlowAccess
builder.Logger,
metrics.NewExecutionCollector(builder.Tracer),
builder.RootChainID,
query.NewProtocolStateWrapper(builder.State),
computation.NewProtocolStateWrapper(builder.State),
builder.Storage.Headers,
builder.ExecutionIndexerCore.RegisterValue,
builder.scriptExecutorConfig,
Expand Down
2 changes: 1 addition & 1 deletion cmd/execution_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (exeNode *ExecutionNode) LoadProviderEngine(
collector,
node.Tracer,
node.Me,
node.State,
computation.NewProtocolStateWrapper(node.State),
vmCtx,
ledgerViewCommitter,
executionDataProvider,
Expand Down
3 changes: 2 additions & 1 deletion cmd/observer/node_builder/observer_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
"github.com/onflow/flow-go/engine/common/stop"
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"
"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 @@ -1454,7 +1455,7 @@ func (builder *ObserverServiceBuilder) BuildExecutionSyncComponents() *ObserverS
builder.Logger,
metrics.NewExecutionCollector(builder.Tracer),
builder.RootChainID,
query.NewProtocolStateWrapper(builder.State),
computation.NewProtocolStateWrapper(builder.State),
builder.Storage.Headers,
builder.ExecutionIndexerCore.RegisterValue,
builder.scriptExecutorConfig,
Expand Down
10 changes: 2 additions & 8 deletions engine/access/rpc/backend/script_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/onflow/flow-go/engine/access/index"
"github.com/onflow/flow-go/engine/common/version"
"github.com/onflow/flow-go/engine/execution/computation/query"
"github.com/onflow/flow-go/engine/execution/computation/query/mock"
"github.com/onflow/flow-go/engine/execution/testutil"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/fvm/storage/derived"
Expand Down Expand Up @@ -109,12 +108,7 @@ func (s *ScriptExecutorSuite) SetupTest() {
s.headers = newBlockHeadersStorage(blockchain)
s.height = blockchain[0].Header.Height

entropyProvider := testutil.EntropyProviderFixture(nil)
entropyBlock := mock.NewEntropyProviderPerBlock(s.T())
entropyBlock.
On("AtBlockID", testifyMock.AnythingOfType("flow.Identifier")).
Return(entropyProvider).
Maybe()
protocolState := testutil.ProtocolStateWithSourceFixture(nil)

s.snapshot = snapshot.NewSnapshotTree(nil)
s.vm = fvm.NewVirtualMachine()
Expand Down Expand Up @@ -153,7 +147,7 @@ func (s *ScriptExecutorSuite) SetupTest() {
s.log,
metrics.NewNoopCollector(),
s.chain.ChainID(),
entropyBlock,
protocolState,
s.headers,
indexerCore.RegisterValue,
query.NewDefaultConfig(),
Expand Down
20 changes: 4 additions & 16 deletions engine/execution/computation/computer/computer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type blockComputer struct {
spockHasher hash.Hasher
receiptHasher hash.Hasher
colResCons []result.ExecutedCollectionConsumer
protocolState protocol.State
protocolState protocol.SnapshotExecutionSubsetProvider
maxConcurrency int
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func NewBlockComputer(
signer module.Local,
executionDataProvider provider.Provider,
colResCons []result.ExecutedCollectionConsumer,
state protocol.State,
state protocol.SnapshotExecutionSubsetProvider,
maxConcurrency int,
) (BlockComputer, error) {
if maxConcurrency < 1 {
Expand Down Expand Up @@ -220,13 +220,7 @@ func (e *blockComputer) queueTransactionRequests(
collectionCtx := fvm.NewContextFromParent(
e.vmCtx,
fvm.WithBlockHeader(blockHeader),
// `protocol.Snapshot` implements `EntropyProvider` interface
// Note that `Snapshot` possible errors for RandomSource() are:
// - storage.ErrNotFound if the QC is unknown.
// - state.ErrUnknownSnapshotReference if the snapshot reference block is unknown
// However, at this stage, snapshot reference block should be known and the QC should also be known,
// so no error is expected in normal operations, as required by `EntropyProvider`.
fvm.WithEntropyProvider(e.protocolState.AtBlockID(blockId)),
fvm.WithProtocolStateSnapshot(e.protocolState.AtBlockID(blockId)),
)

for idx, collection := range rawCollections {
Expand Down Expand Up @@ -261,13 +255,7 @@ func (e *blockComputer) queueTransactionRequests(
systemCtx := fvm.NewContextFromParent(
e.systemChunkCtx,
fvm.WithBlockHeader(blockHeader),
// `protocol.Snapshot` implements `EntropyProvider` interface
// Note that `Snapshot` possible errors for RandomSource() are:
// - storage.ErrNotFound if the QC is unknown.
// - state.ErrUnknownSnapshotReference if the snapshot reference block is unknown
// However, at this stage, snapshot reference block should be known and the QC should also be known,
// so no error is expected in normal operations, as required by `EntropyProvider`.
fvm.WithEntropyProvider(e.protocolState.AtBlockID(blockId)),
fvm.WithProtocolStateSnapshot(e.protocolState.AtBlockID(blockId)),
)
systemCollectionLogger := systemCtx.Logger.With().
Str("block_id", blockIdStr).
Expand Down
3 changes: 0 additions & 3 deletions engine/execution/computation/computer/computer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,6 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
},
),
),
fvm.WithReadVersionFromNodeVersionBeacon(false),
)

vm := fvm.NewVirtualMachine()
Expand Down Expand Up @@ -818,7 +817,6 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
func(_ runtime.Config) runtime.Runtime {
return rt
})),
fvm.WithReadVersionFromNodeVersionBeacon(false),
)

vm := fvm.NewVirtualMachine()
Expand Down Expand Up @@ -933,7 +931,6 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
func(_ runtime.Config) runtime.Runtime {
return rt
})),
fvm.WithReadVersionFromNodeVersionBeacon(false),
)

vm := fvm.NewVirtualMachine()
Expand Down
4 changes: 2 additions & 2 deletions engine/execution/computation/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func New(
metrics module.ExecutionMetrics,
tracer module.Tracer,
me module.Local,
protoState protocol.State,
protoState protocol.SnapshotExecutionSubsetProvider,
vmCtx fvm.Context,
committer computer.ViewCommitter,
executionDataProvider provider.Provider,
Expand Down Expand Up @@ -140,7 +140,7 @@ func New(
vm,
vmCtx,
derivedChainData,
query.NewProtocolStateWrapper(protoState),
protoState,
)

e := Manager{
Expand Down
2 changes: 1 addition & 1 deletion engine/execution/computation/manager_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

blockstore "github.com/ipfs/boxo/blockstore"
"github.com/ipfs/boxo/blockstore"
"github.com/ipfs/go-datastore"
dssync "github.com/ipfs/go-datastore/sync"
"github.com/onflow/cadence/runtime"
Expand Down
40 changes: 0 additions & 40 deletions engine/execution/computation/query/entropy_provider.go

This file was deleted.

37 changes: 19 additions & 18 deletions engine/execution/computation/query/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/onflow/flow-go/fvm/storage/snapshot"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/utils/debug"
"github.com/onflow/flow-go/utils/rand"
)
Expand Down Expand Up @@ -110,14 +111,14 @@ func NewDefaultConfig() QueryConfig {
}

type QueryExecutor struct {
config QueryConfig
logger zerolog.Logger
metrics module.ExecutionMetrics
vm fvm.VM
vmCtx fvm.Context
derivedChainData *derived.DerivedChainData
rngLock *sync.Mutex
entropyPerBlock EntropyProviderPerBlock
config QueryConfig
logger zerolog.Logger
metrics module.ExecutionMetrics
vm fvm.VM
vmCtx fvm.Context
derivedChainData *derived.DerivedChainData
rngLock *sync.Mutex
protocolStateSnapshot protocol.SnapshotExecutionSubsetProvider
}

var _ Executor = &QueryExecutor{}
Expand All @@ -129,20 +130,20 @@ func NewQueryExecutor(
vm fvm.VM,
vmCtx fvm.Context,
derivedChainData *derived.DerivedChainData,
entropyPerBlock EntropyProviderPerBlock,
protocolStateSnapshot protocol.SnapshotExecutionSubsetProvider,
) *QueryExecutor {
if config.ComputationLimit > 0 {
vmCtx = fvm.NewContextFromParent(vmCtx, fvm.WithComputationLimit(config.ComputationLimit))
}
return &QueryExecutor{
config: config,
logger: logger,
metrics: metrics,
vm: vm,
vmCtx: vmCtx,
derivedChainData: derivedChainData,
rngLock: &sync.Mutex{},
entropyPerBlock: entropyPerBlock,
config: config,
logger: logger,
metrics: metrics,
vm: vm,
vmCtx: vmCtx,
derivedChainData: derivedChainData,
rngLock: &sync.Mutex{},
protocolStateSnapshot: protocolStateSnapshot,
}
}

Expand Down Expand Up @@ -215,7 +216,7 @@ func (e *QueryExecutor) ExecuteScript(
fvm.NewContextFromParent(
e.vmCtx,
fvm.WithBlockHeader(blockHeader),
fvm.WithEntropyProvider(e.entropyPerBlock.AtBlockID(blockHeader.ID())),
fvm.WithProtocolStateSnapshot(e.protocolStateSnapshot.AtBlockID(blockHeader.ID())),
fvm.WithDerivedBlockData(
e.derivedChainData.NewDerivedBlockDataForScript(blockHeader.ID()))),
fvm.NewScriptWithContextAndArgs(script, requestCtx, arguments...),
Expand Down

This file was deleted.

29 changes: 29 additions & 0 deletions engine/execution/computation/snapshot_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package computation

import (
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/state/protocol"
)

// SnapshotExecutionSubset is a subset of the protocol state snapshot that is needed by the FVM
var _ protocol.SnapshotExecutionSubset = (protocol.Snapshot)(nil)

// protocolStateWrapper just wraps the protocol.State and returns a SnapshotExecutionSubset
// from the AtBlockID method instead of the protocol.Snapshot interface.
type protocolStateWrapper struct {
protocol.State
}

// protocolStateWrapper implements `EntropyProviderPerBlock`
var _ protocol.SnapshotExecutionSubsetProvider = (*protocolStateWrapper)(nil)

func (p protocolStateWrapper) AtBlockID(blockID flow.Identifier) protocol.SnapshotExecutionSubset {
return p.State.AtBlockID(blockID)
}

// NewProtocolStateWrapper wraps the protocol.State input so that the AtBlockID method returns a
// SnapshotExecutionSubset instead of the protocol.Snapshot interface.
// This is used in the FVM for execution.
func NewProtocolStateWrapper(s protocol.State) protocol.SnapshotExecutionSubsetProvider {
return protocolStateWrapper{s}
}
Loading
Loading