Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat fix peers rating handler #4800

Merged
merged 50 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
15d5512
added missing call to DecreaseRating on peersRatingHandler when a req…
sstanculeanu Dec 2, 2022
348a321
Merge pull request #4755 from ElrondNetwork/fix_peers_rating_handler_…
sstanculeanu Dec 8, 2022
90fbd1c
updated elrond-go-p2p to use the latest version with appStatusHandler…
sstanculeanu Dec 8, 2022
20b68df
updated elrond-go-p2p to latest + extra integration test on cachers c…
sstanculeanu Dec 9, 2022
990acd8
updated elrond-go-p2p to latest
sstanculeanu Dec 12, 2022
b01a1c8
fix toml indentation
sstanculeanu Dec 13, 2022
e8f486b
Merge remote-tracking branch 'origin/feat/fix-peers-rating-handler' i…
sstanculeanu Dec 13, 2022
834c36f
added unittests back after merge
sstanculeanu Dec 13, 2022
9406531
Merge pull request #4780 from ElrondNetwork/fix_peers_rating_handler
sstanculeanu Dec 13, 2022
dd9ea06
Merge remote-tracking branch 'origin/feat/fix-peers-rating-handler' i…
sstanculeanu Dec 13, 2022
8115a09
fixes after merge
sstanculeanu Dec 13, 2022
3c43da0
updated elrond-go-p2p to latest
sstanculeanu Dec 13, 2022
54711c2
Merge pull request #4781 from ElrondNetwork/peers_rating_handler_inte…
sstanculeanu Dec 13, 2022
2fc5c47
Merge remote-tracking branch 'origin/rc/v1.5.0' into merge_rc_into_fe…
sstanculeanu Dec 29, 2022
e46c9f2
updated elrond-go-p2p after merge
sstanculeanu Dec 29, 2022
3e93906
Merge pull request #4840 from ElrondNetwork/merge_rc_into_feat_fix_pe…
sstanculeanu Jan 3, 2023
8ecf3c2
Merge remote-tracking branch 'origin/rc/v1.5.0' into merge_rc_into_fe…
sstanculeanu Jan 25, 2023
70dd0c9
fixes after merge
sstanculeanu Jan 25, 2023
29b7a41
go mod tidy
sstanculeanu Jan 25, 2023
9660162
Merge pull request #4901 from multiversx/merge_rc_into_feat_fix_peers…
sstanculeanu Jan 25, 2023
eaa8e61
Merge remote-tracking branch 'origin/rc/v1.5.0' into merge_rc150_into…
sstanculeanu Feb 14, 2023
ee2b61e
updated mx-chain-p2p-go after merge
sstanculeanu Feb 14, 2023
c0c667c
Merge pull request #4985 from multiversx/merge_rc150_into_feat_fix_pe…
sstanculeanu Feb 14, 2023
70e08e9
updated mx-chain-p2p-go to latest in order to include peers rating ha…
sstanculeanu Mar 2, 2023
182df1e
removed constant not used
sstanculeanu Mar 2, 2023
fca1cb6
added extra broadcast on peers rating tests
sstanculeanu Mar 2, 2023
9ff23e0
removed testing prints
sstanculeanu Mar 3, 2023
1117056
Merge branch 'rc/v1.6.0' into merge_rc160_into_feat_fix_peers_rating_…
sstanculeanu Mar 6, 2023
7bd6b35
Merge pull request #5053 from multiversx/merge_rc160_into_feat_fix_pe…
sstanculeanu Mar 6, 2023
6ea9584
Merge branch 'feat/fix-peers-rating-handler' into update_p2p
sstanculeanu Mar 6, 2023
a52211a
updated mx-chain-p2p-go to latest
sstanculeanu Mar 6, 2023
46aa916
Merge remote-tracking branch 'origin/rc/v1.6.0' into merge_rc_160_int…
sstanculeanu Mar 6, 2023
315ab4d
updated mx-chain-p2p-go to latest
sstanculeanu Mar 6, 2023
30eb7c2
Merge pull request #5054 from multiversx/merge_rc_160_into_feat_fix_p…
sstanculeanu Mar 6, 2023
fa20839
Merge branch 'feat/fix-peers-rating-handler' of https://github.com/mu…
sstanculeanu Mar 6, 2023
2ca1bc4
updated mx-chain-p2p-go to latest
sstanculeanu Mar 6, 2023
d3225fe
Merge pull request #5050 from multiversx/update_p2p
sstanculeanu Mar 8, 2023
5ab0d7e
updated mx-chain-p2p-go to latest and integrated it
sstanculeanu Mar 14, 2023
4ad17e3
added new route /node/peers-rating
sstanculeanu Mar 14, 2023
655c0d6
added missing comma
sstanculeanu Mar 14, 2023
e4a63be
update mx-chain-p2p-go
sstanculeanu Mar 14, 2023
d4f8ec5
update mx-chain-p2p-go with latest fixes after review
sstanculeanu Mar 15, 2023
85a0786
update mx-chain-p2p-go
sstanculeanu Mar 15, 2023
fc41586
update mx-chain-p2p-go and updated node group test
sstanculeanu Mar 15, 2023
5bf61b9
fix after review
sstanculeanu Mar 15, 2023
0687f82
one more typo
sstanculeanu Mar 15, 2023
0c36be9
Merge pull request #5099 from multiversx/new_peers_rating_handler
sstanculeanu Mar 16, 2023
43ed016
Merge branch 'rc/v1.6.0' of https://github.com/multiversx/mx-chain-go…
sstanculeanu Mar 27, 2023
401d0b9
p2p updated
sstanculeanu Mar 27, 2023
79146d3
Merge pull request #5125 from multiversx/merge_rc160_into_feat_fix_pe…
sstanculeanu Mar 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 29 additions & 9 deletions api/groups/nodeGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ import (
)

const (
pidQueryParam = "pid"
debugPath = "/debug"
heartbeatStatusPath = "/heartbeatstatus"
metricsPath = "/metrics"
p2pStatusPath = "/p2pstatus"
peerInfoPath = "/peerinfo"
statusPath = "/status"
epochStartDataForEpoch = "/epoch-start/:epoch"
bootstrapStatusPath = "/bootstrapstatus"
pidQueryParam = "pid"
debugPath = "/debug"
heartbeatStatusPath = "/heartbeatstatus"
metricsPath = "/metrics"
p2pStatusPath = "/p2pstatus"
peerInfoPath = "/peerinfo"
statusPath = "/status"
epochStartDataForEpoch = "/epoch-start/:epoch"
bootstrapStatusPath = "/bootstrapstatus"
connectedPeersRatingsPath = "/connected-peers-ratings"
)

// nodeFacadeHandler defines the methods to be implemented by a facade for node requests
Expand All @@ -35,6 +36,7 @@ type nodeFacadeHandler interface {
GetQueryHandler(name string) (debug.QueryHandler, error)
GetEpochStartDataAPI(epoch uint32) (*common.EpochStartDataAPI, error)
GetPeerInfo(pid string) ([]core.QueryP2PPeerInfo, error)
GetConnectedPeersRatings() string
IsInterfaceNil() bool
}

Expand Down Expand Up @@ -102,6 +104,11 @@ func NewNodeGroup(facade nodeFacadeHandler) (*nodeGroup, error) {
Method: http.MethodGet,
Handler: ng.bootstrapMetrics,
},
{
Path: connectedPeersRatingsPath,
Method: http.MethodGet,
Handler: ng.connectedPeersRatings,
},
}
ng.endpoints = endpoints

Expand Down Expand Up @@ -318,6 +325,19 @@ func (ng *nodeGroup) bootstrapMetrics(c *gin.Context) {
)
}

// connectedPeersRatings returns the node's connected peers ratings
func (ng *nodeGroup) connectedPeersRatings(c *gin.Context) {
ratings := ng.getFacade().GetConnectedPeersRatings()
c.JSON(
http.StatusOK,
shared.GenericAPIResponse{
Data: gin.H{"ratings": ratings},
Error: "",
Code: shared.ReturnCodeSuccess,
},
)
}

func (ng *nodeGroup) getFacade() nodeFacadeHandler {
ng.mutFacade.RLock()
defer ng.mutFacade.RUnlock()
Expand Down
32 changes: 32 additions & 0 deletions api/groups/nodeGroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,37 @@ func TestBootstrapStatusMetrics_ShouldWork(t *testing.T) {
assert.True(t, valuesFound)
}

func TestBootstrapGetConnectedPeersRatings_ShouldWork(t *testing.T) {
providedRatings := map[string]string{
"pid1": "100",
"pid2": "-50",
"pid3": "-5",
}
buff, _ := json.Marshal(providedRatings)
facade := mock.FacadeStub{
GetConnectedPeersRatingsCalled: func() string {
return string(buff)
},
}

nodeGroup, err := groups.NewNodeGroup(&facade)
require.NoError(t, err)

ws := startWebServer(nodeGroup, "node", getNodeRoutesConfig())

req, _ := http.NewRequest("GET", "/node/connected-peers-ratings", nil)
resp := httptest.NewRecorder()
ws.ServeHTTP(resp, req)

response := &shared.GenericAPIResponse{}
loadResponse(resp.Body, response)
respMap, ok := response.Data.(map[string]interface{})
assert.True(t, ok)
ratings, ok := respMap["ratings"].(string)
assert.True(t, ok)
assert.Equal(t, string(buff), ratings)
}

func TestStatusMetrics_ShouldDisplayNonP2pMetrics(t *testing.T) {
statusMetricsProvider := statusHandler.NewStatusMetrics()
key := "test-details-key"
Expand Down Expand Up @@ -595,6 +626,7 @@ func getNodeRoutesConfig() config.ApiRoutesConfig {
{Name: "/peerinfo", Open: true},
{Name: "/epoch-start/:epoch", Open: true},
{Name: "/bootstrapstatus", Open: true},
{Name: "/connected-peers-ratings", Open: true},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions api/mock/facadeStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type FacadeStub struct {
GetQueryHandlerCalled func(name string) (debug.QueryHandler, error)
GetValueForKeyCalled func(address string, key string, options api.AccountQueryOptions) (string, api.BlockInfo, error)
GetPeerInfoCalled func(pid string) ([]core.QueryP2PPeerInfo, error)
GetConnectedPeersRatingsCalled func() string
GetEpochStartDataAPICalled func(epoch uint32) (*common.EpochStartDataAPI, error)
GetThrottlerForEndpointCalled func(endpoint string) (core.Throttler, bool)
GetUsernameCalled func(address string, options api.AccountQueryOptions) (string, api.BlockInfo, error)
Expand Down Expand Up @@ -371,6 +372,11 @@ func (f *FacadeStub) GetPeerInfo(pid string) ([]core.QueryP2PPeerInfo, error) {
return f.GetPeerInfoCalled(pid)
}

// GetConnectedPeersRatings -
func (f *FacadeStub) GetConnectedPeersRatings() string {
return f.GetConnectedPeersRatingsCalled()
}

// GetEpochStartDataAPI -
func (f *FacadeStub) GetEpochStartDataAPI(epoch uint32) (*common.EpochStartDataAPI, error) {
return f.GetEpochStartDataAPICalled(epoch)
Expand Down
1 change: 1 addition & 0 deletions api/shared/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type FacadeHandler interface {
GetQueryHandler(name string) (debug.QueryHandler, error)
GetEpochStartDataAPI(epoch uint32) (*common.EpochStartDataAPI, error)
GetPeerInfo(pid string) ([]core.QueryP2PPeerInfo, error)
GetConnectedPeersRatings() string
GetProof(rootHash string, address string) (*common.GetProofResponse, error)
GetProofDataTrie(rootHash string, address string, key string) (*common.GetProofResponse, *common.GetProofResponse, error)
GetProofCurrentRootHash(address string) (*common.GetProofResponse, error)
Expand Down
5 changes: 4 additions & 1 deletion cmd/node/config/api.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
{ Name = "/epoch-start/:epoch", Open = true },

# /node/bootstrapstatus will return all metrics available during bootstrap
{ Name = "/bootstrapstatus", Open = true }
{ Name = "/bootstrapstatus", Open = true },

# /node/connected-peers-ratings will return the peers ratings
{ Name = "/connected-peers-ratings", Open = true }
]

[APIPackages.address]
Expand Down
4 changes: 2 additions & 2 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@
Type = "LRU"

[PeersRatingConfig]
TopRatedCacheCapacity = 5000
BadRatedCacheCapacity = 5000
TopRatedCacheCapacity = 5000
BadRatedCacheCapacity = 5000

[PoolsCleanersConfig]
MaxRoundsToKeepUnprocessedMiniBlocks = 300 # max number of rounds unprocessed miniblocks are kept in pool
Expand Down
2 changes: 1 addition & 1 deletion config/overridableConfig/configOverriding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/multiversx/mx-chain-go/config"
p2pConfig "github.com/multiversx/mx-chain-p2p-go/config"
p2pConfig "github.com/multiversx/mx-chain-go/p2p/config"
"github.com/stretchr/testify/require"
)

Expand Down
4 changes: 2 additions & 2 deletions consensus/mock/messageSigningHandlerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"

"github.com/multiversx/mx-chain-go/p2p"
"github.com/multiversx/mx-chain-p2p-go/message"
"github.com/multiversx/mx-chain-go/p2p/factory"
)

// MessageSignerMock implements P2PSigningHandler interface but it does nothing as it is disabled
Expand All @@ -28,7 +28,7 @@ func (ms *MessageSignerMock) Serialize(messages []p2p.MessageP2P) ([]byte, error

// Deserialize will unmarshal into a list of p2p messages
func (ms *MessageSignerMock) Deserialize(messagesBytes []byte) ([]p2p.MessageP2P, error) {
var messages []*message.Message
var messages []*factory.Message
err := json.Unmarshal(messagesBytes, &messages)
if err != nil {
return nil, err
Expand Down
13 changes: 7 additions & 6 deletions consensus/spos/bls/subroundEndRound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"github.com/multiversx/mx-chain-go/consensus/spos/bls"
"github.com/multiversx/mx-chain-go/dataRetriever/blockchain"
"github.com/multiversx/mx-chain-go/p2p"
"github.com/multiversx/mx-chain-go/p2p/factory"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/p2pmocks"
"github.com/multiversx/mx-chain-go/testscommon/statusHandler"
"github.com/multiversx/mx-chain-p2p-go/message"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -1369,7 +1370,7 @@ func TestVerifyInvalidSigners(t *testing.T) {

container := mock.InitConsensusCore()

invalidSigners := []p2p.MessageP2P{&message.Message{
invalidSigners := []p2p.MessageP2P{&factory.Message{
FromField: []byte("from"),
}}
invalidSignersBytes, _ := container.Marshalizer().Marshal(invalidSigners)
Expand Down Expand Up @@ -1405,7 +1406,7 @@ func TestVerifyInvalidSigners(t *testing.T) {
}
consensusMsgBytes, _ := container.Marshalizer().Marshal(consensusMsg)

invalidSigners := []p2p.MessageP2P{&message.Message{
invalidSigners := []p2p.MessageP2P{&factory.Message{
FromField: []byte("from"),
DataField: consensusMsgBytes,
}}
Expand Down Expand Up @@ -1448,7 +1449,7 @@ func TestVerifyInvalidSigners(t *testing.T) {
}
consensusMsgBytes, _ := container.Marshalizer().Marshal(consensusMsg)

invalidSigners := []p2p.MessageP2P{&message.Message{
invalidSigners := []p2p.MessageP2P{&factory.Message{
FromField: []byte("from"),
DataField: consensusMsgBytes,
}}
Expand Down Expand Up @@ -1536,8 +1537,8 @@ func TestGetFullMessagesForInvalidSigners(t *testing.T) {
container.SetMessageSigningHandler(messageSigningHandler)

sr := *initSubroundEndRoundWithContainer(container, &statusHandler.AppStatusHandlerStub{})
sr.AddMessageWithSignature("B", &mock.P2PMessageMock{})
sr.AddMessageWithSignature("C", &mock.P2PMessageMock{})
sr.AddMessageWithSignature("B", &p2pmocks.P2PMessageMock{})
sr.AddMessageWithSignature("C", &p2pmocks.P2PMessageMock{})

invalidSigners := []string{"B", "C"}

Expand Down