diff --git a/emulator/blockchain.go b/emulator/blockchain.go index 4214603b..0bc76d7d 100644 --- a/emulator/blockchain.go +++ b/emulator/blockchain.go @@ -1795,18 +1795,30 @@ func (b *Blockchain) GetSourceFile(location common.Location) string { } func (b *Blockchain) systemChunkTransaction() (*flowgo.TransactionBody, error) { + serviceAddress := b.GetChain().ServiceAddress() + script := templates.ReplaceAddresses( systemChunkTransactionTemplate, templates.Environment{ - RandomBeaconHistoryAddress: b.GetChain().ServiceAddress().Hex(), + RandomBeaconHistoryAddress: serviceAddress.Hex(), }, ) + // TODO: move this to `templates.Environment` struct + script = strings.ReplaceAll( + script, + `import EVM from "EVM"`, + fmt.Sprintf( + "import EVM from %s", + serviceAddress.HexWithPrefix(), + ), + ) + tx := flowgo.NewTransactionBody(). SetScript([]byte(script)). SetComputeLimit(flowgo.DefaultMaxTransactionGasLimit). - AddAuthorizer(b.GetChain().ServiceAddress()). - SetPayer(b.GetChain().ServiceAddress()). + AddAuthorizer(serviceAddress). + SetPayer(serviceAddress). SetReferenceBlockID(b.pendingBlock.parentID) return tx, nil diff --git a/emulator/templates/systemChunkTransactionTemplate.cdc b/emulator/templates/systemChunkTransactionTemplate.cdc index 4a980dde..ef714ed2 100644 --- a/emulator/templates/systemChunkTransactionTemplate.cdc +++ b/emulator/templates/systemChunkTransactionTemplate.cdc @@ -1,4 +1,5 @@ import RandomBeaconHistory from "RandomBeaconHistory" +import EVM from "EVM" transaction { prepare(serviceAccount: auth(BorrowValue) &Account) { @@ -6,5 +7,10 @@ transaction { .borrow<&RandomBeaconHistory.Heartbeat>(from: RandomBeaconHistory.HeartbeatStoragePath) ?? panic("Couldn't borrow RandomBeaconHistory.Heartbeat Resource") randomBeaconHistoryHeartbeat.heartbeat(randomSourceHistory: randomSourceHistory()) + + let evmHeartbeat = serviceAccount.storage + .borrow<&EVM.Heartbeat>(from: /storage/EVMHeartbeat) + ?? panic("Couldn't borrow EVM.Heartbeat Resource") + evmHeartbeat.heartbeat() } } diff --git a/server/access/streamBackend.go b/server/access/streamBackend.go index cffffb95..3f57418e 100644 --- a/server/access/streamBackend.go +++ b/server/access/streamBackend.go @@ -24,10 +24,12 @@ import ( "fmt" "time" + "github.com/onflow/cadence/runtime/common" "github.com/onflow/flow-go/engine/access/state_stream" "github.com/onflow/flow-go/engine/access/state_stream/backend" "github.com/onflow/flow-go/engine/access/subscription" "github.com/onflow/flow-go/engine/common/rpc" + evmEvents "github.com/onflow/flow-go/fvm/evm/events" "github.com/onflow/flow-go/model/flow" "github.com/onflow/flow-go/module/executiondatasync/execution_data" "github.com/onflow/flow-go/storage" @@ -196,6 +198,30 @@ func getExecutionDataFunc(blockchain *emulator.Blockchain) GetExecutionDataFunc chunks[i] = chunk } + // The `EVM.BlockExecuted` event is only emitted from the + // system chunk transaction, and we need to make it available + // in the returned response. + evmBlockExecutedEventType := common.AddressLocation{ + Address: common.Address(blockchain.GetChain().ServiceAddress()), + Name: string(evmEvents.EventTypeBlockExecuted), + } + + events, err := blockchain.GetEventsByHeight( + height, + evmBlockExecutedEventType.ID(), + ) + if err != nil { + return nil, err + } + // Add the `EVM.BlockExecuted` event to the events of the last + // chunk. + if len(chunks) > 0 { + lastChunk := chunks[len(chunks)-1] + for _, event := range events { + lastChunk.Events = append(lastChunk.Events, event) + } + } + executionData := &execution_data.BlockExecutionData{ BlockID: block.ID(), ChunkExecutionDatas: chunks, diff --git a/storage/migration/cadence1_test.go b/storage/migration/cadence1_test.go index 7acbbbcc..d7aa8f96 100644 --- a/storage/migration/cadence1_test.go +++ b/storage/migration/cadence1_test.go @@ -94,7 +94,7 @@ func migrateEmulatorState(t *testing.T, store *sqlite.Store) { err := MigrateCadence1( store, t.TempDir(), - migrations.EVMContractChangeNone, + migrations.EVMContractChangeDeployMinimalAndUpdateFull, migrations.BurnerContractChangeDeploy, stagedContracts, rwf,