mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
Remove deduplication in NodeInfo response (#3070)
* Remove deduplication in NodeInfo response * remove unused dependencies
This commit is contained in:
parent
094ab5e77d
commit
d1d2dd6881
@ -25,6 +25,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -71,7 +72,6 @@ import (
|
|||||||
"github.com/ledgerwatch/log/v3"
|
"github.com/ledgerwatch/log/v3"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
"modernc.org/sortutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config contains the configuration options of the ETH protocol.
|
// Config contains the configuration options of the ETH protocol.
|
||||||
@ -650,7 +650,7 @@ func (s *Ethereum) NodesInfo(limit int) (*remote.NodesInfoReply, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nodesInfo := &remote.NodesInfoReply{NodesInfo: nodes}
|
nodesInfo := &remote.NodesInfoReply{NodesInfo: nodes}
|
||||||
nodesInfo.NodesInfo = nodesInfo.NodesInfo[:sortutil.Dedupe(nodesInfo)]
|
sort.Sort(nodesInfo)
|
||||||
|
|
||||||
return nodesInfo, nil
|
return nodesInfo, nil
|
||||||
}
|
}
|
||||||
|
@ -1,108 +0,0 @@
|
|||||||
package eth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/ledgerwatch/erigon-lib/direct"
|
|
||||||
"github.com/ledgerwatch/erigon-lib/gointerfaces/sentry"
|
|
||||||
"github.com/ledgerwatch/erigon-lib/gointerfaces/types"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/protobuf/types/known/emptypb"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNodesInfo_Deduplication(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
limit int
|
|
||||||
nodes []*types.NodeInfoReply
|
|
||||||
want []*types.NodeInfoReply
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "one node",
|
|
||||||
nodes: []*types.NodeInfoReply{{Name: "name", Enode: "enode"}},
|
|
||||||
want: []*types.NodeInfoReply{{Name: "name", Enode: "enode"}},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "two different nodes",
|
|
||||||
nodes: []*types.NodeInfoReply{
|
|
||||||
{Name: "name1", Enode: "enode1"},
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
},
|
|
||||||
want: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name1", Enode: "enode1"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "two same nodes",
|
|
||||||
nodes: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
},
|
|
||||||
want: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "three nodes",
|
|
||||||
nodes: []*types.NodeInfoReply{
|
|
||||||
{Name: "name2", Enode: "enode2"},
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name1", Enode: "enode1"},
|
|
||||||
},
|
|
||||||
want: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name1", Enode: "enode1"},
|
|
||||||
{Name: "name2", Enode: "enode2"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "three nodes with repeats",
|
|
||||||
nodes: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name1", Enode: "enode1"},
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
},
|
|
||||||
want: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name1", Enode: "enode1"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "three same nodes",
|
|
||||||
nodes: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
},
|
|
||||||
want: []*types.NodeInfoReply{
|
|
||||||
{Name: "name", Enode: "enode"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
eth := Ethereum{}
|
|
||||||
|
|
||||||
for _, n := range tt.nodes {
|
|
||||||
n := n
|
|
||||||
eth.sentries = append(eth.sentries,
|
|
||||||
direct.NewSentryClientRemote(&sentry.SentryClientMock{
|
|
||||||
NodeInfoFunc: func(context.Context, *emptypb.Empty, ...grpc.CallOption) (*types.NodeInfoReply, error) {
|
|
||||||
return n, nil
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
got, err := eth.NodesInfo(tt.limit)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Equal(t, tt.want, got.NodesInfo)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
1
go.mod
1
go.mod
@ -63,6 +63,5 @@ require (
|
|||||||
google.golang.org/protobuf v1.27.1
|
google.golang.org/protobuf v1.27.1
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
|
||||||
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6
|
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200619000410-60c24ae608a6
|
||||||
modernc.org/sortutil v1.1.0 // indirect
|
|
||||||
pgregory.net/rapid v0.4.7
|
pgregory.net/rapid v0.4.7
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -832,7 +832,6 @@ github.com/prometheus/procfs v0.3.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
|
|||||||
github.com/quasilyte/go-ruleguard/dsl v0.3.6 h1:W2wnISJifyda0x/RXq15Qjrsu9iOhX2gy4+Ku+owylw=
|
github.com/quasilyte/go-ruleguard/dsl v0.3.6 h1:W2wnISJifyda0x/RXq15Qjrsu9iOhX2gy4+Ku+owylw=
|
||||||
github.com/quasilyte/go-ruleguard/dsl v0.3.6/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU=
|
github.com/quasilyte/go-ruleguard/dsl v0.3.6/go.mod h1:KeCP03KrjuSO0H1kTuZQCWlQPulDV6YMIXmpQss17rU=
|
||||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
|
||||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
@ -1507,9 +1506,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
|||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||||
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
|
|
||||||
modernc.org/sortutil v1.1.0 h1:oP3U4uM+NT/qBQcbg/K2iqAX0Nx7B1b6YZtq3Gk/PjM=
|
|
||||||
modernc.org/sortutil v1.1.0/go.mod h1:ZyL98OQHJgH9IEfN71VsamvJgrtRX9Dj2gX+vH86L1k=
|
|
||||||
pgregory.net/rapid v0.4.7 h1:MTNRktPuv5FNqOO151TM9mDTa+XHcX6ypYeISDVD14g=
|
pgregory.net/rapid v0.4.7 h1:MTNRktPuv5FNqOO151TM9mDTa+XHcX6ypYeISDVD14g=
|
||||||
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
|
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
|
||||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||||
|
Loading…
Reference in New Issue
Block a user