taiko-mono icon indicating copy to clipboard operation
taiko-mono copied to clipboard

feat(eventindexer): add indexer in MySQL

Open xiaodino opened this issue 1 year ago • 1 comments

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.

xiaodino avatar Feb 19 '24 23:02 xiaodino

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

:exclamation: 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%) :arrow_down:
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.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 20 '24 00:02 codecov[bot]