Skip to content

Commit

Permalink
Improve performance of checker
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Oct 29, 2024
1 parent 8339648 commit d94937b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 69 deletions.
3 changes: 1 addition & 2 deletions pkg/indexer/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
70 changes: 3 additions & 67 deletions pkg/indexer/status_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit d94937b

Please sign in to comment.