From f28c56492ff74f0681568684f6b6e244d3087b97 Mon Sep 17 00:00:00 2001 From: Miguel Montes <miguel.montes@gmail.com> Date: Tue, 11 Dec 2018 15:41:47 -0300 Subject: [PATCH] =?UTF-8?q?Agregado=20de=20informaci=C3=B3n=20de=20=C3=BAl?= =?UTF-8?q?timo=20bloque=20firmado=20a=20nodeStatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bfa_client/src/bfa/node.go | 19 +++++++++++++++ bfa_client/src/client/bfa_client.go | 38 ++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/bfa_client/src/bfa/node.go b/bfa_client/src/bfa/node.go index 23f6c08..93f8c87 100644 --- a/bfa_client/src/bfa/node.go +++ b/bfa_client/src/bfa/node.go @@ -253,6 +253,25 @@ func (node *Node) Votes(blockNumber int64) (votes Proposals) { return } +func (node *Node) LastBlockSignedBy(address string, upperLimit int64) (blockNumber int64) { + if upperLimit == 0 || !node.IsSealer(address) { + return + } + for i := 0; i < 5; i++ { + snapshot := node.SnapshotAtBlock(upperLimit) + for number, sealer := range snapshot.Recents { + if BytesToHex(sealer[:]) == address { + return int64(number) + } + } + upperLimit = int64(snapshot.Number) - int64((len(snapshot.Recents))) + if upperLimit <= 0 { + return + } + } + return +} + func (node *Node) SealersStatus(blockNumber int64) (status map[string]*SealerStatus) { if blockNumber == 0 { // Genesis block doesn't have signer return diff --git a/bfa_client/src/client/bfa_client.go b/bfa_client/src/client/bfa_client.go index eac8434..4820b57 100644 --- a/bfa_client/src/client/bfa_client.go +++ b/bfa_client/src/client/bfa_client.go @@ -358,17 +358,22 @@ func propose() { func status() { nodeStatus := struct { - Enode string `json:"enode"` - Network uint64 `json:"network"` - Genesis string `json:"genesis"` - BFANetwork bool `json:"bfaNetwork"` - BFAGenesis bool `json:"bfaGenesis"` - Accounts map[string]*big.Int `json:"accounts"` - Coinbase string `json:"coinbase"` - IsSealer bool `json:"isSealer"` - IsMining bool `json:"isMining"` - BlockNumber int64 `json:"blockNumber"` - PeerCount uint64 `json:"peerCount"` + Enode string `json:"enode"` + Network uint64 `json:"network"` + Genesis string `json:"genesis"` + BFANetwork bool `json:"bfaNetwork"` + BFAGenesis bool `json:"bfaGenesis"` + Accounts map[string]*big.Int `json:"accounts"` + Coinbase string `json:"coinbase"` + IsSealer bool `json:"isSealer"` + IsMining bool `json:"isMining"` + BlockNumber int64 `json:"blockNumber"` + Time int64 `json:"timestamp"` + DateTime string `json:"datetime"` + LastBlockSigned int64 `json:"lastBlockSigned,omitempty"` + LastTimeSigned int64 `json:"lastTimeSigned,omitempty"` + DateTimeLastBlockSigned string `json:"datetimeLastSigned,omitempty"` + PeerCount uint64 `json:"peerCount"` }{ Accounts: make(map[string]*big.Int), } @@ -384,8 +389,19 @@ func status() { } nodeStatus.Coinbase, _ = node.Coinbase() nodeStatus.BlockNumber = node.BlockNumber() + header := node.HeaderByNumber(nodeStatus.BlockNumber) + nodeStatus.Time = header.Time.Int64() + nodeStatus.DateTime = time.Unix(nodeStatus.Time, 0).Format("2006-01-02 15:04:05") nodeStatus.IsSealer = node.IsSealer(bfa.Self) nodeStatus.IsMining = node.IsMining() + if nodeStatus.IsSealer { + nodeStatus.LastBlockSigned = node.LastBlockSignedBy(nodeStatus.Coinbase, nodeStatus.BlockNumber) + if nodeStatus.LastBlockSigned != 0 { + header := node.HeaderByNumber(nodeStatus.LastBlockSigned) + nodeStatus.LastTimeSigned = header.Time.Int64() + nodeStatus.DateTimeLastBlockSigned = time.Unix(nodeStatus.LastTimeSigned, 0).Format("2006-01-02 15:04:05") + } + } nodeInfo := node.NodeInfo() nodeStatus.Enode = nodeInfo.Enode ethInfo := nodeInfo.Protocols["eth"].(map[string]interface{}) -- GitLab