diff --git a/consensus/reactor.go b/consensus/reactor.go index eb662c6af2..323fad4086 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -338,7 +338,16 @@ func (conR *Reactor) ReceiveEnvelope(e p2p.Envelope) { case *BlockPartMessage: ps.SetHasProposalBlockPart(msg.Height, msg.Round, int(msg.Part.Index)) conR.Metrics.BlockParts.With("peer_id", string(e.Src.ID())).Add(1) - schema.WriteBlockPart(conR.traceClient, msg.Height, msg.Round, e.Src.ID(), msg.Part.Index, schema.TransferTypeDownload) + // The .ToProto conversion is only needed to get the part size. + // This is consistent with how it is measured in the gossipDataRoutine. + part, err := msg.Part.ToProto() + partSize := -1 + if err != nil { + partSize = part.Size() + } + schema.WriteBlockPart(conR.traceClient, msg.Height, msg.Round, + e.Src.ID(), msg.Part.Index, schema.TransferTypeDownload, + int64(partSize)) conR.conS.peerMsgQueue <- msgInfo{msg, e.Src.ID()} default: conR.Logger.Error(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg))) @@ -595,7 +604,9 @@ OUTER_LOOP: Part: *parts, }, }, logger) { - schema.WriteBlockPart(conR.traceClient, rs.Height, rs.Round, peer.ID(), part.Index, schema.TransferTypeUpload) + schema.WriteBlockPart(conR.traceClient, rs.Height, + rs.Round, peer.ID(), part.Index, + schema.TransferTypeUpload, int64(parts.Size())) ps.SetHasProposalBlockPart(prs.Height, prs.Round, index) } continue OUTER_LOOP diff --git a/pkg/trace/schema/consensus.go b/pkg/trace/schema/consensus.go index 3fea523853..dd47254c1d 100644 --- a/pkg/trace/schema/consensus.go +++ b/pkg/trace/schema/consensus.go @@ -55,13 +55,20 @@ const ( // BlockPartIndexFieldKey is the name of the field that stores the block // part BlockPartIndexFieldKey = "index" + + // BlockPartSizeFieldKey is the name of the field that stores the size of a block + // part in bytes. The value is an int64. + // Negative value indicates unknown block part size. + BlockPartSizeFieldKey = "block_part_size" ) // WriteBlockPart writes a tracing point for a BlockPart using the predetermined // schema for consensus state tracing. This is used to create a table in the // following schema: // -// | time | height | round | index | peer | transfer type | +// | time | height | round | peer | index | transfer type | block_part_size | +// Negative value for `size` i.e., block_part_size indicates unknown block part +// size. func WriteBlockPart( client *trace.Client, height int64, @@ -69,6 +76,7 @@ func WriteBlockPart( peer p2p.ID, index uint32, transferType string, + size int64, ) { // this check is redundant to what is checked during WritePoint, although it // is an optimization to avoid allocations from the map of fields. @@ -78,9 +86,10 @@ func WriteBlockPart( client.WritePoint(BlockPartsTable, map[string]interface{}{ HeightFieldKey: height, RoundFieldKey: round, - BlockPartIndexFieldKey: index, PeerFieldKey: peer, + BlockPartIndexFieldKey: index, TransferTypeFieldKey: transferType, + BlockPartSizeFieldKey: size, }) } @@ -88,7 +97,7 @@ const ( // BlockTable is the name of the table that stores metadata about consensus blocks. // following schema: // - // | time | height | timestamp | + // | time | height | unix_millisecond_timestamp | tx_count | square_size | block_size | proposer | last_commit_round | BlockTable = "consensus_block" // UnixMillisecondTimestampFieldKey is the name of the field that stores the timestamp in @@ -101,7 +110,7 @@ const ( // SquareSizeFieldKey is the name of the field that stores the square size // of the block. SquareSize is the number of shares in a single row or - // column of the origianl data square. + // column of the original data square. SquareSizeFieldKey = "square_size" // BlockSizeFieldKey is the name of the field that stores the size of