From d94937b65e9e66889cab6ad6ee52a72d17b8a1b1 Mon Sep 17 00:00:00 2001 From: Artem Date: Tue, 29 Oct 2024 17:05:12 +0300 Subject: [PATCH] Improve performance of checker --- pkg/indexer/state.go | 3 +- pkg/indexer/status_checker.go | 70 ++--------------------------------- 2 files changed, 4 insertions(+), 69 deletions(-) diff --git a/pkg/indexer/state.go b/pkg/indexer/state.go index 12ab084..f449c36 100644 --- a/pkg/indexer/state.go +++ b/pkg/indexer/state.go @@ -4,7 +4,6 @@ import ( "sync" "github.com/dipdup-io/starknet-indexer/internal/storage" - models "github.com/dipdup-io/starknet-indexer/internal/storage" ) type state struct { @@ -15,7 +14,7 @@ type state struct { func newState(s *storage.State) *state { if s == nil { - s = new(models.State) + s = new(storage.State) } return &state{ state: s, diff --git a/pkg/indexer/status_checker.go b/pkg/indexer/status_checker.go index d5ceae8..2a6df64 100644 --- a/pkg/indexer/status_checker.go +++ b/pkg/indexer/status_checker.go @@ -144,76 +144,12 @@ func (checker *statusChecker) init(ctx context.Context) error { end = limit != count for i := range blocks { - if err := checker.addIndexedBlockToQueue(ctx, blocks[i]); err != nil { - return err - } - } - } - - return nil -} - -func (checker *statusChecker) addIndexedBlockToQueue(ctx context.Context, block storage.Block) error { - if block.InvokeCount > 0 { - hash, err := checker.invoke.HashByHeight(ctx, block.Height) - if err != nil { - return err - } - checker.acceptedOnL2.Push(acceptedOnL2{ - TransactionHash: hash, - Height: block.Height, - }) - return nil - } - if block.DeployCount > 0 { - hash, err := checker.deploys.HashByHeight(ctx, block.Height) - if err != nil { - return err - } - checker.acceptedOnL2.Push(acceptedOnL2{ - TransactionHash: hash, - Height: block.Height, - }) - return nil - } - if block.DeployAccountCount > 0 { - hash, err := checker.deployAccounts.HashByHeight(ctx, block.Height) - if err != nil { - return err - } - checker.acceptedOnL2.Push(acceptedOnL2{ - TransactionHash: hash, - Height: block.Height, - }) - return nil - } - if block.DeclareCount > 0 { - hash, err := checker.declares.HashByHeight(ctx, block.Height) - if err != nil { - return err - } - checker.acceptedOnL2.Push(acceptedOnL2{ - TransactionHash: hash, - Height: block.Height, - }) - return nil - } - if block.L1HandlerCount > 0 { - hash, err := checker.l1Handlers.HashByHeight(ctx, block.Height) - if err != nil { - return err + checker.acceptedOnL2.Push(acceptedOnL2{ + Height: blocks[i].Height, + }) } - checker.acceptedOnL2.Push(acceptedOnL2{ - TransactionHash: hash, - Height: block.Height, - }) - return nil } - checker.acceptedOnL2.Push(acceptedOnL2{ - Height: block.Height, - }) - return nil }