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(relayer): add indexer in MySQL #15927

Merged
merged 1 commit 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/relayer/pkg/repo/block.go#L49

func (r *BlockRepository) GetLatestBlockProcessedForEvent(eventName string, chainID *big.Int) (*relayer.Block, error) {
	b := &relayer.Block{}
	if err := r.
		startQuery().
		Raw(`SELECT id, block_height, hash, event_name, chain_id 
		FROM processed_blocks 
		WHERE block_height = 
		( SELECT MAX(block_height) from processed_blocks 
		WHERE chain_id = ? AND event_name = ? )`, chainID.Int64(), eventName).
		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 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5a1f671) 26.82% compared to head (f2ed0f6) 26.82%.
Report is 1 commits behind head on main.

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

*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.

@davidtaikocha davidtaikocha added this pull request to the merge queue Feb 20, 2024
Merged via the queue into main with commit 9704769 Feb 20, 2024
17 checks passed
@davidtaikocha davidtaikocha deleted the xiaodino/add-index-processed_blocks branch February 20, 2024 00:34
xiaodino added a commit that referenced this pull request Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants