Skip to content
Open
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
20 changes: 2 additions & 18 deletions cmd/util/ledger/util/nop_meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ type NopMeter struct{}

func (n NopMeter) RunWithMeteringDisabled(f func()) {}

func (n NopMeter) ComputationAvailable(_ common.ComputationUsage) bool {
return false
}

func (n NopMeter) MeterComputation(_ common.ComputationUsage) error {
return nil
}

func (n NopMeter) ComputationUsed() (uint64, error) {
return 0, nil
}

func (n NopMeter) ComputationIntensities() meter.MeteredComputationIntensities {
return meter.MeteredComputationIntensities{}
func (n NopMeter) MeteringResult() (meter.MeteringResult, error) {
return meter.MeteringResult{}, nil
}

func (n NopMeter) ComputationRemaining(_ common.ComputationKind) uint64 {
Expand All @@ -38,18 +30,10 @@ func (n NopMeter) MeterMemory(_ common.MemoryUsage) error {
return nil
}

func (n NopMeter) MemoryUsed() (uint64, error) {
return 0, nil
}

func (n NopMeter) MeterEmittedEvent(_ uint64) error {
return nil
}

func (n NopMeter) TotalEmittedEventBytes() uint64 {
return 0
}

func (n NopMeter) InteractionUsed() (uint64, error) {
return 0, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/fvm/inspection"
"github.com/onflow/flow-go/fvm/meter"
"github.com/onflow/flow-go/fvm/storage"
"github.com/onflow/flow-go/fvm/storage/logical"
"github.com/onflow/flow-go/fvm/storage/snapshot"
Expand Down Expand Up @@ -77,7 +78,7 @@ func (testCoordinatorExecutor) Execute() error {

func (executor testCoordinatorExecutor) Output() fvm.ProcedureOutput {
return fvm.ProcedureOutput{
ComputationUsed: uint64(executor.executionTime),
MeteringResult: meter.MeteringResult{ComputationUsed: uint64(executor.executionTime)},
}
}

Expand Down
4 changes: 0 additions & 4 deletions fvm/environment/event_emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ func (collection *EventCollection) AppendServiceEvent(
return collection.meter.MeterEmittedEvent(size)
}

func (collection *EventCollection) TotalByteSize() uint64 {
return collection.meter.TotalEmittedEventBytes()
}

func (collection *EventCollection) TotalEventCounter() uint32 {
return collection.eventCounter
}
Expand Down
63 changes: 13 additions & 50 deletions fvm/environment/meter.go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

brief documentation of errors would be great on MeteringResult and MeterComputation, specifically because it seems we are dealing with sentinel errors. Please consider this as very desired but still optional, just in case properly documenting expected error returns would require a large stack of code changes at the lower layers.

Original file line number Diff line number Diff line change
Expand Up @@ -107,71 +107,34 @@ var MainnetExecutionEffortWeights = meter.ExecutionEffortWeights{
type Meter interface {
common.Gauge

ComputationUsed() (uint64, error)
MemoryUsed() (uint64, error)
// MeteringResult returns the metering totals accumulated so far.
//
// No error returns are expected during normal operation.
MeteringResult() (meter.MeteringResult, error)

ComputationIntensities() meter.MeteredComputationIntensities
ComputationAvailable(common.ComputationUsage) bool
ComputationRemaining(kind common.ComputationKind) uint64

MeterEmittedEvent(byteSize uint64) error
TotalEmittedEventBytes() uint64

RunWithMeteringDisabled(f func())
}

type meterImpl struct {
txnState state.NestedTransactionPreparer
state.NestedTransactionPreparer
}

func NewMeter(txnState state.NestedTransactionPreparer) Meter {
return &meterImpl{
txnState: txnState,
NestedTransactionPreparer: txnState,
}
}

func (meter *meterImpl) MeterComputation(usage common.ComputationUsage) error {
return meter.txnState.MeterComputation(usage)
}

func (meter *meterImpl) ComputationIntensities() meter.MeteredComputationIntensities {
return meter.txnState.ComputationIntensities()
}

func (meter *meterImpl) ComputationAvailable(usage common.ComputationUsage) bool {
return meter.txnState.ComputationAvailable(usage)
}

func (meter *meterImpl) ComputationRemaining(kind common.ComputationKind) uint64 {
return meter.txnState.ComputationRemaining(kind)
}

func (meter *meterImpl) ComputationUsed() (uint64, error) {
return meter.txnState.TotalComputationUsed(), nil
}

func (meter *meterImpl) MeterMemory(usage common.MemoryUsage) error {
return meter.txnState.MeterMemory(usage)
}

func (meter *meterImpl) MemoryUsed() (uint64, error) {
return meter.txnState.TotalMemoryEstimate(), nil
}

func (meter *meterImpl) InteractionUsed() (uint64, error) {
return meter.txnState.InteractionUsed(), nil
}

func (meter *meterImpl) MeterEmittedEvent(byteSize uint64) error {
return meter.txnState.MeterEmittedEvent(byteSize)
}

func (meter *meterImpl) TotalEmittedEventBytes() uint64 {
return meter.txnState.TotalEmittedEventBytes()
}

func (meter *meterImpl) RunWithMeteringDisabled(f func()) {
meter.txnState.RunWithMeteringDisabled(f)
func (m *meterImpl) MeteringResult() (meter.MeteringResult, error) {
return meter.MeteringResult{
ComputationUsed: m.TotalComputationUsed(),
MemoryEstimate: m.TotalMemoryEstimate(),
ComputationIntensities: m.ComputationIntensities(),
}, nil
}

type cancellableMeter struct {
Expand All @@ -186,7 +149,7 @@ func NewCancellableMeter(
) Meter {
return &cancellableMeter{
meterImpl: meterImpl{
txnState: txnState,
NestedTransactionPreparer: txnState,
},
ctx: ctx,
}
Expand Down
Loading
Loading