From 9109b5414ce2a840e987935e7c80975e47aecba1 Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 13:03:27 -0700 Subject: [PATCH 1/9] adds a TODO --- consensus/state.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index 5cdb99a875..a7c325c0d0 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -457,7 +457,7 @@ func (cs *State) OpenWAL(walFile string) (WAL, error) { return wal, nil } -//------------------------------------------------------------ +// ------------------------------------------------------------ // Public interface for passing messages into the consensus state, possibly causing a state transition. // If peerID == "", the msg is considered internal. // Messages are added to the appropriate queue (peer or internal). @@ -521,7 +521,7 @@ func (cs *State) SetProposalAndBlock( return nil } -//------------------------------------------------------------ +// ------------------------------------------------------------ // internal functions for managing the state func (cs *State) updateHeight(height int64) { @@ -716,7 +716,7 @@ func (cs *State) newStep() { } } -//----------------------------------------- +// ----------------------------------------- // the main go routines // receiveRoutine handles messages which may cause state transitions. @@ -981,7 +981,7 @@ func (cs *State) handleTxsAvailable() { } } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // State functions // Used internally by handleTimeout and handleMsg to make state transitions @@ -1712,6 +1712,10 @@ func (cs *State) finalizeCommit(height int64) { // must be called before we update state cs.recordMetrics(height, block) + // TODO log block.time + // blockTime := block.Header.Time + // block.Header.Height + // NewHeightStep! cs.updateToState(stateCopy) @@ -1730,6 +1734,7 @@ func (cs *State) finalizeCommit(height int64) { // * cs.Height has been increment to height+1 // * cs.Step is now cstypes.RoundStepNewHeight // * cs.StartTime is set to when we will start round0. + } func (cs *State) pruneBlocks(retainHeight int64) (uint64, error) { @@ -1836,7 +1841,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { cs.metrics.CommittedHeight.Set(float64(block.Height)) } -//----------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- func (cs *State) defaultSetProposal(proposal *types.Proposal) error { // Already have one @@ -1991,7 +1996,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // If the vote height is off, we'll just ignore it, // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. - //nolint: gocritic + // nolint: gocritic if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { if cs.privValidatorPubKey == nil { return false, errPubKeyIsNotSet @@ -2366,7 +2371,7 @@ func (cs *State) calculatePrevoteMessageDelayMetrics() { } } -//--------------------------------------------------------- +// --------------------------------------------------------- func CompareHRS(h1 int64, r1 int32, s1 cstypes.RoundStepType, h2 int64, r2 int32, s2 cstypes.RoundStepType) int { if h1 < h2 { From f1eced25f45ae0bcf3390f0e8d88501bf894382b Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 13:30:37 -0700 Subject: [PATCH 2/9] introduces block table schema --- pkg/trace/schema/consensus.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/trace/schema/consensus.go b/pkg/trace/schema/consensus.go index 726a53d262..28140e2264 100644 --- a/pkg/trace/schema/consensus.go +++ b/pkg/trace/schema/consensus.go @@ -4,6 +4,7 @@ import ( cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/pkg/trace" + "time" ) // ConsensusTables returns the list of tables that are used for consensus @@ -12,6 +13,7 @@ func ConsensusTables() []string { return []string{ RoundStateTable, BlockPartsTable, + BlockTable, } } @@ -81,3 +83,22 @@ func WriteBlockPart( TransferTypeFieldKey: transferType, }) } + +const ( + // BlockTable is the name of the table that stores metadata about consensus blocks. + // following schema: + // + // | time | height | + BlockTable = "consensus_block" + + // TimestampFieldKey is the name of the field that stores the time at which + // the block is proposed. + TimestampFieldKey = "timestamp" +) + +func WriteBlock(client *trace.Client, height int64, blockTimestamp time.Time) { + client.WritePoint(BlockTable, map[string]interface{}{ + HeightFieldKey: height, + TimestampFieldKey: blockTimestamp, + }) +} From 64687dedfab998d955012fb26c228f3b01d9f8a0 Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 13:30:49 -0700 Subject: [PATCH 3/9] writes block timestamp --- consensus/state.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index a7c325c0d0..9b31253856 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1712,9 +1712,7 @@ func (cs *State) finalizeCommit(height int64) { // must be called before we update state cs.recordMetrics(height, block) - // TODO log block.time - // blockTime := block.Header.Time - // block.Header.Height + schema.WriteBlock(cs.traceClient, block.Header.Height, block.Header.Time) // NewHeightStep! cs.updateToState(stateCopy) From 061b92690132f75338d09c835e1e6d2b9985bad8 Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 13:33:42 -0700 Subject: [PATCH 4/9] makes a comment --- consensus/state.go | 1 + 1 file changed, 1 insertion(+) diff --git a/consensus/state.go b/consensus/state.go index 9b31253856..a972b3a1cd 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1712,6 +1712,7 @@ func (cs *State) finalizeCommit(height int64) { // must be called before we update state cs.recordMetrics(height, block) + // trace some metadata about the block schema.WriteBlock(cs.traceClient, block.Header.Height, block.Header.Time) // NewHeightStep! From e4dc897f7357aa1b6d9567d628df8befff046bf2 Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 14:23:03 -0700 Subject: [PATCH 5/9] adds timestamp field to the schema description --- pkg/trace/schema/consensus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/trace/schema/consensus.go b/pkg/trace/schema/consensus.go index 28140e2264..923df5d1ab 100644 --- a/pkg/trace/schema/consensus.go +++ b/pkg/trace/schema/consensus.go @@ -88,7 +88,7 @@ const ( // BlockTable is the name of the table that stores metadata about consensus blocks. // following schema: // - // | time | height | + // | time | height | timestamp | BlockTable = "consensus_block" // TimestampFieldKey is the name of the field that stores the time at which From 7bdbf8899d50b4be328d0b0921c48ab61cced8bc Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 16:37:26 -0700 Subject: [PATCH 6/9] fixes linter issue --- consensus/state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/state.go b/consensus/state.go index a972b3a1cd..b921933a25 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1995,7 +1995,7 @@ func (cs *State) tryAddVote(vote *types.Vote, peerID p2p.ID) (bool, error) { // If the vote height is off, we'll just ignore it, // But if it's a conflicting sig, add it to the cs.evpool. // If it's otherwise invalid, punish peer. - // nolint: gocritic + //nolint: gocritic if voteErr, ok := err.(*types.ErrVoteConflictingVotes); ok { if cs.privValidatorPubKey == nil { return false, errPubKeyIsNotSet From 04ce8da5452ce724b40488747b4dab5120ff7020 Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 16:39:59 -0700 Subject: [PATCH 7/9] deletes excess spaces --- consensus/state.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/consensus/state.go b/consensus/state.go index b921933a25..7eb48593c5 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -457,7 +457,7 @@ func (cs *State) OpenWAL(walFile string) (WAL, error) { return wal, nil } -// ------------------------------------------------------------ +//------------------------------------------------------------ // Public interface for passing messages into the consensus state, possibly causing a state transition. // If peerID == "", the msg is considered internal. // Messages are added to the appropriate queue (peer or internal). @@ -521,7 +521,7 @@ func (cs *State) SetProposalAndBlock( return nil } -// ------------------------------------------------------------ +//------------------------------------------------------------ // internal functions for managing the state func (cs *State) updateHeight(height int64) { @@ -716,7 +716,7 @@ func (cs *State) newStep() { } } -// ----------------------------------------- +//----------------------------------------- // the main go routines // receiveRoutine handles messages which may cause state transitions. @@ -981,7 +981,7 @@ func (cs *State) handleTxsAvailable() { } } -// ----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // State functions // Used internally by handleTimeout and handleMsg to make state transitions @@ -1733,7 +1733,6 @@ func (cs *State) finalizeCommit(height int64) { // * cs.Height has been increment to height+1 // * cs.Step is now cstypes.RoundStepNewHeight // * cs.StartTime is set to when we will start round0. - } func (cs *State) pruneBlocks(retainHeight int64) (uint64, error) { @@ -1840,7 +1839,7 @@ func (cs *State) recordMetrics(height int64, block *types.Block) { cs.metrics.CommittedHeight.Set(float64(block.Height)) } -// ----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- func (cs *State) defaultSetProposal(proposal *types.Proposal) error { // Already have one @@ -2370,7 +2369,7 @@ func (cs *State) calculatePrevoteMessageDelayMetrics() { } } -// --------------------------------------------------------- +//--------------------------------------------------------- func CompareHRS(h1 int64, r1 int32, s1 cstypes.RoundStepType, h2 int64, r2 int32, s2 cstypes.RoundStepType) int { if h1 < h2 { From 10004289637603ed1c5724a21f434a28ba93ee6a Mon Sep 17 00:00:00 2001 From: sanaz Date: Wed, 16 Aug 2023 17:16:52 -0700 Subject: [PATCH 8/9] fixes goimports problem --- pkg/trace/schema/consensus.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/trace/schema/consensus.go b/pkg/trace/schema/consensus.go index 923df5d1ab..2f7c9769cd 100644 --- a/pkg/trace/schema/consensus.go +++ b/pkg/trace/schema/consensus.go @@ -1,10 +1,11 @@ package schema import ( + "time" + cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/pkg/trace" - "time" ) // ConsensusTables returns the list of tables that are used for consensus From 1d29ac2058cdfd162b643ae0a8bba2dadb4e726f Mon Sep 17 00:00:00 2001 From: sanaz Date: Thu, 17 Aug 2023 10:17:01 -0700 Subject: [PATCH 9/9] adds _time suffix to the table name --- pkg/trace/schema/consensus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/trace/schema/consensus.go b/pkg/trace/schema/consensus.go index 2f7c9769cd..dc8e1a93df 100644 --- a/pkg/trace/schema/consensus.go +++ b/pkg/trace/schema/consensus.go @@ -90,7 +90,7 @@ const ( // following schema: // // | time | height | timestamp | - BlockTable = "consensus_block" + BlockTable = "consensus_block_time" // TimestampFieldKey is the name of the field that stores the time at which // the block is proposed.