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

Method getValidatorBehaviorMetrics

controller/block.go:680–710  ·  view source on GitHub ↗

getValidatorBehaviorMetrics() gets metrics for validator behavior in this block

(address crypto.AddressI, qc *lib.QuorumCertificate)

Source from the content-addressed store, hash-verified

678
679// getValidatorBehaviorMetrics() gets metrics for validator behavior in this block
680func (c *Controller) getValidatorBehaviorMetrics(address crypto.AddressI, qc *lib.QuorumCertificate) (isProducer bool, nonSigners map[string]uint64, doubleSigners []crypto.AddressI) {
681 nonSigners = make(map[string]uint64)
682 // 1. Track block producer
683 if proposerPubKey, err := crypto.NewPublicKeyFromBytes(qc.ProposerKey); err == nil {
684 isProducer = proposerPubKey.Address().Equals(address)
685 }
686
687 // 2. Track non-signers - only if we have the validator set for this chain
688 if ns, err := c.FSM.GetNonSigners(); err == nil {
689 for _, n := range ns {
690 nonSigners[lib.BytesToString(n.Address)] = n.Counter
691 }
692 }
693
694 // 3. Track double signers (if evidence is available in the QC results)
695 // TODO this call is really inefficient - we need to segment double signers by block or address
696 if doubleSigner, err := c.FSM.GetDoubleSigners(); err == nil {
697 // for each double signer
698 for _, ds := range doubleSigner {
699 // for each height
700 for _, height := range ds.Heights {
701 // if double signed on the last height
702 if height == qc.Header.Height {
703 // update list
704 doubleSigners = append(doubleSigners, crypto.NewAddress(ds.Id))
705 }
706 }
707 }
708 }
709 return
710}
711
712// debugDumpHeaderDiff() logs the differences between the candidate and the constructed
713func (c *Controller) debugDumpHeaderDiff(candidate, compare *lib.BlockHeader) {

Callers 1

UpdateTelemetryMethod · 0.95

Calls 7

NewPublicKeyFromBytesFunction · 0.92
BytesToStringFunction · 0.92
NewAddressFunction · 0.92
EqualsMethod · 0.65
AddressMethod · 0.65
GetDoubleSignersMethod · 0.65
GetNonSignersMethod · 0.45

Tested by

no test coverage detected