diff --git a/cmd/mempool/bakers.go b/cmd/mempool/bakers.go index b226951..4b28a64 100644 --- a/cmd/mempool/bakers.go +++ b/cmd/mempool/bakers.go @@ -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() @@ -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") } } } @@ -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 } @@ -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 -