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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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"
fvmExecution "github.com/onflow/flow-go/engine/execution"
"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),
fvmExecution.NewProtocolStateWrapper(builder.State),
builder.Storage.Headers,
builder.ExecutionIndexerCore.RegisterValue,
builder.scriptExecutorConfig,
Expand Down
3 changes: 2 additions & 1 deletion cmd/execution_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/onflow/flow-go/engine/common/provider"
"github.com/onflow/flow-go/engine/common/requester"
"github.com/onflow/flow-go/engine/common/synchronization"
"github.com/onflow/flow-go/engine/execution"
"github.com/onflow/flow-go/engine/execution/checker"
"github.com/onflow/flow-go/engine/execution/computation"
"github.com/onflow/flow-go/engine/execution/computation/committer"
Expand Down Expand Up @@ -569,7 +570,7 @@ func (exeNode *ExecutionNode) LoadProviderEngine(
collector,
node.Tracer,
node.Me,
node.State,
execution.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"
fvmExecution "github.com/onflow/flow-go/engine/execution"
"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),
fvmExecution.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
21 changes: 4 additions & 17 deletions engine/execution/computation/computer/computer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/onflow/flow-go/module/executiondatasync/provider"
"github.com/onflow/flow-go/module/mempool/entity"
"github.com/onflow/flow-go/module/trace"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/utils/logging"
)

Expand Down Expand Up @@ -115,7 +114,7 @@ type blockComputer struct {
spockHasher hash.Hasher
receiptHasher hash.Hasher
colResCons []result.ExecutedCollectionConsumer
protocolState protocol.State
protocolState fvm.ProtocolStateSnapshotProvider
maxConcurrency int
}

Expand Down Expand Up @@ -146,7 +145,7 @@ func NewBlockComputer(
signer module.Local,
executionDataProvider provider.Provider,
colResCons []result.ExecutedCollectionConsumer,
state protocol.State,
state fvm.ProtocolStateSnapshotProvider,
maxConcurrency int,
) (BlockComputer, error) {
if maxConcurrency < 1 {
Expand Down Expand Up @@ -220,13 +219,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(blockHeader.ID())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fvm.WithProtocolStateSnapshot(e.protocolState.AtBlockID(blockHeader.ID())),
fvm.WithProtocolStateSnapshot(e.protocolState.AtBlockID(blockID)),

)

for idx, collection := range rawCollections {
Expand Down Expand Up @@ -261,13 +254,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(blockHeader.ID())),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fvm.WithProtocolStateSnapshot(e.protocolState.AtBlockID(blockHeader.ID())),
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
5 changes: 2 additions & 3 deletions engine/execution/computation/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/executiondatasync/provider"
"github.com/onflow/flow-go/module/mempool/entity"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/utils/logging"
)

Expand Down Expand Up @@ -91,7 +90,7 @@ func New(
metrics module.ExecutionMetrics,
tracer module.Tracer,
me module.Local,
protoState protocol.State,
protoState fvm.ProtocolStateSnapshotProvider,
vmCtx fvm.Context,
committer computer.ViewCommitter,
executionDataProvider provider.Provider,
Expand Down Expand Up @@ -140,7 +139,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.

36 changes: 18 additions & 18 deletions engine/execution/computation/query/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,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 fvm.ProtocolStateSnapshotProvider
}

var _ Executor = &QueryExecutor{}
Expand All @@ -129,20 +129,20 @@ func NewQueryExecutor(
vm fvm.VM,
vmCtx fvm.Context,
derivedChainData *derived.DerivedChainData,
entropyPerBlock EntropyProviderPerBlock,
protocolStateSnapshot fvm.ProtocolStateSnapshotProvider,
) *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 +215,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.

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

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

// protocolStateWrapper implements `EntropyProviderPerBlock`
var _ fvm.ProtocolStateSnapshotProvider = protocolStateWrapper{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var _ fvm.ProtocolStateSnapshotProvider = protocolStateWrapper{}
var _ fvm.ProtocolStateSnapshotProvider = (*protocolStateWrapper)(nil)


type protocolStateWrapper struct {
protocol.State
}

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

// NewProtocolStateWrapper wraps a protocol.State input as an `EntropyProviderPerBlock`
func NewProtocolStateWrapper(s protocol.State) fvm.ProtocolStateSnapshotProvider {
return protocolStateWrapper{s}
}
Loading
Loading