From 260244d3969fcb16bbaf583753297264b092bb1c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 23 Nov 2023 17:56:34 +0200 Subject: [PATCH 1/4] wrapped all ErrSendingRequest --- process/accountProcessor.go | 48 ++++++++-------- process/accountProcessor_test.go | 4 +- process/blockProcessor.go | 36 ++++++------ process/blockProcessor_test.go | 16 +++--- process/economicMetrics.go | 7 ++- process/esdtSupplyProcessor.go | 5 +- process/nodeGroupProcessor.go | 2 +- process/nodeGroupProcessor_test.go | 4 +- process/nodeStatusProcessor.go | 66 +++++++++++----------- process/nodeStatusProcessor_test.go | 18 +++--- process/proofProcessor.go | 16 +++--- process/scQueryProcessor.go | 4 +- process/scQueryProcessor_test.go | 2 +- process/transactionProcessor.go | 8 +-- process/txcost/transactionCostProcessor.go | 5 +- 15 files changed, 122 insertions(+), 119 deletions(-) diff --git a/process/accountProcessor.go b/process/accountProcessor.go index 75cf7b52..25210160 100644 --- a/process/accountProcessor.go +++ b/process/accountProcessor.go @@ -57,8 +57,8 @@ func (ap *AccountProcessor) GetAccount(address string, options common.AccountQue return nil, err } + responseAccount := &data.AccountApiResponse{} for _, observer := range observers { - responseAccount := &data.AccountApiResponse{} url := common.BuildUrlWithAccountQueryOptions(addressPath+address, options) _, err = ap.proc.CallGetRestEndPoint(observer.Address, url, responseAccount) @@ -70,7 +70,7 @@ func (ap *AccountProcessor) GetAccount(address string, options common.AccountQue log.Error("account request", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseAccount.Error) } // GetValueForKey returns the value for the given address and key @@ -80,8 +80,8 @@ func (ap *AccountProcessor) GetValueForKey(address string, key string, options c return "", err } + apiResponse := data.AccountKeyValueResponse{} for _, observer := range observers { - apiResponse := data.AccountKeyValueResponse{} apiPath := addressPath + address + "/key/" + key apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -101,7 +101,7 @@ func (ap *AccountProcessor) GetValueForKey(address string, key string, options c log.Error("account value for key request", "observer", observer.Address, "address", address, "error", err.Error()) } - return "", ErrSendingRequest + return "", fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetESDTTokenData returns the token data for a token with the given name @@ -111,8 +111,8 @@ func (ap *AccountProcessor) GetESDTTokenData(address string, key string, options return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/esdt/" + key apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -133,7 +133,7 @@ func (ap *AccountProcessor) GetESDTTokenData(address string, key string, options log.Error("account get ESDT token data", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetESDTsWithRole returns the token identifiers where the given address has the given role assigned @@ -143,8 +143,8 @@ func (ap *AccountProcessor) GetESDTsWithRole(address string, role string, option return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/esdts-with-role/" + role apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -165,7 +165,7 @@ func (ap *AccountProcessor) GetESDTsWithRole(address string, role string, option log.Error("account get ESDTs with role", "observer", observer.Address, "address", address, "role", role, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetESDTsRoles returns all the tokens and their roles for a given address @@ -175,8 +175,8 @@ func (ap *AccountProcessor) GetESDTsRoles(address string, options common.Account return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/esdts/roles" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, errGet := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -196,7 +196,7 @@ func (ap *AccountProcessor) GetESDTsRoles(address string, options common.Account log.Error("account get ESDTs roles", "observer", observer.Address, "address", address, "error", errGet.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetNFTTokenIDsRegisteredByAddress returns the token identifiers of the NFTs registered by the address @@ -208,8 +208,8 @@ func (ap *AccountProcessor) GetNFTTokenIDsRegisteredByAddress(address string, op return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/registered-nfts/" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -229,7 +229,7 @@ func (ap *AccountProcessor) GetNFTTokenIDsRegisteredByAddress(address string, op log.Error("account get owned NFTs", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetESDTNftTokenData returns the nft token data for a token with the given identifier and nonce @@ -239,8 +239,8 @@ func (ap *AccountProcessor) GetESDTNftTokenData(address string, key string, nonc return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} nonceAsString := fmt.Sprintf("%d", nonce) apiPath := addressPath + address + "/nft/" + key + "/nonce/" + nonceAsString apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) @@ -262,7 +262,7 @@ func (ap *AccountProcessor) GetESDTNftTokenData(address string, key string, nonc log.Error("account get ESDT nft token data", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetAllESDTTokens returns all the tokens for a given address @@ -272,8 +272,8 @@ func (ap *AccountProcessor) GetAllESDTTokens(address string, options common.Acco return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/esdt" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -293,7 +293,7 @@ func (ap *AccountProcessor) GetAllESDTTokens(address string, options common.Acco log.Error("account get all ESDT tokens", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetKeyValuePairs returns all the key-value pairs for a given address @@ -303,8 +303,8 @@ func (ap *AccountProcessor) GetKeyValuePairs(address string, options common.Acco return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/keys" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -324,7 +324,7 @@ func (ap *AccountProcessor) GetKeyValuePairs(address string, options common.Acco log.Error("account get all key-value pairs error", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetGuardianData returns the guardian data for the given address @@ -334,8 +334,8 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/guardian-data" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -355,7 +355,7 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou log.Error("account get guardian data", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } // GetTransactions resolves the request and returns a slice of transaction for the specific address @@ -374,8 +374,8 @@ func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQu return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/code-hash" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -395,7 +395,7 @@ func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQu log.Error("account get code hash error", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } func (ap *AccountProcessor) getObserversForAddress(address string) ([]*data.NodeData, error) { @@ -429,8 +429,8 @@ func (ap *AccountProcessor) IsDataTrieMigrated(address string, options common.Ac return nil, err } + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { - apiResponse := data.GenericAPIResponse{} apiPath := addressPath + address + "/is-data-trie-migrated" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) @@ -450,5 +450,5 @@ func (ap *AccountProcessor) IsDataTrieMigrated(address string, options common.Ac log.Error("account is data trie migrated", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } diff --git a/process/accountProcessor_test.go b/process/accountProcessor_test.go index eeef7123..9c8c5396 100644 --- a/process/accountProcessor_test.go +++ b/process/accountProcessor_test.go @@ -127,7 +127,7 @@ func TestAccountProcessor_GetAccountSendingFailsOnAllObserversShouldErr(t *testi accnt, err := ap.GetAccount(address, common.AccountQueryOptions{}) assert.Nil(t, accnt) - assert.Equal(t, process.ErrSendingRequest, err) + assert.True(t, errors.Is(err, process.ErrSendingRequest)) } func TestAccountProcessor_GetAccountSendingFailsOnFirstObserverShouldStillSend(t *testing.T) { @@ -228,7 +228,7 @@ func TestAccountProcessor_GetValueForAKeyShouldError(t *testing.T) { addr1 := "DEADBEEF" value, err := ap.GetValueForKey(addr1, key, common.AccountQueryOptions{}) assert.Equal(t, "", value) - assert.Equal(t, process.ErrSendingRequest, err) + assert.True(t, errors.Is(err, process.ErrSendingRequest)) } func TestAccountProcessor_GetShardIForAddressShouldWork(t *testing.T) { diff --git a/process/blockProcessor.go b/process/blockProcessor.go index a983262d..5ebf3fd5 100644 --- a/process/blockProcessor.go +++ b/process/blockProcessor.go @@ -70,8 +70,8 @@ func (bp *BlockProcessor) GetBlockByHash(shardID uint32, hash string, options co path := common.BuildUrlWithBlockQueryOptions(fmt.Sprintf("%s/%s", blockByHashPath, hash), options) + var response data.BlockApiResponse for _, observer := range observers { - var response data.BlockApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -84,7 +84,7 @@ func (bp *BlockProcessor) GetBlockByHash(shardID uint32, hash string, options co } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } // GetBlockByNonce will return the block based on the nonce @@ -96,8 +96,8 @@ func (bp *BlockProcessor) GetBlockByNonce(shardID uint32, nonce uint64, options path := common.BuildUrlWithBlockQueryOptions(fmt.Sprintf("%s/%d", blockByNoncePath, nonce), options) + var response data.BlockApiResponse for _, observer := range observers { - var response data.BlockApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -110,7 +110,7 @@ func (bp *BlockProcessor) GetBlockByNonce(shardID uint32, nonce uint64, options } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } func (bp *BlockProcessor) getObserversOrFullHistoryNodes(shardID uint32) ([]*data.NodeData, error) { @@ -226,8 +226,8 @@ func (bp *BlockProcessor) GetInternalBlockByHash(shardID uint32, hash string, fo return nil, err } + var response data.InternalBlockApiResponse for _, observer := range observers { - var response data.InternalBlockApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -240,7 +240,7 @@ func (bp *BlockProcessor) GetInternalBlockByHash(shardID uint32, hash string, fo } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } func getInternalBlockByHashPath(shardID uint32, format common.OutputFormat, hash string) (string, error) { @@ -272,8 +272,8 @@ func (bp *BlockProcessor) GetInternalBlockByNonce(shardID uint32, nonce uint64, return nil, err } + var response data.InternalBlockApiResponse for _, observer := range observers { - var response data.InternalBlockApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -286,7 +286,7 @@ func (bp *BlockProcessor) GetInternalBlockByNonce(shardID uint32, nonce uint64, } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } func getInternalBlockByNoncePath(shardID uint32, format common.OutputFormat, nonce uint64) (string, error) { @@ -319,8 +319,8 @@ func (bp *BlockProcessor) GetInternalMiniBlockByHash(shardID uint32, hash string } path := fmt.Sprintf(internalMiniBlockByHashPath, outputStr, hash, epoch) + var response data.InternalMiniBlockApiResponse for _, observer := range observers { - var response data.InternalMiniBlockApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -333,7 +333,7 @@ func (bp *BlockProcessor) GetInternalMiniBlockByHash(shardID uint32, hash string } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } func getOutputFormat(format common.OutputFormat) (string, error) { @@ -365,8 +365,8 @@ func (bp *BlockProcessor) GetInternalStartOfEpochMetaBlock(epoch uint32, format path := fmt.Sprintf(internalStartOfEpochMetaBlockPath, outputStr, epoch) + var response data.InternalBlockApiResponse for _, observer := range observers { - var response data.InternalBlockApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -379,7 +379,7 @@ func (bp *BlockProcessor) GetInternalStartOfEpochMetaBlock(epoch uint32, format } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } // GetInternalStartOfEpochValidatorsInfo will return the internal start of epoch validators info based on epoch @@ -391,8 +391,8 @@ func (bp *BlockProcessor) GetInternalStartOfEpochValidatorsInfo(epoch uint32) (* path := fmt.Sprintf(internalStartOfEpochValidatorsInfoPath, epoch) + var response data.ValidatorsInfoApiResponse for _, observer := range observers { - var response data.ValidatorsInfoApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -405,7 +405,7 @@ func (bp *BlockProcessor) GetInternalStartOfEpochValidatorsInfo(epoch uint32) (* } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } // GetAlteredAccountsByNonce will return altered accounts by block nonce @@ -416,8 +416,8 @@ func (bp *BlockProcessor) GetAlteredAccountsByNonce(shardID uint32, nonce uint64 } path := common.BuildUrlWithAlteredAccountsQueryOptions(fmt.Sprintf("%s/%d", alteredAccountByBlockNonce, nonce), options) + var response data.AlteredAccountsApiResponse for _, observer := range observers { - var response data.AlteredAccountsApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -430,7 +430,7 @@ func (bp *BlockProcessor) GetAlteredAccountsByNonce(shardID uint32, nonce uint64 } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } // GetAlteredAccountsByHash will return altered accounts by block hash @@ -441,8 +441,8 @@ func (bp *BlockProcessor) GetAlteredAccountsByHash(shardID uint32, hash string, } path := common.BuildUrlWithAlteredAccountsQueryOptions(fmt.Sprintf("%s/%s", alteredAccountByBlockHash, hash), options) + var response data.AlteredAccountsApiResponse for _, observer := range observers { - var response data.AlteredAccountsApiResponse _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { @@ -455,5 +455,5 @@ func (bp *BlockProcessor) GetAlteredAccountsByHash(shardID uint32, hash string, } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } diff --git a/process/blockProcessor_test.go b/process/blockProcessor_test.go index 729e6e9c..ed637a9a 100644 --- a/process/blockProcessor_test.go +++ b/process/blockProcessor_test.go @@ -143,7 +143,7 @@ func TestBlockProcessor_GetBlockByHashCallGetFailsShouldErr(t *testing.T) { require.NotNil(t, bp) res, err := bp.GetBlockByHash(0, "hash", common.BlockQueryOptions{}) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) } @@ -292,7 +292,7 @@ func TestBlockProcessor_GetBlockByNonceCallGetFailsShouldErr(t *testing.T) { require.NotNil(t, bp) res, err := bp.GetBlockByNonce(0, 0, common.BlockQueryOptions{}) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) } @@ -508,7 +508,7 @@ func TestBlockProcessor_GetInternalBlockByNonceCallGetFailsShouldErr(t *testing. require.NotNil(t, bp) res, err := bp.GetInternalBlockByNonce(0, 0, common.Internal) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) } @@ -656,7 +656,7 @@ func TestBlockProcessor_GetInternalBlockByHashCallGetFailsShouldErr(t *testing.T require.NotNil(t, bp) res, err := bp.GetInternalBlockByHash(0, "aaaa", common.Internal) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) } @@ -803,7 +803,7 @@ func TestBlockProcessor_GetInternalMiniBlockByHashCallGetFailsShouldErr(t *testi require.NotNil(t, bp) res, err := bp.GetInternalMiniBlockByHash(0, "aaaa", 1, common.Internal) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) } @@ -951,7 +951,7 @@ func TestBlockProcessor_GetInternalStartOfEpochMetaBlockCallGetFailsShouldErr(t require.NotNil(t, bp) res, err := bp.GetInternalStartOfEpochMetaBlock(0, common.Internal) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) } @@ -1037,7 +1037,7 @@ func TestBlockProcessor_GetAlteredAccountsByNonce(t *testing.T) { bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) res, err := bp.GetAlteredAccountsByNonce(requestedShardID, 4, common.GetAlteredAccountsForBlockOptions{}) require.Equal(t, 2, callGetEndpointCt) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) }) @@ -1124,7 +1124,7 @@ func TestBlockProcessor_GetAlteredAccountsByHash(t *testing.T) { bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) res, err := bp.GetAlteredAccountsByHash(requestedShardID, "hash", common.GetAlteredAccountsForBlockOptions{}) require.Equal(t, 2, callGetEndpointCt) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) require.Nil(t, res) }) diff --git a/process/economicMetrics.go b/process/economicMetrics.go index 6f4dd3bc..fa73aae3 100644 --- a/process/economicMetrics.go +++ b/process/economicMetrics.go @@ -2,6 +2,7 @@ package process import ( "context" + "fmt" "time" "github.com/multiversx/mx-chain-core-go/core" @@ -28,8 +29,8 @@ func (nsp *NodeStatusProcessor) getEconomicsDataMetricsFromApi() (*data.GenericA } func (nsp *NodeStatusProcessor) getEconomicsDataMetrics(observers []*data.NodeData) (*data.GenericAPIResponse, error) { + var responseNetworkMetrics data.GenericAPIResponse for _, observer := range observers { - var responseNetworkMetrics *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, EconomicsDataPath, &responseNetworkMetrics) if err != nil { @@ -38,10 +39,10 @@ func (nsp *NodeStatusProcessor) getEconomicsDataMetrics(observers []*data.NodeDa } log.Info("economics data request", "shard id", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) } // StartCacheUpdate will update the economic metrics cache at a given time diff --git a/process/esdtSupplyProcessor.go b/process/esdtSupplyProcessor.go index 37998d80..161e085b 100644 --- a/process/esdtSupplyProcessor.go +++ b/process/esdtSupplyProcessor.go @@ -1,6 +1,7 @@ package process import ( + "fmt" "math/big" "strings" @@ -161,9 +162,9 @@ func (esp *esdtSupplyProcessor) getShardSupply(token string, shardID uint32) (*d return nil, errObs } + var responseEsdtSupply data.ESDTSupplyResponse apiPath := networkESDTSupplyPath + token for _, observer := range shardObservers { - var responseEsdtSupply data.ESDTSupplyResponse _, errGet := esp.baseProc.CallGetRestEndPoint(observer.Address, apiPath, &responseEsdtSupply) if errGet != nil { @@ -177,7 +178,7 @@ func (esp *esdtSupplyProcessor) getShardSupply(token string, shardID uint32) (*d } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseEsdtSupply.Error) } func isFungibleESDT(tokenIdentifier string) bool { diff --git a/process/nodeGroupProcessor.go b/process/nodeGroupProcessor.go index caf4bf92..c859259b 100644 --- a/process/nodeGroupProcessor.go +++ b/process/nodeGroupProcessor.go @@ -87,7 +87,7 @@ func (ngp *NodeGroupProcessor) IsOldStorageForToken(tokenID string, nonce uint64 return false, nil } } else { - return false, ErrSendingRequest + return false, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) } } diff --git a/process/nodeGroupProcessor_test.go b/process/nodeGroupProcessor_test.go index 0c960bf5..9f5ba0e2 100644 --- a/process/nodeGroupProcessor_test.go +++ b/process/nodeGroupProcessor_test.go @@ -540,7 +540,7 @@ func TestNodeGroupProcessor_IsOldStorageForToken(t *testing.T) { ) _, err := proc.IsOldStorageForToken("token", 37) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) }) t.Run("some observers fail, should return error", func(t *testing.T) { @@ -566,7 +566,7 @@ func TestNodeGroupProcessor_IsOldStorageForToken(t *testing.T) { ) _, err := proc.IsOldStorageForToken("token", 37) - require.Equal(t, process.ErrSendingRequest, err) + require.True(t, errors.Is(err, process.ErrSendingRequest)) }) t.Run("should work and return false", func(t *testing.T) { diff --git a/process/nodeStatusProcessor.go b/process/nodeStatusProcessor.go index 72f588ef..9aef4cda 100644 --- a/process/nodeStatusProcessor.go +++ b/process/nodeStatusProcessor.go @@ -95,8 +95,8 @@ func (nsp *NodeStatusProcessor) GetNetworkStatusMetrics(shardID uint32) (*data.G return nil, err } + var responseNetworkMetrics data.GenericAPIResponse for _, observer := range observers { - var responseNetworkMetrics *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, NetworkStatusPath, &responseNetworkMetrics) if err != nil { @@ -105,11 +105,11 @@ func (nsp *NodeStatusProcessor) GetNetworkStatusMetrics(shardID uint32) (*data.G } log.Info("network metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) } // GetNetworkConfigMetrics will simply forward the network config metrics from an observer in the given shard @@ -119,8 +119,8 @@ func (nsp *NodeStatusProcessor) GetNetworkConfigMetrics() (*data.GenericAPIRespo return nil, err } + var responseNetworkMetrics data.GenericAPIResponse for _, observer := range observers { - var responseNetworkMetrics *data.GenericAPIResponse _, err = nsp.proc.CallGetRestEndPoint(observer.Address, NetworkConfigPath, &responseNetworkMetrics) if err != nil { @@ -129,11 +129,11 @@ func (nsp *NodeStatusProcessor) GetNetworkConfigMetrics() (*data.GenericAPIRespo } log.Info("network metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) } // GetEnableEpochsMetrics will simply forward the activation epochs config metrics from an observer @@ -143,8 +143,8 @@ func (nsp *NodeStatusProcessor) GetEnableEpochsMetrics() (*data.GenericAPIRespon return nil, err } + var responseEnableEpochsMetrics data.GenericAPIResponse for _, observer := range observers { - var responseEnableEpochsMetrics *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, EnableEpochsPath, &responseEnableEpochsMetrics) if err != nil { @@ -153,10 +153,10 @@ func (nsp *NodeStatusProcessor) GetEnableEpochsMetrics() (*data.GenericAPIRespon } log.Info("enable epochs metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseEnableEpochsMetrics, nil + return &responseEnableEpochsMetrics, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseEnableEpochsMetrics.Error) } // GetAllIssuedESDTs will forward the issued ESDTs based on the provided type @@ -170,8 +170,8 @@ func (nsp *NodeStatusProcessor) GetAllIssuedESDTs(tokenType string) (*data.Gener return nil, err } + var responseAllIssuedESDTs data.GenericAPIResponse for _, observer := range observers { - var responseAllIssuedESDTs *data.GenericAPIResponse path := AllIssuedESDTsPath if tokenType != "" { @@ -184,11 +184,11 @@ func (nsp *NodeStatusProcessor) GetAllIssuedESDTs(tokenType string) (*data.Gener } log.Info("all issued esdts request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseAllIssuedESDTs, nil + return &responseAllIssuedESDTs, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseAllIssuedESDTs.Error) } // GetDelegatedInfo returns the delegated info from nodes @@ -198,8 +198,8 @@ func (nsp *NodeStatusProcessor) GetDelegatedInfo() (*data.GenericAPIResponse, er return nil, err } + var delegatedInfoResponse data.GenericAPIResponse for _, observer := range observers { - var delegatedInfoResponse *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, DelegatedInfoPath, &delegatedInfoResponse) if err != nil { @@ -208,11 +208,11 @@ func (nsp *NodeStatusProcessor) GetDelegatedInfo() (*data.GenericAPIResponse, er } log.Info("network delegated info request", "shard ID", observer.ShardId, "observer", observer.Address) - return delegatedInfoResponse, nil + return &delegatedInfoResponse, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, delegatedInfoResponse.Error) } // GetDirectStakedInfo returns the delegated info from nodes @@ -222,8 +222,8 @@ func (nsp *NodeStatusProcessor) GetDirectStakedInfo() (*data.GenericAPIResponse, return nil, err } + var directStakedResponse data.GenericAPIResponse for _, observer := range observers { - var directStakedResponse *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, DirectStakedPath, &directStakedResponse) if err != nil { @@ -232,11 +232,11 @@ func (nsp *NodeStatusProcessor) GetDirectStakedInfo() (*data.GenericAPIResponse, } log.Info("network direct staked request", "shard ID", observer.ShardId, "observer", observer.Address) - return directStakedResponse, nil + return &directStakedResponse, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, directStakedResponse.Error) } // GetRatingsConfig will simply forward the ratings configuration from an observer @@ -246,8 +246,8 @@ func (nsp *NodeStatusProcessor) GetRatingsConfig() (*data.GenericAPIResponse, er return nil, err } + var responseRatingsConfig data.GenericAPIResponse for _, observer := range observers { - var responseRatingsConfig *data.GenericAPIResponse _, err = nsp.proc.CallGetRestEndPoint(observer.Address, RatingsConfigPath, &responseRatingsConfig) if err != nil { @@ -256,11 +256,11 @@ func (nsp *NodeStatusProcessor) GetRatingsConfig() (*data.GenericAPIResponse, er } log.Info("ratings metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseRatingsConfig, nil + return &responseRatingsConfig, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseRatingsConfig.Error) } func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.GenericAPIResponse, error) { @@ -269,8 +269,8 @@ func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.Gene return nil, err } + var responseNetworkMetrics data.GenericAPIResponse for _, observer := range observers { - var responseNetworkMetrics *data.GenericAPIResponse _, err = nsp.proc.CallGetRestEndPoint(observer.Address, NodeStatusPath, &responseNetworkMetrics) if err != nil { @@ -279,11 +279,11 @@ func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.Gene } log.Info("node status metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) } // GetLatestFullySynchronizedHyperblockNonce will compute nonce of the latest hyperblock that can be returned @@ -451,8 +451,8 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon return nil, err } + var responseGenesisNodesConfig data.GenericAPIResponse for _, observer := range observers { - var responseGenesisNodesConfig *data.GenericAPIResponse _, err = nsp.proc.CallGetRestEndPoint(observer.Address, GenesisNodesConfigPath, &responseGenesisNodesConfig) if err != nil { @@ -461,11 +461,11 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon } log.Info("genesis nodes request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseGenesisNodesConfig, nil + return &responseGenesisNodesConfig, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGenesisNodesConfig.Error) } // GetGasConfigs will return gas configs @@ -475,8 +475,8 @@ func (nsp *NodeStatusProcessor) GetGasConfigs() (*data.GenericAPIResponse, error return nil, err } + var responseGenesisNodesConfig data.GenericAPIResponse for _, observer := range observers { - var responseGenesisNodesConfig *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, GasConfigsPath, &responseGenesisNodesConfig) if err != nil { @@ -485,11 +485,11 @@ func (nsp *NodeStatusProcessor) GetGasConfigs() (*data.GenericAPIResponse, error } log.Info("gas configs request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseGenesisNodesConfig, nil + return &responseGenesisNodesConfig, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGenesisNodesConfig.Error) } // GetEpochStartData will return the epoch-start data for the given epoch and shard @@ -499,9 +499,9 @@ func (nsp *NodeStatusProcessor) GetEpochStartData(epoch uint32, shardID uint32) return nil, err } + var responseEpochStartData data.GenericAPIResponse path := fmt.Sprintf("/node/epoch-start/%d", epoch) for _, observer := range observers { - var responseEpochStartData *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, path, &responseEpochStartData) if err != nil { @@ -510,8 +510,8 @@ func (nsp *NodeStatusProcessor) GetEpochStartData(epoch uint32, shardID uint32) } log.Info("epoch start data request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseEpochStartData, nil + return &responseEpochStartData, nil } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseEpochStartData.Error) } diff --git a/process/nodeStatusProcessor_test.go b/process/nodeStatusProcessor_test.go index e1ac1394..7490b41d 100644 --- a/process/nodeStatusProcessor_test.go +++ b/process/nodeStatusProcessor_test.go @@ -58,7 +58,7 @@ func TestNodeStatusProcessor_GetConfigMetricsGetRestEndPointError(t *testing.T) ) status, err := nodeStatusProc.GetNetworkConfigMetrics() - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) require.Nil(t, status) } @@ -135,7 +135,7 @@ func TestNodeStatusProcessor_GetNetworkMetricsGetRestEndPointError(t *testing.T) ) status, err := nodeStatusProc.GetNetworkStatusMetrics(0) - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) require.Nil(t, status) } @@ -265,7 +265,7 @@ func TestNodeStatusProcessor_GetAllIssuedESDTsGetRestEndPointError(t *testing.T) ) status, err := nodeStatusProc.GetAllIssuedESDTs("") - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) require.Nil(t, status) } @@ -368,7 +368,7 @@ func TestNodeStatusProcessor_GetDelegatedInfoGetRestEndPointError(t *testing.T) ) status, err := nodeStatusProc.GetDelegatedInfo() - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) require.Nil(t, status) } @@ -434,7 +434,7 @@ func TestNodeStatusProcessor_GetDirectStakedInfoGetRestEndPointError(t *testing. ) status, err := nodeStatusProc.GetDirectStakedInfo() - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) require.Nil(t, status) } @@ -482,7 +482,7 @@ func TestNodeStatusProcessor_GetEnableEpochsMetricsGetEndpointErr(t *testing.T) ) status, err := nodesStatusProc.GetEnableEpochsMetrics() - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) require.Nil(t, status) } @@ -631,7 +631,7 @@ func TestNodeStatusProcessor_GetGasConfigs(t *testing.T) { actualResponse, err := nodeStatusProc.GetGasConfigs() require.Nil(t, actualResponse) - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) }) t.Run("should work", func(t *testing.T) { @@ -682,7 +682,7 @@ func TestNodeStatusProcessor_GetTriesStatistics(t *testing.T) { response, err := nodeStatusProc.GetTriesStatistics(0) require.Nil(t, response) - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) }) t.Run("missing metric from response", func(t *testing.T) { t.Parallel() @@ -767,7 +767,7 @@ func TestNodeStatusProcessor_GetEpochStartData(t *testing.T) { actualResponse, err := nodeStatusProc.GetEpochStartData(0, 0) require.Nil(t, actualResponse) - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) }) t.Run("should work", func(t *testing.T) { diff --git a/process/proofProcessor.go b/process/proofProcessor.go index b6a0877c..73f15529 100644 --- a/process/proofProcessor.go +++ b/process/proofProcessor.go @@ -36,9 +36,9 @@ func (pp *ProofProcessor) GetProof(rootHash string, address string) (*data.Gener return nil, err } + responseGetProof := &data.GenericAPIResponse{} getProofEndpoint := "/proof/root-hash/" + rootHash + "/address/" + address for _, observer := range observers { - responseGetProof := &data.GenericAPIResponse{} respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofEndpoint, responseGetProof) @@ -69,7 +69,7 @@ func (pp *ProofProcessor) GetProof(rootHash string, address string) (*data.Gener } } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGetProof.Error) } // GetProofDataTrie sends the request to the right observer and then replies with the returned answer @@ -79,9 +79,9 @@ func (pp *ProofProcessor) GetProofDataTrie(rootHash string, address string, key return nil, err } + responseGetProof := &data.GenericAPIResponse{} getProofDataTrieEndpoint := fmt.Sprintf("/proof/root-hash/%s/address/%s/key/%s", rootHash, address, key) for _, observer := range observers { - responseGetProof := &data.GenericAPIResponse{} respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofDataTrieEndpoint, responseGetProof) @@ -112,7 +112,7 @@ func (pp *ProofProcessor) GetProofDataTrie(rootHash string, address string, key } } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGetProof.Error) } // GetProofCurrentRootHash sends the request to the right observer and then replies with the returned answer @@ -122,9 +122,9 @@ func (pp *ProofProcessor) GetProofCurrentRootHash(address string) (*data.Generic return nil, err } + responseGetProof := &data.GenericAPIResponse{} getProofEndpoint := "/proof/address/" + address for _, observer := range observers { - responseGetProof := &data.GenericAPIResponse{} respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofEndpoint, responseGetProof) @@ -154,7 +154,7 @@ func (pp *ProofProcessor) GetProofCurrentRootHash(address string) (*data.Generic } } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGetProof.Error) } // VerifyProof sends the request to the right observer and then replies with the returned answer @@ -170,8 +170,8 @@ func (pp *ProofProcessor) VerifyProof(rootHash string, address string, proof []s Address: address, Proof: proof, } + responseVerifyProof := &data.GenericAPIResponse{} for _, observer := range observers { - responseVerifyProof := &data.GenericAPIResponse{} respCode, err := pp.proc.CallPostRestEndPoint(observer.Address, verifyProofEndpoint, requestParams, responseVerifyProof) @@ -203,7 +203,7 @@ func (pp *ProofProcessor) VerifyProof(rootHash string, address string, proof []s } } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseVerifyProof.Error) } func (pp *ProofProcessor) getObserversForAddress(address string) ([]*data.NodeData, error) { diff --git a/process/scQueryProcessor.go b/process/scQueryProcessor.go index 6584a409..84ef0e81 100644 --- a/process/scQueryProcessor.go +++ b/process/scQueryProcessor.go @@ -55,9 +55,9 @@ func (scQueryProcessor *SCQueryProcessor) ExecuteQuery(query *data.SCQuery) (*vm return nil, data.BlockInfo{}, err } + response := &data.ResponseVmValue{} for _, observer := range observers { request := scQueryProcessor.createRequestFromQuery(query) - response := &data.ResponseVmValue{} params := url.Values{} if query.BlockNonce.HasValue { @@ -95,7 +95,7 @@ func (scQueryProcessor *SCQueryProcessor) ExecuteQuery(query *data.SCQuery) (*vm return nil, data.BlockInfo{}, err } - return nil, data.BlockInfo{}, ErrSendingRequest + return nil, data.BlockInfo{}, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } func (scQueryProcessor *SCQueryProcessor) createRequestFromQuery(query *data.SCQuery) data.VmValueRequest { diff --git a/process/scQueryProcessor_test.go b/process/scQueryProcessor_test.go index dcfd4461..b1050d64 100644 --- a/process/scQueryProcessor_test.go +++ b/process/scQueryProcessor_test.go @@ -96,7 +96,7 @@ func TestSCQueryProcessor_ExecuteQuerySendingFailsOnAllObserversShouldErr(t *tes value, _, err := processor.ExecuteQuery(&data.SCQuery{ScAddress: dummyScAddress}) require.Empty(t, value) - require.Equal(t, ErrSendingRequest, err) + require.True(t, errors.Is(err, ErrSendingRequest)) } func TestSCQueryProcessor_ExecuteQuery(t *testing.T) { diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 317e7949..d4a8f8a7 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -134,8 +134,8 @@ func (tp *TransactionProcessor) SendTransaction(tx *data.Transaction) (int, stri return http.StatusInternalServerError, "", err } + txResponse := &data.ResponseTransaction{} for _, observer := range observers { - txResponse := &data.ResponseTransaction{} respCode, err := tp.proc.CallPostRestEndPoint(observer.Address, TransactionSendPath, tx, txResponse) if respCode == http.StatusOK && err == nil { @@ -157,7 +157,7 @@ func (tp *TransactionProcessor) SendTransaction(tx *data.Transaction) (int, stri return respCode, "", err } - return http.StatusInternalServerError, "", ErrSendingRequest + return http.StatusInternalServerError, "", fmt.Errorf("%w, %s", ErrSendingRequest, txResponse.Error) } // SimulateTransaction relays the post request by sending the request to the right observer and replies back the answer @@ -238,8 +238,8 @@ func (tp *TransactionProcessor) simulateTransaction( txSimulatePath += checkSignatureFalse } + txResponse := &data.ResponseTransactionSimulation{} for _, observer := range observers { - txResponse := &data.ResponseTransactionSimulation{} respCode, err := tp.proc.CallPostRestEndPoint(observer.Address, txSimulatePath, tx, txResponse) if respCode == http.StatusOK && err == nil { @@ -261,7 +261,7 @@ func (tp *TransactionProcessor) simulateTransaction( return nil, err } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, txResponse.Error) } // SendMultipleTransactions relays the post request by sending the request to the first available observer and replies back the answer diff --git a/process/txcost/transactionCostProcessor.go b/process/txcost/transactionCostProcessor.go index c8805430..e982f8f7 100644 --- a/process/txcost/transactionCostProcessor.go +++ b/process/txcost/transactionCostProcessor.go @@ -2,6 +2,7 @@ package txcost import ( "bytes" + "fmt" "net/http" "github.com/multiversx/mx-chain-core-go/core" @@ -119,8 +120,8 @@ func (tcp *transactionCostProcessor) executeRequest( observers []*data.NodeData, tx *data.Transaction, ) (*data.TxCostResponseData, error) { + txCostResponse := &data.ResponseTxCost{} for _, observer := range observers { - txCostResponse := &data.ResponseTxCost{} respCode, errCall := tcp.proc.CallPostRestEndPoint(observer.Address, TransactionCostPath, tx, txCostResponse) if respCode == http.StatusOK && errCall == nil { return tcp.processResponse(senderShardID, receiverShardID, txCostResponse, tx) @@ -137,7 +138,7 @@ func (tcp *transactionCostProcessor) executeRequest( } - return nil, ErrSendingRequest + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, txCostResponse.Error) } func (tcp *transactionCostProcessor) processResponse( From f3b1a47eb06a2e533b12535057d45778bb6b7153 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 24 Nov 2023 15:23:59 +0200 Subject: [PATCH 2/4] fix after review --- process/nodeStatusProcessor.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/process/nodeStatusProcessor.go b/process/nodeStatusProcessor.go index 9aef4cda..a29111eb 100644 --- a/process/nodeStatusProcessor.go +++ b/process/nodeStatusProcessor.go @@ -451,21 +451,21 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon return nil, err } - var responseGenesisNodesConfig data.GenericAPIResponse + var response data.GenericAPIResponse for _, observer := range observers { - _, err = nsp.proc.CallGetRestEndPoint(observer.Address, GenesisNodesConfigPath, &responseGenesisNodesConfig) + _, err = nsp.proc.CallGetRestEndPoint(observer.Address, GenesisNodesConfigPath, &response) if err != nil { log.Error("genesis nodes request", "observer", observer.Address, "error", err.Error()) continue } log.Info("genesis nodes request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseGenesisNodesConfig, nil + return &response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGenesisNodesConfig.Error) + return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) } // GetGasConfigs will return gas configs From eb07285791b599c95918292a0518fd0caf93f7be Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 24 Nov 2023 18:21:20 +0200 Subject: [PATCH 3/4] fixes after review --- process/accountProcessor.go | 97 ++++++++++++---------- process/blockProcessor.go | 72 ++++++++-------- process/economicMetrics.go | 7 +- process/esdtSupplyProcessor.go | 7 +- process/nodeGroupProcessor.go | 14 ++-- process/nodeStatusProcessor.go | 66 +++++++-------- process/proofProcessor.go | 8 +- process/scQueryProcessor.go | 2 +- process/transactionProcessor.go | 4 +- process/txcost/transactionCostProcessor.go | 3 +- 10 files changed, 143 insertions(+), 137 deletions(-) diff --git a/process/accountProcessor.go b/process/accountProcessor.go index 25210160..29c0a4fa 100644 --- a/process/accountProcessor.go +++ b/process/accountProcessor.go @@ -70,7 +70,7 @@ func (ap *AccountProcessor) GetAccount(address string, options common.AccountQue log.Error("account request", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseAccount.Error) + return nil, WrapObserversError(responseAccount.Error) } // GetValueForKey returns the value for the given address and key @@ -80,11 +80,11 @@ func (ap *AccountProcessor) GetValueForKey(address string, key string, options c return "", err } - apiResponse := data.AccountKeyValueResponse{} + apiResponse := &data.AccountKeyValueResponse{} for _, observer := range observers { apiPath := addressPath + address + "/key/" + key apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account value for key request", "address", address, @@ -101,7 +101,7 @@ func (ap *AccountProcessor) GetValueForKey(address string, key string, options c log.Error("account value for key request", "observer", observer.Address, "address", address, "error", err.Error()) } - return "", fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return "", WrapObserversError(apiResponse.Error) } // GetESDTTokenData returns the token data for a token with the given name @@ -111,11 +111,11 @@ func (ap *AccountProcessor) GetESDTTokenData(address string, key string, options return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdt/" + key apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDT token data", "address", address, @@ -127,13 +127,13 @@ func (ap *AccountProcessor) GetESDTTokenData(address string, key string, options return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get ESDT token data", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetESDTsWithRole returns the token identifiers where the given address has the given role assigned @@ -143,11 +143,11 @@ func (ap *AccountProcessor) GetESDTsWithRole(address string, role string, option return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdts-with-role/" + role apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDTs with role", "address", address, @@ -159,13 +159,13 @@ func (ap *AccountProcessor) GetESDTsWithRole(address string, role string, option return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get ESDTs with role", "observer", observer.Address, "address", address, "role", role, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetESDTsRoles returns all the tokens and their roles for a given address @@ -175,11 +175,11 @@ func (ap *AccountProcessor) GetESDTsRoles(address string, options common.Account return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdts/roles" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, errGet := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, errGet := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if errGet == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDTs roles", "address", address, @@ -190,13 +190,13 @@ func (ap *AccountProcessor) GetESDTsRoles(address string, options common.Account return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get ESDTs roles", "observer", observer.Address, "address", address, "error", errGet.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetNFTTokenIDsRegisteredByAddress returns the token identifiers of the NFTs registered by the address @@ -208,11 +208,11 @@ func (ap *AccountProcessor) GetNFTTokenIDsRegisteredByAddress(address string, op return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/registered-nfts/" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get owned NFTs", "address", address, @@ -223,13 +223,13 @@ func (ap *AccountProcessor) GetNFTTokenIDsRegisteredByAddress(address string, op return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get owned NFTs", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetESDTNftTokenData returns the nft token data for a token with the given identifier and nonce @@ -239,12 +239,12 @@ func (ap *AccountProcessor) GetESDTNftTokenData(address string, key string, nonc return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { nonceAsString := fmt.Sprintf("%d", nonce) apiPath := addressPath + address + "/nft/" + key + "/nonce/" + nonceAsString apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDT NFT token data", "address", address, @@ -256,13 +256,13 @@ func (ap *AccountProcessor) GetESDTNftTokenData(address string, key string, nonc return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get ESDT nft token data", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetAllESDTTokens returns all the tokens for a given address @@ -272,11 +272,11 @@ func (ap *AccountProcessor) GetAllESDTTokens(address string, options common.Acco return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdt" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account all ESDT tokens", "address", address, @@ -287,13 +287,13 @@ func (ap *AccountProcessor) GetAllESDTTokens(address string, options common.Acco return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get all ESDT tokens", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetKeyValuePairs returns all the key-value pairs for a given address @@ -303,11 +303,11 @@ func (ap *AccountProcessor) GetKeyValuePairs(address string, options common.Acco return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/keys" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get all key-value pairs", "address", address, @@ -318,13 +318,13 @@ func (ap *AccountProcessor) GetKeyValuePairs(address string, options common.Acco return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get all key-value pairs error", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetGuardianData returns the guardian data for the given address @@ -334,11 +334,11 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/guardian-data" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get guardian data", "address", address, @@ -349,13 +349,13 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get guardian data", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } // GetTransactions resolves the request and returns a slice of transaction for the specific address @@ -374,11 +374,11 @@ func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQu return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/code-hash" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get code hash", "address", address, @@ -389,13 +389,13 @@ func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQu return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account get code hash error", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) } func (ap *AccountProcessor) getObserversForAddress(address string) ([]*data.NodeData, error) { @@ -429,11 +429,11 @@ func (ap *AccountProcessor) IsDataTrieMigrated(address string, options common.Ac return nil, err } - apiResponse := data.GenericAPIResponse{} + apiResponse := &data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/is-data-trie-migrated" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("is data trie migrated", "address", address, @@ -444,11 +444,20 @@ func (ap *AccountProcessor) IsDataTrieMigrated(address string, options common.Ac return nil, errors.New(apiResponse.Error) } - return &apiResponse, nil + return apiResponse, nil } log.Error("account is data trie migrated", "observer", observer.Address, "address", address, "error", err.Error()) } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return nil, WrapObserversError(apiResponse.Error) +} + +// WrapObserversError wraps the observers error +func WrapObserversError(responseError string) error { + if len(responseError) == 0 { + return ErrSendingRequest + } + + return fmt.Errorf("%w, %s", ErrSendingRequest, responseError) } diff --git a/process/blockProcessor.go b/process/blockProcessor.go index 5ebf3fd5..04405bd4 100644 --- a/process/blockProcessor.go +++ b/process/blockProcessor.go @@ -70,21 +70,21 @@ func (bp *BlockProcessor) GetBlockByHash(shardID uint32, hash string, options co path := common.BuildUrlWithBlockQueryOptions(fmt.Sprintf("%s/%s", blockByHashPath, hash), options) - var response data.BlockApiResponse + response := &data.BlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("block request", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } // GetBlockByNonce will return the block based on the nonce @@ -96,21 +96,21 @@ func (bp *BlockProcessor) GetBlockByNonce(shardID uint32, nonce uint64, options path := common.BuildUrlWithBlockQueryOptions(fmt.Sprintf("%s/%d", blockByNoncePath, nonce), options) - var response data.BlockApiResponse + response := &data.BlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("block request", "shard id", observer.ShardId, "nonce", nonce, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } func (bp *BlockProcessor) getObserversOrFullHistoryNodes(shardID uint32) ([]*data.NodeData, error) { @@ -226,21 +226,21 @@ func (bp *BlockProcessor) GetInternalBlockByHash(shardID uint32, hash string, fo return nil, err } - var response data.InternalBlockApiResponse + response := &data.InternalBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("internal block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal block request", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } func getInternalBlockByHashPath(shardID uint32, format common.OutputFormat, hash string) (string, error) { @@ -272,21 +272,21 @@ func (bp *BlockProcessor) GetInternalBlockByNonce(shardID uint32, nonce uint64, return nil, err } - var response data.InternalBlockApiResponse + response := &data.InternalBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("internal block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal block request", "shard id", observer.ShardId, "round", nonce, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } func getInternalBlockByNoncePath(shardID uint32, format common.OutputFormat, nonce uint64) (string, error) { @@ -319,21 +319,21 @@ func (bp *BlockProcessor) GetInternalMiniBlockByHash(shardID uint32, hash string } path := fmt.Sprintf(internalMiniBlockByHashPath, outputStr, hash, epoch) - var response data.InternalMiniBlockApiResponse + response := &data.InternalMiniBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("miniblock request", "observer", observer.Address, "error", err.Error()) continue } log.Info("miniblock request", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } func getOutputFormat(format common.OutputFormat) (string, error) { @@ -365,21 +365,21 @@ func (bp *BlockProcessor) GetInternalStartOfEpochMetaBlock(epoch uint32, format path := fmt.Sprintf(internalStartOfEpochMetaBlockPath, outputStr, epoch) - var response data.InternalBlockApiResponse + response := &data.InternalBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("internal block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal block request", "shard id", observer.ShardId, "epoch", epoch, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } // GetInternalStartOfEpochValidatorsInfo will return the internal start of epoch validators info based on epoch @@ -391,21 +391,21 @@ func (bp *BlockProcessor) GetInternalStartOfEpochValidatorsInfo(epoch uint32) (* path := fmt.Sprintf(internalStartOfEpochValidatorsInfoPath, epoch) - var response data.ValidatorsInfoApiResponse + response := &data.ValidatorsInfoApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("internal validators info request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal validators info request", "shard id", observer.ShardId, "epoch", epoch, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } // GetAlteredAccountsByNonce will return altered accounts by block nonce @@ -416,21 +416,21 @@ func (bp *BlockProcessor) GetAlteredAccountsByNonce(shardID uint32, nonce uint64 } path := common.BuildUrlWithAlteredAccountsQueryOptions(fmt.Sprintf("%s/%d", alteredAccountByBlockNonce, nonce), options) - var response data.AlteredAccountsApiResponse + response := &data.AlteredAccountsApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("altered accounts request by nonce", "observer", observer.Address, "error", err.Error()) continue } log.Info("altered accounts request by nonce", "shard id", observer.ShardId, "nonce", nonce, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } // GetAlteredAccountsByHash will return altered accounts by block hash @@ -441,19 +441,19 @@ func (bp *BlockProcessor) GetAlteredAccountsByHash(shardID uint32, hash string, } path := common.BuildUrlWithAlteredAccountsQueryOptions(fmt.Sprintf("%s/%s", alteredAccountByBlockHash, hash), options) - var response data.AlteredAccountsApiResponse + response := &data.AlteredAccountsApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) if err != nil { log.Error("altered accounts request by hash", "observer", observer.Address, "hash", hash, "error", err.Error()) continue } log.Info("altered accounts request by hash", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } diff --git a/process/economicMetrics.go b/process/economicMetrics.go index fa73aae3..99328214 100644 --- a/process/economicMetrics.go +++ b/process/economicMetrics.go @@ -2,7 +2,6 @@ package process import ( "context" - "fmt" "time" "github.com/multiversx/mx-chain-core-go/core" @@ -29,7 +28,7 @@ func (nsp *NodeStatusProcessor) getEconomicsDataMetricsFromApi() (*data.GenericA } func (nsp *NodeStatusProcessor) getEconomicsDataMetrics(observers []*data.NodeData) (*data.GenericAPIResponse, error) { - var responseNetworkMetrics data.GenericAPIResponse + responseNetworkMetrics := &data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, EconomicsDataPath, &responseNetworkMetrics) @@ -39,10 +38,10 @@ func (nsp *NodeStatusProcessor) getEconomicsDataMetrics(observers []*data.NodeDa } log.Info("economics data request", "shard id", observer.ShardId, "observer", observer.Address) - return &responseNetworkMetrics, nil + return responseNetworkMetrics, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) + return nil, WrapObserversError(responseNetworkMetrics.Error) } // StartCacheUpdate will update the economic metrics cache at a given time diff --git a/process/esdtSupplyProcessor.go b/process/esdtSupplyProcessor.go index 161e085b..8c08927d 100644 --- a/process/esdtSupplyProcessor.go +++ b/process/esdtSupplyProcessor.go @@ -1,7 +1,6 @@ package process import ( - "fmt" "math/big" "strings" @@ -162,11 +161,11 @@ func (esp *esdtSupplyProcessor) getShardSupply(token string, shardID uint32) (*d return nil, errObs } - var responseEsdtSupply data.ESDTSupplyResponse + responseEsdtSupply := &data.ESDTSupplyResponse{} apiPath := networkESDTSupplyPath + token for _, observer := range shardObservers { - _, errGet := esp.baseProc.CallGetRestEndPoint(observer.Address, apiPath, &responseEsdtSupply) + _, errGet := esp.baseProc.CallGetRestEndPoint(observer.Address, apiPath, responseEsdtSupply) if errGet != nil { log.Error("esdt supply request", "shard ID", observer.ShardId, "observer", observer.Address, "error", errGet.Error()) continue @@ -178,7 +177,7 @@ func (esp *esdtSupplyProcessor) getShardSupply(token string, shardID uint32) (*d } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseEsdtSupply.Error) + return nil, WrapObserversError(responseEsdtSupply.Error) } func isFungibleESDT(tokenIdentifier string) bool { diff --git a/process/nodeGroupProcessor.go b/process/nodeGroupProcessor.go index c859259b..80289d04 100644 --- a/process/nodeGroupProcessor.go +++ b/process/nodeGroupProcessor.go @@ -69,9 +69,9 @@ func (ngp *NodeGroupProcessor) IsOldStorageForToken(tokenID string, nonce uint64 continue } - apiResponse := data.AccountKeyValueResponse{} + apiResponse := &data.AccountKeyValueResponse{} apiPath := addressPath + systemAccountAddress + "/key/" + tokenStorageKey - respCode, err := ngp.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) + respCode, err := ngp.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account value for key request", "address", systemAccountAddress, @@ -87,7 +87,7 @@ func (ngp *NodeGroupProcessor) IsOldStorageForToken(tokenID string, nonce uint64 return false, nil } } else { - return false, fmt.Errorf("%w, %s", ErrSendingRequest, apiResponse.Error) + return false, WrapObserversError(apiResponse.Error) } } @@ -254,21 +254,21 @@ func (ngp *NodeGroupProcessor) GetWaitingEpochsLeftForPublicKey(publicKey string } var lastErr error - var responseWaitingEpochsLeft data.WaitingEpochsLeftApiResponse + responseWaitingEpochsLeft := &data.WaitingEpochsLeftApiResponse{} path := fmt.Sprintf(waitingEpochsLeftPath, publicKey) for _, observer := range observers { - _, lastErr = ngp.proc.CallGetRestEndPoint(observer.Address, path, &responseWaitingEpochsLeft) + _, lastErr = ngp.proc.CallGetRestEndPoint(observer.Address, path, responseWaitingEpochsLeft) if lastErr != nil { log.Error("waiting epochs left request", "observer", observer.Address, "public key", publicKey, "error", lastErr.Error()) continue } log.Info("waiting epochs left request", "shard ID", observer.ShardId, "observer", observer.Address, "public key", publicKey) - return &responseWaitingEpochsLeft, nil + return responseWaitingEpochsLeft, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseWaitingEpochsLeft.Error) + return nil, WrapObserversError(responseWaitingEpochsLeft.Error) } // Close will handle the closing of the cache update go routine diff --git a/process/nodeStatusProcessor.go b/process/nodeStatusProcessor.go index a29111eb..bdc19ac4 100644 --- a/process/nodeStatusProcessor.go +++ b/process/nodeStatusProcessor.go @@ -95,7 +95,7 @@ func (nsp *NodeStatusProcessor) GetNetworkStatusMetrics(shardID uint32) (*data.G return nil, err } - var responseNetworkMetrics data.GenericAPIResponse + responseNetworkMetrics := &data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, NetworkStatusPath, &responseNetworkMetrics) @@ -105,11 +105,11 @@ func (nsp *NodeStatusProcessor) GetNetworkStatusMetrics(shardID uint32) (*data.G } log.Info("network metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseNetworkMetrics, nil + return responseNetworkMetrics, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) + return nil, WrapObserversError(responseNetworkMetrics.Error) } // GetNetworkConfigMetrics will simply forward the network config metrics from an observer in the given shard @@ -119,7 +119,7 @@ func (nsp *NodeStatusProcessor) GetNetworkConfigMetrics() (*data.GenericAPIRespo return nil, err } - var responseNetworkMetrics data.GenericAPIResponse + responseNetworkMetrics := &data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, NetworkConfigPath, &responseNetworkMetrics) @@ -129,11 +129,11 @@ func (nsp *NodeStatusProcessor) GetNetworkConfigMetrics() (*data.GenericAPIRespo } log.Info("network metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseNetworkMetrics, nil + return responseNetworkMetrics, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) + return nil, WrapObserversError(responseNetworkMetrics.Error) } // GetEnableEpochsMetrics will simply forward the activation epochs config metrics from an observer @@ -143,7 +143,7 @@ func (nsp *NodeStatusProcessor) GetEnableEpochsMetrics() (*data.GenericAPIRespon return nil, err } - var responseEnableEpochsMetrics data.GenericAPIResponse + responseEnableEpochsMetrics := &data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, EnableEpochsPath, &responseEnableEpochsMetrics) @@ -153,10 +153,10 @@ func (nsp *NodeStatusProcessor) GetEnableEpochsMetrics() (*data.GenericAPIRespon } log.Info("enable epochs metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseEnableEpochsMetrics, nil + return responseEnableEpochsMetrics, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseEnableEpochsMetrics.Error) + return nil, WrapObserversError(responseEnableEpochsMetrics.Error) } // GetAllIssuedESDTs will forward the issued ESDTs based on the provided type @@ -170,7 +170,7 @@ func (nsp *NodeStatusProcessor) GetAllIssuedESDTs(tokenType string) (*data.Gener return nil, err } - var responseAllIssuedESDTs data.GenericAPIResponse + responseAllIssuedESDTs := &data.GenericAPIResponse{} for _, observer := range observers { path := AllIssuedESDTsPath @@ -184,11 +184,11 @@ func (nsp *NodeStatusProcessor) GetAllIssuedESDTs(tokenType string) (*data.Gener } log.Info("all issued esdts request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseAllIssuedESDTs, nil + return responseAllIssuedESDTs, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseAllIssuedESDTs.Error) + return nil, WrapObserversError(responseAllIssuedESDTs.Error) } // GetDelegatedInfo returns the delegated info from nodes @@ -198,7 +198,7 @@ func (nsp *NodeStatusProcessor) GetDelegatedInfo() (*data.GenericAPIResponse, er return nil, err } - var delegatedInfoResponse data.GenericAPIResponse + delegatedInfoResponse := &data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, DelegatedInfoPath, &delegatedInfoResponse) @@ -208,11 +208,11 @@ func (nsp *NodeStatusProcessor) GetDelegatedInfo() (*data.GenericAPIResponse, er } log.Info("network delegated info request", "shard ID", observer.ShardId, "observer", observer.Address) - return &delegatedInfoResponse, nil + return delegatedInfoResponse, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, delegatedInfoResponse.Error) + return nil, WrapObserversError(delegatedInfoResponse.Error) } // GetDirectStakedInfo returns the delegated info from nodes @@ -222,7 +222,7 @@ func (nsp *NodeStatusProcessor) GetDirectStakedInfo() (*data.GenericAPIResponse, return nil, err } - var directStakedResponse data.GenericAPIResponse + directStakedResponse := &data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, DirectStakedPath, &directStakedResponse) @@ -232,11 +232,11 @@ func (nsp *NodeStatusProcessor) GetDirectStakedInfo() (*data.GenericAPIResponse, } log.Info("network direct staked request", "shard ID", observer.ShardId, "observer", observer.Address) - return &directStakedResponse, nil + return directStakedResponse, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, directStakedResponse.Error) + return nil, WrapObserversError(directStakedResponse.Error) } // GetRatingsConfig will simply forward the ratings configuration from an observer @@ -246,7 +246,7 @@ func (nsp *NodeStatusProcessor) GetRatingsConfig() (*data.GenericAPIResponse, er return nil, err } - var responseRatingsConfig data.GenericAPIResponse + responseRatingsConfig := &data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, RatingsConfigPath, &responseRatingsConfig) @@ -256,11 +256,11 @@ func (nsp *NodeStatusProcessor) GetRatingsConfig() (*data.GenericAPIResponse, er } log.Info("ratings metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseRatingsConfig, nil + return responseRatingsConfig, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseRatingsConfig.Error) + return nil, WrapObserversError(responseRatingsConfig.Error) } func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.GenericAPIResponse, error) { @@ -269,7 +269,7 @@ func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.Gene return nil, err } - var responseNetworkMetrics data.GenericAPIResponse + responseNetworkMetrics := &data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, NodeStatusPath, &responseNetworkMetrics) @@ -279,11 +279,11 @@ func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.Gene } log.Info("node status metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseNetworkMetrics, nil + return responseNetworkMetrics, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseNetworkMetrics.Error) + return nil, WrapObserversError(responseNetworkMetrics.Error) } // GetLatestFullySynchronizedHyperblockNonce will compute nonce of the latest hyperblock that can be returned @@ -451,7 +451,7 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon return nil, err } - var response data.GenericAPIResponse + response := &data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, GenesisNodesConfigPath, &response) @@ -461,11 +461,11 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon } log.Info("genesis nodes request", "shard ID", observer.ShardId, "observer", observer.Address) - return &response, nil + return response, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, WrapObserversError(response.Error) } // GetGasConfigs will return gas configs @@ -475,7 +475,7 @@ func (nsp *NodeStatusProcessor) GetGasConfigs() (*data.GenericAPIResponse, error return nil, err } - var responseGenesisNodesConfig data.GenericAPIResponse + responseGenesisNodesConfig := &data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, GasConfigsPath, &responseGenesisNodesConfig) @@ -485,11 +485,11 @@ func (nsp *NodeStatusProcessor) GetGasConfigs() (*data.GenericAPIResponse, error } log.Info("gas configs request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseGenesisNodesConfig, nil + return responseGenesisNodesConfig, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGenesisNodesConfig.Error) + return nil, WrapObserversError(responseGenesisNodesConfig.Error) } // GetEpochStartData will return the epoch-start data for the given epoch and shard @@ -499,7 +499,7 @@ func (nsp *NodeStatusProcessor) GetEpochStartData(epoch uint32, shardID uint32) return nil, err } - var responseEpochStartData data.GenericAPIResponse + responseEpochStartData := &data.GenericAPIResponse{} path := fmt.Sprintf("/node/epoch-start/%d", epoch) for _, observer := range observers { @@ -510,8 +510,8 @@ func (nsp *NodeStatusProcessor) GetEpochStartData(epoch uint32, shardID uint32) } log.Info("epoch start data request", "shard ID", observer.ShardId, "observer", observer.Address) - return &responseEpochStartData, nil + return responseEpochStartData, nil } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseEpochStartData.Error) + return nil, WrapObserversError(responseEpochStartData.Error) } diff --git a/process/proofProcessor.go b/process/proofProcessor.go index 73f15529..6dd9f54e 100644 --- a/process/proofProcessor.go +++ b/process/proofProcessor.go @@ -69,7 +69,7 @@ func (pp *ProofProcessor) GetProof(rootHash string, address string) (*data.Gener } } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGetProof.Error) + return nil, WrapObserversError(responseGetProof.Error) } // GetProofDataTrie sends the request to the right observer and then replies with the returned answer @@ -112,7 +112,7 @@ func (pp *ProofProcessor) GetProofDataTrie(rootHash string, address string, key } } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGetProof.Error) + return nil, WrapObserversError(responseGetProof.Error) } // GetProofCurrentRootHash sends the request to the right observer and then replies with the returned answer @@ -154,7 +154,7 @@ func (pp *ProofProcessor) GetProofCurrentRootHash(address string) (*data.Generic } } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseGetProof.Error) + return nil, WrapObserversError(responseGetProof.Error) } // VerifyProof sends the request to the right observer and then replies with the returned answer @@ -203,7 +203,7 @@ func (pp *ProofProcessor) VerifyProof(rootHash string, address string, proof []s } } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, responseVerifyProof.Error) + return nil, WrapObserversError(responseVerifyProof.Error) } func (pp *ProofProcessor) getObserversForAddress(address string) ([]*data.NodeData, error) { diff --git a/process/scQueryProcessor.go b/process/scQueryProcessor.go index 84ef0e81..2fd66b18 100644 --- a/process/scQueryProcessor.go +++ b/process/scQueryProcessor.go @@ -95,7 +95,7 @@ func (scQueryProcessor *SCQueryProcessor) ExecuteQuery(query *data.SCQuery) (*vm return nil, data.BlockInfo{}, err } - return nil, data.BlockInfo{}, fmt.Errorf("%w, %s", ErrSendingRequest, response.Error) + return nil, data.BlockInfo{}, WrapObserversError(response.Error) } func (scQueryProcessor *SCQueryProcessor) createRequestFromQuery(query *data.SCQuery) data.VmValueRequest { diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index d4a8f8a7..5ab946b0 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -157,7 +157,7 @@ func (tp *TransactionProcessor) SendTransaction(tx *data.Transaction) (int, stri return respCode, "", err } - return http.StatusInternalServerError, "", fmt.Errorf("%w, %s", ErrSendingRequest, txResponse.Error) + return http.StatusInternalServerError, "", WrapObserversError(txResponse.Error) } // SimulateTransaction relays the post request by sending the request to the right observer and replies back the answer @@ -261,7 +261,7 @@ func (tp *TransactionProcessor) simulateTransaction( return nil, err } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, txResponse.Error) + return nil, WrapObserversError(txResponse.Error) } // SendMultipleTransactions relays the post request by sending the request to the first available observer and replies back the answer diff --git a/process/txcost/transactionCostProcessor.go b/process/txcost/transactionCostProcessor.go index e982f8f7..b323e67f 100644 --- a/process/txcost/transactionCostProcessor.go +++ b/process/txcost/transactionCostProcessor.go @@ -2,7 +2,6 @@ package txcost import ( "bytes" - "fmt" "net/http" "github.com/multiversx/mx-chain-core-go/core" @@ -138,7 +137,7 @@ func (tcp *transactionCostProcessor) executeRequest( } - return nil, fmt.Errorf("%w, %s", ErrSendingRequest, txCostResponse.Error) + return nil, process.WrapObserversError(txCostResponse.Error) } func (tcp *transactionCostProcessor) processResponse( From cbc3831c4ff65320c4c157705b172ed935721e1c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 27 Nov 2023 10:07:38 +0200 Subject: [PATCH 4/4] further fixes after review --- process/accountProcessor.go | 68 +++++++++++----------- process/blockProcessor.go | 54 ++++++++--------- process/economicMetrics.go | 4 +- process/esdtSupplyProcessor.go | 4 +- process/nodeGroupProcessor.go | 10 ++-- process/nodeStatusProcessor.go | 44 +++++++------- process/proofProcessor.go | 24 ++++---- process/scQueryProcessor.go | 4 +- process/transactionProcessor.go | 10 ++-- process/txcost/transactionCostProcessor.go | 6 +- 10 files changed, 114 insertions(+), 114 deletions(-) diff --git a/process/accountProcessor.go b/process/accountProcessor.go index 29c0a4fa..7b66995c 100644 --- a/process/accountProcessor.go +++ b/process/accountProcessor.go @@ -57,11 +57,11 @@ func (ap *AccountProcessor) GetAccount(address string, options common.AccountQue return nil, err } - responseAccount := &data.AccountApiResponse{} + responseAccount := data.AccountApiResponse{} for _, observer := range observers { url := common.BuildUrlWithAccountQueryOptions(addressPath+address, options) - _, err = ap.proc.CallGetRestEndPoint(observer.Address, url, responseAccount) + _, err = ap.proc.CallGetRestEndPoint(observer.Address, url, &responseAccount) if err == nil { log.Info("account request", "address", address, "shard ID", observer.ShardId, "observer", observer.Address) return &responseAccount.Data, nil @@ -80,11 +80,11 @@ func (ap *AccountProcessor) GetValueForKey(address string, key string, options c return "", err } - apiResponse := &data.AccountKeyValueResponse{} + apiResponse := data.AccountKeyValueResponse{} for _, observer := range observers { apiPath := addressPath + address + "/key/" + key apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account value for key request", "address", address, @@ -111,11 +111,11 @@ func (ap *AccountProcessor) GetESDTTokenData(address string, key string, options return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdt/" + key apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDT token data", "address", address, @@ -127,7 +127,7 @@ func (ap *AccountProcessor) GetESDTTokenData(address string, key string, options return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get ESDT token data", "observer", observer.Address, "address", address, "error", err.Error()) @@ -143,11 +143,11 @@ func (ap *AccountProcessor) GetESDTsWithRole(address string, role string, option return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdts-with-role/" + role apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDTs with role", "address", address, @@ -159,7 +159,7 @@ func (ap *AccountProcessor) GetESDTsWithRole(address string, role string, option return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get ESDTs with role", "observer", observer.Address, "address", address, "role", role, "error", err.Error()) @@ -175,11 +175,11 @@ func (ap *AccountProcessor) GetESDTsRoles(address string, options common.Account return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdts/roles" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, errGet := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, errGet := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if errGet == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDTs roles", "address", address, @@ -190,7 +190,7 @@ func (ap *AccountProcessor) GetESDTsRoles(address string, options common.Account return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get ESDTs roles", "observer", observer.Address, "address", address, "error", errGet.Error()) @@ -208,11 +208,11 @@ func (ap *AccountProcessor) GetNFTTokenIDsRegisteredByAddress(address string, op return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/registered-nfts/" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get owned NFTs", "address", address, @@ -223,7 +223,7 @@ func (ap *AccountProcessor) GetNFTTokenIDsRegisteredByAddress(address string, op return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get owned NFTs", "observer", observer.Address, "address", address, "error", err.Error()) @@ -239,12 +239,12 @@ func (ap *AccountProcessor) GetESDTNftTokenData(address string, key string, nonc return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { nonceAsString := fmt.Sprintf("%d", nonce) apiPath := addressPath + address + "/nft/" + key + "/nonce/" + nonceAsString apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account ESDT NFT token data", "address", address, @@ -256,7 +256,7 @@ func (ap *AccountProcessor) GetESDTNftTokenData(address string, key string, nonc return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get ESDT nft token data", "observer", observer.Address, "address", address, "error", err.Error()) @@ -272,11 +272,11 @@ func (ap *AccountProcessor) GetAllESDTTokens(address string, options common.Acco return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/esdt" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account all ESDT tokens", "address", address, @@ -287,7 +287,7 @@ func (ap *AccountProcessor) GetAllESDTTokens(address string, options common.Acco return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get all ESDT tokens", "observer", observer.Address, "address", address, "error", err.Error()) @@ -303,11 +303,11 @@ func (ap *AccountProcessor) GetKeyValuePairs(address string, options common.Acco return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/keys" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get all key-value pairs", "address", address, @@ -318,7 +318,7 @@ func (ap *AccountProcessor) GetKeyValuePairs(address string, options common.Acco return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get all key-value pairs error", "observer", observer.Address, "address", address, "error", err.Error()) @@ -334,11 +334,11 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/guardian-data" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get guardian data", "address", address, @@ -349,7 +349,7 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get guardian data", "observer", observer.Address, "address", address, "error", err.Error()) @@ -374,11 +374,11 @@ func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQu return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/code-hash" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account get code hash", "address", address, @@ -389,7 +389,7 @@ func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQu return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account get code hash error", "observer", observer.Address, "address", address, "error", err.Error()) @@ -429,11 +429,11 @@ func (ap *AccountProcessor) IsDataTrieMigrated(address string, options common.Ac return nil, err } - apiResponse := &data.GenericAPIResponse{} + apiResponse := data.GenericAPIResponse{} for _, observer := range observers { apiPath := addressPath + address + "/is-data-trie-migrated" apiPath = common.BuildUrlWithAccountQueryOptions(apiPath, options) - respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ap.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("is data trie migrated", "address", address, @@ -444,7 +444,7 @@ func (ap *AccountProcessor) IsDataTrieMigrated(address string, options common.Ac return nil, errors.New(apiResponse.Error) } - return apiResponse, nil + return &apiResponse, nil } log.Error("account is data trie migrated", "observer", observer.Address, "address", address, "error", err.Error()) diff --git a/process/blockProcessor.go b/process/blockProcessor.go index 04405bd4..88f99cd3 100644 --- a/process/blockProcessor.go +++ b/process/blockProcessor.go @@ -70,17 +70,17 @@ func (bp *BlockProcessor) GetBlockByHash(shardID uint32, hash string, options co path := common.BuildUrlWithBlockQueryOptions(fmt.Sprintf("%s/%s", blockByHashPath, hash), options) - response := &data.BlockApiResponse{} + response := data.BlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("block request", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return response, nil + return &response, nil } @@ -96,17 +96,17 @@ func (bp *BlockProcessor) GetBlockByNonce(shardID uint32, nonce uint64, options path := common.BuildUrlWithBlockQueryOptions(fmt.Sprintf("%s/%d", blockByNoncePath, nonce), options) - response := &data.BlockApiResponse{} + response := data.BlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("block request", "shard id", observer.ShardId, "nonce", nonce, "observer", observer.Address) - return response, nil + return &response, nil } @@ -226,17 +226,17 @@ func (bp *BlockProcessor) GetInternalBlockByHash(shardID uint32, hash string, fo return nil, err } - response := &data.InternalBlockApiResponse{} + response := data.InternalBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("internal block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal block request", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return response, nil + return &response, nil } @@ -272,17 +272,17 @@ func (bp *BlockProcessor) GetInternalBlockByNonce(shardID uint32, nonce uint64, return nil, err } - response := &data.InternalBlockApiResponse{} + response := data.InternalBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("internal block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal block request", "shard id", observer.ShardId, "round", nonce, "observer", observer.Address) - return response, nil + return &response, nil } @@ -319,17 +319,17 @@ func (bp *BlockProcessor) GetInternalMiniBlockByHash(shardID uint32, hash string } path := fmt.Sprintf(internalMiniBlockByHashPath, outputStr, hash, epoch) - response := &data.InternalMiniBlockApiResponse{} + response := data.InternalMiniBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("miniblock request", "observer", observer.Address, "error", err.Error()) continue } log.Info("miniblock request", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return response, nil + return &response, nil } @@ -365,17 +365,17 @@ func (bp *BlockProcessor) GetInternalStartOfEpochMetaBlock(epoch uint32, format path := fmt.Sprintf(internalStartOfEpochMetaBlockPath, outputStr, epoch) - response := &data.InternalBlockApiResponse{} + response := data.InternalBlockApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("internal block request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal block request", "shard id", observer.ShardId, "epoch", epoch, "observer", observer.Address) - return response, nil + return &response, nil } @@ -391,17 +391,17 @@ func (bp *BlockProcessor) GetInternalStartOfEpochValidatorsInfo(epoch uint32) (* path := fmt.Sprintf(internalStartOfEpochValidatorsInfoPath, epoch) - response := &data.ValidatorsInfoApiResponse{} + response := data.ValidatorsInfoApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("internal validators info request", "observer", observer.Address, "error", err.Error()) continue } log.Info("internal validators info request", "shard id", observer.ShardId, "epoch", epoch, "observer", observer.Address) - return response, nil + return &response, nil } @@ -416,17 +416,17 @@ func (bp *BlockProcessor) GetAlteredAccountsByNonce(shardID uint32, nonce uint64 } path := common.BuildUrlWithAlteredAccountsQueryOptions(fmt.Sprintf("%s/%d", alteredAccountByBlockNonce, nonce), options) - response := &data.AlteredAccountsApiResponse{} + response := data.AlteredAccountsApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("altered accounts request by nonce", "observer", observer.Address, "error", err.Error()) continue } log.Info("altered accounts request by nonce", "shard id", observer.ShardId, "nonce", nonce, "observer", observer.Address) - return response, nil + return &response, nil } @@ -441,17 +441,17 @@ func (bp *BlockProcessor) GetAlteredAccountsByHash(shardID uint32, hash string, } path := common.BuildUrlWithAlteredAccountsQueryOptions(fmt.Sprintf("%s/%s", alteredAccountByBlockHash, hash), options) - response := &data.AlteredAccountsApiResponse{} + response := data.AlteredAccountsApiResponse{} for _, observer := range observers { - _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, response) + _, err := bp.proc.CallGetRestEndPoint(observer.Address, path, &response) if err != nil { log.Error("altered accounts request by hash", "observer", observer.Address, "hash", hash, "error", err.Error()) continue } log.Info("altered accounts request by hash", "shard id", observer.ShardId, "hash", hash, "observer", observer.Address) - return response, nil + return &response, nil } diff --git a/process/economicMetrics.go b/process/economicMetrics.go index 99328214..3f0b255d 100644 --- a/process/economicMetrics.go +++ b/process/economicMetrics.go @@ -28,7 +28,7 @@ func (nsp *NodeStatusProcessor) getEconomicsDataMetricsFromApi() (*data.GenericA } func (nsp *NodeStatusProcessor) getEconomicsDataMetrics(observers []*data.NodeData) (*data.GenericAPIResponse, error) { - responseNetworkMetrics := &data.GenericAPIResponse{} + responseNetworkMetrics := data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, EconomicsDataPath, &responseNetworkMetrics) @@ -38,7 +38,7 @@ func (nsp *NodeStatusProcessor) getEconomicsDataMetrics(observers []*data.NodeDa } log.Info("economics data request", "shard id", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } return nil, WrapObserversError(responseNetworkMetrics.Error) diff --git a/process/esdtSupplyProcessor.go b/process/esdtSupplyProcessor.go index 8c08927d..19f283e7 100644 --- a/process/esdtSupplyProcessor.go +++ b/process/esdtSupplyProcessor.go @@ -161,11 +161,11 @@ func (esp *esdtSupplyProcessor) getShardSupply(token string, shardID uint32) (*d return nil, errObs } - responseEsdtSupply := &data.ESDTSupplyResponse{} + responseEsdtSupply := data.ESDTSupplyResponse{} apiPath := networkESDTSupplyPath + token for _, observer := range shardObservers { - _, errGet := esp.baseProc.CallGetRestEndPoint(observer.Address, apiPath, responseEsdtSupply) + _, errGet := esp.baseProc.CallGetRestEndPoint(observer.Address, apiPath, &responseEsdtSupply) if errGet != nil { log.Error("esdt supply request", "shard ID", observer.ShardId, "observer", observer.Address, "error", errGet.Error()) continue diff --git a/process/nodeGroupProcessor.go b/process/nodeGroupProcessor.go index 80289d04..53ebe641 100644 --- a/process/nodeGroupProcessor.go +++ b/process/nodeGroupProcessor.go @@ -69,9 +69,9 @@ func (ngp *NodeGroupProcessor) IsOldStorageForToken(tokenID string, nonce uint64 continue } - apiResponse := &data.AccountKeyValueResponse{} + apiResponse := data.AccountKeyValueResponse{} apiPath := addressPath + systemAccountAddress + "/key/" + tokenStorageKey - respCode, err := ngp.proc.CallGetRestEndPoint(observer.Address, apiPath, apiResponse) + respCode, err := ngp.proc.CallGetRestEndPoint(observer.Address, apiPath, &apiResponse) if err == nil || respCode == http.StatusBadRequest || respCode == http.StatusInternalServerError { log.Info("account value for key request", "address", systemAccountAddress, @@ -254,17 +254,17 @@ func (ngp *NodeGroupProcessor) GetWaitingEpochsLeftForPublicKey(publicKey string } var lastErr error - responseWaitingEpochsLeft := &data.WaitingEpochsLeftApiResponse{} + responseWaitingEpochsLeft := data.WaitingEpochsLeftApiResponse{} path := fmt.Sprintf(waitingEpochsLeftPath, publicKey) for _, observer := range observers { - _, lastErr = ngp.proc.CallGetRestEndPoint(observer.Address, path, responseWaitingEpochsLeft) + _, lastErr = ngp.proc.CallGetRestEndPoint(observer.Address, path, &responseWaitingEpochsLeft) if lastErr != nil { log.Error("waiting epochs left request", "observer", observer.Address, "public key", publicKey, "error", lastErr.Error()) continue } log.Info("waiting epochs left request", "shard ID", observer.ShardId, "observer", observer.Address, "public key", publicKey) - return responseWaitingEpochsLeft, nil + return &responseWaitingEpochsLeft, nil } diff --git a/process/nodeStatusProcessor.go b/process/nodeStatusProcessor.go index bdc19ac4..124f475b 100644 --- a/process/nodeStatusProcessor.go +++ b/process/nodeStatusProcessor.go @@ -95,7 +95,7 @@ func (nsp *NodeStatusProcessor) GetNetworkStatusMetrics(shardID uint32) (*data.G return nil, err } - responseNetworkMetrics := &data.GenericAPIResponse{} + responseNetworkMetrics := data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, NetworkStatusPath, &responseNetworkMetrics) @@ -105,7 +105,7 @@ func (nsp *NodeStatusProcessor) GetNetworkStatusMetrics(shardID uint32) (*data.G } log.Info("network metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } @@ -119,7 +119,7 @@ func (nsp *NodeStatusProcessor) GetNetworkConfigMetrics() (*data.GenericAPIRespo return nil, err } - responseNetworkMetrics := &data.GenericAPIResponse{} + responseNetworkMetrics := data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, NetworkConfigPath, &responseNetworkMetrics) @@ -129,7 +129,7 @@ func (nsp *NodeStatusProcessor) GetNetworkConfigMetrics() (*data.GenericAPIRespo } log.Info("network metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } @@ -143,7 +143,7 @@ func (nsp *NodeStatusProcessor) GetEnableEpochsMetrics() (*data.GenericAPIRespon return nil, err } - responseEnableEpochsMetrics := &data.GenericAPIResponse{} + responseEnableEpochsMetrics := data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, EnableEpochsPath, &responseEnableEpochsMetrics) @@ -153,7 +153,7 @@ func (nsp *NodeStatusProcessor) GetEnableEpochsMetrics() (*data.GenericAPIRespon } log.Info("enable epochs metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseEnableEpochsMetrics, nil + return &responseEnableEpochsMetrics, nil } return nil, WrapObserversError(responseEnableEpochsMetrics.Error) @@ -170,7 +170,7 @@ func (nsp *NodeStatusProcessor) GetAllIssuedESDTs(tokenType string) (*data.Gener return nil, err } - responseAllIssuedESDTs := &data.GenericAPIResponse{} + responseAllIssuedESDTs := data.GenericAPIResponse{} for _, observer := range observers { path := AllIssuedESDTsPath @@ -184,7 +184,7 @@ func (nsp *NodeStatusProcessor) GetAllIssuedESDTs(tokenType string) (*data.Gener } log.Info("all issued esdts request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseAllIssuedESDTs, nil + return &responseAllIssuedESDTs, nil } @@ -198,7 +198,7 @@ func (nsp *NodeStatusProcessor) GetDelegatedInfo() (*data.GenericAPIResponse, er return nil, err } - delegatedInfoResponse := &data.GenericAPIResponse{} + delegatedInfoResponse := data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, DelegatedInfoPath, &delegatedInfoResponse) @@ -208,7 +208,7 @@ func (nsp *NodeStatusProcessor) GetDelegatedInfo() (*data.GenericAPIResponse, er } log.Info("network delegated info request", "shard ID", observer.ShardId, "observer", observer.Address) - return delegatedInfoResponse, nil + return &delegatedInfoResponse, nil } @@ -222,7 +222,7 @@ func (nsp *NodeStatusProcessor) GetDirectStakedInfo() (*data.GenericAPIResponse, return nil, err } - directStakedResponse := &data.GenericAPIResponse{} + directStakedResponse := data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, DirectStakedPath, &directStakedResponse) @@ -232,7 +232,7 @@ func (nsp *NodeStatusProcessor) GetDirectStakedInfo() (*data.GenericAPIResponse, } log.Info("network direct staked request", "shard ID", observer.ShardId, "observer", observer.Address) - return directStakedResponse, nil + return &directStakedResponse, nil } @@ -246,7 +246,7 @@ func (nsp *NodeStatusProcessor) GetRatingsConfig() (*data.GenericAPIResponse, er return nil, err } - responseRatingsConfig := &data.GenericAPIResponse{} + responseRatingsConfig := data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, RatingsConfigPath, &responseRatingsConfig) @@ -256,7 +256,7 @@ func (nsp *NodeStatusProcessor) GetRatingsConfig() (*data.GenericAPIResponse, er } log.Info("ratings metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseRatingsConfig, nil + return &responseRatingsConfig, nil } @@ -269,7 +269,7 @@ func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.Gene return nil, err } - responseNetworkMetrics := &data.GenericAPIResponse{} + responseNetworkMetrics := data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, NodeStatusPath, &responseNetworkMetrics) @@ -279,7 +279,7 @@ func (nsp *NodeStatusProcessor) getNodeStatusMetrics(shardID uint32) (*data.Gene } log.Info("node status metrics request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseNetworkMetrics, nil + return &responseNetworkMetrics, nil } @@ -451,7 +451,7 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon return nil, err } - response := &data.GenericAPIResponse{} + response := data.GenericAPIResponse{} for _, observer := range observers { _, err = nsp.proc.CallGetRestEndPoint(observer.Address, GenesisNodesConfigPath, &response) @@ -461,7 +461,7 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon } log.Info("genesis nodes request", "shard ID", observer.ShardId, "observer", observer.Address) - return response, nil + return &response, nil } @@ -475,7 +475,7 @@ func (nsp *NodeStatusProcessor) GetGasConfigs() (*data.GenericAPIResponse, error return nil, err } - responseGenesisNodesConfig := &data.GenericAPIResponse{} + responseGenesisNodesConfig := data.GenericAPIResponse{} for _, observer := range observers { _, err := nsp.proc.CallGetRestEndPoint(observer.Address, GasConfigsPath, &responseGenesisNodesConfig) @@ -485,7 +485,7 @@ func (nsp *NodeStatusProcessor) GetGasConfigs() (*data.GenericAPIResponse, error } log.Info("gas configs request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseGenesisNodesConfig, nil + return &responseGenesisNodesConfig, nil } @@ -499,7 +499,7 @@ func (nsp *NodeStatusProcessor) GetEpochStartData(epoch uint32, shardID uint32) return nil, err } - responseEpochStartData := &data.GenericAPIResponse{} + responseEpochStartData := data.GenericAPIResponse{} path := fmt.Sprintf("/node/epoch-start/%d", epoch) for _, observer := range observers { @@ -510,7 +510,7 @@ func (nsp *NodeStatusProcessor) GetEpochStartData(epoch uint32, shardID uint32) } log.Info("epoch start data request", "shard ID", observer.ShardId, "observer", observer.Address) - return responseEpochStartData, nil + return &responseEpochStartData, nil } return nil, WrapObserversError(responseEpochStartData.Error) diff --git a/process/proofProcessor.go b/process/proofProcessor.go index 6dd9f54e..885c98d2 100644 --- a/process/proofProcessor.go +++ b/process/proofProcessor.go @@ -36,11 +36,11 @@ func (pp *ProofProcessor) GetProof(rootHash string, address string) (*data.Gener return nil, err } - responseGetProof := &data.GenericAPIResponse{} + responseGetProof := data.GenericAPIResponse{} getProofEndpoint := "/proof/root-hash/" + rootHash + "/address/" + address for _, observer := range observers { - respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofEndpoint, responseGetProof) + respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofEndpoint, &responseGetProof) if responseGetProof.Error != "" { return nil, errors.New(responseGetProof.Error) @@ -65,7 +65,7 @@ func (pp *ProofProcessor) GetProof(rootHash string, address string) (*data.Gener "http code", respCode, ) - return responseGetProof, nil + return &responseGetProof, nil } } @@ -79,11 +79,11 @@ func (pp *ProofProcessor) GetProofDataTrie(rootHash string, address string, key return nil, err } - responseGetProof := &data.GenericAPIResponse{} + responseGetProof := data.GenericAPIResponse{} getProofDataTrieEndpoint := fmt.Sprintf("/proof/root-hash/%s/address/%s/key/%s", rootHash, address, key) for _, observer := range observers { - respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofDataTrieEndpoint, responseGetProof) + respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofDataTrieEndpoint, &responseGetProof) if responseGetProof.Error != "" { return nil, errors.New(responseGetProof.Error) @@ -108,7 +108,7 @@ func (pp *ProofProcessor) GetProofDataTrie(rootHash string, address string, key "http code", respCode, ) - return responseGetProof, nil + return &responseGetProof, nil } } @@ -122,11 +122,11 @@ func (pp *ProofProcessor) GetProofCurrentRootHash(address string) (*data.Generic return nil, err } - responseGetProof := &data.GenericAPIResponse{} + responseGetProof := data.GenericAPIResponse{} getProofEndpoint := "/proof/address/" + address for _, observer := range observers { - respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofEndpoint, responseGetProof) + respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofEndpoint, &responseGetProof) if responseGetProof.Error != "" { return nil, errors.New(responseGetProof.Error) @@ -150,7 +150,7 @@ func (pp *ProofProcessor) GetProofCurrentRootHash(address string) (*data.Generic "http code", respCode, ) - return responseGetProof, nil + return &responseGetProof, nil } } @@ -170,10 +170,10 @@ func (pp *ProofProcessor) VerifyProof(rootHash string, address string, proof []s Address: address, Proof: proof, } - responseVerifyProof := &data.GenericAPIResponse{} + responseVerifyProof := data.GenericAPIResponse{} for _, observer := range observers { - respCode, err := pp.proc.CallPostRestEndPoint(observer.Address, verifyProofEndpoint, requestParams, responseVerifyProof) + respCode, err := pp.proc.CallPostRestEndPoint(observer.Address, verifyProofEndpoint, requestParams, &responseVerifyProof) if responseVerifyProof.Error != "" { return nil, errors.New(responseVerifyProof.Error) @@ -199,7 +199,7 @@ func (pp *ProofProcessor) VerifyProof(rootHash string, address string, proof []s "http code", respCode, ) - return responseVerifyProof, nil + return &responseVerifyProof, nil } } diff --git a/process/scQueryProcessor.go b/process/scQueryProcessor.go index 2fd66b18..3e4e9311 100644 --- a/process/scQueryProcessor.go +++ b/process/scQueryProcessor.go @@ -55,7 +55,7 @@ func (scQueryProcessor *SCQueryProcessor) ExecuteQuery(query *data.SCQuery) (*vm return nil, data.BlockInfo{}, err } - response := &data.ResponseVmValue{} + response := data.ResponseVmValue{} for _, observer := range observers { request := scQueryProcessor.createRequestFromQuery(query) @@ -73,7 +73,7 @@ func (scQueryProcessor *SCQueryProcessor) ExecuteQuery(query *data.SCQuery) (*vm path = path + "?" + queryParams } - httpStatus, err := scQueryProcessor.proc.CallPostRestEndPoint(observer.Address, path, request, response) + httpStatus, err := scQueryProcessor.proc.CallPostRestEndPoint(observer.Address, path, request, &response) isObserverDown := httpStatus == http.StatusNotFound || httpStatus == http.StatusRequestTimeout isOk := httpStatus == http.StatusOK responseHasExplicitError := len(response.Error) > 0 diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 5ab946b0..7fd8c97c 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -134,10 +134,10 @@ func (tp *TransactionProcessor) SendTransaction(tx *data.Transaction) (int, stri return http.StatusInternalServerError, "", err } - txResponse := &data.ResponseTransaction{} + txResponse := data.ResponseTransaction{} for _, observer := range observers { - respCode, err := tp.proc.CallPostRestEndPoint(observer.Address, TransactionSendPath, tx, txResponse) + respCode, err := tp.proc.CallPostRestEndPoint(observer.Address, TransactionSendPath, tx, &txResponse) if respCode == http.StatusOK && err == nil { log.Info(fmt.Sprintf("Transaction sent successfully to observer %v from shard %v, received tx hash %s", observer.Address, @@ -238,17 +238,17 @@ func (tp *TransactionProcessor) simulateTransaction( txSimulatePath += checkSignatureFalse } - txResponse := &data.ResponseTransactionSimulation{} + txResponse := data.ResponseTransactionSimulation{} for _, observer := range observers { - respCode, err := tp.proc.CallPostRestEndPoint(observer.Address, txSimulatePath, tx, txResponse) + respCode, err := tp.proc.CallPostRestEndPoint(observer.Address, txSimulatePath, tx, &txResponse) if respCode == http.StatusOK && err == nil { log.Info(fmt.Sprintf("Transaction simulation sent successfully to observer %v from shard %v, received tx hash %s", observer.Address, observer.ShardId, txResponse.Data.Result.Hash, )) - return txResponse, nil + return &txResponse, nil } // if observer was down (or didn't respond in time), skip to the next one diff --git a/process/txcost/transactionCostProcessor.go b/process/txcost/transactionCostProcessor.go index b323e67f..b4445315 100644 --- a/process/txcost/transactionCostProcessor.go +++ b/process/txcost/transactionCostProcessor.go @@ -119,11 +119,11 @@ func (tcp *transactionCostProcessor) executeRequest( observers []*data.NodeData, tx *data.Transaction, ) (*data.TxCostResponseData, error) { - txCostResponse := &data.ResponseTxCost{} + txCostResponse := data.ResponseTxCost{} for _, observer := range observers { - respCode, errCall := tcp.proc.CallPostRestEndPoint(observer.Address, TransactionCostPath, tx, txCostResponse) + respCode, errCall := tcp.proc.CallPostRestEndPoint(observer.Address, TransactionCostPath, tx, &txCostResponse) if respCode == http.StatusOK && errCall == nil { - return tcp.processResponse(senderShardID, receiverShardID, txCostResponse, tx) + return tcp.processResponse(senderShardID, receiverShardID, &txCostResponse, tx) } // if observer was down (or didn't respond in time), skip to the next one