Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel' into download-1by1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Sharp authored and Alexey Sharp committed Apr 25, 2022
2 parents 12f123c + fc3eeca commit c6807b5
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 15 deletions.
11 changes: 2 additions & 9 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
}
log.Info("if you run RPCDaemon on same machine with Erigon add --datadir option")
}

if db != nil {
var cc *params.ChainConfig
if err := db.View(context.Background(), func(tx kv.Tx) error {
Expand All @@ -313,20 +314,17 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
cfg.Snapshot = ethconfig.NewSnapshotCfg(cfg.Snapshot.Enabled, cfg.Snapshot.KeepBlocks)
}

// if chain config has terminal total difficulty then rpc has to have these API's to function
// if chain config has terminal total difficulty then rpc must have eth and engine APIs enableds
if cc.TerminalTotalDifficulty != nil {
hasEthApiEnabled := false
hasEngineApiEnabled := false
hasNetApiEnabled := false

for _, api := range cfg.API {
switch api {
case "eth":
hasEthApiEnabled = true
case "engine":
hasEngineApiEnabled = true
case "net":
hasNetApiEnabled = true
}
}

Expand All @@ -337,11 +335,6 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
if !hasEngineApiEnabled {
cfg.API = append(cfg.API, "engine")
}

if !hasNetApiEnabled {
cfg.API = append(cfg.API, "net")
}

}
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/rpcdaemon/commands/admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import (
type AdminAPI interface {
// NodeInfo returns a collection of metadata known about the host.
NodeInfo(ctx context.Context) (*p2p.NodeInfo, error)

// Peers returns information about the connected remote nodes.
// https://geth.ethereum.org/docs/rpc/ns-admin#admin_peers
Peers(ctx context.Context) ([]*p2p.PeerInfo, error)
}

// AdminAPIImpl data structure to store things needed for admin_* commands.
Expand All @@ -39,3 +43,7 @@ func (api *AdminAPIImpl) NodeInfo(ctx context.Context) (*p2p.NodeInfo, error) {

return &nodes[0], nil
}

func (api *AdminAPIImpl) Peers(ctx context.Context) ([]*p2p.PeerInfo, error) {
return api.ethBackend.Peers(ctx)
}
38 changes: 38 additions & 0 deletions cmd/rpcdaemon/services/eth_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ApiBackend interface {
EngineForkchoiceUpdatedV1(ctx context.Context, request *remote.EngineForkChoiceUpdatedRequest) (*remote.EngineForkChoiceUpdatedReply, error)
EngineGetPayloadV1(ctx context.Context, payloadId uint64) (*types2.ExecutionPayload, error)
NodeInfo(ctx context.Context, limit uint32) ([]p2p.NodeInfo, error)
Peers(ctx context.Context) ([]*p2p.PeerInfo, error)
}

type RemoteBackend struct {
Expand Down Expand Up @@ -245,3 +246,40 @@ func (back *RemoteBackend) NodeInfo(ctx context.Context, limit uint32) ([]p2p.No

return ret, nil
}

func (back *RemoteBackend) Peers(ctx context.Context) ([]*p2p.PeerInfo, error) {
rpcPeers, err := back.remoteEthBackend.Peers(ctx, &emptypb.Empty{})
if err != nil {
return nil, fmt.Errorf("ETHBACKENDClient.Peers() error: %w", err)
}

peers := make([]*p2p.PeerInfo, 0, len(rpcPeers.Peers))

for _, rpcPeer := range rpcPeers.Peers {
peer := p2p.PeerInfo{
ENR: rpcPeer.Enr,
Enode: rpcPeer.Enode,
ID: rpcPeer.Id,
Name: rpcPeer.Name,
Caps: rpcPeer.Caps,
Network: struct {
LocalAddress string `json:"localAddress"`
RemoteAddress string `json:"remoteAddress"`
Inbound bool `json:"inbound"`
Trusted bool `json:"trusted"`
Static bool `json:"static"`
}{
LocalAddress: rpcPeer.ConnLocalAddr,
RemoteAddress: rpcPeer.ConnRemoteAddr,
Inbound: rpcPeer.ConnIsInbound,
Trusted: rpcPeer.ConnIsTrusted,
Static: rpcPeer.ConnIsStatic,
},
Protocols: nil,
}

peers = append(peers, &peer)
}

return peers, nil
}
33 changes: 30 additions & 3 deletions cmd/sentry/sentry/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,7 @@ func NewSentryServer(ctx context.Context, dialCandidates enode.Iterator, readNod
return readNodeInfo()
},
PeerInfo: func(peerID [64]byte) interface{} {
if peerInfo := ss.getPeer(peerID); peerInfo != nil {
return peerInfo.peer.Info()
}
// TODO: remember handshake reply per peer ID and return eth-related Status info (see ethPeerInfo in geth)
return nil
},
//Attributes: []enr.Entry{eth.CurrentENREntry(chainConfig, genesisHash, headHeight)},
Expand Down Expand Up @@ -871,6 +869,35 @@ func (ss *SentryServerImpl) SetStatus(ctx context.Context, statusData *proto_sen
return reply, nil
}

func (ss *SentryServerImpl) Peers(_ context.Context, _ *emptypb.Empty) (*proto_sentry.PeersReply, error) {
if ss.P2pServer == nil {
return nil, errors.New("p2p server was not started")
}

peers := ss.P2pServer.PeersInfo()

var reply proto_sentry.PeersReply
reply.Peers = make([]*proto_types.PeerInfo, 0, len(peers))

for _, peer := range peers {
rpcPeer := proto_types.PeerInfo{
Id: peer.ID,
Name: peer.Name,
Enode: peer.Enode,
Enr: peer.ENR,
Caps: peer.Caps,
ConnLocalAddr: peer.Network.LocalAddress,
ConnRemoteAddr: peer.Network.RemoteAddress,
ConnIsInbound: peer.Network.Inbound,
ConnIsTrusted: peer.Network.Trusted,
ConnIsStatic: peer.Network.Static,
}
reply.Peers = append(reply.Peers, &rpcPeer)
}

return &reply, nil
}

func (ss *SentryServerImpl) SimplePeerCount() (pc int) {
ss.rangePeers(func(peerInfo *PeerInfo) bool {
pc++
Expand Down
13 changes: 13 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"google.golang.org/protobuf/types/known/emptypb"
"math/big"
"os"
"path/filepath"
Expand Down Expand Up @@ -770,6 +771,18 @@ func (s *Ethereum) NodesInfo(limit int) (*remote.NodesInfoReply, error) {
return nodesInfo, nil
}

func (s *Ethereum) Peers(ctx context.Context) (*remote.PeersReply, error) {
var reply remote.PeersReply
for _, sentryClient := range s.sentries {
peers, err := sentryClient.Peers(ctx, &emptypb.Empty{})
if err != nil {
return nil, fmt.Errorf("Ethereum backend SentryClient.Peers error: %w", err)
}
reply.Peers = append(reply.Peers, peers.Peers...)
}
return &reply, nil
}

// Protocols returns all the currently configured
// network protocols to start.
func (s *Ethereum) Protocols() []p2p.Protocol {
Expand Down
5 changes: 5 additions & 0 deletions ethdb/privateapi/ethbackend.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type EthBackend interface {
NetVersion() (uint64, error)
NetPeerCount() (uint64, error)
NodesInfo(limit int) (*remote.NodesInfoReply, error)
Peers(ctx context.Context) (*remote.PeersReply, error)
}

// This is the status of a newly execute block.
Expand Down Expand Up @@ -616,6 +617,10 @@ func (s *EthBackendServer) NodeInfo(_ context.Context, r *remote.NodesInfoReques
return nodesInfo, nil
}

func (s *EthBackendServer) Peers(ctx context.Context, _ *emptypb.Empty) (*remote.PeersReply, error) {
return s.eth.Peers(ctx)
}

func (s *EthBackendServer) SubscribeLogs(server remote.ETHBACKEND_SubscribeLogsServer) (err error) {
if s.logsFilter != nil {
return s.logsFilter.subscribeLogs(server)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/json-iterator/go v1.1.12
github.com/julienschmidt/httprouter v1.3.0
github.com/kevinburke/go-bindata v3.21.0+incompatible
github.com/ledgerwatch/erigon-lib v0.0.0-20220423144324-c3b480409230
github.com/ledgerwatch/erigon-lib v0.0.0-20220425121849-c73165f269e0
github.com/ledgerwatch/log/v3 v3.4.1
github.com/ledgerwatch/secp256k1 v1.0.0
github.com/pelletier/go-toml v1.9.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3P
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20220423144324-c3b480409230 h1:zcnLesdHt2/hLmCPo21zSzMcmhupkZfYp4GyesmodiY=
github.com/ledgerwatch/erigon-lib v0.0.0-20220423144324-c3b480409230/go.mod h1:0VKhW10UjEr7I6DaV+N0KNbXvMygC99qmRl2CfaN9gw=
github.com/ledgerwatch/erigon-lib v0.0.0-20220425121849-c73165f269e0 h1:nDbzAEItEqkoxjJrnegSGUrxJjuJatATww5QZT40hmo=
github.com/ledgerwatch/erigon-lib v0.0.0-20220425121849-c73165f269e0/go.mod h1:0VKhW10UjEr7I6DaV+N0KNbXvMygC99qmRl2CfaN9gw=
github.com/ledgerwatch/log/v3 v3.4.1 h1:/xGwlVulXnsO9Uq+tzaExc8OWmXXHU0dnLalpbnY5Bc=
github.com/ledgerwatch/log/v3 v3.4.1/go.mod h1:VXcz6Ssn6XEeU92dCMc39/g1F0OYAjw1Mt+dGP5DjXY=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=
Expand Down

0 comments on commit c6807b5

Please sign in to comment.