diff --git a/process/accountProcessor.go b/process/accountProcessor.go index 75cf7b52..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{} for _, observer := range observers { - responseAccount := &data.AccountApiResponse{} 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 @@ -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, WrapObserversError(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 "", WrapObserversError(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, WrapObserversError(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, WrapObserversError(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, WrapObserversError(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, WrapObserversError(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, WrapObserversError(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, WrapObserversError(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, WrapObserversError(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, WrapObserversError(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, WrapObserversError(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,14 @@ 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, 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/accountProcessor_test.go b/process/accountProcessor_test.go index 61f0f13a..638acc82 100644 --- a/process/accountProcessor_test.go +++ b/process/accountProcessor_test.go @@ -126,7 +126,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) { @@ -227,7 +227,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 a3f5075a..56ea22c0 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) + 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, WrapObserversError(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) + 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, WrapObserversError(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 } + 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, WrapObserversError(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 } + 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, WrapObserversError(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) + 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, WrapObserversError(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) + 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, WrapObserversError(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) + 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, WrapObserversError(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) + 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, WrapObserversError(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) + 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, WrapObserversError(response.Error) } diff --git a/process/blockProcessor_test.go b/process/blockProcessor_test.go index 23c3cd63..f968223a 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..3f0b255d 100644 --- a/process/economicMetrics.go +++ b/process/economicMetrics.go @@ -28,8 +28,8 @@ func (nsp *NodeStatusProcessor) getEconomicsDataMetricsFromApi() (*data.GenericA } func (nsp *NodeStatusProcessor) getEconomicsDataMetrics(observers []*data.NodeData) (*data.GenericAPIResponse, error) { + responseNetworkMetrics := data.GenericAPIResponse{} for _, observer := range observers { - var responseNetworkMetrics *data.GenericAPIResponse _, err := nsp.proc.CallGetRestEndPoint(observer.Address, EconomicsDataPath, &responseNetworkMetrics) if err != nil { @@ -38,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, ErrSendingRequest + 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 ebc390ba..6f78a326 100644 --- a/process/esdtSupplyProcessor.go +++ b/process/esdtSupplyProcessor.go @@ -159,9 +159,9 @@ func (esp *esdtSupplyProcessor) getShardSupply(token string, shardID uint32) (*d return nil, errObs } + 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 { @@ -175,7 +175,7 @@ func (esp *esdtSupplyProcessor) getShardSupply(token string, shardID uint32) (*d } - return nil, ErrSendingRequest + return nil, WrapObserversError(responseEsdtSupply.Error) } func isFungibleESDT(tokenIdentifier string) bool { diff --git a/process/nodeGroupProcessor.go b/process/nodeGroupProcessor.go index caf4bf92..53ebe641 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, WrapObserversError(apiResponse.Error) } } @@ -254,7 +254,7 @@ 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) @@ -268,7 +268,7 @@ func (ngp *NodeGroupProcessor) GetWaitingEpochsLeftForPublicKey(publicKey string } - 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/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..124f475b 100644 --- a/process/nodeStatusProcessor.go +++ b/process/nodeStatusProcessor.go @@ -95,8 +95,8 @@ func (nsp *NodeStatusProcessor) GetNetworkStatusMetrics(shardID uint32) (*data.G return nil, err } + 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, WrapObserversError(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 } + 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, WrapObserversError(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 } + 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, WrapObserversError(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 } + 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, WrapObserversError(responseAllIssuedESDTs.Error) } // GetDelegatedInfo returns the delegated info from nodes @@ -198,8 +198,8 @@ func (nsp *NodeStatusProcessor) GetDelegatedInfo() (*data.GenericAPIResponse, er return nil, err } + 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, WrapObserversError(delegatedInfoResponse.Error) } // GetDirectStakedInfo returns the delegated info from nodes @@ -222,8 +222,8 @@ func (nsp *NodeStatusProcessor) GetDirectStakedInfo() (*data.GenericAPIResponse, return nil, err } + 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, WrapObserversError(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 } + 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, WrapObserversError(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 } + 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, WrapObserversError(responseNetworkMetrics.Error) } // GetLatestFullySynchronizedHyperblockNonce will compute nonce of the latest hyperblock that can be returned @@ -451,21 +451,21 @@ func (nsp *NodeStatusProcessor) GetGenesisNodesPubKeys() (*data.GenericAPIRespon return nil, err } + response := data.GenericAPIResponse{} for _, observer := range observers { - var responseGenesisNodesConfig *data.GenericAPIResponse - _, 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, ErrSendingRequest + return nil, WrapObserversError(response.Error) } // GetGasConfigs will return gas configs @@ -475,8 +475,8 @@ func (nsp *NodeStatusProcessor) GetGasConfigs() (*data.GenericAPIResponse, error return nil, err } + 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, WrapObserversError(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 } + 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, WrapObserversError(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..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{} getProofEndpoint := "/proof/root-hash/" + rootHash + "/address/" + address for _, observer := range observers { - responseGetProof := &data.GenericAPIResponse{} - 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,11 +65,11 @@ func (pp *ProofProcessor) GetProof(rootHash string, address string) (*data.Gener "http code", respCode, ) - return responseGetProof, nil + return &responseGetProof, nil } } - return nil, ErrSendingRequest + return nil, WrapObserversError(responseGetProof.Error) } // GetProofDataTrie sends the request to the right observer and then replies with the returned answer @@ -79,11 +79,11 @@ 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) + respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofDataTrieEndpoint, &responseGetProof) if responseGetProof.Error != "" { return nil, errors.New(responseGetProof.Error) @@ -108,11 +108,11 @@ func (pp *ProofProcessor) GetProofDataTrie(rootHash string, address string, key "http code", respCode, ) - return responseGetProof, nil + return &responseGetProof, nil } } - return nil, ErrSendingRequest + return nil, WrapObserversError(responseGetProof.Error) } // GetProofCurrentRootHash sends the request to the right observer and then replies with the returned answer @@ -122,11 +122,11 @@ 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) + respCode, err := pp.proc.CallGetRestEndPoint(observer.Address, getProofEndpoint, &responseGetProof) if responseGetProof.Error != "" { return nil, errors.New(responseGetProof.Error) @@ -150,11 +150,11 @@ func (pp *ProofProcessor) GetProofCurrentRootHash(address string) (*data.Generic "http code", respCode, ) - return responseGetProof, nil + return &responseGetProof, nil } } - return nil, ErrSendingRequest + return nil, WrapObserversError(responseGetProof.Error) } // VerifyProof sends the request to the right observer and then replies with the returned answer @@ -170,10 +170,10 @@ 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) + respCode, err := pp.proc.CallPostRestEndPoint(observer.Address, verifyProofEndpoint, requestParams, &responseVerifyProof) if responseVerifyProof.Error != "" { return nil, errors.New(responseVerifyProof.Error) @@ -199,11 +199,11 @@ func (pp *ProofProcessor) VerifyProof(rootHash string, address string, proof []s "http code", respCode, ) - return responseVerifyProof, nil + return &responseVerifyProof, nil } } - return nil, ErrSendingRequest + 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 6584a409..3e4e9311 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 { @@ -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 @@ -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{}, WrapObserversError(response.Error) } func (scQueryProcessor *SCQueryProcessor) createRequestFromQuery(query *data.SCQuery) data.VmValueRequest { diff --git a/process/scQueryProcessor_test.go b/process/scQueryProcessor_test.go index 9fe8ddcd..132e39e4 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 20335589..af125355 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{} for _, observer := range observers { - txResponse := &data.ResponseTransaction{} - 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, @@ -157,7 +157,7 @@ func (tp *TransactionProcessor) SendTransaction(tx *data.Transaction) (int, stri return respCode, "", err } - return http.StatusInternalServerError, "", ErrSendingRequest + return http.StatusInternalServerError, "", WrapObserversError(txResponse.Error) } // SimulateTransaction relays the post request by sending the request to the right observer and replies back the answer @@ -238,17 +238,17 @@ 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) + 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 @@ -261,7 +261,7 @@ func (tp *TransactionProcessor) simulateTransaction( return nil, err } - return nil, ErrSendingRequest + 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 c8805430..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{} for _, observer := range observers { - txCostResponse := &data.ResponseTxCost{} - 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 @@ -137,7 +137,7 @@ func (tcp *transactionCostProcessor) executeRequest( } - return nil, ErrSendingRequest + return nil, process.WrapObserversError(txCostResponse.Error) } func (tcp *transactionCostProcessor) processResponse(