Merge pull request #1390 from flicker-harmony/pr_explorer_fixes

explorer fixes
pull/1405/head
Leo Chen 5 years ago committed by GitHub
commit 4683826b93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      api/service/explorer/service.go
  2. 4
      api/service/explorer/structs.go
  3. 14
      cmd/harmony/main.go
  4. 9
      node/node.go
  5. 9
      node/node_explorer.go

@ -296,7 +296,26 @@ func (s *Service) GetCommittee(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(400)
return
}
// fetch current epoch if epoch is 0
db := s.storage.GetDB()
if epoch == 0 {
bytes, err := db.Get([]byte(BlockHeightKey))
blockHeight, err := strconv.Atoi(string(bytes))
if err != nil {
utils.Logger().Warn().Err(err).Msg("cannot decode block height from DB")
w.WriteHeader(500)
return
}
key := GetBlockKey(blockHeight)
data, err := db.Get([]byte(key))
block := new(types.Block)
if rlp.DecodeBytes(data, block) != nil {
utils.Logger().Warn().Err(err).Msg("cannot get block from db")
w.WriteHeader(500)
return
}
epoch = block.Epoch().Uint64()
}
bytes, err := db.Get([]byte(GetCommitteeKey(uint32(shardID), epoch)))
if err != nil {
utils.Logger().Warn().Err(err).Msg("cannot read committee")

@ -64,6 +64,7 @@ type Block struct {
NextBlock RefBlock `json:"nextBlock"`
TXs []*Transaction `json:"txs"`
Signers []string `json:"signers"`
Epoch uint64 `json:"epoch"`
ExtraData string `json:"extra_data"`
}
@ -100,6 +101,8 @@ func NewBlock(block *types.Block, height int) *Block {
}
}
}
} else {
utils.Logger().Warn().Err(err).Msgf("bad state block %d", block.NumberU64())
}
return &Block{
Height: strconv.Itoa(height),
@ -109,6 +112,7 @@ func NewBlock(block *types.Block, height int) *Block {
MerkleRoot: block.Root().Hex(),
Bytes: strconv.Itoa(int(block.Size())),
Signers: signers,
Epoch: block.Epoch().Uint64(),
ExtraData: string(block.Extra()),
}
}

@ -167,6 +167,9 @@ func initSetup() {
func passphraseForBls() {
// If FN node running, they should either specify blsPrivateKey or the file with passphrase
if *isExplorer {
return
}
if *blsKeyFile == "" || *blsPass == "" {
fmt.Println("Internal nodes need to have pass to decrypt blskey")
os.Exit(101)
@ -450,5 +453,16 @@ func main() {
}
}
currentNode.RunServices()
// Run additional node collectors
// Collect node metrics if metrics flag is set
if currentNode.NodeConfig.GetMetricsFlag() {
go currentNode.CollectMetrics()
}
// Commit committtee if node role is explorer
if currentNode.NodeConfig.Role() == nodeconfig.ExplorerNode {
go currentNode.CommitCommittee()
}
currentNode.StartServer()
}

@ -387,15 +387,6 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardc
// FIXME (leo): we use beacon client topic as the global topic for now
go node.ReceiveGlobalMessage()
// if metrics flag is set start the goroutine to collect metrics
if node.NodeConfig.MetricsFlag {
go node.CollectMetrics()
}
if node.NodeConfig.Role() == nodeconfig.ExplorerNode {
go node.CommitCommittee()
}
// Setup initial state of syncing.
node.peerRegistrationRecord = make(map[string]*syncConfig)

@ -152,10 +152,13 @@ func (node *Node) commitBlockForExplorer(block *types.Block) {
// CommitCommittee commits committee with shard id and epoch to explorer service.
func (node *Node) CommitCommittee() {
events := make(chan core.ChainHeadEvent)
node.Blockchain().SubscribeChainHeadEvent(events)
events := make(chan core.ChainEvent)
node.Blockchain().SubscribeChainEvent(events)
for event := range events {
curBlock := event.Block
if curBlock == nil {
continue
}
state, err := node.Blockchain().ReadShardState(curBlock.Epoch())
if err != nil {
utils.Logger().Error().Err(err).Msg("[Explorer] Error reading shard state")
@ -166,7 +169,7 @@ func (node *Node) CommitCommittee() {
utils.Logger().Info().Msg("[Explorer] Dumping committee")
err := explorer.GetStorageInstance(node.SelfPeer.IP, node.SelfPeer.Port, false).DumpCommittee(curBlock.ShardID(), curBlock.Epoch().Uint64(), committee)
if err != nil {
utils.Logger().Warn().Err(err).Msgf("[Explorer] Eror dumping committee for block %d", curBlock.NumberU64())
utils.Logger().Warn().Err(err).Msgf("[Explorer] Error dumping committee for block %d", curBlock.NumberU64())
}
}
}

Loading…
Cancel
Save