fix typos and add check nil condition for beaconchain in staking service. fix comments

pull/480/head
Minh Doan 6 years ago committed by Minh Doan
parent 089b40ccc4
commit d84e65889d
  1. 22
      api/service/staking/service.go
  2. 2
      node/node.go

@ -16,10 +16,13 @@ import (
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/host"
)
const (
WaitTime = 5 * time.Second
// WaitTime is the delay time for resending staking transaction if the previous transaction did not get approved.
WaitTime = 5 * time.Second
// StakingContractAddress is the staking deployed contract address
StakingContractAddress = "TODO(minhdoan): Create a PR to generate staking contract address"
)
@ -68,7 +71,7 @@ func (s *Service) Run() {
for {
select {
case <-tick.C:
if s.Staked() {
if s.IsStaked() {
return
}
s.DoService()
@ -79,16 +82,21 @@ func (s *Service) Run() {
}()
}
func (s *Service) Staked() bool {
// IsStaked checks if the txn gets accepted and approved in the beacon chain.
func (s *Service) IsStaked() bool {
return false
}
// DoService does staking.
func (s *Service) DoService() {
utils.GetLogInstance().Info("Trying to send a staking transaction.")
if s.beaconChain == nil {
utils.GetLogInstance().Info("Can not send a staking transaction because of nil beacon chain.")
return
}
if msg := s.createStakingMessage(); msg != nil {
s.host.SendMessageToGroups([]p2p.GroupID{p2p.GroupIDBeacon}, msg)
s.host.SendMessageToGroups([]p2p.GroupID{p2p.GroupIDBeacon}, host.ConstructP2pMessage(byte(17), msg))
} else {
utils.GetLogInstance().Error("Can not create staking transaction")
}
@ -131,11 +139,9 @@ func constructStakingMessage(ts types.Transactions) []byte {
}
if data, err := protobuf.Marshal(msg); err == nil {
return data
} else {
utils.GetLogInstance().Error("Error when creating staking message")
return nil
}
utils.GetLogInstance().Error("Error when creating staking message")
return nil
}
func (s *Service) createStakingMessage() []byte {

@ -683,7 +683,7 @@ func (node *Node) setupForNewNode() {
nodeConfig, chanPeer := node.initNodeConfiguration()
// Register staking service.
node.serviceManager.RegisterService(service_manager.Staking, staking.New(node.host, node.AccountKey, 0, stakingPeer, nil))
node.serviceManager.RegisterService(service_manager.Staking, staking.New(node.host, node.AccountKey, 0, node.beaconChain))
// Register peer discovery service. "0" is the beacon shard ID
node.serviceManager.RegisterService(service_manager.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer))
// Register networkinfo service. "0" is the beacon shard ID

Loading…
Cancel
Save