diff --git a/bfa_client/src/bfa/node.go b/bfa_client/src/bfa/node.go index 349d9d1f68365605392e955142657d7983feb4eb..53551617a5957baec596ab272c0e60308e6e28d6 100644 --- a/bfa_client/src/bfa/node.go +++ b/bfa_client/src/bfa/node.go @@ -44,6 +44,11 @@ type SealerInfo struct { LastBlock int64 } +type SealerStatus struct { + LastBlock int64 `json:"lastBlockSigned"` + Time uint64 `json:"timestamp"` +} + const ( Latest = "latest" Self = "self" @@ -60,12 +65,15 @@ func (node *Node) blockNumber() int64 { } func (node *Node) Coinbase() (coinbase string, err error) { - defer func(){ + defer func() { if e := recover(); e != nil { - switch s := e.(type){ - case string: err = fmt.Errorf(s) - case error: err = s - default: err = fmt.Errorf("unknown error while getting coinbase: %v", e) + switch s := e.(type) { + case string: + err = fmt.Errorf(s) + case error: + err = s + default: + err = fmt.Errorf("unknown error while getting coinbase: %v", e) } } }() @@ -199,13 +207,13 @@ func (node *Node) GetVotes(blockNumber int64) (votes Proposals) { return } -func (node *Node) SealersStatus(blockNumber int64) (status map[string]int64) { +func (node *Node) SealersStatus(blockNumber int64) (status map[string]*SealerStatus) { if blockNumber == 0 { // Genesis block doesn't have signer return } - status = make(map[string]int64) + status = make(map[string]*SealerStatus) for _, address := range node.GetSignersAtBlock(blockNumber) { - status[address] = -1 + status[address] = &SealerStatus{} } notSeen := int64(len(status)) block := node.GetBlockByNumber(blockNumber) @@ -213,8 +221,9 @@ func (node *Node) SealersStatus(blockNumber int64) (status map[string]int64) { until := Max(1, blockNumber-5*notSeen) for notSeen > 0 { signer, _ := GetSigner(&block) - if status[signer] == -1 { - status[signer] = block.Number.Int64() + if status[signer].LastBlock == 0 { + status[signer].LastBlock = block.Number.Int64() + status[signer].Time = block.Time.Uint64() notSeen-- } if blockNumber == until { @@ -295,7 +304,7 @@ func (node *Node) getSignerFirstBlock(signer string, since int64, until int64) ( case found := <-ch: switch { case found < 0: - n-- // a goroutine has ended + n-- // a goroutine has ended if n == 0 { // all goroutines have ended return } @@ -359,7 +368,7 @@ func (node *Node) getSignerLastBlock(signer string, since int64, until int64) (b case found := <-ch: switch { case found < 0: - n-- // a goroutine has ended + n-- // a goroutine has ended if n == 0 { // all goroutines have ended return } diff --git a/bfa_client/src/client/bfa_client.go b/bfa_client/src/client/bfa_client.go index ba8661259fa11c4fcb9da5febafe38edd226ac20..2b11e791afb3f13dbe54bb6c871a4cedf18c85f1 100644 --- a/bfa_client/src/client/bfa_client.go +++ b/bfa_client/src/client/bfa_client.go @@ -106,11 +106,14 @@ func sealers() { var ( blockNumber int64 status bool + timestamp bool + length int64 = 10 // timestamp length ) description = "Presenta la lista de selladores. Opcionalmente indica el último bloque sellado por cada uno." setFlags() flags.Int64Var(&blockNumber, "block-number", latest, "Número del bloque en el cual se quiere conocer la lista de selladores (-1 para el último)") - flags.BoolVar(&status, "status", false, "Indica el último bloque sellado por cada sellador, o -1 si un nodo no ha sellado en las últimas 5 rondas.") + flags.BoolVar(&status, "status", false, "Indica el último bloque sellado por cada sellador, o 0 si un nodo no ha sellado en las últimas 5 rondas.") + flags.BoolVar(×tamp, "timestamp", false, "Muestra el timestamp del sellado en lugar del número de bloque.") parseFlags() if blockNumber == 0 { panic("El bloque génesis no tiene firmantes") @@ -129,10 +132,18 @@ func sealers() { for sealer := range sealers { list = append(list, sealer) } - sort.Slice(list, func(i, j int) bool { return sealers[list[i]] > sealers[list[j]] }) - length := util.Max(2, int64(len(strconv.FormatInt(sealers[list[0]], 10)))) + sort.Slice(list, func(i, j int) bool { return sealers[list[i]].LastBlock > sealers[list[j]].LastBlock }) + if !timestamp { + length = util.Max(2, int64(len(strconv.FormatInt(sealers[list[0]].LastBlock, 10)))) + } for _, sealer := range list { - fmt.Printf("%v: %*d\n", sealer, length, sealers[sealer]) + var output interface{} + if timestamp { + output = sealers[sealer].Time + } else { + output = sealers[sealer].LastBlock + } + fmt.Printf("%v: %*d\n", sealer, length, output) } } else { sealers := node.GetSignersAtBlock(blockNumber)