[RPC] Expose if current node leader (#1677)

pull/1673/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 8aa1e10e99
commit dac42117ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      hmy/api_backend.go
  2. 1
      hmy/backend.go
  3. 1
      internal/hmyapi/backend.go
  4. 2
      internal/hmyapi/harmony.go
  5. 6
      node/rpc.go

@ -275,3 +275,8 @@ func (b *APIBackend) ResendCx(ctx context.Context, txID common.Hash) (uint64, bo
success := b.hmy.CxPool().Add(entry)
return blockNum, success
}
// IsLeader exposes if node is currently leader
func (b *APIBackend) IsLeader() bool {
return b.hmy.nodeAPI.IsCurrentlyLeader()
}

@ -49,6 +49,7 @@ type NodeAPI interface {
GetBalanceOfAddress(address common.Address) (*big.Int, error)
GetNonceOfAddress(address common.Address) uint64
GetTransactionsHistory(address string) ([]common.Hash, error)
IsCurrentlyLeader() bool
}
// New creates a new Harmony object (including the

@ -71,6 +71,7 @@ type Backend interface {
GetTransactionsHistory(address string) ([]common.Hash, error)
// retrieve the blockHash using txID and add blockHash to CxPool for resending
ResendCx(ctx context.Context, txID common.Hash) (uint64, bool)
IsLeader() bool
}
// GetAPIs returns all the APIs.

@ -49,6 +49,7 @@ type NodeMetadata struct {
Version string `json:"version"`
NetworkType string `json:"network"`
ChainID string `json:"chainid"`
IsLeader bool `json:"is-leader"`
}
// GetNodeMetadata produces a NodeMetadata record. Note the data is from the answering RPC
@ -59,5 +60,6 @@ func (s *PublicHarmonyAPI) GetNodeMetadata() NodeMetadata {
nodeconfig.GetVersion(),
string(cfg.GetNetworkType()),
s.b.ChainConfig().ChainID.String(),
s.b.IsLeader(),
}
}

@ -44,6 +44,11 @@ var (
harmony *hmy.Harmony
)
// IsCurrentlyLeader exposes if node is currently the leader node
func (node *Node) IsCurrentlyLeader() bool {
return node.Consensus.IsLeader()
}
// StartRPC start RPC service
func (node *Node) StartRPC(nodePort string) error {
// Gather all the possible APIs to surface
@ -66,7 +71,6 @@ func (node *Node) StartRPC(nodePort string) error {
if err := node.startHTTP(httpEndpoint, apis, httpModules, httpOrigins, httpVirtualHosts, httpTimeouts); err != nil {
return err
}
wsEndpoint = fmt.Sprintf("%v:%v", ip, port+rpcWSPortOffset)
if err := node.startWS(wsEndpoint, apis, wsModules, wsOrigins, true); err != nil {
node.stopHTTP()

Loading…
Cancel
Save