Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eventindexer): add indexer in MySQL #15930

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

xiaodino
Copy link
Contributor

@xiaodino xiaodino commented Feb 19, 2024

In https://github.com/taikoxyz/taiko-mono/blob/main/packages/eventindexer/pkg/repo/processed_block.go#L48

func (r *ProcessedBlockRepository) GetLatestBlockProcessed(chainID *big.Int) (*eventindexer.ProcessedBlock, error) {
	b := &eventindexer.ProcessedBlock{}
	if err := r.
		startQuery().
		Raw(`SELECT id, block_height, hash, chain_id 
		FROM processed_blocks 
		WHERE block_height = 
		( SELECT MAX(block_height) from processed_blocks 
		WHERE chain_id = ? )`, chainID.Int64()).
		FirstOrInit(b).Error; err != nil {
		return nil, err
	}

	return b, nil
}

The database query scans rows in processed_blocks and it's being used heavily based on the database monitoring.

Other query is

SELECT * FROM `processed_blocks` WHERE `block_height` = ? AND `chain_id` = ? ORDER BY `processed_blocks` . `id` LIMIT ?

The PR is to add indexer to optimize the database performance.

Copy link

codecov bot commented Feb 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5a1f671) 26.82% compared to head (93fc9e3) 26.79%.
Report is 4 commits behind head on main.

❗ Current head 93fc9e3 differs from pull request most recent head 18976a7. Consider uploading reports for the commit 18976a7 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15930      +/-   ##
==========================================
- Coverage   26.82%   26.79%   -0.04%     
==========================================
  Files         105      105              
  Lines        6188     6188              
==========================================
- Hits         1660     1658       -2     
- Misses       4348     4350       +2     
  Partials      180      180              
Flag Coverage Δ *Carryforward flag
eventindexer 17.16% <ø> (-0.07%) ⬇️
guardian-prover-health-check 34.81% <ø> (ø) Carriedforward from 5a1f671
relayer 37.88% <ø> (ø) Carriedforward from 5a1f671

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dantaik dantaik added this pull request to the merge queue Feb 20, 2024
Merged via the queue into main with commit b00d0b1 Feb 20, 2024
15 checks passed
@dantaik dantaik deleted the xiaodino/add-index-processed_blocks-eventindexer branch February 20, 2024 01:47
xiaodino added a commit that referenced this pull request Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants