From 6a50f9851c42b94eb3eeea7c1ae944bd600226e3 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Thu, 5 Oct 2023 15:06:37 +0300 Subject: [PATCH 1/2] Added stopwatches in important functions. --- go/enclave/enclave.go | 3 +++ go/enclave/evm/evm_facade.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/go/enclave/enclave.go b/go/enclave/enclave.go index b4ea2ba6e4..3206629e93 100644 --- a/go/enclave/enclave.go +++ b/go/enclave/enclave.go @@ -1006,6 +1006,8 @@ func (e *enclaveImpl) EstimateGas(encryptedParams common.EncryptedParamsEstimate return nil, responses.ToInternalError(fmt.Errorf("requested EstimateGas with the enclave stopping")) } + defer core.LogMethodDuration(e.logger, measure.NewStopwatch(), "enclave.go:EstimateGas()") + // decode the received request into a []interface paramList, err := e.decodeRequest(encryptedParams) if err != nil { @@ -1396,6 +1398,7 @@ func (e *enclaveImpl) GetPublicTransactionData(pagination *common.QueryPaginatio // Create a helper to check if a gas allowance results in an executable transaction // isGasEnough returns whether the gaslimit should be raised, lowered, or if it was impossible to execute the message func (e *enclaveImpl) isGasEnough(args *gethapi.TransactionArgs, gas uint64, blkNumber *gethrpc.BlockNumber) (bool, *gethcore.ExecutionResult, error) { + core.LogMethodDuration(e.logger, measure.NewStopwatch(), "enclave.go:IsGasEnough") args.Gas = (*hexutil.Uint64)(&gas) result, err := e.chain.ObsCallAtBlock(args, blkNumber) if err != nil { diff --git a/go/enclave/evm/evm_facade.go b/go/enclave/evm/evm_facade.go index b35e0e9e79..08550c5f8a 100644 --- a/go/enclave/evm/evm_facade.go +++ b/go/enclave/evm/evm_facade.go @@ -16,6 +16,8 @@ import ( "github.com/obscuronet/go-obscuro/go/common/errutil" "github.com/obscuronet/go-obscuro/go/common/gethencoding" "github.com/obscuronet/go-obscuro/go/common/log" + "github.com/obscuronet/go-obscuro/go/common/measure" + "github.com/obscuronet/go-obscuro/go/enclave/core" "github.com/obscuronet/go-obscuro/go/enclave/crypto" "github.com/obscuronet/go-obscuro/go/enclave/storage" @@ -162,6 +164,8 @@ func ExecuteObsCall( noBaseFee = false } + core.LogMethodDuration(logger, measure.NewStopwatch(), "evm_facade.go:ObsCall()") + chain, vmCfg, gp := initParams(storage, noBaseFee, nil) ethHeader, err := gethencoding.CreateEthHeaderForBatch(header, secret(storage)) if err != nil { From 65754a768175f7fa9da156fb8c8f52797d9afe7e Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Thu, 5 Oct 2023 17:36:19 +0300 Subject: [PATCH 2/2] Using defer. --- go/enclave/enclave.go | 2 +- go/enclave/evm/evm_facade.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go/enclave/enclave.go b/go/enclave/enclave.go index 3206629e93..da711fcb15 100644 --- a/go/enclave/enclave.go +++ b/go/enclave/enclave.go @@ -1398,7 +1398,7 @@ func (e *enclaveImpl) GetPublicTransactionData(pagination *common.QueryPaginatio // Create a helper to check if a gas allowance results in an executable transaction // isGasEnough returns whether the gaslimit should be raised, lowered, or if it was impossible to execute the message func (e *enclaveImpl) isGasEnough(args *gethapi.TransactionArgs, gas uint64, blkNumber *gethrpc.BlockNumber) (bool, *gethcore.ExecutionResult, error) { - core.LogMethodDuration(e.logger, measure.NewStopwatch(), "enclave.go:IsGasEnough") + defer core.LogMethodDuration(e.logger, measure.NewStopwatch(), "enclave.go:IsGasEnough") args.Gas = (*hexutil.Uint64)(&gas) result, err := e.chain.ObsCallAtBlock(args, blkNumber) if err != nil { diff --git a/go/enclave/evm/evm_facade.go b/go/enclave/evm/evm_facade.go index 08550c5f8a..cf0fc976f4 100644 --- a/go/enclave/evm/evm_facade.go +++ b/go/enclave/evm/evm_facade.go @@ -164,7 +164,7 @@ func ExecuteObsCall( noBaseFee = false } - core.LogMethodDuration(logger, measure.NewStopwatch(), "evm_facade.go:ObsCall()") + defer core.LogMethodDuration(logger, measure.NewStopwatch(), "evm_facade.go:ObsCall()") chain, vmCfg, gp := initParams(storage, noBaseFee, nil) ethHeader, err := gethencoding.CreateEthHeaderForBatch(header, secret(storage))