Skip to content

Commit

Permalink
Merge pull request #6998 from onflow/petera/monotonous-monotonic
Browse files Browse the repository at this point in the history
Rename MonotonousCounter to MonotonicCounter
  • Loading branch information
peterargue authored Feb 10, 2025
2 parents 8b1120d + 53d629f commit 73ebfbc
Show file tree
Hide file tree
Showing 29 changed files with 70 additions and 70 deletions.
2 changes: 1 addition & 1 deletion access/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ func (h *Handler) SendAndSubscribeTransactionStatuses(

sub := h.api.SendAndSubscribeTransactionStatuses(ctx, &tx, request.GetEventEncodingVersion())

messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)
return subscription.HandleRPCSubscription(sub, func(txResults []*TransactionResult) error {
for i := range txResults {
index := messageIndex.Value()
Expand Down
2 changes: 1 addition & 1 deletion consensus/hotstuff/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ The event handler is designed to be executed single-threaded.
To separate general graph-theoretical concepts from the concrete blockchain application, `LevelledForest` refers to blocks as graph `vertices`
and to a block's view number as `level`.
* `Validator` validates the HotStuff-relevant aspects of
- QC: total weight of all signers is more than 2/3 of committee weight, validity of signatures, view number is strictly monotonously increasing;
- QC: total weight of all signers is more than 2/3 of committee weight, validity of signatures, view number is strictly monotonicly increasing;
- TC: total weight of all signers is more than 2/3 of committee weight, validity of signatures, proof for entering view;
- block proposal: from designated primary for the block's respective view, contains proposer's vote for its own block, QC in block is valid,
a valid TC for the previous view is included if and only if the QC is not for the previous view;
Expand Down
2 changes: 1 addition & 1 deletion consensus/hotstuff/integration/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func NewInstance(t *testing.T, options ...Option) *Instance {
// mock signature aggregator which doesn't perform any crypto operations and just tracks total weight
aggregator := &mocks.TimeoutSignatureAggregator{}
totalWeight := atomic.NewUint64(0)
newestView := counters.NewMonotonousCounter(0)
newestView := counters.NewMonotonicCounter(0)
aggregator.On("View").Return(view).Maybe()
aggregator.On("TotalWeight").Return(func() uint64 {
return totalWeight.Load()
Expand Down
6 changes: 3 additions & 3 deletions consensus/hotstuff/pacemaker/view_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ func (vt *viewTracker) ProcessTC(tc *flow.TimeoutCertificate) (uint64, error) {
}

// updateLivenessData updates the current view, qc, tc. We want to avoid unnecessary data-base
// writes, which we enforce by requiring that the view number is STRICTLY monotonously increasing.
// writes, which we enforce by requiring that the view number is STRICTLY monotonicly increasing.
// Otherwise, an exception is returned. No errors are expected, any error should be treated as exception.
func (vt *viewTracker) updateLivenessData(newView uint64, qc *flow.QuorumCertificate, tc *flow.TimeoutCertificate) error {
if newView <= vt.livenessData.CurrentView {
// This should never happen: in the current implementation, it is trivially apparent that
// newView is _always_ larger than currentView. This check is to protect the code from
// future modifications that violate the necessary condition for
// STRICTLY monotonously increasing view numbers.
return fmt.Errorf("cannot move from view %d to %d: currentView must be strictly monotonously increasing",
// STRICTLY monotonicly increasing view numbers.
return fmt.Errorf("cannot move from view %d to %d: currentView must be strictly monotonicly increasing",
vt.livenessData.CurrentView, newView)
}

Expand Down
6 changes: 3 additions & 3 deletions consensus/hotstuff/safetyrules/safety_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (s *SafetyRulesTestSuite) TestProduceVote_UpdateLockedOneChainView() {
// TestProduceVote_InvalidCurrentView tests that no vote is created if `curView` has invalid values.
// In particular, `SafetyRules` requires that:
// - the block's view matches `curView`
// - that values for `curView` are monotonously increasing
// - that values for `curView` are monotonicly increasing
//
// Failing any of these conditions is a symptom of an internal bug; hence `SafetyRules` should
// _not_ return a `NoVoteError`.
Expand All @@ -208,7 +208,7 @@ func (s *SafetyRulesTestSuite) TestProduceVote_InvalidCurrentView() {
require.Error(s.T(), err)
require.False(s.T(), model.IsNoVoteError(err))
})
s.Run("view-not-monotonously-increasing", func() {
s.Run("view-not-monotonicly-increasing", func() {
// create block with view < HighestAcknowledgedView
proposal := helper.MakeSignedProposal(helper.WithProposal(helper.MakeProposal(
helper.WithBlock(
Expand Down Expand Up @@ -450,7 +450,7 @@ func (s *SafetyRulesTestSuite) TestProduceVote_VotingOnInvalidProposals() {
// TestProduceVote_VoteEquivocation tests scenario when we try to vote twice in same view. We require that replica
// follows next rules:
// - replica votes once per view
// - replica votes in monotonously increasing views
// - replica votes in monotonicly increasing views
//
// Voting twice per round on equivocating proposals is considered a byzantine behavior.
// Expect a `model.NoVoteError` sentinel in such scenario.
Expand Down
4 changes: 2 additions & 2 deletions consensus/hotstuff/timeoutaggregator/timeout_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type TimeoutAggregator struct {
log zerolog.Logger
hotstuffMetrics module.HotstuffMetrics
engineMetrics module.EngineMetrics
lowestRetainedView counters.StrictMonotonousCounter // lowest view, for which we still process timeouts
lowestRetainedView counters.StrictMonotonicCounter // lowest view, for which we still process timeouts
collectors hotstuff.TimeoutCollectors
queuedTimeoutsNotifier engine.Notifier
enteringViewNotifier engine.Notifier
Expand Down Expand Up @@ -64,7 +64,7 @@ func NewTimeoutAggregator(log zerolog.Logger,
log: log.With().Str("component", "hotstuff.timeout_aggregator").Logger(),
hotstuffMetrics: hotstuffMetrics,
engineMetrics: engineMetrics,
lowestRetainedView: counters.NewMonotonousCounter(lowestRetainedView),
lowestRetainedView: counters.NewMonotonicCounter(lowestRetainedView),
collectors: collectors,
queuedTimeoutsNotifier: engine.NewNotifier(),
enteringViewNotifier: engine.NewNotifier(),
Expand Down
10 changes: 5 additions & 5 deletions consensus/hotstuff/timeoutcollector/timeout_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type TimeoutCollector struct {
timeoutsCache *TimeoutObjectsCache // cache for tracking double timeout and timeout equivocation
notifier hotstuff.TimeoutAggregationConsumer
processor hotstuff.TimeoutProcessor
newestReportedQC counters.StrictMonotonousCounter // view of newest QC that was reported
newestReportedTC counters.StrictMonotonousCounter // view of newest TC that was reported
newestReportedQC counters.StrictMonotonicCounter // view of newest QC that was reported
newestReportedTC counters.StrictMonotonicCounter // view of newest TC that was reported
}

var _ hotstuff.TimeoutCollector = (*TimeoutCollector)(nil)
Expand All @@ -40,8 +40,8 @@ func NewTimeoutCollector(log zerolog.Logger,
notifier: notifier,
timeoutsCache: NewTimeoutObjectsCache(view),
processor: processor,
newestReportedQC: counters.NewMonotonousCounter(0),
newestReportedTC: counters.NewMonotonousCounter(0),
newestReportedQC: counters.NewMonotonicCounter(0),
newestReportedTC: counters.NewMonotonicCounter(0),
}
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *TimeoutCollector) processTimeout(timeout *model.TimeoutObject) error {
// * Over larger time scales, the emitted events are for statistically increasing views.
// * However, on short time scales there are _no_ monotonicity guarantees w.r.t. the views.
// Explanation:
// While only QCs with strict monotonously increasing views pass the
// While only QCs with strict monotonicly increasing views pass the
// `if c.newestReportedQC.Set(timeout.NewestQC.View)` statement, we emit the notification in a separate
// step. Therefore, emitting the notifications is subject to races, where on very short time-scales
// the notifications can be out of order.
Expand Down
8 changes: 4 additions & 4 deletions consensus/hotstuff/voteaggregator/vote_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ type VoteAggregator struct {
hotstuffMetrics module.HotstuffMetrics
engineMetrics module.EngineMetrics
notifier hotstuff.VoteAggregationViolationConsumer
lowestRetainedView counters.StrictMonotonousCounter // lowest view, for which we still process votes
lowestRetainedView counters.StrictMonotonicCounter // lowest view, for which we still process votes
collectors hotstuff.VoteCollectors
queuedMessagesNotifier engine.Notifier
finalizationEventsNotifier engine.Notifier
finalizedView counters.StrictMonotonousCounter // cache the last finalized view to queue up the pruning work, and unblock the caller who's delivering the finalization event.
finalizedView counters.StrictMonotonicCounter // cache the last finalized view to queue up the pruning work, and unblock the caller who's delivering the finalization event.
queuedVotes *fifoqueue.FifoQueue
queuedBlocks *fifoqueue.FifoQueue
}
Expand Down Expand Up @@ -79,8 +79,8 @@ func NewVoteAggregator(
hotstuffMetrics: hotstuffMetrics,
engineMetrics: engineMetrics,
notifier: notifier,
lowestRetainedView: counters.NewMonotonousCounter(lowestRetainedView),
finalizedView: counters.NewMonotonousCounter(lowestRetainedView),
lowestRetainedView: counters.NewMonotonicCounter(lowestRetainedView),
finalizedView: counters.NewMonotonicCounter(lowestRetainedView),
collectors: collectors,
queuedVotes: queuedVotes,
queuedBlocks: queuedBlocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (p *AccountStatusesDataProvider) createSubscription(ctx context.Context, ar
// No errors are expected during normal operations.
func (p *AccountStatusesDataProvider) handleResponse() func(accountStatusesResponse *backend.AccountStatusesResponse) error {
blocksSinceLastMessage := uint64(0)
messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)

return func(accountStatusesResponse *backend.AccountStatusesResponse) error {
// check if there are any events in the response. if not, do not send a message unless the last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (p *EventsDataProvider) Run() error {
// No errors are expected during normal operations.
func (p *EventsDataProvider) handleResponse() func(eventsResponse *backend.EventsResponse) error {
blocksSinceLastMessage := uint64(0)
messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)

return func(eventsResponse *backend.EventsResponse) error {
// check if there are any events in the response. if not, do not send a message unless the last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p *SendAndGetTransactionStatusesDataProvider) createSubscription(
//
// No errors are expected during normal operations.
func (p *SendAndGetTransactionStatusesDataProvider) handleResponse() func(txResults []*access.TransactionResult) error {
messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)

return func(txResults []*access.TransactionResult) error {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (p *TransactionStatusesDataProvider) createSubscription(
//
// No errors are expected during normal operations.
func (p *TransactionStatusesDataProvider) handleResponse() func(txResults []*access.TransactionResult) error {
messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)

return func(txResults []*access.TransactionResult) error {

Expand Down
4 changes: 2 additions & 2 deletions engine/access/state_stream/backend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (h *Handler) handleEventsResponse(send sendSubscribeEventsResponseFunc, hea
}

blocksSinceLastMessage := uint64(0)
messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)

return func(resp *EventsResponse) error {
// check if there are any events in the response. if not, do not send a message unless the last
Expand Down Expand Up @@ -480,7 +480,7 @@ func (h *Handler) handleAccountStatusesResponse(
}

blocksSinceLastMessage := uint64(0)
messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)

return func(resp *AccountStatusesResponse) error {
// check if there are any events in the response. if not, do not send a message unless the last
Expand Down
8 changes: 4 additions & 4 deletions engine/access/subscription/block_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ type BlockTrackerImpl struct {
broadcaster *engine.Broadcaster

// finalizedHighestHeight contains the highest consecutive block height for which we have received a new notification.
finalizedHighestHeight counters.StrictMonotonousCounter
finalizedHighestHeight counters.StrictMonotonicCounter
// sealedHighestHeight contains the highest consecutive block height for which we have received a new notification.
sealedHighestHeight counters.StrictMonotonousCounter
sealedHighestHeight counters.StrictMonotonicCounter
}

// NewBlockTracker creates a new BlockTrackerImpl instance.
Expand Down Expand Up @@ -70,8 +70,8 @@ func NewBlockTracker(
return &BlockTrackerImpl{
BaseTracker: NewBaseTrackerImpl(rootHeight, state, headers),
state: state,
finalizedHighestHeight: counters.NewMonotonousCounter(lastFinalized.Height),
sealedHighestHeight: counters.NewMonotonousCounter(lastSealed.Height),
finalizedHighestHeight: counters.NewMonotonicCounter(lastFinalized.Height),
sealedHighestHeight: counters.NewMonotonicCounter(lastSealed.Height),
broadcaster: broadcaster,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions engine/access/subscription/execution_data_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type ExecutionDataTrackerImpl struct {
useIndex bool

// highestHeight contains the highest consecutive block height that we have consecutive execution data for
highestHeight counters.StrictMonotonousCounter
highestHeight counters.StrictMonotonicCounter
}

// NewExecutionDataTracker creates a new ExecutionDataTrackerImpl instance.
Expand Down Expand Up @@ -96,7 +96,7 @@ func NewExecutionDataTracker(
log: log,
headers: headers,
broadcaster: broadcaster,
highestHeight: counters.NewMonotonousCounter(highestAvailableFinalizedHeight),
highestHeight: counters.NewMonotonicCounter(highestAvailableFinalizedHeight),
indexReporter: indexReporter,
useIndex: useIndex,
}
Expand Down
4 changes: 2 additions & 2 deletions engine/collection/compliance/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type Core struct {
headers storage.Headers
state clusterkv.MutableState
// track latest finalized view/height - used to efficiently drop outdated or too-far-ahead blocks
finalizedView counters.StrictMonotonousCounter
finalizedHeight counters.StrictMonotonousCounter
finalizedView counters.StrictMonotonicCounter
finalizedHeight counters.StrictMonotonicCounter
pending module.PendingClusterBlockBuffer // pending block cache
sync module.BlockRequester
hotstuff module.HotStuff
Expand Down
2 changes: 1 addition & 1 deletion engine/common/follower/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Cache struct {
byParent map[flow.Identifier]BlocksByID // lookup of blocks by their parentID, for finding a block's known children

notifier hotstuff.ProposalViolationConsumer // equivocations will be reported using this notifier
lowestView counters.StrictMonotonousCounter // lowest view that the cache accepts blocks for
lowestView counters.StrictMonotonicCounter // lowest view that the cache accepts blocks for
}

// Peek performs lookup of cached block by blockID.
Expand Down
2 changes: 1 addition & 1 deletion engine/common/follower/compliance_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (e *ComplianceEngine) OnSyncedBlocks(blocks flow.Slashable[[]*messages.Bloc

// OnFinalizedBlock informs the compliance layer about finalization of a new block. It does not block
// and asynchronously executes the internal pruning logic. We accept inputs out of order, and only act
// on inputs with strictly monotonously increasing views.
// on inputs with strictly monotonicly increasing views.
//
// Implements the `OnFinalizedBlock` callback from the `hotstuff.FinalizationConsumer`
// CAUTION: the input to this callback is treated as trusted; precautions should be taken that messages
Expand Down
4 changes: 2 additions & 2 deletions engine/common/stop/stop_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type StopControl struct {
doneProcessingEvents chan struct{}

// Stores latest processed block height
lastProcessedHeight counters.StrictMonotonousCounter
lastProcessedHeight counters.StrictMonotonicCounter
}

// NewStopControl creates a new StopControl instance.
Expand All @@ -53,7 +53,7 @@ func NewStopControl(
log: log.With().
Str("component", "stop_control").
Logger(),
lastProcessedHeight: counters.NewMonotonousCounter(0),
lastProcessedHeight: counters.NewMonotonicCounter(0),
versionData: atomic.NewPointer[VersionMetadata](nil),
processedHeightChannel: make(chan uint64),
doneProcessingEvents: make(chan struct{}),
Expand Down
4 changes: 2 additions & 2 deletions engine/common/version/version_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type VersionControl struct {
// Notifier for new finalized block height
finalizedHeightNotifier engine.Notifier

finalizedHeight counters.StrictMonotonousCounter
finalizedHeight counters.StrictMonotonicCounter

// lastProcessedHeight the last handled block height
lastProcessedHeight *atomic.Uint64
Expand Down Expand Up @@ -108,7 +108,7 @@ func NewVersionControl(
versionBeacons: versionBeacons,
sealedRootBlockHeight: atomic.NewUint64(sealedRootBlockHeight),
lastProcessedHeight: atomic.NewUint64(latestFinalizedBlockHeight),
finalizedHeight: counters.NewMonotonousCounter(latestFinalizedBlockHeight),
finalizedHeight: counters.NewMonotonicCounter(latestFinalizedBlockHeight),
finalizedHeightNotifier: engine.NewNotifier(),
startHeight: atomic.NewUint64(NoHeight),
endHeight: atomic.NewUint64(NoHeight),
Expand Down
4 changes: 2 additions & 2 deletions engine/consensus/compliance/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type Core struct {
payloads storage.Payloads
state protocol.ParticipantState
// track latest finalized view/height - used to efficiently drop outdated or too-far-ahead blocks
finalizedView counters.StrictMonotonousCounter
finalizedHeight counters.StrictMonotonousCounter
finalizedView counters.StrictMonotonicCounter
finalizedHeight counters.StrictMonotonicCounter
pending module.PendingBlockBuffer // pending block cache
sync module.BlockRequester
hotstuff module.HotStuff
Expand Down
8 changes: 4 additions & 4 deletions engine/consensus/sealing/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type Core struct {
log zerolog.Logger // used to log relevant actions with context
collectorTree *approvals.AssignmentCollectorTree // levelled forest for assignment collectors
approvalsCache *approvals.LruCache // in-memory cache of approvals that weren't verified
counterLastSealedHeight counters.StrictMonotonousCounter // monotonous counter for last sealed block height
counterLastFinalizedHeight counters.StrictMonotonousCounter // monotonous counter for last finalized block height
counterLastSealedHeight counters.StrictMonotonicCounter // monotonic counter for last sealed block height
counterLastFinalizedHeight counters.StrictMonotonicCounter // monotonic counter for last finalized block height
headers storage.Headers // used to access block headers in storage
state protocol.State // used to access protocol state
seals storage.Seals // used to get last sealed block
Expand Down Expand Up @@ -81,8 +81,8 @@ func NewCore(
sealingTracker: sealingTracker,
unit: unit,
approvalsCache: approvals.NewApprovalsLRUCache(1000),
counterLastSealedHeight: counters.NewMonotonousCounter(lastSealed.Height),
counterLastFinalizedHeight: counters.NewMonotonousCounter(lastSealed.Height),
counterLastSealedHeight: counters.NewMonotonicCounter(lastSealed.Height),
counterLastFinalizedHeight: counters.NewMonotonicCounter(lastSealed.Height),
headers: headers,
state: state,
seals: sealsDB,
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/access/cohort4/grpc_state_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (s *GrpcStateStreamSuite) TestHappyPath() {
foundANTxControlCount := 0
foundONTxCount := 0

messageIndex := counters.NewMonotonousCounter(0)
messageIndex := counters.NewMonotonicCounter(0)

r := NewResponseTracker(compareEventsResponse, 3)

Expand Down
Loading

0 comments on commit 73ebfbc

Please sign in to comment.