Browse Source

node: excise node handle within rpc env (#8063)

pull/8070/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
9d98484845
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 31 deletions
  1. +7
    -8
      internal/rpc/core/env.go
  2. +2
    -2
      internal/rpc/core/net.go
  3. +1
    -1
      internal/rpc/core/status.go
  4. +3
    -20
      node/node.go

+ 7
- 8
internal/rpc/core/env.go View File

@ -57,12 +57,6 @@ type consensusState interface {
GetRoundStateSimpleJSON() ([]byte, error) GetRoundStateSimpleJSON() ([]byte, error)
} }
type transport interface {
Listeners() []string
IsListening() bool
NodeInfo() types.NodeInfo
}
type peerManager interface { type peerManager interface {
Peers() []types.NodeID Peers() []types.NodeID
Addresses(types.NodeID) []p2p.NodeAddress Addresses(types.NodeID) []p2p.NodeAddress
@ -84,8 +78,9 @@ type Environment struct {
ConsensusReactor *consensus.Reactor ConsensusReactor *consensus.Reactor
BlockSyncReactor *blocksync.Reactor BlockSyncReactor *blocksync.Reactor
// Legacy p2p stack
P2PTransport transport
IsListening bool
Listeners []string
NodeInfo types.NodeInfo
// interfaces for new p2p interfaces // interfaces for new p2p interfaces
PeerManager peerManager PeerManager peerManager
@ -226,6 +221,10 @@ func (env *Environment) StartService(ctx context.Context, conf *config.Config) (
return nil, err return nil, err
} }
env.Listeners = []string{
fmt.Sprintf("Listener(@%v)", conf.P2P.ExternalAddress),
}
listenAddrs := strings.SplitAndTrimEmpty(conf.RPC.ListenAddress, ",", " ") listenAddrs := strings.SplitAndTrimEmpty(conf.RPC.ListenAddress, ",", " ")
routes := NewRoutesMap(env, &RouteOptions{ routes := NewRoutesMap(env, &RouteOptions{
Unsafe: conf.RPC.Unsafe, Unsafe: conf.RPC.Unsafe,


+ 2
- 2
internal/rpc/core/net.go View File

@ -27,8 +27,8 @@ func (env *Environment) NetInfo(ctx context.Context) (*coretypes.ResultNetInfo,
} }
return &coretypes.ResultNetInfo{ return &coretypes.ResultNetInfo{
Listening: env.P2PTransport.IsListening(),
Listeners: env.P2PTransport.Listeners(),
Listening: env.IsListening,
Listeners: env.Listeners,
NPeers: len(peers), NPeers: len(peers),
Peers: peers, Peers: peers,
}, nil }, nil


+ 1
- 1
internal/rpc/core/status.go View File

@ -66,7 +66,7 @@ func (env *Environment) Status(ctx context.Context) (*coretypes.ResultStatus, er
} }
result := &coretypes.ResultStatus{ result := &coretypes.ResultStatus{
NodeInfo: env.P2PTransport.NodeInfo(),
NodeInfo: env.NodeInfo,
ApplicationInfo: applicationInfo, ApplicationInfo: applicationInfo,
SyncInfo: coretypes.SyncInfo{ SyncInfo: coretypes.SyncInfo{
LatestBlockHash: latestBlockHash, LatestBlockHash: latestBlockHash,


+ 3
- 20
node/node.go View File

@ -58,7 +58,6 @@ type nodeImpl struct {
router *p2p.Router router *p2p.Router
nodeInfo types.NodeInfo nodeInfo types.NodeInfo
nodeKey types.NodeKey // our node privkey nodeKey types.NodeKey // our node privkey
isListening bool
// services // services
eventSinks []indexer.EventSink eventSinks []indexer.EventSink
@ -421,8 +420,6 @@ func makeNode(
node.rpcEnv.PubKey = pubKey node.rpcEnv.PubKey = pubKey
} }
node.rpcEnv.P2PTransport = node
node.BaseService = *service.NewBaseService(logger, "Node", node) node.BaseService = *service.NewBaseService(logger, "Node", node)
return node, nil return node, nil
@ -467,6 +464,7 @@ func (n *nodeImpl) OnStart(ctx context.Context) error {
} }
} }
n.rpcEnv.NodeInfo = n.nodeInfo
// Start the RPC server before the P2P server // Start the RPC server before the P2P server
// so we can eg. receive txs for the first block // so we can eg. receive txs for the first block
if n.config.RPC.ListenAddress != "" { if n.config.RPC.ListenAddress != "" {
@ -485,7 +483,7 @@ func (n *nodeImpl) OnStart(ctx context.Context) error {
if err := n.router.Start(ctx); err != nil { if err := n.router.Start(ctx); err != nil {
return err return err
} }
n.isListening = true
n.rpcEnv.IsListening = true
for _, reactor := range n.services { for _, reactor := range n.services {
if err := reactor.Start(ctx); err != nil { if err := reactor.Start(ctx); err != nil {
@ -580,7 +578,7 @@ func (n *nodeImpl) OnStop() {
n.stateSyncReactor.Wait() n.stateSyncReactor.Wait()
n.router.Wait() n.router.Wait()
n.isListening = false
n.rpcEnv.IsListening = false
// finally stop the listeners / external services // finally stop the listeners / external services
for _, l := range n.rpcListeners { for _, l := range n.rpcListeners {
@ -669,21 +667,6 @@ func (n *nodeImpl) RPCEnvironment() *rpccore.Environment {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
func (n *nodeImpl) Listeners() []string {
return []string{
fmt.Sprintf("Listener(@%v)", n.config.P2P.ExternalAddress),
}
}
func (n *nodeImpl) IsListening() bool {
return n.isListening
}
// NodeInfo returns the Node's Info from the Switch.
func (n *nodeImpl) NodeInfo() types.NodeInfo {
return n.nodeInfo
}
// genesisDocProvider returns a GenesisDoc. // genesisDocProvider returns a GenesisDoc.
// It allows the GenesisDoc to be pulled from sources other than the // It allows the GenesisDoc to be pulled from sources other than the
// filesystem, for instance from a distributed key-value store cluster. // filesystem, for instance from a distributed key-value store cluster.


Loading…
Cancel
Save