Skip to content

Commit

Permalink
Refactoring set bakers to endorsements
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 13, 2023
1 parent a93d85f commit a0412d4
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions cmd/mempool/bakers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"github.com/dipdup-net/go-lib/tzkt/data"
"github.com/dipdup-net/mempool/cmd/mempool/endorsement"
"github.com/dipdup-net/mempool/cmd/mempool/models"
pg "github.com/go-pg/pg/v10"
"github.com/rs/zerolog/log"
)

const unknownBaker = "unknown"

func (indexer *Indexer) setEndorsementBakers(ctx context.Context) {
defer indexer.wg.Done()

Expand All @@ -26,11 +27,16 @@ func (indexer *Indexer) setEndorsementBakers(ctx context.Context) {
case <-ctx.Done():
return
case endorsement := <-indexer.endorsements:
if len(endorsement.Errors) == 0 {
continue
if len(endorsement.Errors) > 0 {
if err := indexer.findBaker(ctx, endorsement); err != nil {
log.Err(err).Msg("find baker")
continue
}
} else {
endorsement.Baker = unknownBaker
}
if err := indexer.findBaker(ctx, indexer.db.DB(), endorsement); err != nil {
log.Err(err).Msg("find baker")
if _, err := indexer.db.DB().Model(endorsement).WherePK().Update("baker", endorsement.Baker); err != nil {
log.Err(err).Msg("set baker to endorsement")
}
}
}
Expand All @@ -56,7 +62,7 @@ func (indexer *Indexer) getEndorsingRights(ctx context.Context, level uint64) ([
}
}

func (indexer *Indexer) findBaker(ctx context.Context, tx pg.DBI, e *models.Endorsement) error {
func (indexer *Indexer) findBaker(ctx context.Context, e *models.Endorsement) error {
if err := indexer.delegates.Update(ctx, e.Level); err != nil {
return err
}
Expand Down Expand Up @@ -96,8 +102,7 @@ func (indexer *Indexer) findBaker(ctx context.Context, tx pg.DBI, e *models.Endo
e.Baker = "unknown"
}

_, err = tx.Model(e).WherePK().Update("baker", e.Baker)
return err
return nil
}

// BySlots -
Expand Down

0 comments on commit a0412d4

Please sign in to comment.