ConsensusSummary() for the RPC - returns the summary json object of the bft for a specific chainID
()
| 741 | |
| 742 | // ConsensusSummary() for the RPC - returns the summary json object of the bft for a specific chainID |
| 743 | func (c *Controller) ConsensusSummary() ([]byte, lib.ErrorI) { |
| 744 | // lock for thread safety |
| 745 | c.Lock() |
| 746 | defer c.Unlock() |
| 747 | // convert self public key from bytes into an object |
| 748 | selfKey, _ := crypto.NewPublicKeyFromBytes(c.PublicKey) |
| 749 | // create the consensus summary object |
| 750 | consensusSummary := &ConsensusSummary{ |
| 751 | Syncing: c.isSyncing.Load(), |
| 752 | View: c.Consensus.View, |
| 753 | Locked: c.Consensus.HighQC != nil, |
| 754 | Address: selfKey.Address().Bytes(), |
| 755 | PublicKey: c.PublicKey, |
| 756 | Proposer: c.Consensus.ProposerKey, |
| 757 | Proposals: c.Consensus.Proposals, |
| 758 | PartialQCs: c.Consensus.PartialQCs, |
| 759 | PacemakerVotes: c.Consensus.PacemakerMessages, |
| 760 | MinimumPowerFor23Maj: c.Consensus.ValidatorSet.MinimumMaj23, |
| 761 | Votes: c.Consensus.Votes, |
| 762 | Status: "", |
| 763 | } |
| 764 | consensusSummary.BlockHash = c.Consensus.BlockHash |
| 765 | // if exists, populate the proposal hash |
| 766 | if c.Consensus.Results != nil { |
| 767 | consensusSummary.ResultsHash = c.Consensus.Results.Hash() |
| 768 | } |
| 769 | // if high qc exists, populate the block hash and results hash |
| 770 | if c.Consensus.HighQC != nil { |
| 771 | consensusSummary.BlockHash = c.Consensus.BlockHash |
| 772 | consensusSummary.ResultsHash = c.Consensus.HighQC.ResultsHash |
| 773 | } |
| 774 | // if exists, populate the proposer address |
| 775 | if c.Consensus.ProposerKey != nil { |
| 776 | propKey, _ := crypto.NewPublicKeyFromBytes(c.Consensus.ProposerKey) |
| 777 | consensusSummary.ProposerAddress = propKey.Address().Bytes() |
| 778 | } |
| 779 | // create a status string |
| 780 | switch c.Consensus.View.Phase { |
| 781 | case bft.Election, bft.Propose, bft.Precommit, bft.Commit: |
| 782 | proposal := c.Consensus.GetProposal() |
| 783 | if proposal == nil { |
| 784 | consensusSummary.Status = "waiting for proposal" |
| 785 | } else { |
| 786 | consensusSummary.Status = "received proposal" |
| 787 | } |
| 788 | case bft.ElectionVote, bft.ProposeVote, bft.CommitProcess: |
| 789 | if bytes.Equal(c.Consensus.ProposerKey, c.PublicKey) { |
| 790 | _, _, votedPercentage := c.Consensus.GetLeadingVote() |
| 791 | consensusSummary.Status = fmt.Sprintf("received %d%% of votes", votedPercentage) |
| 792 | } else { |
| 793 | consensusSummary.Status = "voting on proposal" |
| 794 | } |
| 795 | } |
| 796 | // convert the object into json |
| 797 | return lib.MarshalJSONIndent(&consensusSummary) |
| 798 | } |
| 799 | |
| 800 | // ConsensusSummary is simply a json informational structure about the local status of the BFT |
no test coverage detected