Skip to content

Commit

Permalink
Measure get block, get account.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Aug 29, 2024
1 parent 2d96435 commit b3d12da
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
30 changes: 26 additions & 4 deletions server/services/accountService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions server/services/blockService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
35 changes: 19 additions & 16 deletions server/services/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions server/services/transactionsTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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{
{
Expand Down

0 comments on commit b3d12da

Please sign in to comment.