@@ -21,162 +21,148 @@ func ConsensusTables() []string {
21
21
// Schema constants for the consensus round state tracing database.
22
22
const (
23
23
// RoundStateTable is the name of the table that stores the consensus
24
- // state traces. Follows this schema:
25
- //
26
- // | time | height | round | step |
24
+ // state traces.
27
25
RoundStateTable = "consensus_round_state"
28
-
29
- // StepFieldKey is the name of the field that stores the consensus step. The
30
- // value is a string.
31
- StepFieldKey = "step"
32
26
)
33
27
28
+ // RoundState describes schema for the "consensus_round_state" table.
29
+ type RoundState struct {
30
+ Height int64 `json:"height"`
31
+ Round int32 `json:"round"`
32
+ Step cstypes.RoundStepType `json:"step"`
33
+ }
34
+
35
+ // Table returns the table name for the RoundState struct.
36
+ func (r RoundState ) Table () string {
37
+ return RoundStateTable
38
+ }
39
+
34
40
// WriteRoundState writes a tracing point for a tx using the predetermined
35
- // schema for consensus state tracing. This is used to create a table in the following
36
- // schema:
37
- //
38
- // | time | height | round | step |
39
- func WriteRoundState (client * trace.Client , height int64 , round int32 , step cstypes.RoundStepType ) {
40
- client .WritePoint (RoundStateTable , map [string ]interface {}{
41
- HeightFieldKey : height ,
42
- RoundFieldKey : round ,
43
- StepFieldKey : step .String (),
44
- })
41
+ // schema for consensus state tracing.
42
+ func WriteRoundState (client trace.Tracer , height int64 , round int32 , step cstypes.RoundStepType ) {
43
+ client .Write (RoundState {Height : height , Round : round , Step : step })
45
44
}
46
45
47
46
// Schema constants for the "consensus_block_parts" table.
48
47
const (
49
48
// BlockPartsTable is the name of the table that stores the consensus block
50
49
// parts.
51
- // following schema:
52
- //
53
- // | time | height | round | index | peer | transfer type |
54
50
BlockPartsTable = "consensus_block_parts"
55
-
56
- // BlockPartIndexFieldKey is the name of the field that stores the block
57
- // part
58
- BlockPartIndexFieldKey = "index"
59
51
)
60
52
53
+ // BlockPart describes schema for the "consensus_block_parts" table.
54
+ type BlockPart struct {
55
+ Height int64 `json:"height"`
56
+ Round int32 `json:"round"`
57
+ Index int32 `json:"index"`
58
+ Peer p2p.ID `json:"peer"`
59
+ TransferType TransferType `json:"transfer_type"`
60
+ }
61
+
62
+ // Table returns the table name for the BlockPart struct.
63
+ func (b BlockPart ) Table () string {
64
+ return BlockPartsTable
65
+ }
66
+
61
67
// WriteBlockPart writes a tracing point for a BlockPart using the predetermined
62
- // schema for consensus state tracing. This is used to create a table in the
63
- // following schema:
64
- //
65
- // | time | height | round | index | peer | transfer type |
68
+ // schema for consensus state tracing.
66
69
func WriteBlockPart (
67
- client * trace.Client ,
70
+ client trace.Tracer ,
68
71
height int64 ,
69
72
round int32 ,
70
73
peer p2p.ID ,
71
74
index uint32 ,
72
- transferType string ,
75
+ transferType TransferType ,
73
76
) {
74
77
// this check is redundant to what is checked during WritePoint, although it
75
78
// is an optimization to avoid allocations from the map of fields.
76
79
if ! client .IsCollecting (BlockPartsTable ) {
77
80
return
78
81
}
79
- client .WritePoint (BlockPartsTable , map [string ]interface {}{
80
- HeightFieldKey : height ,
81
- RoundFieldKey : round ,
82
- BlockPartIndexFieldKey : index ,
83
- PeerFieldKey : peer ,
84
- TransferTypeFieldKey : transferType ,
85
- })
86
- }
87
-
88
- const (
89
- // BlockTable is the name of the table that stores metadata about consensus blocks.
90
- // following schema:
91
- //
92
- // | time | height | timestamp |
93
- BlockTable = "consensus_block"
94
-
95
- // UnixMillisecondTimestampFieldKey is the name of the field that stores the timestamp in
96
- // the last commit in unix milliseconds.
97
- UnixMillisecondTimestampFieldKey = "unix_millisecond_timestamp"
98
-
99
- // TxCountFieldKey is the name of the field that stores the number of
100
- // transactions in the block.
101
- TxCountFieldKey = "tx_count"
102
-
103
- // SquareSizeFieldKey is the name of the field that stores the square size
104
- // of the block. SquareSize is the number of shares in a single row or
105
- // column of the origianl data square.
106
- SquareSizeFieldKey = "square_size"
107
-
108
- // BlockSizeFieldKey is the name of the field that stores the size of
109
- // the block data in bytes.
110
- BlockSizeFieldKey = "block_size"
111
-
112
- // ProposerFieldKey is the name of the field that stores the proposer of
113
- // the block.
114
- ProposerFieldKey = "proposer"
115
-
116
- // LastCommitRoundFieldKey is the name of the field that stores the round
117
- // of the last commit.
118
- LastCommitRoundFieldKey = "last_commit_round"
119
- )
120
-
121
- func WriteBlock (client * trace.Client , block * types.Block , size int ) {
122
- client .WritePoint (BlockTable , map [string ]interface {}{
123
- HeightFieldKey : block .Height ,
124
- UnixMillisecondTimestampFieldKey : block .Time .UnixMilli (),
125
- TxCountFieldKey : len (block .Data .Txs ),
126
- SquareSizeFieldKey : block .SquareSize ,
127
- BlockSizeFieldKey : size ,
128
- ProposerFieldKey : block .ProposerAddress .String (),
129
- LastCommitRoundFieldKey : block .LastCommit .Round ,
82
+ client .Write (BlockPart {
83
+ Height : height ,
84
+ Round : round ,
85
+ Index : int32 (index ),
86
+ Peer : peer ,
87
+ TransferType : transferType ,
130
88
})
131
89
}
132
90
133
91
// Schema constants for the consensus votes tracing database.
134
92
const (
135
93
// VoteTable is the name of the table that stores the consensus
136
- // voting traces. Follows this schema:
137
- //
138
- // | time | height | round | vote_type | vote_height | vote_round
139
- // | vote_block_id| vote_unix_millisecond_timestamp
140
- // | vote_validator_address | vote_validator_index | peer
141
- // | transfer_type |
94
+ // voting traces.
142
95
VoteTable = "consensus_vote"
143
-
144
- VoteTypeFieldKey = "vote_type"
145
- VoteHeightFieldKey = "vote_height"
146
- VoteRoundFieldKey = "vote_round"
147
- VoteBlockIDFieldKey = "vote_block_id"
148
- VoteTimestampFieldKey = "vote_unix_millisecond_timestamp"
149
- ValidatorAddressFieldKey = "vote_validator_address"
150
- ValidatorIndexFieldKey = "vote_validator_index"
151
96
)
152
97
98
+ // Vote describes schema for the "consensus_vote" table.
99
+ type Vote struct {
100
+ Height int64 `json:"height"`
101
+ Round int32 `json:"round"`
102
+ VoteType string `json:"vote_type"`
103
+ VoteHeight int64 `json:"vote_height"`
104
+ VoteRound int32 `json:"vote_round"`
105
+ VoteMillisecondTimestamp int64 `json:"vote_unix_millisecond_timestamp"`
106
+ ValidatorAddress string `json:"vote_validator_address"`
107
+ Peer p2p.ID `json:"peer"`
108
+ TransferType TransferType `json:"transfer_type"`
109
+ }
110
+
111
+ func (v Vote ) Table () string {
112
+ return VoteTable
113
+ }
114
+
153
115
// WriteVote writes a tracing point for a vote using the predetermined
154
116
// schema for consensus vote tracing.
155
- // This is used to create a table in the following
156
- // schema:
157
- //
158
- // | time | height | round | vote_type | vote_height | vote_round
159
- // | vote_block_id| vote_unix_millisecond_timestamp
160
- // | vote_validator_address | vote_validator_index | peer
161
- // | transfer_type |
162
- func WriteVote (client * trace.Client ,
117
+ func WriteVote (client trace.Tracer ,
163
118
height int64 , // height of the current peer when it received/sent the vote
164
119
round int32 , // round of the current peer when it received/sent the vote
165
120
vote * types.Vote , // vote received by the current peer
166
121
peer p2p.ID , // the peer from which it received the vote or the peer to which it sent the vote
167
- transferType string , // download (received) or upload(sent)
122
+ transferType TransferType , // download (received) or upload(sent)
168
123
) {
169
- client .WritePoint (VoteTable , map [string ]interface {}{
170
- HeightFieldKey : height ,
171
- RoundFieldKey : round ,
172
- VoteTypeFieldKey : vote .Type .String (),
173
- VoteHeightFieldKey : vote .Height ,
174
- VoteRoundFieldKey : vote .Round ,
175
- VoteBlockIDFieldKey : vote .BlockID .Hash .String (),
176
- VoteTimestampFieldKey : vote .Timestamp .UnixMilli (),
177
- ValidatorAddressFieldKey : vote .ValidatorAddress .String (),
178
- ValidatorIndexFieldKey : vote .ValidatorIndex ,
179
- PeerFieldKey : peer ,
180
- TransferTypeFieldKey : transferType ,
124
+ client .Write (Vote {
125
+ Height : height ,
126
+ Round : round ,
127
+ VoteType : vote .Type .String (),
128
+ VoteHeight : vote .Height ,
129
+ VoteRound : vote .Round ,
130
+ VoteMillisecondTimestamp : vote .Timestamp .UnixMilli (),
131
+ ValidatorAddress : vote .ValidatorAddress .String (),
132
+ Peer : peer ,
133
+ TransferType : transferType ,
134
+ })
135
+ }
136
+
137
+ const (
138
+ // BlockTable is the name of the table that stores metadata about consensus blocks.
139
+ BlockTable = "consensus_block"
140
+ )
141
+
142
+ // BlockSummary describes schema for the "consensus_block" table.
143
+ type BlockSummary struct {
144
+ Height int64 `json:"height"`
145
+ UnixMillisecondTimestamp int64 `json:"unix_millisecond_timestamp"`
146
+ TxCount int `json:"tx_count"`
147
+ SquareSize uint64 `json:"square_size"`
148
+ BlockSize int `json:"block_size"`
149
+ Proposer string `json:"proposer"`
150
+ LastCommitRound int32 `json:"last_commit_round"`
151
+ }
152
+
153
+ func (b BlockSummary ) Table () string {
154
+ return BlockTable
155
+ }
156
+
157
+ // WriteBlockSummary writes a tracing point for a block using the predetermined
158
+ func WriteBlockSummary (client trace.Tracer , block * types.Block , size int ) {
159
+ client .Write (BlockSummary {
160
+ Height : block .Height ,
161
+ UnixMillisecondTimestamp : block .Time .UnixMilli (),
162
+ TxCount : len (block .Data .Txs ),
163
+ SquareSize : block .SquareSize ,
164
+ BlockSize : size ,
165
+ Proposer : block .ProposerAddress .String (),
166
+ LastCommitRound : block .LastCommit .Round ,
181
167
})
182
168
}
0 commit comments