From a93d85f96a442cd07f8ac3494fe56de503970b05 Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 13 Oct 2023 22:11:41 +0200 Subject: [PATCH 1/2] Set endorsement bakers only for failed --- cmd/mempool/bakers.go | 5 ++++- cmd/mempool/endorsement/check_test.go | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/mempool/bakers.go b/cmd/mempool/bakers.go index b27673c..b226951 100644 --- a/cmd/mempool/bakers.go +++ b/cmd/mempool/bakers.go @@ -19,13 +19,16 @@ import ( func (indexer *Indexer) setEndorsementBakers(ctx context.Context) { defer indexer.wg.Done() - log.Info().Str("network", indexer.network).Msg("Thread for finding endorsement baker started") + indexer.info().Msg("Thread for finding endorsement baker started") for { select { case <-ctx.Done(): return case endorsement := <-indexer.endorsements: + if len(endorsement.Errors) == 0 { + continue + } if err := indexer.findBaker(ctx, indexer.db.DB(), endorsement); err != nil { log.Err(err).Msg("find baker") } diff --git a/cmd/mempool/endorsement/check_test.go b/cmd/mempool/endorsement/check_test.go index bf51e6b..5013f88 100644 --- a/cmd/mempool/endorsement/check_test.go +++ b/cmd/mempool/endorsement/check_test.go @@ -86,8 +86,8 @@ func TestCheckKey(t *testing.T) { } func BenchmarkCheckKey(b *testing.B) { - key := "edpkuEhzJqdFBCWMw6TU3deADRK2fq3GuwWFUphwyH7ero1Na4oGFP" - signature := "siggEYDRoz7tiECt2fc1M75ieJNeVAP6MGHLhpyPpPue8EU3QYjYSJLnDoDPgxkmrjr6R33qGrAxLASwkyQqa1r3tc5mGPwT" + key := DecodePublicKey("edpkuEhzJqdFBCWMw6TU3deADRK2fq3GuwWFUphwyH7ero1Na4oGFP") + signature := DecodeSignature("siggEYDRoz7tiECt2fc1M75ieJNeVAP6MGHLhpyPpPue8EU3QYjYSJLnDoDPgxkmrjr6R33qGrAxLASwkyQqa1r3tc5mGPwT") chainID := "NetXdQprcVkpaWU" endorsement := models.Endorsement{ Level: 751292, @@ -100,7 +100,8 @@ func BenchmarkCheckKey(b *testing.B) { if err != nil { return } + hash := Hash(chainID, data) for i := 0; i < b.N; i++ { - CheckKey(key[:4], DecodePublicKey(key), DecodeSignature(signature), Hash(chainID, data)) + CheckKey("edpk", key, signature, hash) } } From a0412d49373002bf06dd186fae5f61484f1b794f Mon Sep 17 00:00:00 2001 From: Artem Date: Fri, 13 Oct 2023 22:20:04 +0200 Subject: [PATCH 2/2] Refactoring set bakers to endorsements --- cmd/mempool/bakers.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 -