From 8b51ee6017266864e1b3c5c7bd906e283f6c84e0 Mon Sep 17 00:00:00 2001 From: Dan Tudor Date: Mon, 9 Nov 2020 10:15:20 +0000 Subject: [PATCH] 2.1.2 * Clear Id * Clean softfork log * Fix consensus rewinder --- internal/service/dao/consensus/consensus.go | 49 +++++++++----------- internal/service/dao/consensus/indexer.go | 1 + internal/service/dao/consensus/repository.go | 11 +++++ internal/service/dao/consensus/rewinder.go | 10 ++-- internal/service/dao/consensus/service.go | 3 -- internal/service/softfork/rewinder.go | 4 +- 6 files changed, 41 insertions(+), 37 deletions(-) diff --git a/internal/service/dao/consensus/consensus.go b/internal/service/dao/consensus/consensus.go index d3b0d41..3255c73 100644 --- a/internal/service/dao/consensus/consensus.go +++ b/internal/service/dao/consensus/consensus.go @@ -12,34 +12,27 @@ var Parameters consensusParameters type Parameter int var ( - VOTING_CYCLE_LENGTH Parameter = 0 - - CONSULTATION_MIN_SUPPORT Parameter = 1 - CONSULTATION_ANSWER_MIN_SUPPORT Parameter = 2 - - CONSULTATION_MIN_CYCLES Parameter = 3 - CONSULTATION_MAX_VOTING_CYCLES Parameter = 4 - CONSULTATION_MAX_SUPPORT_CYCLES Parameter = 5 - CONSULTATION_REFLECTION_LENGTH Parameter = 6 - CONSULTATION_MIN_FEE Parameter = 7 - - CONSULTATION_ANSWER_MIN_FEE Parameter = 8 - - PROPOSAL_MIN_QUORUM Parameter = 9 - PROPOSAL_MIN_ACCEPT Parameter = 10 - PROPOSAL_MIN_REJECT Parameter = 11 - PROPOSAL_MIN_FEE Parameter = 12 - PROPOSAL_MAX_VOTING_CYCLES Parameter = 13 - - PAYMENT_REQUEST_MIN_QUORUM Parameter = 14 - PAYMENT_REQUEST_MIN_ACCEPT Parameter = 15 - PAYMENT_REQUEST_MIN_REJECT Parameter = 16 - PAYMENT_REQUEST_MIN_FEE Parameter = 17 - PAYMENT_REQUEST_MAX_VOTING_CYCLES Parameter = 18 - - FUND_SPREAD_ACCUMULATION Parameter = 19 - FUND_PERCENT_PER_BLOCK Parameter = 20 - + VOTING_CYCLE_LENGTH Parameter = 0 + CONSULTATION_MIN_SUPPORT Parameter = 1 + CONSULTATION_ANSWER_MIN_SUPPORT Parameter = 2 + CONSULTATION_MIN_CYCLES Parameter = 3 + CONSULTATION_MAX_VOTING_CYCLES Parameter = 4 + CONSULTATION_MAX_SUPPORT_CYCLES Parameter = 5 + CONSULTATION_REFLECTION_LENGTH Parameter = 6 + CONSULTATION_MIN_FEE Parameter = 7 + CONSULTATION_ANSWER_MIN_FEE Parameter = 8 + PROPOSAL_MIN_QUORUM Parameter = 9 + PROPOSAL_MIN_ACCEPT Parameter = 10 + PROPOSAL_MIN_REJECT Parameter = 11 + PROPOSAL_MIN_FEE Parameter = 12 + PROPOSAL_MAX_VOTING_CYCLES Parameter = 13 + PAYMENT_REQUEST_MIN_QUORUM Parameter = 14 + PAYMENT_REQUEST_MIN_ACCEPT Parameter = 15 + PAYMENT_REQUEST_MIN_REJECT Parameter = 16 + PAYMENT_REQUEST_MIN_FEE Parameter = 17 + PAYMENT_REQUEST_MAX_VOTING_CYCLES Parameter = 18 + FUND_SPREAD_ACCUMULATION Parameter = 19 + FUND_PERCENT_PER_BLOCK Parameter = 20 GENERATION_PER_BLOCK Parameter = 21 NAVNS_FEE Parameter = 22 CONSENSUS_PARAMS_DAO_VOTE_LIGHT_MIN_FEE Parameter = 23 diff --git a/internal/service/dao/consensus/indexer.go b/internal/service/dao/consensus/indexer.go index b4b1f13..c4cd1bc 100644 --- a/internal/service/dao/consensus/indexer.go +++ b/internal/service/dao/consensus/indexer.go @@ -32,6 +32,7 @@ func (i *Indexer) Index() error { for _, initialParameter := range initialParameters { for _, consensusParameter := range consensusParameters { if initialParameter.Uid == consensusParameter.Uid { + initialParameter.SetId(consensusParameter.Id()) i.elastic.AddUpdateRequest(elastic_cache.ConsensusIndex.Get(), initialParameter) c = append(c, consensusParameter) } diff --git a/internal/service/dao/consensus/repository.go b/internal/service/dao/consensus/repository.go index 4462072..bd56b92 100644 --- a/internal/service/dao/consensus/repository.go +++ b/internal/service/dao/consensus/repository.go @@ -6,6 +6,7 @@ import ( "github.com/NavExplorer/navexplorer-indexer-go/v2/internal/elastic_cache" "github.com/NavExplorer/navexplorer-indexer-go/v2/pkg/explorer" "github.com/olivere/elastic/v7" + log "github.com/sirupsen/logrus" ) type Repository struct { @@ -41,3 +42,13 @@ func (r *Repository) GetConsensusParameters() ([]*explorer.ConsensusParameter, e return consensusParameters, nil } + +func (r *Repository) DeleteAll() error { + log.Info("Deleting all consensus records") + _, err := elastic.NewDeleteByQueryService(r.Client). + Index(elastic_cache.ConsensusIndex.Get()). + Query(elastic.NewMatchAllQuery()). + Do(context.Background()) + + return err +} diff --git a/internal/service/dao/consensus/rewinder.go b/internal/service/dao/consensus/rewinder.go index 39f42f0..8e96d50 100644 --- a/internal/service/dao/consensus/rewinder.go +++ b/internal/service/dao/consensus/rewinder.go @@ -40,15 +40,19 @@ func (r *Rewinder) Rewind(consultations []*explorer.Consultation) error { } } + err = r.repo.DeleteAll() + if err != nil { + log.WithError(err).Fatal("Failed to clear old parameters") + } for idx := range parameters { - _, err := r.elastic.Client.Index(). + result, err := r.elastic.Client.Index(). Index(elastic_cache.ConsensusIndex.Get()). - Id(parameters[idx].Id()). BodyJson(parameters[idx]). Do(context.Background()) if err != nil { - log.WithError(err).Fatal("Failed to get consensus parameters from repo") + log.WithError(err).Fatal("Failed to save consensus parameters from repo") } + parameters[idx].SetId(result.Id) } Parameters = parameters diff --git a/internal/service/dao/consensus/service.go b/internal/service/dao/consensus/service.go index 9f67747..ebdbbf5 100644 --- a/internal/service/dao/consensus/service.go +++ b/internal/service/dao/consensus/service.go @@ -6,7 +6,6 @@ import ( "github.com/NavExplorer/navexplorer-indexer-go/v2/internal/config" "github.com/NavExplorer/navexplorer-indexer-go/v2/internal/elastic_cache" "github.com/NavExplorer/navexplorer-indexer-go/v2/pkg/explorer" - "github.com/getsentry/raven-go" log "github.com/sirupsen/logrus" ) @@ -23,7 +22,6 @@ func NewService(network string, elastic *elastic_cache.Index, repo *Repository) func (s *Service) InitConsensusParameters() { parameters, err := s.repo.GetConsensusParameters() if err != nil && err != elastic_cache.ErrRecordNotFound { - raven.CaptureError(err, nil) log.WithError(err).Fatal("Failed to load consensus parameters") return } @@ -65,7 +63,6 @@ func (s *Service) InitialState() ([]*explorer.ConsensusParameter, error) { err := json.Unmarshal(byteParams, ¶meters) if err != nil { - raven.CaptureError(err, nil) log.WithError(err).Fatalf("Failed to load consensus parameters from JSON") return nil, err } diff --git a/internal/service/softfork/rewinder.go b/internal/service/softfork/rewinder.go index 7020d1d..556aaff 100644 --- a/internal/service/softfork/rewinder.go +++ b/internal/service/softfork/rewinder.go @@ -2,7 +2,6 @@ package softfork import ( "context" - "encoding/json" "github.com/NavExplorer/navexplorer-indexer-go/v2/internal/config" "github.com/NavExplorer/navexplorer-indexer-go/v2/internal/elastic_cache" "github.com/NavExplorer/navexplorer-indexer-go/v2/internal/service/softfork/signal" @@ -94,8 +93,7 @@ func (r *Rewinder) Rewind(height uint64) error { bulk := r.elastic.Client.Bulk() for _, sf := range SoftForks { - sfJson, _ := json.Marshal(sf) - log.WithField("softfork", string(sfJson)).Info("Updating softFork ", sf.Name) + log.Info("Updating softFork ", sf.Name) bulk.Add(elastic.NewBulkUpdateRequest(). Index(elastic_cache.SoftForkIndex.Get()). Id(sf.Id()).