Merge pull request #794 from harmony-one/rj_cello

Fix 0 balance issue on explorer; increase consensus delay
pull/795/head
Rongjian Lan 6 years ago committed by GitHub
commit d887c5cac5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      api/service/explorer/service.go
  2. 2
      core/blockchain.go
  3. 2
      node/node_newblock.go
  4. 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)
}

@ -70,7 +70,7 @@ const (
// BlocksPerEpoch is the number of blocks in one epoch
// currently set to small number for testing
// in future, this need to be adjusted dynamically instead of constant
BlocksPerEpoch = 5
BlocksPerEpoch = 1000000000
// BlockChainVersion ensures that an incompatible database forces a resync from scratch.
BlockChainVersion = 3

@ -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