From b3d12dab192add24069ce1a54b1c5afef427bad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 29 Aug 2024 14:43:41 +0300 Subject: [PATCH] Measure get block, get account. --- server/services/accountService.go | 30 ++++++++++++++++--- server/services/blockService.go | 16 ++++++++++ server/services/constants.go | 35 ++++++++++++---------- server/services/transactionsTransformer.go | 4 +-- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/server/services/accountService.go b/server/services/accountService.go index 153d32b7..0c79ed84 100644 --- a/server/services/accountService.go +++ b/server/services/accountService.go @@ -2,9 +2,11 @@ package services import ( "context" + "fmt" "github.com/coinbase/rosetta-sdk-go/server" "github.com/coinbase/rosetta-sdk-go/types" + "github.com/multiversx/mx-chain-core-go/core" ) type accountService struct { @@ -23,10 +25,30 @@ func NewAccountService(provider NetworkProvider) server.AccountAPIServicer { } // AccountBalance implements the /account/balance endpoint. -func (service *accountService) AccountBalance( - _ context.Context, - request *types.AccountBalanceRequest, -) (*types.AccountBalanceResponse, *types.Error) { +func (service *accountService) AccountBalance(_ context.Context, request *types.AccountBalanceRequest) (*types.AccountBalanceResponse, *types.Error) { + stopWatch := core.NewStopWatch() + stopWatch.Start("account") + + response, err := service.doGetAccountBalance(request) + if err != nil { + return nil, err + } + + stopWatch.Stop("account") + duration := stopWatch.GetMeasurement("account") + + if duration > durationAlarmThresholdAccountServiceGetAccountBalance { + log.Debug(fmt.Sprintf("accountService.AccountBalance() took more than %s", durationAlarmThresholdAccountServiceGetAccountBalance), + "duration", duration, + "address", request.AccountIdentifier.Address, + "blockNonce", response.BlockIdentifier.Index, + ) + } + + return response, nil +} + +func (service *accountService) doGetAccountBalance(request *types.AccountBalanceRequest) (*types.AccountBalanceResponse, *types.Error) { options, err := blockIdentifierToAccountQueryOptions(request.BlockIdentifier) if err != nil { return nil, service.errFactory.newErrWithOriginal(ErrUnableToGetAccount, err) diff --git a/server/services/blockService.go b/server/services/blockService.go index c96b9201..6f84c574 100644 --- a/server/services/blockService.go +++ b/server/services/blockService.go @@ -2,10 +2,12 @@ package services import ( "context" + "fmt" "sync" "github.com/coinbase/rosetta-sdk-go/server" "github.com/coinbase/rosetta-sdk-go/types" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-rosetta/server/resources" ) @@ -37,11 +39,25 @@ func (service *blockService) Block( _ context.Context, request *types.BlockRequest, ) (*types.BlockResponse, *types.Error) { + stopWatch := core.NewStopWatch() + stopWatch.Start("block") + response, err := service.doGetBlock(request) if err != nil { return nil, err } + stopWatch.Stop("block") + duration := stopWatch.GetMeasurement("block") + + if duration > durationAlarmThresholdBlockServiceGetBlock { + log.Debug(fmt.Sprintf("blockService.Block() took more than %s", durationAlarmThresholdBlockServiceGetBlock), + "duration", duration, + "blockNonce", response.Block.BlockIdentifier.Index, + "blockHash", response.Block.BlockIdentifier.Hash, + ) + } + traceBlockResponse(response) return response, nil } diff --git a/server/services/constants.go b/server/services/constants.go index 3f6e146a..954380d9 100644 --- a/server/services/constants.go +++ b/server/services/constants.go @@ -3,27 +3,30 @@ package services import ( "encoding/hex" "strings" + "time" "github.com/multiversx/mx-chain-core-go/core" ) var ( - transactionVersion = 1 - transactionProcessingTypeRelayedV1 = "RelayedTx" - transactionProcessingTypeBuiltInFunctionCall = "BuiltInFunctionCall" - transactionProcessingTypeMoveBalance = "MoveBalance" - transactionProcessingTypeContractInvoking = "SCInvoking" - transactionProcessingTypeContractDeployment = "SCDeployment" - amountZero = "0" - builtInFunctionClaimDeveloperRewards = core.BuiltInFunctionClaimDeveloperRewards - builtInFunctionESDTTransfer = core.BuiltInFunctionESDTTransfer - refundGasMessage = "refundedGas" - argumentsSeparator = "@" - sendingValueToNonPayableContractDataPrefix = argumentsSeparator + hex.EncodeToString([]byte("sending value to non payable contract")) - emptyHash = strings.Repeat("0", 64) - nodeVersionForOfflineRosetta = "N / A" - systemContractDeployAddress = "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu" - nativeAsESDTIdentifier = "EGLD-000000" + transactionVersion = 1 + transactionProcessingTypeRelayedV1 = "RelayedTx" + transactionProcessingTypeBuiltInFunctionCall = "BuiltInFunctionCall" + transactionProcessingTypeMoveBalance = "MoveBalance" + transactionProcessingTypeContractInvoking = "SCInvoking" + transactionProcessingTypeContractDeployment = "SCDeployment" + amountZero = "0" + builtInFunctionClaimDeveloperRewards = core.BuiltInFunctionClaimDeveloperRewards + builtInFunctionESDTTransfer = core.BuiltInFunctionESDTTransfer + refundGasMessage = "refundedGas" + argumentsSeparator = "@" + sendingValueToNonPayableContractDataPrefix = argumentsSeparator + hex.EncodeToString([]byte("sending value to non payable contract")) + emptyHash = strings.Repeat("0", 64) + nodeVersionForOfflineRosetta = "N / A" + systemContractDeployAddress = "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu" + nativeAsESDTIdentifier = "EGLD-000000" + durationAlarmThresholdBlockServiceGetBlock = time.Duration(250) * time.Millisecond + durationAlarmThresholdAccountServiceGetAccountBalance = time.Duration(250) * time.Millisecond ) var ( diff --git a/server/services/transactionsTransformer.go b/server/services/transactionsTransformer.go index 50a53ea1..7c98c70c 100644 --- a/server/services/transactionsTransformer.go +++ b/server/services/transactionsTransformer.go @@ -117,7 +117,7 @@ func (transformer *transactionsTransformer) unsignedTxToRosettaTx( txsInBlock []*transaction.ApiTransactionResult, ) *types.Transaction { if transformer.featuresDetector.isSmartContractResultIneffectiveRefund(scr) { - log.Info("unsignedTxToRosettaTx: ineffective refund", "hash", scr.Hash, "block", scr.BlockNonce) + log.Debug("unsignedTxToRosettaTx: ineffective refund", "hash", scr.Hash, "block", scr.BlockNonce) return &types.Transaction{ TransactionIdentifier: hashToTransactionIdentifier(scr.Hash), @@ -444,7 +444,7 @@ func (transformer *transactionsTransformer) addOperationsGivenTransactionEvents( } for _, event := range eventsTransferValueOnly { - log.Info("eventTransferValueOnly (effective)", "tx", tx.Hash, "block", tx.BlockNonce) + log.Debug("eventTransferValueOnly (effective)", "tx", tx.Hash, "block", tx.BlockNonce) operations := []*types.Operation{ {