From b54b5d0ea4c3212158fb241a2c6bd4a575b5ef04 Mon Sep 17 00:00:00 2001 From: Fedor Partanskiy Date: Thu, 15 Feb 2024 08:32:47 +0300 Subject: [PATCH] up consensus library Signed-off-by: Fedor Partanskiy --- go.mod | 3 +- go.sum | 4 +- .../consensus/internal/bft/controller.go | 162 ++++++------ .../consensus/internal/bft/requestpool.go | 16 +- .../consensus/internal/bft/util.go | 6 +- .../consensus/internal/bft/view.go | 17 ++ .../consensus/internal/bft/viewchanger.go | 9 +- .../SmartBFT-Go/consensus/pkg/api/metrics.go | 241 +++++++++++------- .../consensus/pkg/consensus/consensus.go | 32 ++- .../pkg/metrics/disabled/provider.go | 2 +- .../provider.go} | 61 +---- .../SmartBFT-Go/consensus/pkg/types/config.go | 35 ++- .../SmartBFT-Go/consensus/pkg/wal/metrics.go | 9 +- vendor/modules.txt | 4 +- 14 files changed, 318 insertions(+), 283 deletions(-) rename vendor/github.com/SmartBFT-Go/consensus/pkg/{api/metrics_provider.go => metrics/provider.go} (79%) diff --git a/go.mod b/go.mod index 1cd3f41485a..9b038e4ee08 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/IBM/idemix v0.0.2-0.20231011101252-a4feda90f3f7 github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible github.com/Shopify/sarama v1.20.1 - github.com/SmartBFT-Go/consensus v0.0.0-20230508115939-c2d803ba5515 + github.com/SmartBFT-Go/consensus v0.0.0-20240215044737-fd3c35e3c876 github.com/VictoriaMetrics/fastcache v1.9.0 github.com/bits-and-blooms/bitset v1.13.0 github.com/cheggaaa/pb v1.0.29 @@ -128,7 +128,6 @@ require ( ) replace ( - github.com/SmartBFT-Go/consensus => github.com/scientificideas/consensus v0.0.0-20230802072420-e9c3857fd5d6 // develop //github.com/hyperledger/fabric => ./ github.com/hyperledger/fabric-config => github.com/scientificideas/fabric-config v0.1.1-0.20220421194734-201061bc5f26 diff --git a/go.sum b/go.sum index f26ee0eeded..2b12e3c040c 100644 --- a/go.sum +++ b/go.sum @@ -64,6 +64,8 @@ github.com/Shopify/sarama v1.20.1 h1:Bb0h3I++r4eX333Y0uZV2vwUXepJbt6ig05TUU1qt9I github.com/Shopify/sarama v1.20.1/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/SmartBFT-Go/consensus v0.0.0-20240215044737-fd3c35e3c876 h1:E7XUbc3IePMgCJmdbgwzRucmrBCvCBBnrsWR1I0EMkQ= +github.com/SmartBFT-Go/consensus v0.0.0-20240215044737-fd3c35e3c876/go.mod h1:aeRINA5oFotrrfV/mDlTkN/UePrSIIPziuAjEqETRN0= github.com/VictoriaMetrics/fastcache v1.9.0 h1:oMwsS6c8abz98B7ytAewQ7M1ZN/Im/iwKoE1euaFvhs= github.com/VictoriaMetrics/fastcache v1.9.0/go.mod h1:otoTS3xu+6IzF/qByjqzjp3rTuzM3Qf0ScU1UTj97iU= github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE= @@ -518,8 +520,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/scientificideas/consensus v0.0.0-20230802072420-e9c3857fd5d6 h1:wwvnvMrfsTRz7YyBD5nkltSJlpwaNbLtkVLdh9/lpHE= -github.com/scientificideas/consensus v0.0.0-20230802072420-e9c3857fd5d6/go.mod h1:KsqqnNjG+MiuEdm/9ufh5C0oKJqd1rkpQ5S2mYPvVcA= github.com/scientificideas/fabric-config v0.1.1-0.20220421194734-201061bc5f26 h1:5Yl/L9TbOzcSrp6bCyYTmtmB7GnS8GOUJVLqAhPcWQo= github.com/scientificideas/fabric-config v0.1.1-0.20220421194734-201061bc5f26/go.mod h1:w3A6ezMvoMjxujiCifTvB32ABUlChvnUii48voxD30g= github.com/scientificideas/fabric-protos-go v0.0.0-20221126151030-78861c4f6e73 h1:REK10s1SuyFbiJynrQ94XuxZkD1s8qJSC4yFuKMrU48= diff --git a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/controller.go b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/controller.go index c43a2946cd8..23e5bb41664 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/controller.go +++ b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/controller.go @@ -81,7 +81,7 @@ type Proposer interface { // //go:generate mockery -dir . -name ProposerBuilder -case underscore -output ./mocks/ type ProposerBuilder interface { - NewProposer(leader, proposalSequence, viewNum, decisionsInView uint64, quorumSize int) Proposer + NewProposer(leader, proposalSequence, viewNum, decisionsInView uint64, quorumSize int) (Proposer, Phase) } // Controller controls the entire flow of the consensus @@ -133,7 +133,7 @@ type Controller struct { decisionChan chan decision deliverChan chan struct{} leaderToken chan struct{} - verificationSequence uint64 + verificationSequence atomic.Uint64 controllerDone sync.WaitGroup @@ -373,7 +373,7 @@ func (c *Controller) convertViewMessageToHeartbeat(m *protos.Message) *protos.Me } func (c *Controller) startView(proposalSequence uint64) { - view := c.ProposerBuilder.NewProposer(c.leaderID(), proposalSequence, c.currViewNumber, c.currDecisionsInView, c.quorum) + view, initPhase := c.ProposerBuilder.NewProposer(c.leaderID(), proposalSequence, c.currViewNumber, c.currDecisionsInView, c.quorum) c.currViewLock.Lock() c.currView = view @@ -383,6 +383,12 @@ func (c *Controller) startView(proposalSequence uint64) { role := Follower leader, _ := c.iAmTheLeader() if leader { + if initPhase == COMMITTED || initPhase == ABORT { + c.Logger.Debugf("Acquiring leader token when starting view with phase %s", initPhase.String()) + c.acquireLeaderToken() + } else { + c.Logger.Debugf("Not acquiring leader token when starting view with phase %s", initPhase.String()) + } role = Leader } c.LeaderMonitor.ChangeRole(role, c.currViewNumber, c.leaderID()) @@ -414,10 +420,8 @@ func (c *Controller) changeView(newViewNumber uint64, newProposalSequence uint64 c.Logger.Debugf("Starting view after setting decisions in view to %d", newDecisionsInView) c.startView(newProposalSequence) - // If I'm the leader, I can claim the leader token. if iAm, _ := c.iAmTheLeader(); iAm { c.Batcher.Reset() - c.acquireLeaderToken() } } @@ -468,24 +472,13 @@ func (c *Controller) ViewChanged(newViewNumber uint64, newProposalSequence uint6 c.viewChange <- viewInfo{proposalSeq: newProposalSequence, viewNumber: newViewNumber} } -func (c *Controller) getNextBatch() [][]byte { - var validRequests [][]byte - for len(validRequests) == 0 { // no valid requests in this batch - requests := c.Batcher.NextBatch() - if c.stopped() || c.Batcher.Closed() { - return nil - } - validRequests = append(validRequests, requests...) - } - return validRequests -} - func (c *Controller) propose() { - nextBatch := c.getNextBatch() - if len(nextBatch) == 0 { - // If our next batch is empty, - // it can only be because - // the batcher is stopped and so are we. + if c.stopped() || c.Batcher.Closed() { + return + } + nextBatch := c.Batcher.NextBatch() + if len(nextBatch) == 0 { // no requests in this batch + c.acquireLeaderToken() // try again later return } metadata := c.currView.GetMetadata() @@ -597,66 +590,71 @@ func (c *Controller) sync() (viewNum uint64, seq uint64, decisions uint64) { c.ViewChanger.close() } - decision := syncResponse.Latest - if decision.Proposal.Metadata == nil { - c.Logger.Infof("Synchronizer returned with proposal metadata nil") - response := c.fetchState() - if response == nil { - return 0, 0, 0 - } - if response.View > 0 && response.Seq == 1 { - c.Logger.Infof("The collected state is with view %d and sequence %d", response.View, response.Seq) - newViewToSave := &protos.SavedMessage{ - Content: &protos.SavedMessage_NewView{ - NewView: &protos.ViewMetadata{ - ViewId: response.View, - LatestSequence: 0, - DecisionsInView: 0, - }, - }, - } - if err := c.State.Save(newViewToSave); err != nil { - c.Logger.Panicf("Failed to save message to state, error: %v", err) - } - c.ViewChanger.InformNewView(response.View) - return response.View, 1, 0 + // The synchronizer returns a response which includes the latest decision with its proposal metadata. + // This proposal may be empty (its metadata is empty), meaning the synchronizer is not aware of any decisions made. + // Otherwise, the latest proposal sequence returned may be higher than our latest sequence, meaning we should + // update the checkpoint. + // In other cases we should not update the checkpoint. + // However, we always must fetch the latest state from other nodes, + // since the view may have advanced without this node and with no decisions. + + var newViewNum, newProposalSequence, newDecisionsInView uint64 + + latestDecision := syncResponse.Latest + var latestDecisionSeq, latestDecisionViewNum, latestDecisionDecisions uint64 + var latestDecisionMetadata *protos.ViewMetadata + if len(latestDecision.Proposal.Metadata) == 0 { + c.Logger.Infof("Synchronizer returned with an empty proposal metadata") + latestDecisionMetadata = nil + } else { + md := &protos.ViewMetadata{} + if err := proto.Unmarshal(latestDecision.Proposal.Metadata, md); err != nil { + c.Logger.Panicf("Controller was unable to unmarshal the proposal metadata returned by the Synchronizer") } - return 0, 0, 0 - } - md := &protos.ViewMetadata{} - if err := proto.Unmarshal(decision.Proposal.Metadata, md); err != nil { - c.Logger.Panicf("Controller was unable to unmarshal the proposal metadata returned by the Synchronizer") + latestDecisionSeq = md.LatestSequence + latestDecisionViewNum = md.ViewId + latestDecisionDecisions = md.DecisionsInView + latestDecisionMetadata = md } - latestSequence := c.latestSeq() + controllerSequence := c.latestSeq() + newProposalSequence = controllerSequence + 1 - c.Logger.Debugf("Node %d is setting the checkpoint after sync to view %d and seq %d", c.ID, md.ViewId, md.LatestSequence) - c.Checkpoint.Set(decision.Proposal, decision.Signatures) - c.verificationSequence = uint64(decision.Proposal.VerificationSequence) + controllerViewNum := c.currViewNumber + newViewNum = controllerViewNum - if md.ViewId < c.currViewNumber { - c.Logger.Infof("Synchronizer returned with view number %d but the controller is at view number %d", md.ViewId, c.currViewNumber) - return 0, 0, 0 + if latestDecisionSeq > controllerSequence { + c.Logger.Infof("Synchronizer returned with sequence %d while the controller is at sequence %d", latestDecisionSeq, controllerSequence) + c.Logger.Debugf("Node %d is setting the checkpoint after sync returned with view %d and seq %d", c.ID, latestDecisionViewNum, latestDecisionSeq) + c.Checkpoint.Set(latestDecision.Proposal, latestDecision.Signatures) + c.verificationSequence.Store(uint64(latestDecision.Proposal.VerificationSequence)) + newProposalSequence = latestDecisionSeq + 1 + newDecisionsInView = latestDecisionDecisions + 1 } - c.Logger.Infof("Replicated decisions from view %d and seq %d up to view %d and sequence %d with verification sequence %d", - c.currViewNumber, latestSequence, md.ViewId, md.LatestSequence, decision.Proposal.VerificationSequence) - - c.maybePruneInFlight(md) - - view := md.ViewId - newView := false + if latestDecisionViewNum > controllerViewNum { + c.Logger.Infof("Synchronizer returned with view number %d while the controller is at view number %d", latestDecisionViewNum, controllerViewNum) + newViewNum = latestDecisionViewNum + } response := c.fetchState() - if response != nil { - if response.View > md.ViewId && response.Seq == md.LatestSequence+1 { + if response == nil { + c.Logger.Infof("Fetching state failed") + if latestDecisionMetadata == nil || latestDecisionViewNum < controllerViewNum { + // And the synchronizer did not return a new view + return 0, 0, 0 + } + } else { + if response.View <= controllerViewNum && latestDecisionViewNum < controllerViewNum { + return 0, 0, 0 // no new view to report + } + if response.View > newViewNum && response.Seq == latestDecisionSeq+1 { c.Logger.Infof("Node %d collected state with view %d and sequence %d", c.ID, response.View, response.Seq) - view = response.View newViewToSave := &protos.SavedMessage{ Content: &protos.SavedMessage_NewView{ NewView: &protos.ViewMetadata{ - ViewId: view, - LatestSequence: md.LatestSequence, + ViewId: response.View, + LatestSequence: latestDecisionSeq, DecisionsInView: 0, }, }, @@ -664,16 +662,21 @@ func (c *Controller) sync() (viewNum uint64, seq uint64, decisions uint64) { if err := c.State.Save(newViewToSave); err != nil { c.Logger.Panicf("Failed to save message to state, error: %v", err) } - newView = true + newViewNum = response.View + newDecisionsInView = 0 } } - c.Logger.Debugf("Node %d is informing the view changer after sync of view %d and seq %d", c.ID, md.ViewId, md.LatestSequence) - c.ViewChanger.InformNewView(view) - if md.LatestSequence == 0 || newView { - return view, md.LatestSequence + 1, 0 + if latestDecisionMetadata != nil { + c.maybePruneInFlight(latestDecisionMetadata) + } + + if newViewNum > controllerViewNum { + c.Logger.Debugf("Node %d is informing the view changer of view %d after sync of view %d and seq %d", c.ID, newViewNum, latestDecisionViewNum, latestDecisionSeq) + c.ViewChanger.InformNewView(newViewNum) } - return view, md.LatestSequence + 1, md.DecisionsInView + 1 + + return newViewNum, newProposalSequence, newDecisionsInView } func (c *Controller) maybePruneInFlight(syncResultViewMD *protos.ViewMetadata) { @@ -728,12 +731,12 @@ func (c *Controller) relinquishSyncToken() { // MaybePruneRevokedRequests prunes requests with different verification sequence func (c *Controller) MaybePruneRevokedRequests() { - oldVerSqn := c.verificationSequence + oldVerSqn := c.verificationSequence.Load() newVerSqn := c.Verifier.VerificationSequence() if newVerSqn == oldVerSqn { return } - c.verificationSequence = newVerSqn + c.verificationSequence.Store(newVerSqn) c.Logger.Infof("Verification sequence changed: %d --> %d", oldVerSqn, newVerSqn) c.RequestPool.Prune(func(req []byte) error { @@ -791,7 +794,7 @@ func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64, c.Logger.Debugf("The number of nodes (N) is %d, F is %d, and the quorum size is %d", c.N, F, Q) c.quorum = Q - c.verificationSequence = c.Verifier.VerificationSequence() + c.verificationSequence.Store(c.Verifier.VerificationSequence()) if syncOnStart { startViewNumber, startProposalSequence, startDecisionsInView = c.syncOnStart(startViewNumber, startProposalSequence, startDecisionsInView) @@ -801,9 +804,6 @@ func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64, c.currViewNumber = startViewNumber c.currDecisionsInView = startDecisionsInView c.startView(startProposalSequence) - if iAm, _ := c.iAmTheLeader(); iAm { - c.acquireLeaderToken() - } go func() { defer c.controllerDone.Done() diff --git a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/requestpool.go b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/requestpool.go index 2ab71e84b0d..78870c45cb3 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/requestpool.go +++ b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/requestpool.go @@ -143,8 +143,8 @@ func NewPool(log api.Logger, inspector api.RequestInspector, th RequestTimeoutHa return rp } -// ChangeTimeouts changes the timeout of the pool -func (rp *Pool) ChangeTimeouts(th RequestTimeoutHandler, options PoolOptions) { +// ChangeOptions changes the options of the pool +func (rp *Pool) ChangeOptions(th RequestTimeoutHandler, options PoolOptions) { rp.lock.Lock() defer rp.lock.Unlock() @@ -162,10 +162,18 @@ func (rp *Pool) ChangeTimeouts(th RequestTimeoutHandler, options PoolOptions) { if options.AutoRemoveTimeout == 0 { options.AutoRemoveTimeout = defaultRequestTimeout } + if options.RequestMaxBytes == 0 { + options.RequestMaxBytes = defaultMaxBytes + } + if options.SubmitTimeout == 0 { + options.SubmitTimeout = defaultRequestTimeout + } rp.options.ForwardTimeout = options.ForwardTimeout rp.options.ComplainTimeout = options.ComplainTimeout rp.options.AutoRemoveTimeout = options.AutoRemoveTimeout + rp.options.RequestMaxBytes = options.RequestMaxBytes + rp.options.SubmitTimeout = options.SubmitTimeout rp.timeoutHandler = th @@ -188,7 +196,7 @@ func (rp *Pool) Submit(request []byte) error { if uint64(len(request)) > rp.options.RequestMaxBytes { rp.metrics.CountOfFailAddRequestToPool.With( - rp.metrics.LabelsForWith(api.NameReasonFailAdd, api.ReasonRequestMaxBytes)..., + rp.metrics.LabelsForWith("reason", api.ReasonRequestMaxBytes)..., ).Add(1) return fmt.Errorf( "submitted request (%d) is bigger than request max bytes (%d)", @@ -217,7 +225,7 @@ func (rp *Pool) Submit(request []byte) error { // do not wait for a semaphore with a lock, as it will prevent draining the pool. if err := rp.semaphore.Acquire(ctx, 1); err != nil { rp.metrics.CountOfFailAddRequestToPool.With( - rp.metrics.LabelsForWith(api.NameReasonFailAdd, api.ReasonSemaphoreAcquireFail)..., + rp.metrics.LabelsForWith("reason", api.ReasonSemaphoreAcquireFail)..., ).Add(1) return errors.Wrapf(err, "acquiring semaphore for request: %s", reqInfo) } diff --git a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/util.go b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/util.go index ebe8adf1fed..53ffeaf8dc4 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/util.go +++ b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/util.go @@ -276,7 +276,7 @@ type ProposalMaker struct { } // NewProposer returns a new view -func (pm *ProposalMaker) NewProposer(leader, proposalSequence, viewNum, decisionsInView uint64, quorumSize int) Proposer { +func (pm *ProposalMaker) NewProposer(leader, proposalSequence, viewNum, decisionsInView uint64, quorumSize int) (proposer Proposer, phase Phase) { view := &View{ RetrieveCheckpoint: pm.Checkpoint.Get, DecisionsPerLeader: pm.DecisionsPerLeader, @@ -330,7 +330,7 @@ func (pm *ProposalMaker) NewProposer(leader, proposalSequence, viewNum, decision view.MetricsView.DecisionsInView.Set(float64(view.DecisionsInView)) view.MetricsView.Phase.Set(float64(view.Phase)) - return view + return view, view.Phase } // ViewSequence indicates if a view is currently active and its current proposal sequence @@ -486,7 +486,7 @@ func (bl blacklist) computeUpdate() []uint64 { for _, node := range bl.nodes { inBlacklist := newBlacklistMap[node] bl.metricsBlacklist.NodesInBlackList.With( - bl.metricsBlacklist.LabelsForWith(api.NameBlackListNodeID, strconv.FormatUint(node, 10))..., + bl.metricsBlacklist.LabelsForWith("blackid", strconv.FormatUint(node, 10))..., ).Set(btoi(inBlacklist)) } bl.metricsBlacklist.CountBlackList.Set(float64(len(newBlacklist))) diff --git a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/view.go b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/view.go index 12ec2d30b89..f543024cf5c 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/view.go +++ b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/view.go @@ -30,6 +30,21 @@ const ( ABORT ) +func (p Phase) String() string { + switch p { + case COMMITTED: + return "COMMITTED" + case PROPOSED: + return "PROPOSED" + case PREPARED: + return "PREPARED" + case ABORT: + return "ABORT" + default: + return "Invalid Phase" + } +} + // State can save and restore the state // //go:generate mockery -dir . -name State -case underscore -output ./mocks/ @@ -885,6 +900,8 @@ func (v *View) GetMetadata() []byte { DecisionsInView: v.DecisionsInView, } + v.Logger.Debugf("GetMetadata with view %d, seq %d, dec %d", metadata.ViewId, metadata.LatestSequence, metadata.DecisionsInView) + var ( prevSigs []*protos.Signature prevProp *protos.Proposal diff --git a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/viewchanger.go b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/viewchanger.go index 961722606b6..0d5353df097 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/internal/bft/viewchanger.go +++ b/vendor/github.com/SmartBFT-Go/consensus/internal/bft/viewchanger.go @@ -415,6 +415,7 @@ func (v *ViewChanger) processViewChangeMsg(restore bool) { v.Logger.Panicf("Failed to save message to state, error: %v", err) } } + v.Controller.AbortView(v.currView) // before preparing the view data message abort the current view v.currView = v.nextView v.MetricsViewChange.CurrentView.Set(float64(v.currView)) v.viewChangeMsgs.clear(v.N) @@ -1320,7 +1321,13 @@ func (v *ViewChanger) Decide(proposal types.Proposal, signatures []types.Signatu } } v.Pruner.MaybePruneRevokedRequests() - v.inFlightDecideChan <- struct{}{} + + select { + case v.inFlightDecideChan <- struct{}{}: + return + case <-v.stopChan: + return + } } // Complain panics when a view change is requested diff --git a/vendor/github.com/SmartBFT-Go/consensus/pkg/api/metrics.go b/vendor/github.com/SmartBFT-Go/consensus/pkg/api/metrics.go index 2c25f61b172..7b7585b0487 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/pkg/api/metrics.go +++ b/vendor/github.com/SmartBFT-Go/consensus/pkg/api/metrics.go @@ -1,15 +1,72 @@ package api -import "strconv" +import ( + "fmt" + "sort" + "strconv" -const ( - NameBlackListNodeID = "blackid" - NameReasonFailAdd = "reason" + "github.com/SmartBFT-Go/consensus/pkg/metrics" +) +const ( ReasonRequestMaxBytes = "MAX_BYTES" ReasonSemaphoreAcquireFail = "SEMAPHORE_ACQUIRE_FAIL" ) +func NewGaugeOpts(old metrics.GaugeOpts, labelNames []string) metrics.GaugeOpts { + return metrics.GaugeOpts{ + Namespace: old.Namespace, + Subsystem: old.Subsystem, + Name: old.Name, + Help: old.Help, + LabelNames: makeLabelNames(labelNames, old.LabelNames...), + LabelHelp: old.LabelHelp, + StatsdFormat: makeStatsdFormat(labelNames, old.StatsdFormat), + } +} + +func NewCounterOpts(old metrics.CounterOpts, labelNames []string) metrics.CounterOpts { + return metrics.CounterOpts{ + Namespace: old.Namespace, + Subsystem: old.Subsystem, + Name: old.Name, + Help: old.Help, + LabelNames: makeLabelNames(labelNames, old.LabelNames...), + LabelHelp: old.LabelHelp, + StatsdFormat: makeStatsdFormat(labelNames, old.StatsdFormat), + } +} + +func NewHistogramOpts(old metrics.HistogramOpts, labelNames []string) metrics.HistogramOpts { + return metrics.HistogramOpts{ + Namespace: old.Namespace, + Subsystem: old.Subsystem, + Name: old.Name, + Help: old.Help, + Buckets: old.Buckets, + LabelNames: makeLabelNames(labelNames, old.LabelNames...), + LabelHelp: old.LabelHelp, + StatsdFormat: makeStatsdFormat(labelNames, old.StatsdFormat), + } +} + +func makeStatsdFormat(labelNames []string, str string) string { + sort.Strings(labelNames) + for _, s := range labelNames { + str += fmt.Sprintf(".%%{%s}", s) + } + + return str +} + +func makeLabelNames(labelNames []string, names ...string) []string { + ln := make([]string, 0, len(names)+len(labelNames)) + ln = append(ln, names...) + sort.Strings(labelNames) + ln = append(ln, labelNames...) + return ln +} + type Metrics struct { MetricsRequestPool *MetricsRequestPool MetricsBlacklist *MetricsBlacklist @@ -18,7 +75,7 @@ type Metrics struct { MetricsViewChange *MetricsViewChange } -func NewMetrics(p Provider, labelNames ...string) *Metrics { +func NewMetrics(p metrics.Provider, labelNames ...string) *Metrics { return &Metrics{ MetricsRequestPool: NewMetricsRequestPool(p, labelNames...), MetricsBlacklist: NewMetricsBlacklist(p, labelNames...), @@ -46,64 +103,64 @@ func (m *Metrics) Initialize(nodes []uint64) { m.MetricsViewChange.Initialize() } -var countOfRequestPoolOpts = GaugeOpts{ +var countOfRequestPoolOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "pool_count_of_elements", Help: "Number of elements in the consensus request pool.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var countOfFailAddRequestToPoolOpts = CounterOpts{ +var countOfFailAddRequestToPoolOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "pool_count_of_fail_add_request", Help: "Number of requests pool insertion failure.", - LabelNames: []string{NameReasonFailAdd}, - StatsdFormat: "%{#fqname}.%{" + NameReasonFailAdd + "}", + LabelNames: []string{"reason"}, + StatsdFormat: "%{#fqname}.%{reason}", } // ForwardTimeout -var countOfLeaderForwardRequestOpts = CounterOpts{ +var countOfLeaderForwardRequestOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "pool_count_leader_forward_request", Help: "Number of requests forwarded to the leader.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var countTimeoutTwoStepOpts = CounterOpts{ +var countTimeoutTwoStepOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "pool_count_timeout_two_step", Help: "Number of times requests reached second timeout.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var countOfDeleteRequestPoolOpts = CounterOpts{ +var countOfDeleteRequestPoolOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "pool_count_of_delete_request", Help: "Number of elements removed from the request pool.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var countOfRequestPoolAllOpts = CounterOpts{ +var countOfRequestPoolAllOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "pool_count_of_elements_all", Help: "Total amount of elements in the request pool.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var latencyOfRequestPoolOpts = HistogramOpts{ +var latencyOfRequestPoolOpts = metrics.HistogramOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "pool_latency_of_elements", Help: "The average request processing time, time request resides in the pool.", Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10}, @@ -113,19 +170,19 @@ var latencyOfRequestPoolOpts = HistogramOpts{ // MetricsRequestPool encapsulates request pool metrics type MetricsRequestPool struct { - CountOfRequestPool Gauge - CountOfFailAddRequestToPool Counter - CountOfLeaderForwardRequest Counter - CountTimeoutTwoStep Counter - CountOfDeleteRequestPool Counter - CountOfRequestPoolAll Counter - LatencyOfRequestPool Histogram + CountOfRequestPool metrics.Gauge + CountOfFailAddRequestToPool metrics.Counter + CountOfLeaderForwardRequest metrics.Counter + CountTimeoutTwoStep metrics.Counter + CountOfDeleteRequestPool metrics.Counter + CountOfRequestPoolAll metrics.Counter + LatencyOfRequestPool metrics.Histogram labels []string } // NewMetricsRequestPool create new request pool metrics -func NewMetricsRequestPool(p Provider, labelNames ...string) *MetricsRequestPool { +func NewMetricsRequestPool(p metrics.Provider, labelNames ...string) *MetricsRequestPool { countOfRequestPoolOptsTmp := NewGaugeOpts(countOfRequestPoolOpts, labelNames) countOfFailAddRequestToPoolOptsTmp := NewCounterOpts(countOfFailAddRequestToPoolOpts, labelNames) countOfLeaderForwardRequestOptsTmp := NewCounterOpts(countOfLeaderForwardRequestOpts, labelNames) @@ -160,10 +217,10 @@ func (m *MetricsRequestPool) With(labelValues ...string) *MetricsRequestPool { func (m *MetricsRequestPool) Initialize() { m.CountOfRequestPool.Add(0) m.CountOfFailAddRequestToPool.With( - m.LabelsForWith(NameReasonFailAdd, ReasonRequestMaxBytes)..., + m.LabelsForWith("reason", ReasonRequestMaxBytes)..., ).Add(0) m.CountOfFailAddRequestToPool.With( - m.LabelsForWith(NameReasonFailAdd, ReasonSemaphoreAcquireFail)..., + m.LabelsForWith("reason", ReasonSemaphoreAcquireFail)..., ).Add(0) m.CountOfLeaderForwardRequest.Add(0) m.CountTimeoutTwoStep.Add(0) @@ -179,34 +236,34 @@ func (m *MetricsRequestPool) LabelsForWith(labelValues ...string) []string { return result } -var countBlackListOpts = GaugeOpts{ +var countBlackListOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "blacklist_count", Help: "Count of nodes in blacklist on this channel.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var nodesInBlackListOpts = GaugeOpts{ +var nodesInBlackListOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "node_id_in_blacklist", Help: "Node ID in blacklist on this channel.", - LabelNames: []string{NameBlackListNodeID}, - StatsdFormat: "%{#fqname}.%{" + NameBlackListNodeID + "}", + LabelNames: []string{"blackid"}, + StatsdFormat: "%{#fqname}.%{blackid}", } // MetricsBlacklist encapsulates blacklist metrics type MetricsBlacklist struct { - CountBlackList Gauge - NodesInBlackList Gauge + CountBlackList metrics.Gauge + NodesInBlackList metrics.Gauge labels []string } // NewMetricsBlacklist create new blacklist metrics -func NewMetricsBlacklist(p Provider, labelNames ...string) *MetricsBlacklist { +func NewMetricsBlacklist(p metrics.Provider, labelNames ...string) *MetricsBlacklist { countBlackListOptsTmp := NewGaugeOpts(countBlackListOpts, labelNames) nodesInBlackListOptsTmp := NewGaugeOpts(nodesInBlackListOpts, labelNames) return &MetricsBlacklist{ @@ -227,7 +284,7 @@ func (m *MetricsBlacklist) Initialize(nodes []uint64) { m.CountBlackList.Add(0) for _, n := range nodes { m.NodesInBlackList.With( - m.LabelsForWith(NameBlackListNodeID, strconv.FormatUint(n, 10))..., + m.LabelsForWith("blackid", strconv.FormatUint(n, 10))..., ).Set(0) } } @@ -239,18 +296,18 @@ func (m *MetricsBlacklist) LabelsForWith(labelValues ...string) []string { return result } -var consensusReconfigOpts = CounterOpts{ +var consensusReconfigOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "consensus_reconfig", Help: "Number of reconfiguration requests.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var latencySyncOpts = HistogramOpts{ +var latencySyncOpts = metrics.HistogramOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "consensus_latency_sync", Help: "An average time it takes to sync node.", Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10}, @@ -260,12 +317,12 @@ var latencySyncOpts = HistogramOpts{ // MetricsConsensus encapsulates consensus metrics type MetricsConsensus struct { - CountConsensusReconfig Counter - LatencySync Histogram + CountConsensusReconfig metrics.Counter + LatencySync metrics.Histogram } // NewMetricsConsensus create new consensus metrics -func NewMetricsConsensus(p Provider, labelNames ...string) *MetricsConsensus { +func NewMetricsConsensus(p metrics.Provider, labelNames ...string) *MetricsConsensus { consensusReconfigOptsTmp := NewCounterOpts(consensusReconfigOpts, labelNames) latencySyncOptsTmp := NewHistogramOpts(latencySyncOpts, labelNames) return &MetricsConsensus{ @@ -286,90 +343,90 @@ func (m *MetricsConsensus) Initialize() { m.LatencySync.Observe(0) } -var viewNumberOpts = GaugeOpts{ +var viewNumberOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_number", Help: "The View number value.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var leaderIDOpts = GaugeOpts{ +var leaderIDOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_leader_id", Help: "The leader id.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var proposalSequenceOpts = GaugeOpts{ +var proposalSequenceOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_proposal_sequence", Help: "The sequence number within current view.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var decisionsInViewOpts = GaugeOpts{ +var decisionsInViewOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_decisions", Help: "The number of decisions in the current view.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var phaseOpts = GaugeOpts{ +var phaseOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_phase", Help: "Current consensus phase.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var countTxsInBatchOpts = GaugeOpts{ +var countTxsInBatchOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_count_txs_in_batch", Help: "The number of transactions per batch.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var countBatchAllOpts = CounterOpts{ +var countBatchAllOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_count_batch_all", Help: "Amount of batched processed.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var countTxsAllOpts = CounterOpts{ +var countTxsAllOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_count_txs_all", Help: "Total amount of transactions.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var sizeOfBatchOpts = CounterOpts{ +var sizeOfBatchOpts = metrics.CounterOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_size_batch", Help: "An average batch size.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var latencyBatchProcessingOpts = HistogramOpts{ +var latencyBatchProcessingOpts = metrics.HistogramOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_latency_batch_processing", Help: "Amount of time it take to process batch.", Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10}, @@ -377,9 +434,9 @@ var latencyBatchProcessingOpts = HistogramOpts{ StatsdFormat: "%{#fqname}", } -var latencyBatchSaveOpts = HistogramOpts{ +var latencyBatchSaveOpts = metrics.HistogramOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "view_latency_batch_save", Help: "An average time it takes to persist batch.", Buckets: []float64{0.005, 0.01, 0.015, 0.05, 0.1, 1, 10}, @@ -389,21 +446,21 @@ var latencyBatchSaveOpts = HistogramOpts{ // MetricsView encapsulates view metrics type MetricsView struct { - ViewNumber Gauge - LeaderID Gauge - ProposalSequence Gauge - DecisionsInView Gauge - Phase Gauge - CountTxsInBatch Gauge - CountBatchAll Counter - CountTxsAll Counter - SizeOfBatch Counter - LatencyBatchProcessing Histogram - LatencyBatchSave Histogram + ViewNumber metrics.Gauge + LeaderID metrics.Gauge + ProposalSequence metrics.Gauge + DecisionsInView metrics.Gauge + Phase metrics.Gauge + CountTxsInBatch metrics.Gauge + CountBatchAll metrics.Counter + CountTxsAll metrics.Counter + SizeOfBatch metrics.Counter + LatencyBatchProcessing metrics.Histogram + LatencyBatchSave metrics.Histogram } // NewMetricsView create new view metrics -func NewMetricsView(p Provider, labelNames ...string) *MetricsView { +func NewMetricsView(p metrics.Provider, labelNames ...string) *MetricsView { viewNumberOptsTmp := NewGaugeOpts(viewNumberOpts, labelNames) leaderIDOptsTmp := NewGaugeOpts(leaderIDOpts, labelNames) proposalSequenceOptsTmp := NewGaugeOpts(proposalSequenceOpts, labelNames) @@ -460,27 +517,27 @@ func (m *MetricsView) Initialize() { m.LatencyBatchSave.Observe(0) } -var currentViewOpts = GaugeOpts{ +var currentViewOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "viewchange_current_view", Help: "current view of viewchange on this channel.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var nextViewOpts = GaugeOpts{ +var nextViewOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "viewchange_next_view", Help: "next view of viewchange on this channel.", LabelNames: []string{}, StatsdFormat: "%{#fqname}", } -var realViewOpts = GaugeOpts{ +var realViewOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "viewchange_real_view", Help: "real view of viewchange on this channel.", LabelNames: []string{}, @@ -489,13 +546,13 @@ var realViewOpts = GaugeOpts{ // MetricsViewChange encapsulates view change metrics type MetricsViewChange struct { - CurrentView Gauge - NextView Gauge - RealView Gauge + CurrentView metrics.Gauge + NextView metrics.Gauge + RealView metrics.Gauge } // NewMetricsViewChange create new view change metrics -func NewMetricsViewChange(p Provider, labelNames ...string) *MetricsViewChange { +func NewMetricsViewChange(p metrics.Provider, labelNames ...string) *MetricsViewChange { currentViewOptsTmp := NewGaugeOpts(currentViewOpts, labelNames) nextViewOptsTmp := NewGaugeOpts(nextViewOpts, labelNames) realViewOptsTmp := NewGaugeOpts(realViewOpts, labelNames) diff --git a/vendor/github.com/SmartBFT-Go/consensus/pkg/consensus/consensus.go b/vendor/github.com/SmartBFT-Go/consensus/pkg/consensus/consensus.go index 15e4cff4124..aac5346e6be 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/pkg/consensus/consensus.go +++ b/vendor/github.com/SmartBFT-Go/consensus/pkg/consensus/consensus.go @@ -216,20 +216,9 @@ func (c *Consensus) reconfig(reconfig types.Reconfig) { c.Logger.Panicf("Configuration is invalid, error: %v", err) } - tmp := c.nodes - var newNodes []uint64 + old := c.nodes c.setNodes(reconfig.CurrentNodes) - -OuterLoop: - for _, i := range c.nodes { - for _, j := range tmp { - if i == j { - continue OuterLoop - } - } - newNodes = append(newNodes, i) - } - c.Metrics.MetricsBlacklist.Initialize(newNodes) + c.initMetricsBlacklistReconfigure(old) c.createComponents() opts := algorithm.PoolOptions{ @@ -239,7 +228,7 @@ OuterLoop: RequestMaxBytes: c.Config.RequestMaxBytes, SubmitTimeout: c.Config.RequestPoolSubmitTimeout, } - c.Pool.ChangeTimeouts(c.controller, opts) // TODO handle reconfiguration of queue size in the pool + c.Pool.ChangeOptions(c.controller, opts) // TODO handle reconfiguration of queue size in the pool c.continueCreateComponents() proposal, _ := c.checkpoint.Get() @@ -262,6 +251,21 @@ OuterLoop: c.Logger.Debugf("Reconfig is done") } +func (c *Consensus) initMetricsBlacklistReconfigure(old []uint64) { + var newNodes []uint64 + +OuterLoop: + for _, i := range c.nodes { + for _, j := range old { + if i == j { + continue OuterLoop + } + } + newNodes = append(newNodes, i) + } + c.Metrics.MetricsBlacklist.Initialize(newNodes) +} + func (c *Consensus) close() { c.stopOnce.Do( func() { diff --git a/vendor/github.com/SmartBFT-Go/consensus/pkg/metrics/disabled/provider.go b/vendor/github.com/SmartBFT-Go/consensus/pkg/metrics/disabled/provider.go index e6babb97f65..457db1f1316 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/pkg/metrics/disabled/provider.go +++ b/vendor/github.com/SmartBFT-Go/consensus/pkg/metrics/disabled/provider.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package disabled import ( - bft "github.com/SmartBFT-Go/consensus/pkg/api" + bft "github.com/SmartBFT-Go/consensus/pkg/metrics" ) type Provider struct{} diff --git a/vendor/github.com/SmartBFT-Go/consensus/pkg/api/metrics_provider.go b/vendor/github.com/SmartBFT-Go/consensus/pkg/metrics/provider.go similarity index 79% rename from vendor/github.com/SmartBFT-Go/consensus/pkg/api/metrics_provider.go rename to vendor/github.com/SmartBFT-Go/consensus/pkg/metrics/provider.go index ca421955159..21cfe46a1f4 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/pkg/api/metrics_provider.go +++ b/vendor/github.com/SmartBFT-Go/consensus/pkg/metrics/provider.go @@ -4,66 +4,7 @@ Copyright IBM Corp. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 */ -package api - -import ( - "fmt" - "sort" -) - -func NewGaugeOpts(old GaugeOpts, labelNames []string) GaugeOpts { - return GaugeOpts{ - Namespace: old.Namespace, - Subsystem: old.Subsystem, - Name: old.Name, - Help: old.Help, - LabelNames: makeLabelNames(labelNames, old.LabelNames...), - LabelHelp: old.LabelHelp, - StatsdFormat: makeStatsdFormat(labelNames, old.StatsdFormat), - } -} - -func NewCounterOpts(old CounterOpts, labelNames []string) CounterOpts { - return CounterOpts{ - Namespace: old.Namespace, - Subsystem: old.Subsystem, - Name: old.Name, - Help: old.Help, - LabelNames: makeLabelNames(labelNames, old.LabelNames...), - LabelHelp: old.LabelHelp, - StatsdFormat: makeStatsdFormat(labelNames, old.StatsdFormat), - } -} - -func NewHistogramOpts(old HistogramOpts, labelNames []string) HistogramOpts { - return HistogramOpts{ - Namespace: old.Namespace, - Subsystem: old.Subsystem, - Name: old.Name, - Help: old.Help, - Buckets: old.Buckets, - LabelNames: makeLabelNames(labelNames, old.LabelNames...), - LabelHelp: old.LabelHelp, - StatsdFormat: makeStatsdFormat(labelNames, old.StatsdFormat), - } -} - -func makeStatsdFormat(labelNames []string, str string) string { - sort.Strings(labelNames) - for _, s := range labelNames { - str += fmt.Sprintf(".%%{%s}", s) - } - - return str -} - -func makeLabelNames(labelNames []string, names ...string) []string { - ln := make([]string, 0, len(names)+len(labelNames)) - ln = append(ln, names...) - sort.Strings(labelNames) - ln = append(ln, labelNames...) - return ln -} +package metrics // A Provider is an abstraction for a metrics provider. It is a factory for // Counter, Gauge, and Histogram meters. diff --git a/vendor/github.com/SmartBFT-Go/consensus/pkg/types/config.go b/vendor/github.com/SmartBFT-Go/consensus/pkg/types/config.go index c97f7c36b93..5438653b4bd 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/pkg/types/config.go +++ b/vendor/github.com/SmartBFT-Go/consensus/pkg/types/config.go @@ -114,50 +114,49 @@ var DefaultConfig = Configuration{ } func (c Configuration) Validate() error { - if !(c.SelfID > 0) { + if c.SelfID == 0 { return errors.Errorf("SelfID is lower than or equal to zero") } - - if !(c.RequestBatchMaxCount > 0) { + if c.RequestBatchMaxCount == 0 { return errors.Errorf("RequestBatchMaxCount should be greater than zero") } - if !(c.RequestBatchMaxBytes > 0) { + if c.RequestBatchMaxBytes == 0 { return errors.Errorf("RequestBatchMaxBytes should be greater than zero") } - if !(c.RequestBatchMaxInterval > 0) { + if c.RequestBatchMaxInterval <= 0 { return errors.Errorf("RequestBatchMaxInterval should be greater than zero") } - if !(c.IncomingMessageBufferSize > 0) { + if c.IncomingMessageBufferSize == 0 { return errors.Errorf("IncomingMessageBufferSize should be greater than zero") } - if !(c.RequestPoolSize > 0) { + if c.RequestPoolSize == 0 { return errors.Errorf("RequestPoolSize should be greater than zero") } - if !(c.RequestForwardTimeout > 0) { + if c.RequestForwardTimeout <= 0 { return errors.Errorf("RequestForwardTimeout should be greater than zero") } - if !(c.RequestComplainTimeout > 0) { + if c.RequestComplainTimeout <= 0 { return errors.Errorf("RequestComplainTimeout should be greater than zero") } - if !(c.RequestAutoRemoveTimeout > 0) { + if c.RequestAutoRemoveTimeout <= 0 { return errors.Errorf("RequestAutoRemoveTimeout should be greater than zero") } - if !(c.ViewChangeResendInterval > 0) { + if c.ViewChangeResendInterval <= 0 { return errors.Errorf("ViewChangeResendInterval should be greater than zero") } - if !(c.ViewChangeTimeout > 0) { + if c.ViewChangeTimeout <= 0 { return errors.Errorf("ViewChangeTimeout should be greater than zero") } - if !(c.LeaderHeartbeatTimeout > 0) { + if c.LeaderHeartbeatTimeout <= 0 { return errors.Errorf("LeaderHeartbeatTimeout should be greater than zero") } - if !(c.LeaderHeartbeatCount > 0) { + if c.LeaderHeartbeatCount == 0 { return errors.Errorf("LeaderHeartbeatCount should be greater than zero") } - if !(c.NumOfTicksBehindBeforeSyncing > 0) { + if c.NumOfTicksBehindBeforeSyncing == 0 { return errors.Errorf("NumOfTicksBehindBeforeSyncing should be greater than zero") } - if !(c.CollectTimeout > 0) { + if c.CollectTimeout <= 0 { return errors.Errorf("CollectTimeout should be greater than zero") } if c.RequestBatchMaxCount > c.RequestBatchMaxBytes { @@ -176,11 +175,11 @@ func (c Configuration) Validate() error { return errors.Errorf("DecisionsPerLeader should be greater than zero when leader rotation is active") } - if !(c.RequestMaxBytes > 0) { + if c.RequestMaxBytes == 0 { return errors.Errorf("RequestMaxBytes should be greater than zero") } - if !(c.RequestPoolSubmitTimeout > 0) { + if c.RequestPoolSubmitTimeout <= 0 { return errors.Errorf("RequestPoolSubmitTimeout should be greater than zero") } diff --git a/vendor/github.com/SmartBFT-Go/consensus/pkg/wal/metrics.go b/vendor/github.com/SmartBFT-Go/consensus/pkg/wal/metrics.go index 82c4c328dfc..e6d8ca75c4f 100644 --- a/vendor/github.com/SmartBFT-Go/consensus/pkg/wal/metrics.go +++ b/vendor/github.com/SmartBFT-Go/consensus/pkg/wal/metrics.go @@ -1,10 +1,13 @@ package wal -import metrics "github.com/SmartBFT-Go/consensus/pkg/api" +import ( + "github.com/SmartBFT-Go/consensus/pkg/api" + "github.com/SmartBFT-Go/consensus/pkg/metrics" +) var countOfFilesOpts = metrics.GaugeOpts{ Namespace: "consensus", - Subsystem: "bft", + Subsystem: "smartbft", Name: "wal_count_of_files", Help: "Count of wal-files.", LabelNames: []string{}, @@ -18,7 +21,7 @@ type Metrics struct { // NewMetrics create new wal metrics func NewMetrics(p metrics.Provider, labelNames ...string) *Metrics { - countOfFilesOptsTmp := metrics.NewGaugeOpts(countOfFilesOpts, labelNames) + countOfFilesOptsTmp := api.NewGaugeOpts(countOfFilesOpts, labelNames) return &Metrics{ CountOfFiles: p.NewGauge(countOfFilesOptsTmp), } diff --git a/vendor/modules.txt b/vendor/modules.txt index ea8b9c828c0..a0a09584311 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -54,11 +54,12 @@ github.com/Microsoft/go-winio/pkg/guid ## explicit github.com/Shopify/sarama github.com/Shopify/sarama/mocks -# github.com/SmartBFT-Go/consensus v0.0.0-20230508115939-c2d803ba5515 => github.com/scientificideas/consensus v0.0.0-20230802072420-e9c3857fd5d6 +# github.com/SmartBFT-Go/consensus v0.0.0-20240215044737-fd3c35e3c876 ## explicit; go 1.20 github.com/SmartBFT-Go/consensus/internal/bft github.com/SmartBFT-Go/consensus/pkg/api github.com/SmartBFT-Go/consensus/pkg/consensus +github.com/SmartBFT-Go/consensus/pkg/metrics github.com/SmartBFT-Go/consensus/pkg/metrics/disabled github.com/SmartBFT-Go/consensus/pkg/types github.com/SmartBFT-Go/consensus/pkg/wal @@ -688,6 +689,5 @@ gopkg.in/yaml.v3 ## explicit; go 1.17 rsc.io/tmplfunc rsc.io/tmplfunc/internal/parse -# github.com/SmartBFT-Go/consensus => github.com/scientificideas/consensus v0.0.0-20230802072420-e9c3857fd5d6 # github.com/hyperledger/fabric-config => github.com/scientificideas/fabric-config v0.1.1-0.20220421194734-201061bc5f26 # github.com/hyperledger/fabric-protos-go => github.com/scientificideas/fabric-protos-go v0.0.0-20221126151030-78861c4f6e73