Add flag to disable signers

pull/1601/head
Rongjian Lan 5 years ago
parent 8b0e503847
commit dc3e84c56b
  1. 73
      api/service/explorer/service.go

@ -172,6 +172,13 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
to := r.FormValue("to") to := r.FormValue("to")
pageParam := r.FormValue("page") pageParam := r.FormValue("page")
offsetParam := r.FormValue("offset") offsetParam := r.FormValue("offset")
withSignersParam := r.FormValue("with_signers")
withSigners := false
if withSignersParam == "true" {
withSigners = true
}
data := &Data{ data := &Data{
Blocks: []*Block{}, Blocks: []*Block{},
} }
@ -236,19 +243,21 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
accountBlocks := s.ReadBlocksFromDB(fromInt, toInt) accountBlocks := s.ReadBlocksFromDB(fromInt, toInt)
curEpoch := int64(-1) curEpoch := int64(-1)
committee := &shard.Committee{} committee := &shard.Committee{}
if withSigners {
if bytes, err := db.Get([]byte(GetCommitteeKey(uint32(s.ShardID), 0))); err == nil {
if err = rlp.DecodeBytes(bytes, committee); err != nil {
utils.Logger().Warn().Err(err).Msg("cannot read committee for new epoch")
}
}
}
for id, accountBlock := range accountBlocks { for id, accountBlock := range accountBlocks {
if id == 0 || id == len(accountBlocks)-1 || accountBlock == nil { if id == 0 || id == len(accountBlocks)-1 || accountBlock == nil {
continue continue
} }
block := NewBlock(accountBlock, id+fromInt-1) block := NewBlock(accountBlock, id+fromInt-1)
if int64(block.Epoch) > curEpoch { if withSigners && int64(block.Epoch) > curEpoch {
if bytes, err := db.Get([]byte(GetCommitteeKey(uint32(s.ShardID), block.Epoch))); err == nil { if accountBlocks[id-1] != nil {
committee = &shard.Committee{} state, err := accountBlocks[id-1].Header().GetShardState()
if err = rlp.DecodeBytes(bytes, committee); err != nil {
utils.Logger().Warn().Err(err).Msg("cannot read committee for new epoch")
}
} else {
state, err := accountBlock.Header().GetShardState()
if err == nil { if err == nil {
for _, shardCommittee := range state { for _, shardCommittee := range state {
if shardCommittee.ShardID == accountBlock.ShardID() { if shardCommittee.ShardID == accountBlock.ShardID() {
@ -256,28 +265,32 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
break break
} }
} }
} else {
utils.Logger().Warn().Err(err).Msg("error parsing shard state")
} }
} }
curEpoch = int64(block.Epoch) curEpoch = int64(block.Epoch)
} }
pubkeys := make([]*bls.PublicKey, len(committee.NodeList)) if withSigners {
for i, validator := range committee.NodeList { pubkeys := make([]*bls.PublicKey, len(committee.NodeList))
pubkeys[i] = new(bls.PublicKey) for i, validator := range committee.NodeList {
validator.BlsPublicKey.ToLibBLSPublicKey(pubkeys[i]) pubkeys[i] = new(bls.PublicKey)
} validator.BlsPublicKey.ToLibBLSPublicKey(pubkeys[i])
mask, err := bls2.NewMask(pubkeys, nil) }
if err == nil && accountBlocks[id+1] != nil { mask, err := bls2.NewMask(pubkeys, nil)
err = mask.SetMask(accountBlocks[id+1].Header().LastCommitBitmap()) if err == nil && accountBlocks[id+1] != nil {
if err == nil { err = mask.SetMask(accountBlocks[id+1].Header().LastCommitBitmap())
for _, validator := range committee.NodeList { if err == nil {
oneAddress, err := common2.AddressToBech32(validator.EcdsaAddress) for _, validator := range committee.NodeList {
if err != nil { oneAddress, err := common2.AddressToBech32(validator.EcdsaAddress)
continue if err != nil {
} continue
blsPublicKey := new(bls.PublicKey) }
validator.BlsPublicKey.ToLibBLSPublicKey(blsPublicKey) blsPublicKey := new(bls.PublicKey)
if ok, err := mask.KeyEnabled(blsPublicKey); err == nil && ok { validator.BlsPublicKey.ToLibBLSPublicKey(blsPublicKey)
block.Signers = append(block.Signers, oneAddress) if ok, err := mask.KeyEnabled(blsPublicKey); err == nil && ok {
block.Signers = append(block.Signers, oneAddress)
}
} }
} }
} }
@ -316,11 +329,11 @@ func (s *Service) GetExplorerBlocks(w http.ResponseWriter, r *http.Request) {
data.Blocks = append(data.Blocks, block) data.Blocks = append(data.Blocks, block)
} }
paginatedBlocks := make([]*Block, 0) if offset*page+offset > len(data.Blocks) {
for i := 0; i < offset && i+offset*page < len(data.Blocks); i++ { data.Blocks = data.Blocks[offset*page:]
paginatedBlocks = append(paginatedBlocks, data.Blocks[i+offset*page]) } else {
data.Blocks = data.Blocks[offset*page : offset*page+offset]
} }
data.Blocks = paginatedBlocks
} }
// GetExplorerTransaction servers /tx end-point. // GetExplorerTransaction servers /tx end-point.

Loading…
Cancel
Save