Skip to content

Commit f85ed84

Browse files
committed
Add metrics
1 parent 4d99301 commit f85ed84

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

internal/consensus/metrics.go

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ type Metrics struct {
6969
// Number of block parts transmitted by each peer.
7070
BlockParts metrics.Counter `metrics_labels:"peer_id"`
7171

72+
// Number of tx requests transmitted by each peer.
73+
TxsSent metrics.Counter `metrics_labels:"peer_id"`
74+
7275
// Histogram of durations for each step in the consensus protocol.
7376
StepDuration metrics.Histogram `metrics_labels:"step" metrics_buckettype:"exprange" metrics_bucketsizes:"0.1, 100, 8"`
7477
stepStart time.Time
@@ -82,6 +85,10 @@ type Metrics struct {
8285
// was relevant to the block the node is trying to gather or not.
8386
BlockGossipPartsReceived metrics.Counter `metrics_labels:"matches_current"`
8487

88+
ProposalBlockCreated metrics.Counter `metrics_labels:"success"`
89+
ProposalTxsCount metrics.Gauge
90+
MissingTxsCount metrics.Gauge
91+
8592
// QuroumPrevoteMessageDelay is the interval in seconds between the proposal
8693
// timestamp and the timestamp of the earliest prevote that achieved a quorum
8794
// during the prevote step.

internal/consensus/reactor.go

+1
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ func (r *Reactor) handleDataMessage(ctx context.Context, envelope *p2p.Envelope,
12021202
txKeys = append(txKeys, *txKey)
12031203
}
12041204
txs := r.state.blockExec.GetTxsForKeys(txKeys)
1205+
r.Metrics.TxsSent.With("peer_id", string(envelope.From)).Add(1)
12051206
// TODO(psu): send all txs in 1 msg
12061207
for _, tx := range txs {
12071208
//logger.Info("PSULOG: Sending mempool ch for tx", "tx", tx)

internal/consensus/state.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"runtime/debug"
1212
"sort"
13+
"strconv"
1314
"sync"
1415
"time"
1516

@@ -1029,6 +1030,7 @@ func (cs *State) handleMsg(ctx context.Context, mi msgInfo, fsyncUponCompletion
10291030
err = cs.setProposal(msg.Proposal, mi.ReceiveTime)
10301031
if cs.config.GossipTransactionHashOnly && !cs.isProposer(cs.privValidatorPubKey.Address()) {
10311032
created := cs.tryCreateProposalBlock(msg.Proposal.Height, msg.Proposal.Round, msg.Proposal.Header, msg.Proposal.LastCommit, msg.Proposal.Evidence, msg.Proposal.ProposerAddress)
1033+
cs.metrics.ProposalBlockCreated.With("success", strconv.FormatBool(created)).Add(1)
10321034
if created {
10331035
if fsyncUponCompletion {
10341036
if err := cs.wal.FlushAndSync(); err != nil { // fsync
@@ -2467,12 +2469,17 @@ func (cs *State) tryCreateProposalBlock(height int64, round int32, header types.
24672469
cs.metrics.BlockGossipPartsReceived.With("matches_current", "false").Add(1)
24682470
return false
24692471
}
2470-
2471-
if cs.Proposal == nil || len(cs.blockExec.GetMissingTxs(cs.Proposal.TxKeys)) != 0 {
2472+
if cs.Proposal == nil {
2473+
return false
2474+
}
2475+
txKeys := cs.Proposal.TxKeys
2476+
cs.metrics.ProposalTxsCount.Set(float64(len(cs.Proposal.TxKeys)))
2477+
missingTxKeys := cs.blockExec.GetMissingTxs(txKeys)
2478+
if len(missingTxKeys) != 0 {
24722479
//cs.logger.Info("PSULOG - cannot create block, either proposal is missing or we have missing keys", "proposal", cs.Proposal)
2480+
cs.metrics.MissingTxsCount.Set(float64(len(cs.blockExec.GetMissingTxs(cs.Proposal.TxKeys))))
24732481
return false
24742482
} else {
2475-
txKeys := cs.Proposal.TxKeys
24762483
//block := types.MakeBlock(height, cs.blockExec.GetTxsForKeys(txKeys), lastCommit, evidence, false)
24772484
block := cs.state.MakeBlock(height, cs.blockExec.GetTxsForKeys(txKeys), lastCommit, evidence, proposerAddress, false)
24782485
// We have full proposal block. Set txs in proposal block from mempool

internal/mempool/reactor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (r *Reactor) handleMempoolMessage(ctx context.Context, envelope *p2p.Envelo
120120
switch msg := envelope.Message.(type) {
121121
case *protomem.Txs:
122122
protoTxs := msg.GetTxs()
123-
logger.Info("PSULOG - handling mempool message", "peer", envelope.From, "txs", protoTxs)
123+
//logger.Info("PSULOG - handling mempool message", "peer", envelope.From, "txs", protoTxs)
124124
if len(protoTxs) == 0 {
125125
return errors.New("empty txs received from peer")
126126
}

0 commit comments

Comments
 (0)