MCPcopy
hub / github.com/canopy-network/canopy / ConsensusSummary

Method ConsensusSummary

controller/consensus.go:743–798  ·  view source on GitHub ↗

ConsensusSummary() for the RPC - returns the summary json object of the bft for a specific chainID

()

Source from the content-addressed store, hash-verified

741
742// ConsensusSummary() for the RPC - returns the summary json object of the bft for a specific chainID
743func (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

Callers 1

ConsensusInfoMethod · 0.80

Calls 11

LockMethod · 0.95
UnlockMethod · 0.95
NewPublicKeyFromBytesFunction · 0.92
MarshalJSONIndentFunction · 0.92
LoadMethod · 0.80
GetProposalMethod · 0.80
EqualMethod · 0.80
GetLeadingVoteMethod · 0.80
BytesMethod · 0.65
AddressMethod · 0.65
HashMethod · 0.45

Tested by

no test coverage detected