Fix 0 balance issue on explorer; increase consensus delay

pull/794/head
Rongjian Lan 6 years ago
parent f5d8eea764
commit bc6eb8d1fa
  1. 37
      api/service/explorer/service.go
  2. 2
      node/node_newblock.go
  3. 4
      node/service_setup.go

@ -4,11 +4,14 @@ import (
"context"
"encoding/json"
"fmt"
"math/big"
"net"
"net/http"
"os"
"strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/gorilla/mux"
msg_pb "github.com/harmony-one/harmony/api/proto/message"
@ -25,21 +28,23 @@ const (
// Service is the struct for explorer service.
type Service struct {
router *mux.Router
IP string
Port string
GetNodeIDs func() []libp2p_peer.ID
storage *Storage
server *http.Server
messageChan chan *msg_pb.Message
router *mux.Router
IP string
Port string
GetNodeIDs func() []libp2p_peer.ID
storage *Storage
server *http.Server
messageChan chan *msg_pb.Message
GetAccountBalance func(common.Address) (*big.Int, error)
}
// New returns explorer service.
func New(selfPeer *p2p.Peer, GetNodeIDs func() []libp2p_peer.ID) *Service {
func New(selfPeer *p2p.Peer, GetNodeIDs func() []libp2p_peer.ID, GetAccountBalance func(common.Address) (*big.Int, error)) *Service {
return &Service{
IP: selfPeer.IP,
Port: selfPeer.Port,
GetNodeIDs: GetNodeIDs,
IP: selfPeer.IP,
Port: selfPeer.Port,
GetNodeIDs: GetNodeIDs,
GetAccountBalance: GetAccountBalance,
}
}
@ -255,6 +260,16 @@ func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
return
}
data.Address = address
// Check the balance from blockchain rather than local DB dump
if s.GetAccountBalance != nil {
address := common.HexToAddress(id)
balance, err := s.GetAccountBalance(address)
if err == nil {
data.Address.Balance = balance
}
}
json.NewEncoder(w).Encode(data.Address)
}

@ -31,7 +31,7 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}, stopChan chan
// keep waiting for Consensus ready
select {
case <-readySignal:
time.Sleep(100 * time.Millisecond) // Delay a bit so validator is catched up (test-only).
time.Sleep(1000 * time.Millisecond) // Delay a bit so validator is catched up (test-only).
case <-time.After(ConsensusTimeOut * time.Second):
node.Consensus.ResetState()
timeoutCount++

@ -26,7 +26,7 @@ func (node *Node) setupForShardLeader() {
node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, node.NodeConfig.GetShardGroupID(), chanPeer, nil))
// Register explorer service.
node.serviceManager.RegisterService(service.SupportExplorer, explorer.New(&node.SelfPeer, node.Consensus.GetNodeIDs))
node.serviceManager.RegisterService(service.SupportExplorer, explorer.New(&node.SelfPeer, node.Consensus.GetNodeIDs, node.GetBalanceOfAddress))
// Register consensus service.
node.serviceManager.RegisterService(service.Consensus, consensus.New(node.BlockChannel, node.Consensus, node.startConsensus))
// Register new block service.
@ -68,7 +68,7 @@ func (node *Node) setupForBeaconLeader() {
// Register randomness service
node.serviceManager.RegisterService(service.Randomness, randomness.New(node.DRand))
// Register explorer service.
node.serviceManager.RegisterService(service.SupportExplorer, explorer.New(&node.SelfPeer, node.Consensus.GetNodeIDs))
node.serviceManager.RegisterService(service.SupportExplorer, explorer.New(&node.SelfPeer, node.Consensus.GetNodeIDs, node.GetBalanceOfAddress))
}
func (node *Node) setupForBeaconValidator() {

Loading…
Cancel
Save