Skip to content

Commit

Permalink
2.1.2
Browse files Browse the repository at this point in the history
* Clear Id

* Clean softfork log

* Fix consensus rewinder
  • Loading branch information
dantudor authored Nov 9, 2020
1 parent e424cb0 commit 8b51ee6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 37 deletions.
49 changes: 21 additions & 28 deletions internal/service/dao/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions internal/service/dao/consensus/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions internal/service/dao/consensus/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
10 changes: 7 additions & 3 deletions internal/service/dao/consensus/rewinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions internal/service/dao/consensus/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
Expand Down Expand Up @@ -65,7 +63,6 @@ func (s *Service) InitialState() ([]*explorer.ConsensusParameter, error) {

err := json.Unmarshal(byteParams, &parameters)
if err != nil {
raven.CaptureError(err, nil)
log.WithError(err).Fatalf("Failed to load consensus parameters from JSON")
return nil, err
}
Expand Down
4 changes: 1 addition & 3 deletions internal/service/softfork/rewinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()).
Expand Down

0 comments on commit 8b51ee6

Please sign in to comment.