Skip to content

Commit

Permalink
Replace ID field in ProcedureReport with Path instead
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Mar 19, 2024
1 parent 004a0e0 commit 82897b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions emulator/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,12 +1298,14 @@ func (b *Blockchain) executeNextTransaction(ctx fvm.Context) (*types.Transaction
}

if b.conf.ComputationReportingEnabled {
location := common.NewTransactionLocation(nil, tr.TransactionID.Bytes())
arguments := make([]string, 0)
for _, argument := range txnBody.Arguments {
arguments = append(arguments, string(argument))
}
b.computationReport.ReportTransaction(
tr,
b.sourceFileMap[location],
b.currentCode,
arguments,
output.ComputationIntensities,
Expand Down Expand Up @@ -1538,12 +1540,14 @@ func (b *Blockchain) executeScriptAtBlockID(script []byte, arguments [][]byte, i
}

if b.conf.ComputationReportingEnabled {
location := common.NewScriptLocation(nil, scriptID.Bytes())
scriptArguments := make([]string, 0)
for _, argument := range arguments {
scriptArguments = append(scriptArguments, string(argument))
}
b.computationReport.ReportScript(
scriptResult,
b.sourceFileMap[location],
b.currentCode,
scriptArguments,
output.ComputationIntensities,
Expand Down
8 changes: 5 additions & 3 deletions emulator/computation_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

type ProcedureReport struct {
ID string `json:"ID"`
Path string `json:"path"`
ComputationUsed uint64 `json:"computation"`
// To get the computation from the intensities map, see:
// https://github.com/onflow/flow-go/blob/master/fvm/meter/computation_meter.go#L32-L39
Expand All @@ -43,12 +43,13 @@ type ComputationReport struct {

func (cr *ComputationReport) ReportScript(
scriptResult *types.ScriptResult,
path string,
code string,
arguments []string,
intensities meter.MeteredComputationIntensities,
) {
scriptReport := ProcedureReport{
ID: scriptResult.ScriptID.String(),
Path: path,
ComputationUsed: scriptResult.ComputationUsed,
Intensities: transformIntensities(intensities),
MemoryEstimate: scriptResult.MemoryEstimate,
Expand All @@ -60,12 +61,13 @@ func (cr *ComputationReport) ReportScript(

func (cr *ComputationReport) ReportTransaction(
txResult *types.TransactionResult,
path string,
code string,
arguments []string,
intensities meter.MeteredComputationIntensities,
) {
txReport := ProcedureReport{
ID: txResult.TransactionID.String(),
Path: path,
ComputationUsed: txResult.ComputationUsed,
Intensities: transformIntensities(intensities),
MemoryEstimate: txResult.MemoryEstimate,
Expand Down
2 changes: 0 additions & 2 deletions emulator/computation_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func TestComputationReportingForScript(t *testing.T) {
require.Len(t, computationReport.Scripts, 1)

scriptProfile := computationReport.Scripts[scriptResult.ScriptID.String()]
assert.Equal(t, scriptResult.ScriptID.String(), scriptProfile.ID)
assert.GreaterOrEqual(t, scriptProfile.ComputationUsed, uint64(1))

expectedIntensities := map[string]uint{
Expand Down Expand Up @@ -137,7 +136,6 @@ func TestComputationReportingForTransaction(t *testing.T) {
require.Len(t, computationReport.Transactions, 2)

txProfile := computationReport.Transactions[txResult.TransactionID.String()]
assert.Equal(t, tx.ID().String(), txProfile.ID)
assert.GreaterOrEqual(t, txProfile.ComputationUsed, uint64(1))

expectedIntensities := map[string]uint{
Expand Down

0 comments on commit 82897b1

Please sign in to comment.