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" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/big"
"net" "net"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/gorilla/mux" "github.com/gorilla/mux"
msg_pb "github.com/harmony-one/harmony/api/proto/message" msg_pb "github.com/harmony-one/harmony/api/proto/message"
@ -25,21 +28,23 @@ const (
// Service is the struct for explorer service. // Service is the struct for explorer service.
type Service struct { type Service struct {
router *mux.Router router *mux.Router
IP string IP string
Port string Port string
GetNodeIDs func() []libp2p_peer.ID GetNodeIDs func() []libp2p_peer.ID
storage *Storage storage *Storage
server *http.Server server *http.Server
messageChan chan *msg_pb.Message messageChan chan *msg_pb.Message
GetAccountBalance func(common.Address) (*big.Int, error)
} }
// New returns explorer service. // 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{ return &Service{
IP: selfPeer.IP, IP: selfPeer.IP,
Port: selfPeer.Port, Port: selfPeer.Port,
GetNodeIDs: GetNodeIDs, GetNodeIDs: GetNodeIDs,
GetAccountBalance: GetAccountBalance,
} }
} }
@ -255,6 +260,16 @@ func (s *Service) GetExplorerAddress(w http.ResponseWriter, r *http.Request) {
return return
} }
data.Address = address 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) json.NewEncoder(w).Encode(data.Address)
} }

@ -31,7 +31,7 @@ func (node *Node) WaitForConsensusReady(readySignal chan struct{}, stopChan chan
// keep waiting for Consensus ready // keep waiting for Consensus ready
select { select {
case <-readySignal: 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): case <-time.After(ConsensusTimeOut * time.Second):
node.Consensus.ResetState() node.Consensus.ResetState()
timeoutCount++ timeoutCount++

@ -26,7 +26,7 @@ func (node *Node) setupForShardLeader() {
node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, node.NodeConfig.GetShardGroupID(), chanPeer, nil)) node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, node.NodeConfig.GetShardGroupID(), chanPeer, nil))
// Register explorer service. // 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. // Register consensus service.
node.serviceManager.RegisterService(service.Consensus, consensus.New(node.BlockChannel, node.Consensus, node.startConsensus)) node.serviceManager.RegisterService(service.Consensus, consensus.New(node.BlockChannel, node.Consensus, node.startConsensus))
// Register new block service. // Register new block service.
@ -68,7 +68,7 @@ func (node *Node) setupForBeaconLeader() {
// Register randomness service // Register randomness service
node.serviceManager.RegisterService(service.Randomness, randomness.New(node.DRand)) node.serviceManager.RegisterService(service.Randomness, randomness.New(node.DRand))
// Register explorer service. // 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() { func (node *Node) setupForBeaconValidator() {

Loading…
Cancel
Save