Skip to content

Commit

Permalink
Merge branch 'master' into script-executor-populate-env-values
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter authored Jul 20, 2023
2 parents 1aa6e3d + 7c2b340 commit 1237a59
Show file tree
Hide file tree
Showing 38 changed files with 540 additions and 376 deletions.
24 changes: 22 additions & 2 deletions engine/execution/computation/computer/computer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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 @@ -113,6 +114,7 @@ type blockComputer struct {
spockHasher hash.Hasher
receiptHasher hash.Hasher
colResCons []result.ExecutedCollectionConsumer
protocolState protocol.State
maxConcurrency int
}

Expand Down Expand Up @@ -141,6 +143,7 @@ func NewBlockComputer(
signer module.Local,
executionDataProvider *provider.Provider,
colResCons []result.ExecutedCollectionConsumer,
state protocol.State,
maxConcurrency int,
) (BlockComputer, error) {
if maxConcurrency < 1 {
Expand All @@ -164,6 +167,7 @@ func NewBlockComputer(
spockHasher: utils.NewSPOCKHasher(),
receiptHasher: utils.NewExecutionReceiptHasher(),
colResCons: colResCons,
protocolState: state,
maxConcurrency: maxConcurrency,
}, nil
}
Expand Down Expand Up @@ -204,7 +208,15 @@ func (e *blockComputer) queueTransactionRequests(

collectionCtx := fvm.NewContextFromParent(
e.vmCtx,
fvm.WithBlockHeader(blockHeader))
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)),
)

for idx, collection := range rawCollections {
collectionLogger := collectionCtx.Logger.With().
Expand Down Expand Up @@ -237,7 +249,15 @@ func (e *blockComputer) queueTransactionRequests(

systemCtx := fvm.NewContextFromParent(
e.systemChunkCtx,
fvm.WithBlockHeader(blockHeader))
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)),
)
systemCollectionLogger := systemCtx.Logger.With().
Str("block_id", blockIdStr).
Uint64("height", blockHeader.Height).
Expand Down
9 changes: 9 additions & 0 deletions engine/execution/computation/computer/computer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -306,6 +307,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -403,6 +405,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -462,6 +465,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -678,6 +682,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -788,6 +793,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -900,6 +906,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -944,6 +951,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -1263,6 +1271,7 @@ func Test_ExecutingSystemCollection(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ func executeBlockAndVerifyWithParameters(t *testing.T,
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testVerifyMaxConcurrency)
require.NoError(t, err)

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 @@ -119,8 +119,7 @@ func New(
// Capability Controllers are enabled everywhere except for Mainnet
CapabilityControllersEnabled: chainID != flow.Mainnet,
},
),
),
)),
}
if params.ExtensiveTracing {
options = append(options, fvm.WithExtensiveTracing())
Expand All @@ -138,6 +137,7 @@ func New(
me,
executionDataProvider,
nil, // TODO(ramtin): update me with proper consumers
protoState,
params.MaxConcurrency,
)

Expand Down
1 change: 1 addition & 0 deletions engine/execution/computation/manager_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func benchmarkComputeBlock(
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
maxConcurrency)
require.NoError(b, err)

Expand Down
2 changes: 2 additions & 0 deletions engine/execution/computation/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestComputeBlockWithStorage(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -835,6 +836,7 @@ func Test_EventEncodingFailsOnlyTxAndCarriesOn(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down
2 changes: 2 additions & 0 deletions engine/execution/computation/programs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func TestPrograms_TestContractUpdates(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down Expand Up @@ -249,6 +250,7 @@ func TestPrograms_TestBlockForks(t *testing.T) {
me,
prov,
nil,
testutil.ProtocolStateWithSourceFixture(nil),
testMaxConcurrency)
require.NoError(t, err)

Expand Down
32 changes: 32 additions & 0 deletions engine/execution/testutil/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ import (
"github.com/onflow/cadence"
"github.com/onflow/cadence/encoding/ccf"
jsoncdc "github.com/onflow/cadence/encoding/json"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/onflow/flow-go/crypto"
"github.com/onflow/flow-go/crypto/hash"
"github.com/onflow/flow-go/engine/execution"
"github.com/onflow/flow-go/engine/execution/utils"
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/fvm/environment"
envMock "github.com/onflow/flow-go/fvm/environment/mock"
"github.com/onflow/flow-go/fvm/storage/snapshot"
"github.com/onflow/flow-go/ledger"
"github.com/onflow/flow-go/ledger/common/pathfinder"
"github.com/onflow/flow-go/ledger/complete"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/module/epochs"
"github.com/onflow/flow-go/module/executiondatasync/execution_data"
"github.com/onflow/flow-go/state/protocol"
protocolMock "github.com/onflow/flow-go/state/protocol/mock"
"github.com/onflow/flow-go/utils/unittest"
)

Expand Down Expand Up @@ -626,3 +631,30 @@ func ComputationResultFixture(t *testing.T) *execution.ComputationResult {
},
}
}

// EntropyProviderFixture returns an entropy provider mock that
// supports RandomSource().
// If input is nil, a random source fixture is generated.
func EntropyProviderFixture(source []byte) environment.EntropyProvider {
if source == nil {
source = unittest.SignatureFixture()
}
provider := envMock.EntropyProvider{}
provider.On("RandomSource").Return(source, nil)
return &provider
}

// ProtocolStateWithSourceFixture returns a protocol state mock that only
// supports AtBlockID to return a snapshot mock.
// The snapshot mock only supports RandomSource().
// If input is nil, a random source fixture is generated.
func ProtocolStateWithSourceFixture(source []byte) protocol.State {
if source == nil {
source = unittest.SignatureFixture()
}
snapshot := &protocolMock.Snapshot{}
snapshot.On("RandomSource").Return(source, nil)
state := protocolMock.State{}
state.On("AtBlockID", mock.Anything).Return(snapshot)
return &state
}
3 changes: 2 additions & 1 deletion engine/verification/assigner/blockconsumer/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func withConsumer(
root, err := s.State.Params().FinalizedRoot()
require.NoError(t, err)
clusterCommittee := participants.Filter(filter.HasRole(flow.RoleCollection))
results := vertestutils.CompleteExecutionReceiptChainFixture(t, root, blockCount/2, vertestutils.WithClusterCommittee(clusterCommittee))
sources := unittest.RandomSourcesFixture(110)
results := vertestutils.CompleteExecutionReceiptChainFixture(t, root, blockCount/2, sources, vertestutils.WithClusterCommittee(clusterCommittee))
blocks := vertestutils.ExtendStateWithFinalizedBlocks(t, results, s.State)
// makes sure that we generated a block chain of requested length.
require.Len(t, blocks, blockCount)
Expand Down
6 changes: 4 additions & 2 deletions engine/verification/fetcher/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ func (e *Engine) pushToVerifier(chunk *flow.Chunk,
if err != nil {
return fmt.Errorf("could not get block: %w", err)
}

vchunk, err := e.makeVerifiableChunkData(chunk, header, result, chunkDataPack)
snapshot := e.state.AtBlockID(header.ID())
vchunk, err := e.makeVerifiableChunkData(chunk, header, snapshot, result, chunkDataPack)
if err != nil {
return fmt.Errorf("could not verify chunk: %w", err)
}
Expand All @@ -545,6 +545,7 @@ func (e *Engine) pushToVerifier(chunk *flow.Chunk,
// chunk data to verify it.
func (e *Engine) makeVerifiableChunkData(chunk *flow.Chunk,
header *flow.Header,
snapshot protocol.Snapshot,
result *flow.ExecutionResult,
chunkDataPack *flow.ChunkDataPack,
) (*verification.VerifiableChunkData, error) {
Expand All @@ -566,6 +567,7 @@ func (e *Engine) makeVerifiableChunkData(chunk *flow.Chunk,
IsSystemChunk: isSystemChunk,
Chunk: chunk,
Header: header,
Snapshot: snapshot,
Result: result,
ChunkDataPack: chunkDataPack,
EndState: endState,
Expand Down
Loading

0 comments on commit 1237a59

Please sign in to comment.