Skip to content

Commit

Permalink
Merge pull request #411 from multiversx/move_validatorAPIResponse
Browse files Browse the repository at this point in the history
Moved ValidatorAPIResponse to mx-chain-core-go
  • Loading branch information
sstanculeanu authored Dec 12, 2023
2 parents 202181b + a50aa36 commit 3995136
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 54 deletions.
1 change: 1 addition & 0 deletions api/groups/baseGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestCrudOperationsBaseGroup(t *testing.T) {
assert.Equal(t, hd2.Path, bg.endpoints[2].Path)

err = bg.AddEndpoint(hd4.Path, *hd4)
assert.NoError(t, err)
assert.Equal(t, 4, len(bg.endpoints))

// ensure the order
Expand Down
6 changes: 6 additions & 0 deletions api/groups/baseProofGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestGetProof_FailWhenFacadeGetProofFails(t *testing.T) {
ws := startProxyServer(proofGroup, "/proof")

req, err := http.NewRequest("GET", "/proof/root-hash/"+rootHash+"/address/"+address, nil)
require.NoError(t, err)

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)
Expand Down Expand Up @@ -82,6 +83,7 @@ func TestGetProof(t *testing.T) {
ws := startProxyServer(proofGroup, "/proof")

req, err := http.NewRequest("GET", "/proof/root-hash/"+rootHash+"/address/"+address, nil)
require.NoError(t, err)

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)
Expand Down Expand Up @@ -128,6 +130,7 @@ func TestVerifyProof_FailWhenFacadeVerifyProofFails(t *testing.T) {
}
verifyProofBytes, _ := json.Marshal(varifyProofParams)
req, err := http.NewRequest("POST", "/proof/verify", bytes.NewBuffer(verifyProofBytes))
require.NoError(t, err)

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)
Expand Down Expand Up @@ -165,6 +168,7 @@ func TestVerifyProof(t *testing.T) {
}
verifyProofBytes, _ := json.Marshal(varifyProofParams)
req, err := http.NewRequest("POST", "/proof/verify", bytes.NewBuffer(verifyProofBytes))
require.NoError(t, err)

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)
Expand Down Expand Up @@ -200,6 +204,7 @@ func TestGetProofDataTrie_FailWhenFacadeGetProofFails(t *testing.T) {

endpoint := fmt.Sprintf("/proof/root-hash/%s/address/%s/key/%s", rootHash, address, key)
req, err := http.NewRequest("GET", endpoint, nil)
require.NoError(t, err)

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)
Expand Down Expand Up @@ -235,6 +240,7 @@ func TestGetProofDataTrie(t *testing.T) {

endpoint := fmt.Sprintf("/proof/root-hash/%s/address/%s/key/%s", rootHash, address, key)
req, err := http.NewRequest("GET", endpoint, nil)
require.NoError(t, err)

resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)
Expand Down
2 changes: 1 addition & 1 deletion api/groups/baseValidatorGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestValidatorStatistics_ShouldWork(t *testing.T) {
TotalNumValidatorSuccess: 6,
TotalNumValidatorFailure: 7,
TotalNumValidatorIgnoredSignatures: 8,
ShardID: 1,
ShardId: 1,
ValidatorStatus: "ok",
RatingModifier: 1.5,
}
Expand Down
3 changes: 3 additions & 0 deletions api/groups/v_next/accountsGroupV_next.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func NewAccountsGroupV_next(baseAccountsGroup data.GroupHandler, facadeHandler d
Handler: ag.NewEndpoint,
Method: http.MethodGet,
})
if err != nil {
return nil, err
}

return ag, nil
}
Expand Down
2 changes: 2 additions & 0 deletions api/middleware/rateLimiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestRateLimiter_IpRestrictionRaisedAndErased(t *testing.T) {
t.Parallel()

rl, err := NewRateLimiter(map[string]uint64{"/address/:address": 2}, time.Millisecond)
require.NoError(t, err)

facade := &mock.FacadeStub{
GetAccountHandler: func(address string, _ common.AccountQueryOptions) (*data.AccountModel, error) {
Expand Down Expand Up @@ -81,6 +82,7 @@ func TestRateLimiter_EndpointNotLimitedShouldNotRaiseRestrictions(t *testing.T)
t.Parallel()

rl, err := NewRateLimiter(map[string]uint64{"/address/:address/nonce": 1}, time.Millisecond)
require.NoError(t, err)

facade := &mock.FacadeStub{
GetAccountHandler: func(address string, _ common.AccountQueryOptions) (*data.AccountModel, error) {
Expand Down
20 changes: 3 additions & 17 deletions data/account.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package data

import "github.com/multiversx/mx-chain-core-go/data/validator"

// AccountModel defines an account model (with associated information)
type AccountModel struct {
Account Account `json:"account"`
Expand All @@ -21,23 +23,7 @@ type Account struct {
}

// ValidatorApiResponse represents the data which is fetched from each validator for returning it in API call
type ValidatorApiResponse struct {
TempRating float32 `json:"tempRating"`
NumLeaderSuccess uint32 `json:"numLeaderSuccess"`
NumLeaderFailure uint32 `json:"numLeaderFailure"`
NumValidatorSuccess uint32 `json:"numValidatorSuccess"`
NumValidatorFailure uint32 `json:"numValidatorFailure"`
NumValidatorIgnoredSignatures uint32 `json:"numValidatorIgnoredSignatures"`
Rating float32 `json:"rating"`
RatingModifier float32 `json:"ratingModifier"`
TotalNumLeaderSuccess uint32 `json:"totalNumLeaderSuccess"`
TotalNumLeaderFailure uint32 `json:"totalNumLeaderFailure"`
TotalNumValidatorSuccess uint32 `json:"totalNumValidatorSuccess"`
TotalNumValidatorFailure uint32 `json:"totalNumValidatorFailure"`
TotalNumValidatorIgnoredSignatures uint32 `json:"totalNumValidatorIgnoredSignatures"`
ShardID uint32 `json:"shardId"`
ValidatorStatus string `json:"validatorStatus"`
}
type ValidatorApiResponse = validator.ValidatorStatistics

// ValidatorStatisticsResponse respects the format the validator statistics are received from the observers
type ValidatorStatisticsResponse struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gin-contrib/pprof v1.4.0
github.com/gin-contrib/static v0.0.1
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-core-go v1.2.16
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592
github.com/multiversx/mx-chain-crypto-go v1.2.9
github.com/multiversx/mx-chain-es-indexer-go v1.4.13
github.com/multiversx/mx-chain-logger-go v1.0.13
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-core-go v1.2.16 h1:m0hUNmZQjGJxKDLQOHoM9jSaeDfVTbyd+mqiS8+NckE=
github.com/multiversx/mx-chain-core-go v1.2.16/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 h1:fXpqfN64mLKvJycf5doOhvFRLM06eaMi7Ag3mO1fsbg=
github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU=
github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8=
github.com/multiversx/mx-chain-es-indexer-go v1.4.13 h1:3Ayaw9bSpeNOF+Z3L/11MN1rIJH8Rc6dqtt+o4Wfdno=
Expand Down
16 changes: 4 additions & 12 deletions observer/baseNodeProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,10 @@ func (bnp *baseNodeProvider) GetAllNodesWithSyncState() []*data.NodeData {
defer bnp.mutNodes.RUnlock()

nodesSlice := make([]*data.NodeData, 0)
for _, node := range bnp.syncedNodes {
nodesSlice = append(nodesSlice, node)
}
for _, node := range bnp.outOfSyncNodes {
nodesSlice = append(nodesSlice, node)
}
for _, node := range bnp.syncedFallbackNodes {
nodesSlice = append(nodesSlice, node)
}
for _, node := range bnp.outOfSyncFallbackNodes {
nodesSlice = append(nodesSlice, node)
}
nodesSlice = append(nodesSlice, bnp.syncedNodes...)
nodesSlice = append(nodesSlice, bnp.outOfSyncNodes...)
nodesSlice = append(nodesSlice, bnp.syncedFallbackNodes...)
nodesSlice = append(nodesSlice, bnp.outOfSyncFallbackNodes...)

return nodesSlice
}
Expand Down
6 changes: 2 additions & 4 deletions observer/circularQueueNodesProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ func TestCircularQueueObserversProvider_GetAllObservers_ConcurrentSafe(t *testin
numOfTimesToCallForEachRoutine := 8
mapCalledObservers := make(map[string]int)
mutMap := &sync.RWMutex{}
var observers []*data.NodeData
observers = []*data.NodeData{
observers := []*data.NodeData{
{
Address: "addr1",
ShardId: 0,
Expand Down Expand Up @@ -194,8 +193,7 @@ func TestCircularQueueObserversProvider_GetObserversByShardId_ConcurrentSafe(t *
numOfTimesToCallForEachRoutine := 6
mapCalledObservers := make(map[string]int)
mutMap := &sync.RWMutex{}
var observers []*data.NodeData
observers = []*data.NodeData{
observers := []*data.NodeData{
{
Address: "addr1",
ShardId: shardId0,
Expand Down
6 changes: 2 additions & 4 deletions observer/simpleNodesProvider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func TestSimpleObserversProvider_GetObserversByShardId_ConcurrentSafe(t *testing
numOfTimesToCallForEachRoutine := 6
mapCalledObservers := make(map[string]int)
mutMap := &sync.RWMutex{}
var observers []*data.NodeData
observers = []*data.NodeData{
observers := []*data.NodeData{
{
Address: "addr1",
ShardId: shardId0,
Expand Down Expand Up @@ -135,8 +134,7 @@ func TestSimpleObserversProvider_GetAllObservers_ConcurrentSafe(t *testing.T) {
numOfTimesToCallForEachRoutine := 6
mapCalledObservers := make(map[string]int)
mutMap := &sync.RWMutex{}
var observers []*data.NodeData
observers = []*data.NodeData{
observers := []*data.NodeData{
{
Address: "addr1",
ShardId: shardId0,
Expand Down
6 changes: 1 addition & 5 deletions process/baseProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,7 @@ func (bp *BaseProcessor) getNodeStatusResponseFromAPI(url string) (*proxyData.No
}

func parseBool(metricValue string) bool {
if strconv.FormatBool(true) == metricValue {
return true
}

return false
return strconv.FormatBool(true) == metricValue
}

// IsInterfaceNil returns true if there is no value under the interface
Expand Down
2 changes: 0 additions & 2 deletions process/esdtSupplyProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ func addToSupply(dstSupply, sourceSupply *data.ESDTSupply) {
dstSupply.Supply = sumStr(dstSupply.Supply, sourceSupply.Supply)
dstSupply.Burned = sumStr(dstSupply.Burned, sourceSupply.Burned)
dstSupply.Minted = sumStr(dstSupply.Minted, sourceSupply.Minted)

return
}

func sumStr(s1, s2 string) string {
Expand Down
5 changes: 1 addition & 4 deletions process/transactionProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,8 @@ func checkIfMoveBalanceNotarized(tx *transaction.ApiTransactionResult) bool {
return false
}
isMoveBalance := tx.ProcessingTypeOnSource == moveBalanceDescriptor && tx.ProcessingTypeOnDestination == moveBalanceDescriptor
if !isMoveBalance {
return false
}

return true
return isMoveBalance
}

func findIdentifierInLogs(logs []*transaction.ApiLogs, identifier string) bool {
Expand Down
4 changes: 2 additions & 2 deletions testing/testHttpServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (ths *TestHttpServer) processRequestValidatorStatistics(rw http.ResponseWri
TotalNumValidatorSuccess: 8,
TotalNumValidatorFailure: 5,
TotalNumValidatorIgnoredSignatures: 120,
ShardID: core.MetachainShardId,
ShardId: core.MetachainShardId,
ValidatorStatus: "waiting",
},
"pubkey2": {
Expand All @@ -255,7 +255,7 @@ func (ths *TestHttpServer) processRequestValidatorStatistics(rw http.ResponseWri
TotalNumValidatorSuccess: 78,
TotalNumValidatorFailure: 25,
TotalNumValidatorIgnoredSignatures: 110,
ShardID: 1,
ShardId: 1,
ValidatorStatus: "eligible",
},
}
Expand Down

0 comments on commit 3995136

Please sign in to comment.