You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.8 KiB

6 years ago
6 years ago
Normalize priorities to not exceed total voting power (#3049) * more proposer priority tests - test that we don't reset to zero when updating / adding - test that same power validators alternate * add another test to track / simulate similar behaviour as in #2960 * address some of Chris' review comments * address some more of Chris' review comments * temporarily pushing branch with the following changes: The total power might change if: - a validator is added - a validator is removed - a validator is updated Decrement the accums (of all validators) directly after any of these events (by the inverse of the change) * Fix 2960 by re-normalizing / scaling priorities to be in bounds of total power, additionally: - remove heap where it doesn't make sense - avg. only at the end of IncrementProposerPriority instead of each iteration - update (and slightly improve) TestAveragingInIncrementProposerPriorityWithVotingPower to reflect above changes * Fix 2960 by re-normalizing / scaling priorities to be in bounds of total power, additionally: - remove heap where it doesn't make sense - avg. only at the end of IncrementProposerPriority instead of each iteration - update (and slightly improve) TestAveragingInIncrementProposerPriorityWithVotingPower to reflect above changes * fix tests * add comment * update changelog pending & some minor changes * comment about division will floor the result & fix typo * Update TestLargeGenesisValidator: - remove TODO and increase large genesis validator's voting power accordingly * move changelog entry to P2P Protocol * Ceil instead of flooring when dividing & update test * quickly fix failing TestProposerPriorityDoesNotGetResetToZero: - divide by Ceil((maxPriority - minPriority) / 2*totalVotingPower) * fix typo: rename getValWitMostPriority -> getValWithMostPriority * test proposer frequencies * return absolute value for diff. keep testing * use for loop for div * cleanup, more tests * spellcheck * get rid of using floats: manually ceil where necessary * Remove float, simplify, fix tests to match chris's proof (#3157)
6 years ago
  1. package p2p
  2. import (
  3. "github.com/go-kit/kit/metrics"
  4. "github.com/go-kit/kit/metrics/discard"
  5. "github.com/go-kit/kit/metrics/prometheus"
  6. stdprometheus "github.com/prometheus/client_golang/prometheus"
  7. )
  8. const (
  9. // MetricsSubsystem is a subsystem shared by all metrics exposed by this
  10. // package.
  11. MetricsSubsystem = "p2p"
  12. )
  13. // Metrics contains metrics exposed by this package.
  14. type Metrics struct {
  15. // Number of peers.
  16. Peers metrics.Gauge
  17. // Number of bytes received from a given peer.
  18. PeerReceiveBytesTotal metrics.Counter
  19. // Number of bytes sent to a given peer.
  20. PeerSendBytesTotal metrics.Counter
  21. // Pending bytes to be sent to a given peer.
  22. PeerPendingSendBytes metrics.Gauge
  23. // Number of transactions submitted by each peer.
  24. NumTxs metrics.Gauge
  25. }
  26. // PrometheusMetrics returns Metrics build using Prometheus client library.
  27. // Optionally, labels can be provided along with their values ("foo",
  28. // "fooValue").
  29. func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
  30. labels := []string{}
  31. for i := 0; i < len(labelsAndValues); i += 2 {
  32. labels = append(labels, labelsAndValues[i])
  33. }
  34. return &Metrics{
  35. Peers: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  36. Namespace: namespace,
  37. Subsystem: MetricsSubsystem,
  38. Name: "peers",
  39. Help: "Number of peers.",
  40. }, labels).With(labelsAndValues...),
  41. PeerReceiveBytesTotal: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  42. Namespace: namespace,
  43. Subsystem: MetricsSubsystem,
  44. Name: "peer_receive_bytes_total",
  45. Help: "Number of bytes received from a given peer.",
  46. }, append(labels, "peer_id", "chID")).With(labelsAndValues...),
  47. PeerSendBytesTotal: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
  48. Namespace: namespace,
  49. Subsystem: MetricsSubsystem,
  50. Name: "peer_send_bytes_total",
  51. Help: "Number of bytes sent to a given peer.",
  52. }, append(labels, "peer_id", "chID")).With(labelsAndValues...),
  53. PeerPendingSendBytes: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  54. Namespace: namespace,
  55. Subsystem: MetricsSubsystem,
  56. Name: "peer_pending_send_bytes",
  57. Help: "Number of pending bytes to be sent to a given peer.",
  58. }, append(labels, "peer_id")).With(labelsAndValues...),
  59. NumTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
  60. Namespace: namespace,
  61. Subsystem: MetricsSubsystem,
  62. Name: "num_txs",
  63. Help: "Number of transactions submitted by each peer.",
  64. }, append(labels, "peer_id")).With(labelsAndValues...),
  65. }
  66. }
  67. // NopMetrics returns no-op Metrics.
  68. func NopMetrics() *Metrics {
  69. return &Metrics{
  70. Peers: discard.NewGauge(),
  71. PeerReceiveBytesTotal: discard.NewCounter(),
  72. PeerSendBytesTotal: discard.NewCounter(),
  73. PeerPendingSendBytes: discard.NewGauge(),
  74. NumTxs: discard.NewGauge(),
  75. }
  76. }